client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package client contains code for OC-Daemon clients.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConfigName is the name of the configuration file.
	ConfigName = "oc-client.json"

	// ConfigDirName is the name of the directory where the configuration
	// file is stored.
	ConfigDirName = "oc-daemon"

	// SystemConfigDirPath is the path of the directory where the directory
	// of the system configuration is stored.
	SystemConfigDirPath = "/var/lib"

	// OpenConnect is the openconnect executable.
	OpenConnect = "openconnect"

	// Protocol is the protocol used by openconnect.
	Protocol = "anyconnect"

	// UserAgent is the user agent used by openconnect.
	UserAgent = "AnyConnect"

	// Quiet specifies whether the quiet flag is set in openconnect.
	Quiet = true

	// NoProxy specifies whether the no proxy flag is set in openconnect.
	NoProxy = true

	// ExtraEnv are extra environment variables used by openconnect.
	ExtraEnv = []string{}

	// ExtraArgs are extra command line arguments used by openconnect.
	ExtraArgs = []string{}
)

Functions

func SystemConfig

func SystemConfig() string

SystemConfig returns the default file path of the system configuration.

func UserConfig

func UserConfig() string

UserConfig returns the default file path of the current user's configuration.

Types

type Client

type Client interface {
	SetConfig(config *Config)
	GetConfig() *Config

	SetEnv(env []string)
	GetEnv() []string

	SetLogin(login *logininfo.LoginInfo)
	GetLogin() *logininfo.LoginInfo

	Ping() error
	Query() (*vpnstatus.Status, error)
	Subscribe() (chan *vpnstatus.Status, error)

	Authenticate() error
	Connect() error
	Disconnect() error

	Close() error
}

Client is an OC-Daemon client.

func NewClient

func NewClient(config *Config) (Client, error)

NewClient returns a new Client.

type Config

type Config struct {
	ClientCertificate string
	ClientKey         string
	UserCertificate   string
	UserKey           string
	CACertificate     string
	XMLProfile        string
	VPNServer         string
	User              string
	Password          string `json:"-"`

	OpenConnect string
	Protocol    string
	UserAgent   string
	Quiet       bool
	NoProxy     bool
	ExtraEnv    []string
	ExtraArgs   []string
}

Config is a configuration for the OC client.

func LoadConfig

func LoadConfig(file string) (*Config, error)

LoadConfig loads a Config from file.

func LoadUserSystemConfig

func LoadUserSystemConfig() *Config

LoadUserSystemConfig loads the user or system configuration from its default location, expands variables in config.

func NewConfig

func NewConfig() *Config

NewConfig returns a new Config.

func (*Config) Copy

func (c *Config) Copy() *Config

Copy returns a copy of Config.

func (*Config) Empty

func (c *Config) Empty() bool

Empty returns whether the config is empty.

func (*Config) Expand

func (c *Config) Expand()

Expand expands variables in config.

func (*Config) Save

func (c *Config) Save(file string) error

Save saves the config to file.

func (*Config) Valid added in v0.1.0

func (c *Config) Valid() bool

Valid returns whether the config is valid.

type DBusClient

type DBusClient struct {
	// contains filtered or unexported fields
}

DBusClient is an OC-Daemon client that uses the D-Bus API of OC-Daemon.

func NewDBusClient

func NewDBusClient(config *Config) (*DBusClient, error)

NewDBusClient returns a new DBusClient.

func (*DBusClient) Authenticate

func (d *DBusClient) Authenticate() error

Authenticate authenticates the client on the VPN server.

func (*DBusClient) Close

func (d *DBusClient) Close() error

Close closes the DBusClient.

func (*DBusClient) Connect

func (d *DBusClient) Connect() error

Connect connects the client with the VPN server, requires successful authentication with Authenticate.

func (*DBusClient) Disconnect

func (d *DBusClient) Disconnect() error

Disconnect disconnects the client from the VPN server.

func (*DBusClient) GetConfig

func (d *DBusClient) GetConfig() *Config

GetConfig returns the client config.

func (*DBusClient) GetEnv

func (d *DBusClient) GetEnv() []string

GetEnv returns the additional environment variables.

func (*DBusClient) GetLogin

func (d *DBusClient) GetLogin() *logininfo.LoginInfo

GetLogin returns the login information.

func (*DBusClient) Ping

func (d *DBusClient) Ping() error

Ping pings the OC-Daemon to check if it is running.

func (*DBusClient) Query

func (d *DBusClient) Query() (*vpnstatus.Status, error)

Query retrieves the VPN status.

func (*DBusClient) SetConfig

func (d *DBusClient) SetConfig(config *Config)

SetConfig sets the client config.

func (*DBusClient) SetEnv

func (d *DBusClient) SetEnv(env []string)

SetEnv sets additional environment variables.

func (*DBusClient) SetLogin

func (d *DBusClient) SetLogin(login *logininfo.LoginInfo)

SetLogin sets the login information.

func (*DBusClient) Subscribe

func (d *DBusClient) Subscribe() (chan *vpnstatus.Status, error)

Subscribe subscribes to PropertiesChanged D-Bus signals, converts incoming PropertiesChanged signals to VPN status updates and sends those updates over the returned channel.

Jump to

Keyboard shortcuts

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