Documentation
¶
Index ¶
- Constants
- Variables
- func ADMIN(ctx context.Context, cmd Command, op string, args ...[]byte) error
- func CONFIG(objs ...ConfigObj) [][]byte
- func CONN(cmd Command, server db.Server, noverify bool) error
- func DEREG(ctx context.Context, cmd Command, username, pass string) error
- func DISCN(cmd Command) error
- func DefaultWaitlist() models.Waitlist[spec.Command]
- func EXPORT(cmd Command, username, pass string) error
- func Find(id spec.ID, ops ...spec.Action) func(cmd spec.Command) bool
- func GetPermissions(ctx context.Context, cmd Command, uname string) (uint, error)
- func IMPORT(cmd Command, username, pass, dir string) error
- func LOGIN(ctx context.Context, cmd Command, username, pass string) error
- func LOGOUT(ctx context.Context, cmd Command) error
- func ListenPackets(cmd Command, cleanup func())
- func MSG(ctx context.Context, cmd Command, username, message string) error
- func PreventIdle(ctx context.Context, data *Data, d time.Duration)
- func RECIV(ctx context.Context, cmd Command) error
- func RECOVER(cmd Command, username, pass string, cleanup bool) error
- func REG(ctx context.Context, cmd Command, username, pass string) error
- func REQ(ctx context.Context, cmd Command, username string) ([][]byte, error)
- func SET(cmd Command, target, value string, objs ...ConfigObj) error
- func SUB(ctx context.Context, cmd Command, name string) error
- func SocketConnect(address string, port uint16, useTLS bool, noVerify bool) (con net.Conn, err error)
- func UNSUB(ctx context.Context, cmd Command, name string) error
- func USRS(ctx context.Context, cmd Command, usrsType USRSType) ([][]byte, error)
- func Version(major float32) string
- func WaitConnect(data Command, endpoint net.Conn, server db.Server) error
- type Command
- type ConfigObj
- type ConfigUpdate
- type Data
- type Message
- type OutputFunc
- type OutputType
- type StaticData
- type USRSType
Constants ¶
const DefaultPerms = 0755
Default level of permissions that should be used
Variables ¶
var ( ErrorInsuficientArgs error = fmt.Errorf("not enough arguments") // not enough arguments ErrorNotConnected error = fmt.Errorf("not connected to a server") // not connected to a server ErrorAlreadyConnected error = fmt.Errorf("already connected to a server") // already connected to a server ErrorNotLoggedIn error = fmt.Errorf("you are not logged in") // you are not logged in ErrorAlreadyLoggedIn error = fmt.Errorf("you are already logged in") // you are already logged in ErrorWrongCredentials error = fmt.Errorf("wrong credentials") // wrong credentials ErrorUnknownUSRSOption error = fmt.Errorf("unknown usrs option provided") // unknown usrs option provided ErrorUsernameEmpty error = fmt.Errorf("username cannot be empty") // username cannot be empty ErrorUserExists error = fmt.Errorf("local user exists") // local user exists ErrorPasswordsDontMatch error = fmt.Errorf("passwords do not match") // passwords do not match ErrorUserNotFound error = fmt.Errorf("user not found") // user not found ErrorUnknownTLSOption error = fmt.Errorf("unknown tls option provided") // unknown tls option provided ErrorOfflineRequired error = fmt.Errorf("you must be offline") // you must be offline ErrorInvalidSkipVerify error = fmt.Errorf("cannot skip verification on a non-TLS endpoint") // cannot skip verification on a non-TLS endpoint ErrorRequestToSelf error = fmt.Errorf("cannot request yourself") // cannot request yourself ErrorUnknownHookOption error = fmt.Errorf("invalid hook provided") // invalid hook provided ErrorInvalidAdminOperation error = fmt.Errorf("invalid admin operation") // invalid admin operation ErrorRecoveryPassword error = fmt.Errorf("could not recover during password checking") // could not recover during password checking ErrorInvalidTarget error = fmt.Errorf("provided object is not an appropiate type") // provided object is not an appropiate type ErrorInvalidField error = fmt.Errorf("provided field is non-existant") // provided field is non-existant ErrorCannotSet error = fmt.Errorf("failed to set a value on the given field") // failed to set a value on the given field ErrorNoReusableToken error = fmt.Errorf("reusable token is empty") // reusable token is empty )
var BuildCode string
Specifies the build code
Functions ¶
func CONFIG ¶
Returns the current configuration values for the given objects. Only needs the object and prefix. Passed objects as "any" can or not be pointers
func CONN ¶
Starts a connection with a server. If noverify is set, in case of TLS connections, certificate origins wont be checked. This command does not spawn a listening thread.
func DefaultWaitlist ¶
Returns an appropiate waitlist
func EXPORT ¶
Exports a local user as a private RSA key in the "export" folder using the spec PEM format.
func Find ¶
Returns a function that returns true if the received command fulfills the given conditions in the arguments (ID and operations). This is used to dinamically create functions that retrieve commands from the waitlist with waitlist.Get()
func GetPermissions ¶
Requests the user logged in to get its permissions
func IMPORT ¶
Imports a private RSA key for a new local user from the "import" directory using the specification PEM format.
func ListenPackets ¶
func ListenPackets(cmd Command, cleanup func())
Listens for incoming server packets. When a packet is received, it is stored in the packet waitlist A cleanup function that cleans up resources can be passed.
func PreventIdle ¶
Sends a KEEP packet every x time
func RECIV ¶
Asks the server to retrieve all messages while the user was offline. This function is not responsible for receiving the messages, only request them.
func RECOVER ¶
Recovers the private key and messages for a specified user Does not require a Data struct in Command
func REQ ¶
Requests the information of an external user to add it to the client database. Returns the arguments of a REQ as by specification.
func SET ¶
Sets a variable on an object as configuration. Passed objects must be pointers. Does not require a Data struct in "Command"
func SocketConnect ¶
func SocketConnect(address string, port uint16, useTLS bool, noVerify bool) (con net.Conn, err error)
Performs the socket connection to the server.
Types ¶
type Command ¶
type Command struct {
Output OutputFunc // Custom output-printing function
Static *StaticData // Static Data (mostly)
Data *Data // Modifiable Data
}
Specifies all structs necessary for a command
type ConfigObj ¶
type ConfigObj struct {
Prefix string // Should start with capital letter
Object any // Can be or not a pointer (read the function precondition)
Precondition func() error // Condition needed for it to be able to set a value
Update ConfigUpdate // Called to update values on the database
Finish func() // Run a function once it has been updated
}
Represents a config struct to be passed to modify
type ConfigUpdate ¶
Represents a function to update an object on the database
type Data ¶
type Data struct {
Conn net.Conn // Specifies the connection to the server
Logout context.CancelFunc // Specifies the function to call on a logout for context propagation
Waitlist models.Waitlist[spec.Command] // Stores all packets to be retrieved later
// Using pointers so that "nil" can be used
Server *db.Server // Specifies the database server
LocalUser *db.LocalUser // Specifies the logged in user
// contains filtered or unexported fields
}
Struct that contains all the data necessary to run a command Requires fields may change between commands Commands may alter the data if necessary
func (*Data) IsConnected ¶
Whether the connection is or not established
func (*Data) IsLoggedIn ¶
Whether the connection is logged in or not
type Message ¶
type Message struct {
Sender string // Who is sending the message
Content string // What the message contains
Timestamp time.Time // When the message was sent
}
Specifies a message that is going through the connection
type OutputFunc ¶
type OutputFunc func(text string, outputType OutputType)
Represents the function that will be called when outputting information
type OutputType ¶
type OutputType uint
Represents the type of a command output This eases specific output printing actions
const ( INTERMEDIATE OutputType = iota // Intermediate status messages PACKET // Packet information messages PROMPT // Prompt message when input is asked RESULT // Messages that show the result of a command ERROR // Error messages that may be printed additionaly in error cases INFO // Message that representes generic info not asocciated to a command USRSRESPONSE // Specific for user printing COLOR // Special output for shell colors PLAIN // Output type that should be printed as-is, with no prefix SECONDARY // Optional text to show after the result )
type StaticData ¶
type StaticData struct {
Verbose bool // Whether or not to print detailed information
DB *gorm.DB // Connection to the database
}
Static data that should only be assigned in specific cases
type USRSType ¶
type USRSType uint
Represents the different USRS command types
const ( ALL USRSType = 0 // Users in the server (as spec) ONLINE USRSType = 1 // Online users in the server (as spec) ALLPERMS USRSType = 2 // All users with perms (as spec) ONLINEPERMS USRSType = 3 // Online users with perms (as spec) LOCAL_SERVER USRSType = 4 // Registered local users for a server LOCAL_ALL USRSType = 5 // All local users REQUESTED USRSType = 6 // All external users whose public key has been saved )