Documentation ¶
Index ¶
- Constants
- Variables
- func CheckPasswordHash(password, hash string) bool
- func Color(color, text string) string
- func GenerateHashPassword(password string) (string, error)
- func HandleCommands(Commands *Command) (handler func(Client, string))
- func Image(width, height int, src, alt string) string
- func InitGin(app *MgmtApp, router *gin.Engine, webPath string, fileSystem fs.FS) error
- func InitMuxRouter(app *MgmtApp, router *mux.Router, webPath string, fileSystem fs.FS) error
- func Link(url, text string) string
- func ServeProxy(app *MgmtApp, webPath string, filesProxy http.Handler) gin.HandlerFunc
- type Authenticated
- type Authentication
- type Authr
- func (a *Authr) AdminIndex(w http.ResponseWriter, r *http.Request)
- func (a *Authr) CloseDatabase(connection *gorm.DB)
- func (a *Authr) GenerateJWT(email, role string) (string, error)
- func (a *Authr) GetDatabase() *gorm.DB
- func (a *Authr) Index(w http.ResponseWriter, r *http.Request)
- func (a *Authr) InitialMigration()
- func (a *Authr) IsAuthorized(handler http.HandlerFunc) http.HandlerFunc
- func (a *Authr) SignIn(w http.ResponseWriter, r *http.Request)
- func (a *Authr) SignUp(w http.ResponseWriter, r *http.Request)
- func (a *Authr) UserIndex(w http.ResponseWriter, r *http.Request)
- type BuildInfo
- type Clickable
- type Client
- type ClientMessage
- type Command
- func (c *Command) AddCommand(cmds ...*Command)
- func (c *Command) CommandPath() string
- func (c *Command) CommandPathPadding() int
- func (c *Command) Commands() []*Command
- func (c *Command) Execute(client Client, cmdLine *CommandArgs)
- func (c *Command) HasAvailableSubCommands() bool
- func (c *Command) HasExample() bool
- func (c *Command) HasHelpSubCommands() bool
- func (c *Command) HasParent() bool
- func (c *Command) HasSubCommands() bool
- func (c *Command) Help(client Client) error
- func (c *Command) HelpFunc() func(*Command, []string, Client)
- func (c *Command) HelpTemplate() string
- func (c *Command) IsAdditionalHelpTopicCommand() bool
- func (c *Command) IsAvailableCommand() bool
- func (c *Command) IsSubCommandAvailable(client Client, cmd string) bool
- func (c *Command) Name() string
- func (c *Command) NamePadding() int
- func (c *Command) Parent() *Command
- func (c *Command) RemoveCommand(cmds ...*Command)
- func (c *Command) Runnable() bool
- func (c *Command) SetHelpCommand(cmd *Command)
- func (c *Command) SetHelpFunc(f func(*Command, []string, Client))
- func (c *Command) SetHelpTemplate(s string)
- func (c *Command) SuggestionsFor(typedName string) []string
- func (c *Command) Usage(io io.Writer) error
- func (c *Command) UsageFunc() (f func(*Command, io.Writer) error)
- func (c *Command) UsagePadding() int
- func (c *Command) UsageString() string
- func (c *Command) UsageTemplate() string
- func (c *Command) UseLine() string
- func (c *Command) VersionTemplate() string
- type CommandArgs
- type CommandFunc
- type Config
- type Echo
- type Error
- type ExecLevel
- type HistoryMode
- type Hub
- type MgmtApp
- type NewPathFS
- type Prompt
- type RawTextMessage
- type ServerMessage
- func AppendErrorText(format string, a ...interface{}) ServerMessage
- func AppendNormalText(format string, a ...interface{}) ServerMessage
- func AppendRawText(text string) ServerMessage
- func AppendText(text, color string) ServerMessage
- func ClickableCommands(commands []string) ServerMessage
- func Cls() ServerMessage
- func Eval(text string) ServerMessage
- func SetAuthenticated(val bool) ServerMessage
- func SetEchoOn(val bool) ServerMessage
- func SetHistoryMode(val bool) ServerMessage
- func SetPrompt(prompt string) ServerMessage
- func SetStatus(text string) ServerMessage
- type ServerMessageBase
- type Status
- type TextMessage
- type Token
- type User
- type WSClient
- func (c *WSClient) ExecLevel() ExecLevel
- func (c *WSClient) History() []string
- func (c *WSClient) HttpReq() *http.Request
- func (c *WSClient) Ip() string
- func (c *WSClient) IsAuthenticated() bool
- func (c *WSClient) IsConnected() bool
- func (c *WSClient) Misc() map[string]interface{}
- func (c *WSClient) Send(msg ServerMessage)
- func (c *WSClient) SetExecLevel(level ExecLevel)
- func (c *WSClient) StdErr() io.Writer
- func (c *WSClient) StdOut() io.Writer
- func (c *WSClient) Username() string
- func (c *WSClient) WriteStdErr(p []byte) (n int, err error)
- func (c *WSClient) WriteStdOut(p []byte) (n int, err error)
- type WSClientWriter
Constants ¶
const ADMIN = ExecLevel(2)
ADMIN level for admin users
const ALL = ExecLevel(0)
ALL level for all users
const USER = ExecLevel(1)
USER level for default users
Variables ¶
var ( // NormalOutputColor color definition for normal output NormalOutputColor = "white" // ErrorOutputColor color definition for error output ErrorOutputColor = "red" )
var ClsCommand = &Command{Use: "cls", Exec: func(client Client, args *CommandArgs) (err error) { client.Send(Cls()) return }, Short: "send cls event to terminal client", ExecLevel: ALL}
ClsCommand command to clear web screen
var DefaultCommands = &Command{ExecLevel: ALL}
DefaultCommands main struct for all commands
var DefaultWebEmbedFS embed.FS
DefaultWebEmbedFS embedded assets
var EnableCommandSorting = true
EnableCommandSorting controls sorting of the slice of commands, which is turned on by default. To disable sorting, set it to false.
var ForegroundColor = "white"
ForegroundColor default foreground color definition
var HistoryCommand = &Command{Use: "history", Exec: displayHistory, Short: "Show the history of commands executed", ExecLevel: ALL}
HistoryCommand command to view history of commands executed
var HttpCommand = &Command{Use: "http", Exec: displayHttpInfo, Short: "Display http request information", ExecLevel: ALL}
HttpCommand command to view http session details
var UserCommand = &Command{Use: "user", Exec: displayUserInfo, Short: "Show user details about logged in user", ExecLevel: ALL}
UserCommand command to view user details
var WebFS fs.FS
Functions ¶
func CheckPasswordHash ¶
CheckPasswordHash plain password with hash password
func GenerateHashPassword ¶
GenerateHashPassword password as input and generate new hash password from it
func HandleCommands ¶
HandleCommands handler function to execute commands
func Image ¶
Image is used to take several predefined fields and return a html snippet to display an image.
func InitGin ¶
InitGin will initialize the Router with the admin web app. It registers the webapp and assets file handler to be under the WebPath config field.
func InitMuxRouter ¶
InitMuxRouter will initialize the Router with the admin web app. It registers the webapp and assets file handler to be under the WebPath config field.
func ServeProxy ¶
Types ¶
type Authenticated ¶
type Authenticated struct { ServerMessageBase Val bool `json:"val"` }
Authenticated is the struct for the server message that is sent to the client to tell the client that is has been authenticated or not.
type Authentication ¶
Authentication struct
type Authr ¶
type Authr struct {
SecretKey string "secretkeyjwt"
}
Authr struct
func InitializeAuthGin ¶
InitializeAuthGin all auth routes for gin router
func InitializeAuthMux ¶
InitializeAuthMux all auth routes
func (*Authr) AdminIndex ¶
func (a *Authr) AdminIndex(w http.ResponseWriter, r *http.Request)
AdminIndex ROUTE HANDLER
func (*Authr) CloseDatabase ¶
CloseDatabase database connection
func (*Authr) GenerateJWT ¶
GenerateJWT JWT token
func (*Authr) Index ¶
func (a *Authr) Index(w http.ResponseWriter, r *http.Request)
Index ROUTE HANDLER
func (*Authr) InitialMigration ¶
func (a *Authr) InitialMigration()
InitialMigration user table in userdb
func (*Authr) IsAuthorized ¶
func (a *Authr) IsAuthorized(handler http.HandlerFunc) http.HandlerFunc
IsAuthorized whether user is authorized or not
func (*Authr) SignIn ¶
func (a *Authr) SignIn(w http.ResponseWriter, r *http.Request)
SignIn ROUTE HANDLER
type BuildInfo ¶
type BuildInfo struct { // AppBuildInfo build information BuildDate string // LatestCommit build information LatestCommit string // BuildNumber build information BuildNumber string // BuiltOnIp build information BuiltOnIp string // BuiltOnOs build information BuiltOnOs string // RuntimeVer build information RuntimeVer string }
BuildInfo is used to define the application build info, and inject values into via the build process.
var ( // AppBuildInfo build information AppBuildInfo *BuildInfo )
type Clickable ¶
type Clickable struct { ServerMessageBase Commands []string `json:"commands"` }
Clickable is the struct for the server message that is sent to the client to tell the client to display clickable.
type Client ¶
type Client interface { IsAuthenticated() bool IsConnected() bool Username() string Send(msg ServerMessage) History() []string HttpReq() *http.Request Misc() map[string]interface{} Ip() string ExecLevel() ExecLevel SetExecLevel(level ExecLevel) StdOut() io.Writer StdErr() io.Writer }
Client is the interface a WebSocket client will implement. It provides access to the authenticated state as well as ability to send it a ServerMessage to be processed on the MgmtApp.
type ClientMessage ¶
type ClientMessage struct {
Payload string `json:"payload"`
}
ClientMessage is the struct for the client message that is sent from the client to the server. nThe contents are passed to the HandleCommand func(c Client, cmd string) defined in the Config.
func ConvertBytesToMessage ¶
func ConvertBytesToMessage(payload []byte) (*ClientMessage, error)
ConvertBytesToMessage converts a byte slice to CLientMessage via json unmarshalling
type Command ¶
type Command struct { Exec CommandFunc // Use is the word to execute the command Use string // Short is the short description shown in the 'help' output. Short string // Long is the long message shown in the 'help <this-command>' output. Long string // Example is examples of how to use the command. Example string // Hidden defines, if this command is hidden and should NOT show up in the list of available commands. Hidden bool // Version defines the version for this command. If this value is non-empty and the command does not // define a "version" flag, a "version" boolean flag will be added to the command and, if specified, // will print content of the "Version" variable. Version string // Deprecated defines, if this command is deprecated and should print this string when used. Deprecated string ExecLevel ExecLevel // DisableSuggestions disables the suggestions based on Levenshtein distance // that go along with 'unknown command' messages. DisableSuggestions bool // SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions. // Must be > 0. SuggestionsMinimumDistance int // SuggestFor is an array of command names for which this command will be suggested - // similar to aliases but only suggests. SuggestFor []string FlagSet *flag.FlagSet HasFlags bool // contains filtered or unexported fields }
Command is just that, a command for your application. E.g. 'go run ...' - 'run' is the command. Cobra requires you to define the usage and description as part of your command definition to ensure usability.
func (*Command) AddCommand ¶
AddCommand adds one or more commands to this parent command.
func (*Command) CommandPath ¶
CommandPath returns the full path to this command.
func (*Command) CommandPathPadding ¶
CommandPathPadding return padding for the command path.
func (*Command) Execute ¶
func (c *Command) Execute(client Client, cmdLine *CommandArgs)
Execute runs a command thru execution
func (*Command) HasAvailableSubCommands ¶
HasAvailableSubCommands determines if a command has available sub commands that need to be shown in the usage/help default template under 'available commands'.
func (*Command) HasExample ¶
HasExample determines if the command has example.
func (*Command) HasHelpSubCommands ¶
HasHelpSubCommands determines if a command has any available 'help' sub commands that need to be shown in the usage/help default template under 'additional help topics'.
func (*Command) HasSubCommands ¶
HasSubCommands determines if the command has children commands.
func (*Command) Help ¶
Help puts out the help for the command. Used when a user calls help [command]. Can be defined by user by overriding HelpFunc.
func (*Command) HelpFunc ¶
HelpFunc returns either the function set by SetHelpFunc for this command or a parent, or it returns a function with default help behavior.
func (*Command) HelpTemplate ¶
HelpTemplate return help template for the command.
func (*Command) IsAdditionalHelpTopicCommand ¶
IsAdditionalHelpTopicCommand determines if a command is an additional help topic command; additional help topic command is determined by the fact that it is NOT runnable/hidden/deprecated, and has no sub commands that are runnable/hidden/deprecated. Concrete example: https://github.com/spf13/cobra/issues/393#issuecomment-282741924.
func (*Command) IsAvailableCommand ¶
IsAvailableCommand determines if a command is available as a non-help command (this includes all non deprecated/hidden commands).
func (*Command) IsSubCommandAvailable ¶
IsSubCommandAvailable checks if sub command exists
func (*Command) NamePadding ¶
NamePadding returns padding for the name.
func (*Command) RemoveCommand ¶
RemoveCommand removes one or more commands from a parent command.
func (*Command) SetHelpCommand ¶
SetHelpCommand sets help command.
func (*Command) SetHelpFunc ¶
SetHelpFunc sets help function. Can be defined by Application.
func (*Command) SetHelpTemplate ¶
SetHelpTemplate sets help template to be used. Application can use it to set custom template.
func (*Command) SuggestionsFor ¶
SuggestionsFor provides suggestions for the typedName.
func (*Command) Usage ¶
Usage puts out the usage for the command. Used when a user provides invalid input. Can be defined by user by overriding UsageFunc.
func (*Command) UsageFunc ¶
UsageFunc returns either the function set by SetUsageFunc for this command or a parent, or it returns a default usage function.
func (*Command) UsagePadding ¶
UsagePadding return padding for the usage.
func (*Command) UsageString ¶
UsageString returns usage string.
func (*Command) UsageTemplate ¶
UsageTemplate returns usage template for the command.
func (*Command) VersionTemplate ¶
VersionTemplate return version template for the command.
type CommandArgs ¶
type CommandArgs struct { CmdLine string CmdName string Args []string FlagSet *flag.FlagSet // contains filtered or unexported fields }
CommandArgs is a struct that is used to store the contents of a parsed command line string.
func NewCommandArgs ¶
func NewCommandArgs(cmdLine string, output io.Writer) (*CommandArgs, error)
NewCommandArgs will take a raw string and output. The Raw string will be parsed into a CommandArgs structure. If an error is encountered such as empty command string it will be returned and the CommandArgs will be nil.
func (*CommandArgs) Debug ¶
func (c *CommandArgs) Debug() string
Debug will return a string listing the original command line and the parsed arguments and flags
func (*CommandArgs) Parse ¶
func (c *CommandArgs) Parse() error
Parse will use the defined FlagSet parsed and return an error if help is invoked or invalid flags
func (*CommandArgs) PealOff ¶
func (c *CommandArgs) PealOff(pos int) string
PealOff will return a command line string after N commands have been pealed off from the front of the command line.
func (*CommandArgs) Shift ¶
func (c *CommandArgs) Shift() (*CommandArgs, error)
Shift will return a new CommandArgs after shifting the first cmd in the string
func (*CommandArgs) String ¶
func (c *CommandArgs) String() string
String will return the CmdLine the original one that is parsed.
type CommandFunc ¶
type CommandFunc func(client Client, args *CommandArgs) error
CommandFunc function definition for a command
type Config ¶
type Config struct { DefaultPrompt string UserAuthenticator func(client Client, username string, password string) bool HandleCommand func(c Client, cmd string) NotifyClientAuthenticated func(client Client) NotifyClientAuthenticatedFailed func(client Client) WelcomeUser func(client Client) UnregisterUser func(client Client) ClientInitializer func(client Client) }
Config struct is used to configure a WebMgmt admin handler.
type Echo ¶
type Echo struct { ServerMessageBase Val bool `json:"val"` }
Echo is the struct for the server message that is sent to the client to tell the client to turn echo on or off.
type HistoryMode ¶
type HistoryMode struct { ServerMessageBase Val bool `json:"val"` }
HistoryMode is the struct for the server message that is sent to the client to tell the client to turn history saving on and off.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to the clients.
func (*Hub) Broadcast ¶
func (h *Hub) Broadcast(msg ServerMessage)
Broadcast sill send a ServerMessage to all users on the System.
type MgmtApp ¶
type MgmtApp struct {
// contains filtered or unexported fields
}
MgmtApp struct is the web admin app.
func NewMgmtApp ¶
NewMgmtApp will create a new web mgmt web handler with the Config passed in, Various funcs can be overwritten for authentication, welcome etc. If an error is encountered, it will be returned
func (*MgmtApp) Broadcast ¶
func (app *MgmtApp) Broadcast(msg ServerMessage)
Broadcast will take a ServerMessage and send to all clients that are currently connected.
type Prompt ¶
type Prompt struct { ServerMessageBase Prompt string `json:"prompt"` }
Prompt is the struct for the server message that is sent to the client to tell the client what the prompt should be
type RawTextMessage ¶
type RawTextMessage struct { ServerMessageBase Text string `json:"text"` }
RawTextMessage is the struct for the server message that is sent to the client to tell the client to display text as raw text in the terminal window.
type ServerMessage ¶
type ServerMessage interface {
Get() interface{}
}
ServerMessage is the interface that all messages from the server to client will implement.
func AppendErrorText ¶
func AppendErrorText(format string, a ...interface{}) ServerMessage
AppendErrorText create a ServerMessage for TextMessage error, format and args are used to create the text via Sprintf
func AppendNormalText ¶
func AppendNormalText(format string, a ...interface{}) ServerMessage
AppendNormalText create a ServerMessage for TextMessage normal, format and args are used to create the text via Sprintf
func AppendRawText ¶
func AppendRawText(text string) ServerMessage
AppendRawText will return a command packet that will append the raw text to the bottom of the output in the web terminal
func AppendText ¶
func AppendText(text, color string) ServerMessage
AppendText will return a command packet that will append the text to the bottom of the output in the web terminal. This will format the text message in the color defined.
func ClickableCommands ¶
func ClickableCommands(commands []string) ServerMessage
ClickableCommands will return a command packet that will append the raw text to the bottom of the output in the web terminal
func Cls ¶
func Cls() ServerMessage
Cls will return a command packet that will clear the current browser.
func Eval ¶
func Eval(text string) ServerMessage
Eval will return a command packet that will be evaluated on the client browser. The text is the javascript that will be evaluated.
func SetAuthenticated ¶
func SetAuthenticated(val bool) ServerMessage
SetAuthenticated will return a command packet that will notify the web terminal that the client has authenticated.
func SetEchoOn ¶
func SetEchoOn(val bool) ServerMessage
SetEchoOn will return a command packet that will set the echo state of text that is executed. Useful for disabling the display of the password entry in the auth process.
func SetHistoryMode ¶
func SetHistoryMode(val bool) ServerMessage
SetHistoryMode will return a command packet that will notify the web terminal that should capture/not capture commands entered into the client's history/
func SetPrompt ¶
func SetPrompt(prompt string) ServerMessage
SetPrompt will return a command packet that will set the prompt in the web terminal.
func SetStatus ¶
func SetStatus(text string) ServerMessage
SetStatus will return a command packet that will set the status in the html window. This is yet to be implemented on the client.
type ServerMessageBase ¶
type ServerMessageBase struct {
Type string `json:"type"`
}
ServerMessageBase is the base structure all server to client messages will use.
func (*ServerMessageBase) Get ¶
func (c *ServerMessageBase) Get() interface{}
Get will return the ServerMessageBase
type Status ¶
type Status struct { ServerMessageBase Text string `json:"text"` }
Status is the struct for the server message that is sent to the client to tell the client to set the status bar to the text defined in the message.
type TextMessage ¶
type TextMessage struct { ServerMessageBase Text string `json:"text"` Color string `json:"color"` }
TextMessage is the struct for the server message that is sent to the client to tell the client to display text in the terminal window.
type Token ¶
type Token struct { Role string `json:"role"` Email string `json:"email"` TokenString string `json:"token"` }
Token struct
type User ¶
type User struct { gorm.Model Name string `json:"name"` Email string `gorm:"unique" json:"email"` Password string `json:"password"` Role string `json:"role"` }
User struct
type WSClient ¶
type WSClient struct {
// contains filtered or unexported fields
}
WSClient is a middleman between the websocket connection and the hub.
func (*WSClient) History ¶
History returns the slice of commands that have been sent from the client to the server, for the existing client connection
func (*WSClient) HttpReq ¶
HttpReq returns Request for the current client to be able to access headers, cookies etc
func (*WSClient) IsAuthenticated ¶
IsAuthenticated returns the auth state of the client connection
func (*WSClient) IsConnected ¶
IsConnected returns the auth state of the client connection
func (*WSClient) Send ¶
func (c *WSClient) Send(msg ServerMessage)
Send push ServerMessage to client
func (*WSClient) SetExecLevel ¶
SetExecLevel sets exec level for the client
func (*WSClient) WriteStdErr ¶
WriteStdErr writes bytes out to client as error text
type WSClientWriter ¶
type WSClientWriter struct {
// contains filtered or unexported fields
}
WSClientWriter writer for clients