connection

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const LoginResultAuthenticationFailed = 2 // {"mt":"LoginResult","error":2,"errorText":"Authentication failed"}
View Source
const LoginResultInvalidParameters = 1 // {"mt":"LoginResult","error":1,"errorText":"Invalid parameters"}
View Source
const LoginResultSessionExpired = 5 // {"mt":"LoginResult","error":5,"errorText":"Session expired"}

Variables

View Source
var ReconnectTimeout = time.Second * 2

Functions

func DecryptRc4

func DecryptRc4(key string, data string) (string, error)

func GetLoginDigestDigest

func GetLoginDigestDigest(type_ string, domain string, username string, password string, nonce string, challenge string) string

func GetRandomHexString

func GetRandomHexString(n int) string

func Hex2bin

func Hex2bin(inputstring string) []int

Types

type App

type App struct {
	Name  string `json:"name"`
	Title string `json:"title"`
	Text  string `json:"text"`
	Url   string `json:"url"`
	Info  struct {
		Hidden bool `json:"hidden"`
	} `json:"info"`
}

type Authenticate

type Authenticate struct {
	Mt        string `json:"mt"`
	Type      string `json:"type"`
	Method    string `json:"method"`
	Domain    string `json:"domain"`
	Challenge string `json:"challenge"`
}

type Authorize

type Authorize struct {
	Mt   string `json:"mt"`
	Code int    `json:"code"`
}

type CallbackHandler

type CallbackHandler interface {
	HandleCallbackMessage(*MyAppsConnection, []byte) error // the function that gets called when a messages received that matches the src
}

the interface all src handlers must implement

type CallbackHandlerRegister

type CallbackHandlerRegister struct {
	Handler map[string]CallbackHandlerRegisterItem
}

func NewCallbackHandlerRegister

func NewCallbackHandlerRegister() *CallbackHandlerRegister

func (*CallbackHandlerRegister) Add

func (cbr *CallbackHandlerRegister) Add(src string, numcallbacks int, handler CallbackHandler) error

func (*CallbackHandlerRegister) HandleMessage

func (cbr *CallbackHandlerRegister) HandleMessage(myAppsConnection *MyAppsConnection, src string, message []byte) error

func (*CallbackHandlerRegister) Remove

func (cbr *CallbackHandlerRegister) Remove(src string) error

type CallbackHandlerRegisterItem

type CallbackHandlerRegisterItem struct {
	NumCallbacks      int
	ReceivedCallbacks int
	Handler           CallbackHandler
}

type CheckBuildResult

type CheckBuildResult struct {
	Mt                  string `json:"mt"`
	Version             string `json:"version"`
	Build               string `json:"build"`
	LauncherUpdateBuild string `json:"launcherUpdateBuild"`
	AppStoreUrl         string `json:"appStoreUrl"`
}

type Config

type Config struct {
	Host               string                 `yaml:"host"`               // IP or Hostname to initialy connect to. could be a DNS name of the pbx like 'pbx.company.com' or a IP address with a Port '192.168.33.11:433'
	InsecureSkipVerify bool                   `yaml:"insecureskipverify"` // disabled the check for valid SSL/TLS certificate on the outgoing websocket connection
	Username           string                 `yaml:"username"`           // Username of the pbx
	Password           string                 `yaml:"password"`           // Password to the Username
	SessionFilePath    string                 `yaml:"sessionfilepath"`    // Filename to a local JSON file to store the session. Will be created if it not exists
	SecretKey          []byte                 `yaml:"-"`                  // the key to encrypt local files
	UserAgent          string                 `yaml:"useragent"`          // the User Agnent shown in the list of current sessions in the user profile
	Handler            MessageHandlerRegister // list of message handler on the session
	RedirectHost       string                 // is set, when the user is located not in the master and should open a connection to the secondary pbx
	Debug              bool                   `yaml:"debug"` // set to true to print log messages of the connection
}

the Values for one Account

func (*Config) DeleteSessionKeys

func (myappconfig *Config) DeleteSessionKeys() error

Deletes the JSON file with stored sessions

func (*Config) GetSessionKeys

func (myappconfig *Config) GetSessionKeys() (string, string, error)

loads session keys from file

func (*Config) Printf

func (config *Config) Printf(format string, a ...interface{})

func (*Config) Println

func (config *Config) Println(v ...any)

func (*Config) SaveSessionKeys

func (myappconfig *Config) SaveSessionKeys(usr, pwd string) error

writes session keys to file

func (*Config) StartSession

func (config *Config) StartSession(wg *sync.WaitGroup)

type Login

type Login struct {
	Mt        string `json:"mt"`
	Type      string `json:"type"` // user/session
	UserAgent string `json:"userAgent"`
	Method    string `json:"method,omitempty"`
	Username  string `json:"username,omitempty"`
	Nonce     string `json:"nonce,omitempty"`
	Response  string `json:"response,omitempty"`
}

type LoginInfo

type LoginInfo struct {
	MT string `json:"mt"`
}

type LoginInfoResult

type LoginInfoResult struct {
	Mt        string `json:"mt"`
	Error     int    `json:"error"`
	ErrorText string `json:"errorText"`
	User      struct {
		Digest     bool   `json:"digest"`
		Ntlm       bool   `json:"ntlm"`
		OAuth2     bool   `json:"oauth2"`
		OAuth2Name string `json:"oauth2Name"`
	} `json:"user"`
	Session struct {
		Digest bool `json:"digest"`
	} `json:"session"`
}

type LoginResult

type LoginResult struct {
	Mt   string `json:"mt"`
	Info struct {
		User     MyAppUserInfo          `json:"user"`
		Account  map[string]interface{} `json:"account"`
		Settings map[string]interface{} `json:"settings"`
		Session  struct {
			Usr string
			Pwd string
		} `json:"session"`
		AltHttp string `json:"altHttp"`
		Alt     string `json:"alt"`
	} `json:"info"`
	Digest    string `json:"digest"`
	Error     int    `json:"error"`
	ErrorText string `json:"errorText"`
}

type Message

type Message struct {
	Mt  string `json:"mt"`
	Src string `json:"src"`
}

Message struct

type MessageHandler

type MessageHandler interface {
	GetMt() string // the MessageHandlerRegister matches this string against the incoming message MT
	HandleMessage(*MyAppsConnection, []byte) error
}

the interface all message handlers must implement

type MessageHandlerRegister

type MessageHandlerRegister struct {
	Handler []MessageHandler
}

func (*MessageHandlerRegister) AddHandler

func (hr *MessageHandlerRegister) AddHandler(handler MessageHandler) error

func (*MessageHandlerRegister) HandleMessage

func (hr *MessageHandlerRegister) HandleMessage(myAppsConnection *MyAppsConnection, mt string, message []byte) error

type MyAppUserInfo

type MyAppUserInfo struct {
	Domain string `json:"domain"`
	Sip    string `json:"sip"`
	Guid   string `json:"guid"`
	Dn     string `json:"dn"`
	Num    string `json:"num"`
	Email  string `json:"email"`
	Prefix struct {
		Intl    string `json:"intl"`
		Ntl     string `json:"ntl"`
		Subs    string `json:"subs"`
		Area    string `json:"area"`
		Country string `json:"country"`
	} `json:"prefix"`
}

type MyAppsConnection

type MyAppsConnection struct {
	Context context.Context
	Conn    *websocket.Conn

	Config *Config

	Nonce string

	LoggedIn                bool                     // indicates if a user is logged in
	User                    *MyAppUserInfo           // the info object of the logged in user
	Apps                    map[string]*App          // keeps a list of apps in the account ["devices", "contacts", ...].
	CallbackHandlerRegister *CallbackHandlerRegister // hold a list of callback handler that are registered for a message with src attribute

}

func NewMyAppsConnection

func NewMyAppsConnection(ctx context.Context, conn *websocket.Conn, config *Config) *MyAppsConnection

func (*MyAppsConnection) OnUserLoggedIn

func (myappsConnection *MyAppsConnection) OnUserLoggedIn(user *MyAppUserInfo)

func (*MyAppsConnection) SendWithResult

func (myappsConnection *MyAppsConnection) SendWithResult(message []byte, src string, num int, handler CallbackHandler) error

type Redirect

type Redirect struct {
	Mt   string `json:"mt"`
	Info struct {
		Host    string `json:"host"`
		Mod     string `json:"mod"`
		Session struct {
			Usr string `json:"usr"`
			Pwd string `json:"pwd"`
		} `json:"session"`
	} `json:"info"`
	Digest string `json:"digest"`
}

type SessionAdded

type SessionAdded struct {
	Mt   string `json:"mt"`
	Id   string `json:"id"`
	Info struct {
		UserAgent string `json:"userAgent"`
		Timestamp int64  `json:"timestamp"`
	} `json:"info"`
}

type SubscribeRegister

type SubscribeRegister struct {
	MT string `json:"mt"`
}

type UpdateAppsInfo

type UpdateAppsInfo struct {
	Mt  string `json:"mt"`
	App App    `json:"app"`
}

type UpdateOwnPresence

type UpdateOwnPresence struct {
	Mt       string `json:"mt"`
	Presence []struct {
		Contact  string `json:"contact"`
		Activity string `json:"activity"`
		Status   string `json:"status"`
	} `json:"presence"`
}

type UpdateRegister

type UpdateRegister struct {
	Mt       string `json:"mt"`
	Profile  string `json:"profile"`
	Tutorial string `json:"tutorial"`
	Signup   string `json:"signup"`
	Reset    string `json:"reset"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL