pkg

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2025 License: MIT Imports: 39 Imported by: 3 modules, 5 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

The function is used to provide the gin interface plug-in and dynamic parameter HTTP transfer

Index

Constants

View Source
const (
	Input          = '0'
	Ping           = '1'
	ResizeTerminal = '2'
	Heartbeat      = '3'
)

TODO: 标准化前端输入类型 xtermjs eventListener

View Source
const (
	Output         = '0'
	Pong           = '1'
	SetWindowTitle = '2'
	SetPreferences = '3'
	SetReconnect   = '4'
)

后端控制前端

Variables

View Source
var (
	PrivateKey string
	PublicKey  string
)
View Source
var Static embed.FS
View Source
var Views embed.FS

Functions

func Admin

func Admin(c *gin.Context)

func AuthMiddleware added in v1.0.2

func AuthMiddleware(accounts gin.Accounts) gin.HandlerFunc

func Check

func Check(c *gin.Context)

func DecodeBase64

func DecodeBase64(in string) (string, error)

解密base64

func DecodeBase64Bytes

func DecodeBase64Bytes(in string) ([]byte, error)

解密base64

func EncodeBase64

func EncodeBase64(in string) string

加密base64

func GenerateRSAKey

func GenerateRSAKey(bits int) error

生成RSA私钥和公钥,保存到文件中

func GetIPs

func GetIPs() (ips []string)

func GetRandomSalt

func GetRandomSalt() string

return len=8 salt

func GetRandomString

func GetRandomString(len int) string

生成随机字符串

func Home

func Home() (string, error)

Home returns the home directory for the executing user.

This uses an OS-specific method for discovering the home directory. An error is returned if a home directory cannot be detected.

func Index

func Index(c *gin.Context)

func InitBoltDB

func InitBoltDB() *storm.DB

func IsPathExists

func IsPathExists(path string) bool

func RegisterTty

func RegisterTty(router *gin.Engine, data *Tty)

isLocal 参数是用于判断是否为第三方引用,进而改变访问路径

func RsaDecrypt

func RsaDecrypt(ciphertext []byte) ([]byte, error)

解密RSA

func RsaEncrypt

func RsaEncrypt(origData []byte) ([]byte, error)

加密RSA

func ServeGin

func ServeGin(data *Tty)

func ServeGin(data.Host,data.Port, username, password, crtpath, keypath string, cmds []string, isdebug, isReconnect, isPermitWrite, isAudit, isXsrf, isProf, enabletls bool, MaxConnections int64) {

func TlsHandler

func TlsHandler(host, port string) gin.HandlerFunc

func Who

func Who(c *gin.Context)

func Ws

func Ws(c *gin.Context)

Types

type Aduit

type Aduit struct {
	Id         int64     `json:"id" storm:"id,increment"`
	Remoteaddr string    `json:"remoteaddr"`
	Token      string    `json:"token" `
	Command    string    `json:"command"`
	Pid        int       `json:"pid"`
	Status     string    `json:"status"`
	Created    time.Time `json:"created"`
}

TODO cgo效率太低 后期转mmap或者bbolt

func GetAduit

func GetAduit(name string) ([]Aduit, error)

func (*Aduit) Save

func (this *Aduit) Save() error

type ClientContext

type ClientContext struct {
	Xtermjs *XtermJs        // 前端配置
	Request *http.Request   // http客户端请求
	WsConn  *websocket.Conn // websocket连接
	Cmd     *exec.Cmd       // exec.Command实例
	Pty     *os.File        // 命令行pty代理
	// Cache      *bytes.Buffer   // 命令缓存
	// CacheMutex *sync.Mutex     // 缓存并发锁
	WriteMutex *sync.Mutex // 并发安全 通过ws发送给客户
}

服务端内部处理对象

func (*ClientContext) HandleClient

func (this *ClientContext) HandleClient()

处理请求 三个go 无阻赛

func (*ClientContext) ParseXsrf

func (this *ClientContext) ParseXsrf(info []byte) (string, string, bool)

xsrf验证 token = xsrf + request.remoteAddr

func (*ClientContext) Receive

func (this *ClientContext) Receive(quitChan chan bool)

获取用户发送命令 发送到pty进行执行

func (*ClientContext) Send

func (this *ClientContext) Send(quitChan chan bool)

发送命令的执行结果 不执行具体任务

type Lflxp

type Lflxp interface {
	Check() error
	Execute() error
}

type Options

type Options struct {
	PermitWrite      bool
	MaxConnections   int64
	CloseSignal      int
	Audit            bool
	Xsrf             bool
	EnableTLS        bool
	CrtPath, KeyPath string
	IsReconnect      bool
	IsDebug          bool
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

原本是命令端http server管理,这里后期可以改成gin server管理 单线程等待

func NewServer

func NewServer() *Server

func (*Server) DoneGo

func (this *Server) DoneGo()

func (*Server) StartGo

func (this *Server) StartGo()

func (*Server) WaitGo

func (this *Server) WaitGo()

type Tty

type Tty struct {
	EnableTLS      bool
	CrtPath        string
	KeyPath        string
	IsProf         bool
	IsXsrf         bool
	IsAudit        bool
	IsPermitWrite  bool
	MaxConnections int64
	IsReconnect    bool
	IsDebug        bool
	Username       string
	Password       string
	Port           string
	Host           string
	Cmds           []string
	Url            string
}

func (*Tty) Check

func (this *Tty) Check() error

func (*Tty) Execute

func (this *Tty) Execute() error

type Whos

type Whos struct {
	Id         int64     `json:"id" storm:"id,increment"`
	Remoteaddr string    `json:"remoteaddr"`
	Path       string    `json:"path"`
	Created    time.Time `json:"created"`
}

记录谁来访问过

func GetWhos

func GetWhos(name string) ([]Whos, error)

func (*Whos) Save

func (this *Whos) Save() error

type XtermJs

type XtermJs struct {
	Title       string
	Server      *Server
	Options     Options
	Connections *int64   // 统计连接数
	XsrfToken   sync.Map // xsrftoken存储
	Cmds        []string // 命令集
}

xtermjs前端配置

Jump to

Keyboard shortcuts

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