panel

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	None    = 0
	Tls     = 1
	Reality = 2
)

Security type

Variables

This section is empty.

Functions

This section is empty.

Types

type AliveMap

type AliveMap struct {
	Alive map[int]int `json:"alive"`
}

type AnyTlsNode

type AnyTlsNode struct {
	CommonNode
	TlsSettings     TlsSettings  `json:"tls_settings"`
	TlsSettingsBack *TlsSettings `json:"tlsSettings"`
	PaddingScheme   []string     `json:"padding_scheme,omitempty"`
}

type BaseConfig

type BaseConfig struct {
	PushInterval any `json:"push_interval"`
	PullInterval any `json:"pull_interval"`
}

type Client

type Client struct {
	APIHost   string
	APISendIP string
	Token     string
	NodeType  string
	NodeId    int

	UserList *UserListBody
	AliveMap *AliveMap
	// contains filtered or unexported fields
}

func New

func New(c *conf.ApiConfig) (*Client, error)

func (*Client) APIStats added in v0.8.3

func (c *Client) APIStats() (success, failure int64)

APIStats returns the cumulative panel-API call counters used by the metrics task. Reads are lock-free.

func (*Client) Debug

func (c *Client) Debug()

Debug set the client debug for client

func (*Client) GetNodeInfo

func (c *Client) GetNodeInfo() (node *NodeInfo, err error)

func (*Client) GetUserAlive

func (c *Client) GetUserAlive() (map[int]int, error)

GetUserAlive will fetch the alive_ip count for users

func (*Client) GetUserList

func (c *Client) GetUserList() ([]UserInfo, error)

GetUserList will pull user from v2board

func (*Client) ReportNodeMetrics added in v0.8.2

func (c *Client) ReportNodeMetrics(metrics *NodeMetrics) error

ReportNodeMetrics pushes the rich runtime metrics to the panel. Preferred transport is the WebSocket `node.status` event because X-Board handles it inline (NodeEventHandlers::handleNodeStatus → updateMetrics) — that's the same path the official Xboard-Node uses to populate the admin popup.

HTTP fallback is the V2 unified `/api/v2/server/report` endpoint with only the `metrics` field set; the controller treats each section as independent so we don't disturb traffic/alive/online/status reporting which continues to flow through the existing V1 paths.

Path is intentionally /api/v2/server/report — the route is registered as prefix "server" + POST "report" inside the V2 route group (/api/v2). An earlier version sent /node/report which 404'd against every panel.

func (*Client) ReportNodeOnlineUsers

func (c *Client) ReportNodeOnlineUsers(data *map[int][]string) error

func (*Client) ReportNodeStatus added in v0.7.0

func (c *Client) ReportNodeStatus(status *NodeStatus) error

ReportNodeStatus pushes the cpu/mem/swap/disk load snapshot to the panel over HTTP. Matches the schema validated by UniProxyController::status in X-Board — the only legacy V1 path that accepts it.

func (*Client) ReportUserTraffic

func (c *Client) ReportUserTraffic(userTraffic []UserTraffic) error

ReportUserTraffic reports the user traffic

func (*Client) SetAliveUpdateHook added in v0.9.0

func (c *Client) SetAliveUpdateHook(hook func(map[int]int))

SetAliveUpdateHook lets the node controller consume real-time device-state pushes from the panel without making the panel package depend on limiter.

func (*Client) StartWebSocket added in v0.8.0

func (c *Client) StartWebSocket()

StartWebSocket spawns the optional WebSocket driver if WebSocket.Enabled is set in config. When disabled the function is a no-op. Safe to call at most once per Client; invoked by the node bootstrap after the HTTP client is confirmed working.

func (*Client) StopWebSocket added in v0.8.0

func (c *Client) StopWebSocket()

StopWebSocket tears down the driver if present. Idempotent.

func (*Client) WebSocketConnected added in v0.8.3

func (c *Client) WebSocketConnected() bool

WebSocketConnected reports whether the WS driver currently has a live session to the panel.

func (*Client) WebSocketEnabled added in v0.8.3

func (c *Client) WebSocketEnabled() bool

WebSocketEnabled exposes the operator-configured opt-in flag so the metrics task can decide whether the popup should render the WS row.

type CommonNode

type CommonNode struct {
	Host       string           `json:"host"`
	ServerPort int              `json:"server_port"`
	ServerName string           `json:"server_name"`
	Routes     []Route          `json:"routes"`
	BaseConfig *BaseConfig      `json:"base_config"`
	CertConfig *conf.CertConfig `json:"cert_config"`
}

type ECHSettings added in v0.8.6

type ECHSettings struct {
	Enabled         bool   `json:"enabled"`
	Config          string `json:"config"`
	QueryServerName string `json:"query_server_name"`
	Key             string `json:"key"`
	KeyPath         string `json:"key_path"`
	ConfigPath      string `json:"config_path"`
}

type EncSettings

type EncSettings struct {
	Mode          string `json:"mode"`
	Ticket        string `json:"ticket"`
	ServerPadding string `json:"server_padding"`
	PrivateKey    string `json:"private_key"`
}

type NodeInfo

type NodeInfo struct {
	Id           int
	Type         string
	Security     int
	PushInterval time.Duration
	PullInterval time.Duration
	RawDNS       RawDNS
	Rules        Rules

	// origin
	VAllss      *VAllssNode
	AnyTls      *AnyTlsNode
	Shadowsocks *ShadowsocksNode
	Trojan      *TrojanNode
	Common      *CommonNode
	CertConfig  *conf.CertConfig
}

type NodeMetrics added in v0.8.2

type NodeMetrics struct {
	Uptime            int64               `json:"uptime"`
	Goroutines        int                 `json:"goroutines"`
	ActiveConnections int                 `json:"active_connections"`
	TotalConnections  int                 `json:"total_connections"`
	TotalUsers        int                 `json:"total_users"`
	ActiveUsers       int                 `json:"active_users"`
	InboundSpeed      int64               `json:"inbound_speed"`
	OutboundSpeed     int64               `json:"outbound_speed"`
	CPUPerCore        []float64           `json:"cpu_per_core"`
	Load              *NodeMetricsLoad    `json:"load,omitempty"`
	SpeedLimiter      *NodeMetricsLimiter `json:"speed_limiter,omitempty"`
	GC                *NodeMetricsGC      `json:"gc,omitempty"`
	API               *NodeMetricsAPI     `json:"api,omitempty"`
	WS                *NodeMetricsWS      `json:"ws,omitempty"`
	Limits            *NodeMetricsLimits  `json:"limits,omitempty"`
	KernelStatus      bool                `json:"kernel_status"`
}

NodeMetrics mirrors the shape consumed by X-Board's ServerService::updateMetrics. Each sub-struct uses the exact JSON keys that the admin frontend (resources/admin) reads via dotted access — e.g. `metrics.load.load5`, `metrics.api.success`, `metrics.ws.connected`. If any of these are sent as arrays or unkeyed maps the popup hides the row.

Every field is optional from the panel's point of view (zeroes are accepted), so the agent can fill what it knows and leave the rest empty without breaking validation.

type NodeMetricsAPI added in v0.8.3

type NodeMetricsAPI struct {
	Success int64 `json:"success"`
	Failure int64 `json:"failure"`
}

NodeMetricsAPI tracks panel-API call counters surfaced as the lightning row "success/failure". The frontend pulses red when failure > 0.

type NodeMetricsGC added in v0.8.3

type NodeMetricsGC struct {
	LastPauseMs float64 `json:"last_pause_ms"`
}

NodeMetricsGC carries Go GC pause info. Optional — the frontend only appends "(Xms)" after kernel_status when last_pause_ms is set.

type NodeMetricsLimiter added in v0.8.3

type NodeMetricsLimiter struct {
	HasLimits    bool `json:"has_limits"`
	LimitedUsers int  `json:"limited_users"`
}

NodeMetricsLimiter reports active speed-limiting state. has_limits gates the destructive "X Limit" row; limited_users is the count shown.

type NodeMetricsLimits added in v0.8.3

type NodeMetricsLimits struct {
	DeviceLimitEvents int `json:"device_limit_events"`
}

NodeMetricsLimits is the device-limit event counter. Falls back path for the Limit row when speed_limiter has nothing to report.

type NodeMetricsLoad added in v0.8.3

type NodeMetricsLoad struct {
	Load1  float64 `json:"load1"`
	Load5  float64 `json:"load5"`
	Load15 float64 `json:"load15"`
}

NodeMetricsLoad maps to `metrics.load.{load1,load5,load15}` on the frontend; the popup specifically renders `load.load5.toFixed(2)`.

type NodeMetricsWS added in v0.8.3

type NodeMetricsWS struct {
	Enabled   bool `json:"enabled"`
	Connected bool `json:"connected"`
}

NodeMetricsWS reports the WebSocket driver state. The frontend only renders the WS-OK/WS-ERR row when Enabled is true.

type NodeStatus added in v0.7.0

type NodeStatus struct {
	Cpu  float64       `json:"cpu"`
	Mem  NodeStatusMem `json:"mem"`
	Swap NodeStatusMem `json:"swap"`
	Disk NodeStatusMem `json:"disk"`
}

NodeStatus is the payload reported to X-Board's /UniProxy/status endpoint. All totals/used values are in bytes; Cpu is a percentage in [0, 100].

IMPORTANT: This payload is *only* delivered over HTTP. The WebSocket event `node.status` is reserved for NodeMetrics — feeding the cpu/mem/swap/disk shape into it would cause X-Board's NodeEventHandlers::handleNodeStatus to call ServerService::updateMetrics with mismatched fields, polluting the METRICS cache with zeros for uptime/goroutines/etc.

type NodeStatusMem added in v0.7.0

type NodeStatusMem struct {
	Total uint64 `json:"total"`
	Used  uint64 `json:"used"`
}

type OnlineUser

type OnlineUser struct {
	UID int
	IP  string
}

type RawDNS

type RawDNS struct {
	DNSMap  map[string]map[string]interface{}
	DNSJson []byte
}

type RealityConfig

type RealityConfig struct {
	Xver         uint64 `json:"Xver"`
	MinClientVer string `json:"MinClientVer"`
	MaxClientVer string `json:"MaxClientVer"`
	MaxTimeDiff  string `json:"MaxTimeDiff"`
}

type Route

type Route struct {
	Id          int         `json:"id"`
	Match       interface{} `json:"match"`
	Action      string      `json:"action"`
	ActionValue string      `json:"action_value"`
}

type Rules

type Rules struct {
	Regexp   []string
	Protocol []string
}

type ShadowsocksNode

type ShadowsocksNode struct {
	CommonNode
	Cipher    string `json:"cipher"`
	ServerKey string `json:"server_key"`
}

type TlsSettings

type TlsSettings struct {
	ServerName    string       `json:"server_name"`
	AllowInsecure bool         `json:"allow_insecure"`
	Dest          string       `json:"dest"`
	ServerPort    string       `json:"server_port"`
	ShortId       string       `json:"short_id"`
	PrivateKey    string       `json:"private_key"`
	Mldsa65Seed   string       `json:"mldsa65Seed"`
	Xver          uint64       `json:"xver,string"`
	Ech           *ECHSettings `json:"ech"`
}

type TrojanNode

type TrojanNode struct {
	CommonNode
	Network         string          `json:"network"`
	NetworkSettings json.RawMessage `json:"networkSettings"`
	TlsSettings     TlsSettings     `json:"tls_settings"`
	TlsSettingsBack *TlsSettings    `json:"tlsSettings"`
}

type UserInfo

type UserInfo struct {
	Id          int    `json:"id" msgpack:"id"`
	Uuid        string `json:"uuid" msgpack:"uuid"`
	SpeedLimit  int    `json:"speed_limit" msgpack:"speed_limit"`
	DeviceLimit int    `json:"device_limit" msgpack:"device_limit"`
}

type UserListBody

type UserListBody struct {
	Users []UserInfo `json:"users" msgpack:"users"`
}

type UserTraffic

type UserTraffic struct {
	UID      int
	Upload   int64
	Download int64
}

type VAllssNode

type VAllssNode struct {
	CommonNode
	Tls                 int             `json:"tls"`
	TlsSettings         TlsSettings     `json:"tls_settings"`
	TlsSettingsBack     *TlsSettings    `json:"tlsSettings"`
	Network             string          `json:"network"`
	NetworkSettings     json.RawMessage `json:"network_settings"`
	NetworkSettingsBack json.RawMessage `json:"networkSettings"`
	Encryption          string          `json:"encryption"`
	EncryptionSettings  EncSettings     `json:"encryption_settings"`
	ServerName          string          `json:"server_name"`

	// vless only
	Flow          string        `json:"flow"`
	RealityConfig RealityConfig `json:"-"`
}

VAllssNode is vmess and vless node info

Jump to

Keyboard shortcuts

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