agent

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2024 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version string
	Config  string
	Dir     string
)
View Source
var ForwardTaskHandlers = map[string]map[string]ForwardTaskHandleFunc{
	"add": {
		"IPTABLES": handleForwardTaskAddIptables,
		"GOST":     handleForwardTaskAddGOST,
	},
	"delete": {
		"IPTABLES": handleForwardTaskDeleteIptables,
		"GOST":     handleForwardTaskDeleteGOST,
	},
}
View Source
var JobDefinitions = map[string]any{
	"AGENT_REPORT_STAT_JOB":    ReportStatExecutor,
	"AGENT_REPORT_TRAFFIC_JOB": ReportTrafficExecutor,
}
View Source
var LogDestinations = []string{"console", "remote"}
View Source
var LogLevels = []string{"debug", "info", "warn", "error", "panic", "fatal"}
View Source
var LogR *zap.Logger
View Source
var TaskHandlers = map[string]TaskHandleFunc{
	"hello": func(task Task) (interface{}, error) {
		GlobalAgent.ReportTaskResult(task.Id, true, "hello")
		return "hello", nil
	},
	"config_change": handleConfigChange,
	"forward":       handleForwardTask,
	"shell":         handleShellTask,
	"ping":          handlePingTask,
	"report_stat": func(task Task) (interface{}, error) {
		ReportStatExecutor()
		GlobalAgent.ReportTaskResult(task.Id, true, "请检查日志中的状态报告")
		return nil, nil
	},
	"report_traffic": func(task Task) (interface{}, error) {
		ReportTrafficExecutor()
		GlobalAgent.ReportTaskResult(task.Id, true, "请检查日志中的流量报告")
		return nil, nil
	},
}

Functions

func AddPortTrafficMonitor

func AddPortTrafficMonitor(localPort int, remoteHost string, remotePort int)

func Decrypt

func Decrypt(encryptedData string, key []byte) ([]byte, error)

func DeletePortTrafficMonitor

func DeletePortTrafficMonitor(localPort int)

func GenerateUnusedPort

func GenerateUnusedPort() int

func GetRandomPort

func GetRandomPort() int

func InitLog

func InitLog(level string, destination string)

func PortIsUsed

func PortIsUsed(port int) bool

func ReInitLog

func ReInitLog(level string)

func ReportStatExecutor

func ReportStatExecutor()

func ReportTrafficExecutor

func ReportTrafficExecutor()

func SelectAvailablePort

func SelectAvailablePort(port *int)

func ShellExecutor

func ShellExecutor(shell Shell) []byte

func Sign

func Sign(payload interface{}, secret string) string

func SyncLog

func SyncLog()

func ValidateLogDest

func ValidateLogDest(logDest string) error

func ValidateLogLevel

func ValidateLogLevel(logLevel string) error

Types

type Agent

type Agent struct {
	AgentId   string
	DB        *redis.Client
	Scheduler gocron.Scheduler
	Jobs      map[string]gocron.Job
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(option Options, agentId string) *Agent

func (*Agent) GetConfig

func (agent *Agent) GetConfig(key string) string

func (*Agent) GetConfigWithGlobal

func (agent *Agent) GetConfigWithGlobal(key string, global bool) string

func (*Agent) Ready

func (agent *Agent) Ready() bool

func (*Agent) ReportLog

func (agent *Agent) ReportLog(log string)

func (*Agent) ReportStat

func (agent *Agent) ReportStat(status string)

func (*Agent) ReportTaskResult

func (agent *Agent) ReportTaskResult(taskId string, success bool, extra string)

func (*Agent) ReportTraffic

func (agent *Agent) ReportTraffic(traffic string)

func (*Agent) Start

func (agent *Agent) Start(ctx context.Context)

func (*Agent) Stop

func (agent *Agent) Stop()

func (*Agent) UpdateJobCron

func (agent *Agent) UpdateJobCron(cronKey string)

type CPUInfo

type CPUInfo struct {
	ModelName string  `json:"modelName"`
	Cores     int32   `json:"cores"`
	Mhz       float64 `json:"mhz"`
}

type ConfigChangeTask

type ConfigChangeTask struct {
	Task
	Key   string
	Value string
}

type ForwardTask

type ForwardTask struct {
	Task
	Action     string
	Method     string
	Options    json.RawMessage
	ForwardId  string
	AgentPort  int
	TargetPort int
	Target     string
}

type ForwardTaskHandleFunc

type ForwardTaskHandleFunc func(forwardTask ForwardTask) (interface{}, error)

type ForwardTaskResult

type ForwardTaskResult struct {
	AgentPort int `json:"agentPort"`
}

type IAgent

type IAgent interface {
	Start(ctx context.Context)
	Stop()
	Ready() bool
	GetConfig(key string) string
	GetConfigWithGlobal(key string, global bool) string
	ReportStat(stat string)
	ReportTraffic(traffic string)
	ReportTaskResult(taskId string, success bool, extra string)
	ReportLog(log string)

	UpdateJobCron(cronKey string)
}
var GlobalAgent IAgent

type IpInfo

type IpInfo struct {
	IPv4       string `json:"ipv4"`
	IPv6       string `json:"ipv6"`
	CountryISO string `json:"country"`
}

func (*IpInfo) String

func (ipInfo *IpInfo) String() string

type Options

type Options struct {
	Addr     string `json:"addr"`
	Username string `json:"username"`
	Password string `json:"password"`
	DB       int    `json:"db"`
}

type PingTask

type PingTask struct {
	Task
	Host    string
	Count   int
	TimeOut int64
}

type RemoteWriteSyncer

type RemoteWriteSyncer struct {
}

func (RemoteWriteSyncer) Write

func (r RemoteWriteSyncer) Write(p []byte) (n int, err error)

type Shell

type Shell struct {
	Command  string
	Args     []string
	Internal bool
}

type ShellTask

type ShellTask struct {
	Task
	Shell    string
	Internal bool
}

type Task

type Task struct {
	Id         string
	Type       string
	OriginData []byte
}

type TaskHandleFunc

type TaskHandleFunc func(task Task) (interface{}, error)

type TaskResult

type TaskResult struct {
	Id      string `json:"id"`
	Success bool   `json:"success"`
	Extra   string `json:"extra"`
}

Jump to

Keyboard shortcuts

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