plugin

package
v0.0.0-...-e25afdc Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const T_ANY = 4
View Source
const T_DIR = 1
View Source
const T_FILE = 2
View Source
const T_SYMLINK = 3

Variables

This section is empty.

Functions

func OptsModule

func OptsModule(L *lua.LState) *lua.LTable

Types

type CmdArgs

type CmdArgs struct {
	RawArgs string
	// contains filtered or unexported fields
}

func (*CmdArgs) Array

func (args *CmdArgs) Array() []string

func (*CmdArgs) ArrayWithCommand

func (args *CmdArgs) ArrayWithCommand(cmd string) []string

func (*CmdArgs) ForEach

func (args *CmdArgs) ForEach(callback func(string, any))

func (*CmdArgs) Get

func (args *CmdArgs) Get(key string) any

func (*CmdArgs) Parse

func (args *CmdArgs) Parse()

func (*CmdArgs) ParseOpts

func (args *CmdArgs) ParseOpts(optsConfig *OptConfig, multiCharSingleDash bool) (map[string]any, []string, error)

type CommandFn

type CommandFn func(*CmdArgs, *Session)

type Config

type Config struct {
	CommandCallbacks    map[string]CommandFn
	PasswordInterceptor PasswordInterceptFn
	PromptFn            PromptFn
	LoginMessageFn      LoginMessageFn
	// contains filtered or unexported fields
}

func (*Config) Init

func (c *Config) Init()

func (*Config) RegisterCommand

func (c *Config) RegisterCommand(cmd, dir string, cmdFn CommandFn) bool

func (*Config) RegisterLoginMessage

func (c *Config) RegisterLoginMessage(loginMsgFn LoginMessageFn)

func (*Config) RegisterPasswordIntercept

func (c *Config) RegisterPasswordIntercept(interceptor PasswordInterceptFn)

func (*Config) RegisterPrompt

func (c *Config) RegisterPrompt(promptFn PromptFn)

type LoginMessageFn

type LoginMessageFn func(*Session) string

type OptConfig

type OptConfig struct {
	Opts       map[string]bool
	ParsedOpts map[string]any
	BareArgs   []string
}

func CreateOptsConfig

func CreateOptsConfig() *OptConfig

func (*OptConfig) AddBoth

func (o *OptConfig) AddBoth(short, long string, hasArg bool)

func (*OptConfig) AddOne

func (o *OptConfig) AddOne(arg string, hasArg bool)

func (*OptConfig) Get

func (o *OptConfig) Get(arg string) any

type PasswordInterceptFn

type PasswordInterceptFn func(string, string, *net.IP) bool

type Perm

type Perm struct {
	Read  bool
	Write bool
	Exec  bool
}

type Plugin

type Plugin struct {
	Path   string
	Dir    fs.DirEntry
	Main   fs.DirEntry
	L      *lua.LState
	Config *Config
	DB     *gorm.DB
	// contains filtered or unexported fields
}

func LoadPlugins

func LoadPlugins(path string, db *gorm.DB) ([]*Plugin, error)

func (*Plugin) CallPasswordInterceptor

func (p *Plugin) CallPasswordInterceptor(username, password string, ip *net.IP) bool

func (*Plugin) Commands

func (p *Plugin) Commands() map[string]CommandFn

func (*Plugin) GetPath

func (p *Plugin) GetPath(withMain bool) string

func (*Plugin) HasCommandDefined

func (p *Plugin) HasCommandDefined() bool

func (*Plugin) HasLoginMessage

func (p *Plugin) HasLoginMessage() bool

func (*Plugin) HasPasswordIntercept

func (p *Plugin) HasPasswordIntercept() bool

func (*Plugin) HasPromptFn

func (p *Plugin) HasPromptFn() bool

func (*Plugin) Init

func (p *Plugin) Init(vfs *VFS) error

func (*Plugin) SetVFS

func (p *Plugin) SetVFS(vfs *VFS)

type PluginManager

type PluginManager struct {
	DB        *gorm.DB
	PluginVFS *VFS

	PromptPlugin   PromptFn
	LoginMessageFn LoginMessageFn
	// contains filtered or unexported fields
}

func (*PluginManager) GetCommand

func (pm *PluginManager) GetCommand(cmd string) (CommandFn, bool)

func (*PluginManager) GetPasswordIntercepts

func (pm *PluginManager) GetPasswordIntercepts() []*Plugin

func (*PluginManager) LoadPlugins

func (pm *PluginManager) LoadPlugins(path string) error

func (*PluginManager) MatchCommand

func (pm *PluginManager) MatchCommand(part string) ([]CommandFn, []string)

type PromptFn

type PromptFn func(*Session) string

type Session

type Session struct {
	VFS     *VFS
	Term    *term.Terminal
	Manager *PluginManager

	User *User
	// contains filtered or unexported fields
}

func (*Session) AutoCompleteCallback

func (s *Session) AutoCompleteCallback(line string, pos int, key rune) (newLine string, newPos int, ok bool)

func (*Session) Chdir

func (s *Session) Chdir(newPath string) error

func (*Session) GetPWD

func (s *Session) GetPWD() string

func (*Session) TermWrite

func (s *Session) TermWrite(data ...string)

type TermWriteFn

type TermWriteFn func(...string)

type User

type User struct {
	Username string
	Group    string
}

type VFS

type VFS struct {
	Root VFSFile `json:"root"`
	Home string  `json:"home"`
	PWD  string  `json:"-"`
	User *User   `json:"-"`
}

func ReadVFSJSONFile

func ReadVFSJSONFile(path string) (*VFS, error)

ReadVFSJSONFile reads the JSON file which contains the the virtual file system model.

func (*VFS) FindFile

func (vfs *VFS) FindFile(path string) (string, *VFSFile, error)

func (*VFS) Mkdir

func (vfs *VFS) Mkdir(path string, mode os.FileMode) (*VFSFile, error)

func (*VFS) Rmfile

func (vfs *VFS) Rmfile(path string) error

func (*VFS) WriteFile

func (vfs *VFS) WriteFile(path, contents string) error

type VFSFile

type VFSFile struct {
	Type     int                `json:"t"`
	Name     string             `json:"n"`
	Files    map[string]VFSFile `json:"f"`
	Contents string             `json:"c"`
	Mode     os.FileMode        `json:"m"`
	Owner    string             `json:"o"`
	Group    string             `json:"g"`
	ModTime  time.Time          `json:"mt"`
	LinkTo   string             `json:"lt"`
	NLink    int                `json:"nl"`
	CmdFn    CommandFn          `json:"-"`
}

func (*VFSFile) CanAccess

func (f *VFSFile) CanAccess(user *User) Perm

func (*VFSFile) ForEach

func (f *VFSFile) ForEach(callback func(*VFSFile, int))

func (*VFSFile) StrMode

func (f *VFSFile) StrMode() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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