appctl

package
v1.15.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: GPL-3.0 Imports: 30 Imported by: 3

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
)
View Source
const (
	// ServerUDS is the UNIX domain socket that server is listening to RPC requests.
	ServerUDS = "/var/run/mita.sock"
)

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 added in v1.13.0

func ApplyURLClientConfig(u string) error

ApplyJSONClientConfig applies user provided client config URL.

func ClientConfigToURL added in v1.13.0

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

ClientConfigToURL creates a URL to share the client configuration.

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 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 GetSocks5ServerGroup added in v1.3.0

func GetSocks5ServerGroup() *socks5.ServerGroup

func GetURLClientConfig added in v1.13.0

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 Marshal

func Marshal(m protoreflect.ProtoMessage) ([]byte, error)

Marshal returns a JSON representation of protobuf.

func NewClientLifecycleRPCClient

func NewClientLifecycleRPCClient(ctx context.Context) (pb.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() (pb.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() (pb.ServerLifecycleServiceClient, error)

NewServerLifecycleRPCClient creates a new ServerLifecycleService RPC client.

func NewServerLifecycleService

func NewServerLifecycleService() *serverLifecycleService

NewServerLifecycleService creates a new ServerLifecycleService RPC server.

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 SetClientRPCServerRef

func SetClientRPCServerRef(server *grpc.Server)

func SetClientSocks5ServerRef

func SetClientSocks5ServerRef(server *socks5.Server)

func SetServerRPCServerRef

func SetServerRPCServerRef(server *grpc.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 added in v1.13.0

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

URLToClientConfig returns a client configuration based on the URL.

func Unmarshal

func Unmarshal(b []byte, m protoreflect.ProtoMessage) error

Unmarshal writes protobuf based on JSON data.

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. for each profile 2.1. profile name is not empty 2.2. user name is not empty 2.3. user has either a password or a hashed password 2.4. it has at least 1 server, and for each server 2.4.1. the server has either IP address or domain name 2.4.2. if set, server's IP address is parsable 2.4.3. the server has at least 1 port binding, and for each port binding 2.4.3.1. port number is valid 2.4.3.2. protocol is valid 2.5. 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 mieru 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. for each port binding 1.1. port number is valid 1.2. protocol is valid 2. for each user 2.1. user name is not empty 2.2. user has either a password or a hashed password 3. if set, MTU is valid

Types

type AppType

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

type ConfigFileType added in v1.6.0

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

func FindConfigFileType added in v1.6.0

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