appctl

package
v3.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RPCTimeout is the timeout to complete a RPC call.
	// We use a very large timeout that works for embedded computer
	// and anti-virus sandbox environment.
	RPCTimeout = time.Second * 10

	// MaxRecvMsgSize is the maximum message size in bytes that
	// can be received in gRPC.
	MaxRecvMsgSize = math.MaxInt32
)

Variables

View Source
var (
	// ClientRPCServerStarted is closed when client RPC server is started.
	ClientRPCServerStarted chan struct{} = make(chan struct{})

	// ClientSocks5ServerStarted is closed when client socks5 server is started.
	ClientSocks5ServerStarted chan struct{} = make(chan struct{})
)
View Source
var (
	// ServerRPCServerStarted is closed when server RPC server is started.
	ServerRPCServerStarted chan struct{} = make(chan struct{})
)

Functions

func ApplyJSONClientConfig

func ApplyJSONClientConfig(path string) error

ApplyJSONClientConfig applies user provided JSON client config from the given file.

func ApplyJSONServerConfig

func ApplyJSONServerConfig(path string) error

ApplyJSONServerConfig applies user provided JSON server config from path.

func ApplyURLClientConfig

func ApplyURLClientConfig(u string) error

ApplyJSONClientConfig applies user provided client config URL.

func ClientConfigToURL

func ClientConfigToURL(config *pb.ClientConfig) (string, error)

ClientConfigToURL creates a URL to share the client configuration.

func ClientUpdaterHistoryPath added in v3.7.0

func ClientUpdaterHistoryPath() (string, error)

ClientUpdaterHistoryPath returns the file path to retrieve client updater history.

func DeleteClientConfigProfile

func DeleteClientConfigProfile(profileName string) error

DeleteClientConfigProfile deletes a profile stored in client config. The profile to delete can't be the active profile.

func DeleteServerUsers

func DeleteServerUsers(names []string) error

DeleteServerUsers deletes the list of users from server config.

func FlatPortBindings

func FlatPortBindings(bindings []*pb.PortBinding) ([]*pb.PortBinding, error)

FlatPortBindings checks port bindings and convert port range to a list of ports.

func GetActiveProfileFromConfig

func GetActiveProfileFromConfig(config *pb.ClientConfig, name string) (*pb.ClientProfile, error)

GetActiveProfileFromConfig returns the active client profile from client config.

func GetAppStatus

func GetAppStatus() pb.AppStatus

GetAppStatus returns the application running status.

func GetJSONClientConfig

func GetJSONClientConfig() (string, error)

GetJSONClientConfig returns the client config as JSON.

func GetJSONServerConfig

func GetJSONServerConfig() (string, error)

GetJSONServerConfig returns the server config as JSON.

func GetServerStatusWithRPC

func GetServerStatusWithRPC(ctx context.Context) (*pb.AppStatusMsg, error)

GetServerStatusWithRPC gets server application status via ServerLifecycleService.GetStatus() RPC.

func GetURLClientConfig

func GetURLClientConfig() (string, error)

GetURLClientConfig returns the client config as a URL.

func HashUserPassword

func HashUserPassword(user *pb.User, keepPlaintext bool) *pb.User

HashUserPassword replaces user's password with hashed password.

func HashUserPasswords

func HashUserPasswords(users []*pb.User, keepPlaintext bool) []*pb.User

HashUserPasswords replaces user's password with hashed password for a slice of users.

func IsClientApp

func IsClientApp() bool

IsClientApp returns true if our application type is client.

func IsClientDaemonRunning

func IsClientDaemonRunning(ctx context.Context) error

IsClientDaemonRunning detects if client daemon is running by using ClientLifecycleService.GetStatus() RPC.

func IsServerApp

func IsServerApp() bool

IsServerApp returns true if our application type is server.

func IsServerDaemonRunning

func IsServerDaemonRunning(appStatus *pb.AppStatusMsg) error

IsServerDaemonRunning returns nil if app status shows server daemon is running.

func IsServerProxyRunning

func IsServerProxyRunning(appStatus *pb.AppStatusMsg) error

IsServerProxyRunning returns nil if app status shows proxy function is running.

func LoadClientConfig

func LoadClientConfig() (*pb.ClientConfig, error)

LoadClientConfig reads client config from disk.

func LoadServerConfig

func LoadServerConfig() (*pb.ServerConfig, error)

LoadServerConfig reads server config from disk.

func NewClientLifecycleRPCClient

func NewClientLifecycleRPCClient() (appctlgrpc.ClientLifecycleServiceClient, error)

NewClientLifecycleRPCClient creates a new ClientLifecycleService RPC client. It loads client config to find the server address.

func NewClientLifecycleService

func NewClientLifecycleService() *clientLifecycleService

NewClientLifecycleService creates a new ClientLifecycleService RPC server.

func NewServerConfigRPCClient

func NewServerConfigRPCClient() (appctlgrpc.ServerConfigServiceClient, error)

NewServerConfigRPCClient creates a new ServerConfigService RPC client.

func NewServerConfigService

func NewServerConfigService() *serverConfigService

NewServerConfigService creates a new ServerConfigService RPC server.

func NewServerLifecycleRPCClient

func NewServerLifecycleRPCClient() (appctlgrpc.ServerLifecycleServiceClient, error)

NewServerLifecycleRPCClient creates a new ServerLifecycleService RPC client.

func NewServerLifecycleService

func NewServerLifecycleService() *serverLifecycleService

NewServerLifecycleService creates a new ServerLifecycleService RPC server.

func PortBindingsToUnderlayProperties

func PortBindingsToUnderlayProperties(portBindings []*pb.PortBinding, mtu int) ([]protocol.UnderlayProperties, error)

PortBindingsToUnderlayProperties converts port bindings to underlay properties.

func ServerUDS

func ServerUDS() string

ServerUDS returns the UNIX domain socket that mita server is listening to RPC requests.

func SetAppStatus

func SetAppStatus(status pb.AppStatus)

SetAppStatus sets the application running status.

func SetAppType

func SetAppType(t AppType)

SetAppType sets the application type. This method is only effective on the first call.

func SetClientMuxRef

func SetClientMuxRef(mux *protocol.Mux)

func SetClientRPCServerRef

func SetClientRPCServerRef(server *grpc.Server)

func SetClientSocks5ServerRef

func SetClientSocks5ServerRef(server *socks5.Server)

func SetServerMuxRef

func SetServerMuxRef(mux *protocol.Mux)

func SetServerRPCServerRef

func SetServerRPCServerRef(server *grpc.Server)

func SetSocks5Server

func SetSocks5Server(server *socks5.Server)

func StoreClientConfig

func StoreClientConfig(config *pb.ClientConfig) error

StoreClientConfig writes client config to disk.

func StoreServerConfig

func StoreServerConfig(config *pb.ServerConfig) error

StoreServerConfig writes server config to disk.

func URLToClientConfig

func URLToClientConfig(s string) (*pb.ClientConfig, error)

URLToClientConfig returns a client configuration based on the URL.

func UserListToMap

func UserListToMap(users []*pb.User) map[string]*pb.User

UserListToMap convert a slice of User to a map of <name, User>.

func ValidateClientConfigPatch

func ValidateClientConfigPatch(patch *pb.ClientConfig) error

ValidateClientConfigPatch validates a patch of client config.

A client config patch must satisfy: 1. it has 0 or more profile 2. validate each profile 3. for each socks5 authentication, the user and password are not empty

func ValidateClientConfigSingleProfile added in v3.6.0

func ValidateClientConfigSingleProfile(profile *pb.ClientProfile) error

ValidateClientConfigSingleProfile validates a single client config profile.

It validates 1. profile name is not empty 2. user name is not empty 3. user has either a password or a hashed password 4. user has no quota 5. it has at least 1 server, and for each server 5.1. the server has either IP address or domain name 5.2. if set, server's IP address is parsable 5.3. the server has at least 1 port binding, and all port bindings are valid 6. if set, MTU is valid

func ValidateFullClientConfig

func ValidateFullClientConfig(config *pb.ClientConfig) error

ValidateFullClientConfig validates the full client config.

In addition to ValidateClientConfigPatch, it also validates: 1. there is at least 1 profile 2. the active profile is available 3. RPC port is valid 4. socks5 port is valid 5. RPC port, socks5 port, http proxy port are different

func ValidateFullServerConfig

func ValidateFullServerConfig(config *pb.ServerConfig) error

ValidateFullServerConfig validates the full server config.

In addition to ValidateServerConfigPatch, it also validates: 1. there is at least 1 port binding

It is not an error if no user is configured. However mita won't be functional.

func ValidateServerConfigPatch

func ValidateServerConfigPatch(patch *pb.ServerConfig) error

ValidateServerConfigPatch validates a patch of server config.

A server config patch must satisfy: 1. port bindings are valid 2. for each user 2.1. user name is not empty 2.2. user has either a password or a hashed password 2.3. for each quota 2.3.1. number of days is valid 2.3.2. traffic volume in megabyte is valid 3. if set, MTU is valid 4. for each egress proxy 4.1. name is not empty 4.2. name is unique 4.3. protocol is valid 4.4. host is not empty 4.5. port is valid 4.6. if socks5 authentication is used, the user and password are not empty 5. there is maximum 1 egress rule 5.1. the IP ranges must be "*" 5.2. the domain names must be "*" 5.3. the action must be "PROXY" 5.4. the proxy name is defined

Types

type AppType

type AppType int
const (
	UNKNOWN_APP AppType = iota
	CLIENT_APP          // client side application
	SERVER_APP          // server side application
)

type ConfigFileType

type ConfigFileType int
const (
	INVALID_CONFIG_FILE_TYPE ConfigFileType = iota
	PROTOBUF_CONFIG_FILE_TYPE
	JSON_CONFIG_FILE_TYPE
)

func FindConfigFileType

func FindConfigFileType(fileName string) ConfigFileType

FindConfigFileType returns the type of configuration file. Similar to Windows, it uses file extension name to make the decision.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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