feat: remove unused plugin version comparison and types, refactor proxy server to support authentication
- Deleted version comparison logic from `pkg/plugin/sign/version.go`. - Removed unused types and constants from `pkg/plugin/types.go`. - Updated `pkg/protocol/message.go` to remove plugin-related message types. - Enhanced `pkg/proxy/http.go` and `pkg/proxy/socks5.go` to include username/password authentication for HTTP and SOCKS5 proxies. - Modified `pkg/proxy/server.go` to pass authentication parameters to server constructors. - Added new API endpoint to generate installation commands with a token for clients. - Created database functions to manage installation tokens in `internal/server/db/install_token.go`. - Implemented the installation command generation logic in `internal/server/router/handler/install.go`. - Updated web frontend to support installation command generation and display in `web/src/views/ClientsView.vue`.
This commit is contained in:
@@ -26,34 +26,11 @@ const (
|
||||
MsgTypeProxyConnect uint8 = 9 // 代理连接请求 (SOCKS5/HTTP)
|
||||
MsgTypeProxyResult uint8 = 10 // 代理连接结果
|
||||
|
||||
// Plugin 相关消息
|
||||
MsgTypePluginList uint8 = 20 // 请求/响应可用 plugins
|
||||
MsgTypePluginDownload uint8 = 21 // 请求下载 plugin
|
||||
MsgTypePluginData uint8 = 22 // Plugin 二进制数据(分块)
|
||||
MsgTypePluginReady uint8 = 23 // Plugin 加载确认
|
||||
|
||||
// UDP 相关消息
|
||||
MsgTypeUDPData uint8 = 30 // UDP 数据包
|
||||
|
||||
// 插件安装消息
|
||||
MsgTypeInstallPlugins uint8 = 24 // 服务端推送安装插件列表
|
||||
MsgTypePluginConfig uint8 = 25 // 插件配置同步
|
||||
|
||||
// 客户端插件消息
|
||||
MsgTypeClientPluginStart uint8 = 40 // 启动客户端插件
|
||||
MsgTypeClientPluginStop uint8 = 41 // 停止客户端插件
|
||||
MsgTypeClientPluginStatus uint8 = 42 // 客户端插件状态
|
||||
MsgTypeClientPluginConn uint8 = 43 // 客户端插件连接请求
|
||||
MsgTypePluginStatusQuery uint8 = 44 // 查询所有插件状态
|
||||
MsgTypePluginStatusQueryResp uint8 = 45 // 插件状态查询响应
|
||||
|
||||
// JS 插件动态安装
|
||||
MsgTypeJSPluginInstall uint8 = 50 // 安装 JS 插件
|
||||
MsgTypeJSPluginResult uint8 = 51 // 安装结果
|
||||
|
||||
// 客户端控制消息
|
||||
MsgTypeClientRestart uint8 = 60 // 重启客户端
|
||||
MsgTypePluginConfigUpdate uint8 = 61 // 更新插件配置
|
||||
MsgTypeClientRestart uint8 = 60 // 重启客户端
|
||||
|
||||
// 更新相关消息
|
||||
MsgTypeUpdateCheck uint8 = 70 // 检查更新请求
|
||||
@@ -68,10 +45,6 @@ const (
|
||||
MsgTypeLogData uint8 = 81 // 日志数据
|
||||
MsgTypeLogStop uint8 = 82 // 停止日志流
|
||||
|
||||
// 插件 API 路由消息
|
||||
MsgTypePluginAPIRequest uint8 = 90 // 插件 API 请求
|
||||
MsgTypePluginAPIResponse uint8 = 91 // 插件 API 响应
|
||||
|
||||
// 系统状态消息
|
||||
MsgTypeSystemStatsRequest uint8 = 100 // 请求系统状态
|
||||
MsgTypeSystemStatsResponse uint8 = 101 // 系统状态响应
|
||||
@@ -111,22 +84,17 @@ type AuthResponse struct {
|
||||
// ProxyRule 代理规则
|
||||
type ProxyRule struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Type string `json:"type" yaml:"type"` // 内置: tcp, udp, http, https, websocket; 插件: socks5 等
|
||||
Type string `json:"type" yaml:"type"` // tcp, udp, http, https, socks5
|
||||
LocalIP string `json:"local_ip" yaml:"local_ip"` // tcp/udp 模式使用
|
||||
LocalPort int `json:"local_port" yaml:"local_port"` // tcp/udp 模式使用
|
||||
RemotePort int `json:"remote_port" yaml:"remote_port"` // 服务端监听端口
|
||||
Enabled *bool `json:"enabled,omitempty" yaml:"enabled"` // 是否启用,默认为 true
|
||||
// Plugin 支持字段
|
||||
PluginID string `json:"plugin_id,omitempty" yaml:"plugin_id"` // 插件实例ID
|
||||
PluginName string `json:"plugin_name,omitempty" yaml:"plugin_name"`
|
||||
PluginVersion string `json:"plugin_version,omitempty" yaml:"plugin_version"`
|
||||
PluginConfig map[string]string `json:"plugin_config,omitempty" yaml:"plugin_config"`
|
||||
// HTTP Basic Auth 字段 (用于独立端口模式)
|
||||
// HTTP Basic Auth 字段
|
||||
AuthEnabled bool `json:"auth_enabled,omitempty" yaml:"auth_enabled"`
|
||||
AuthUsername string `json:"auth_username,omitempty" yaml:"auth_username"`
|
||||
AuthPassword string `json:"auth_password,omitempty" yaml:"auth_password"`
|
||||
// 插件管理标记 - 由插件自动创建的规则,不允许手动编辑/删除
|
||||
PluginManaged bool `json:"plugin_managed,omitempty" yaml:"plugin_managed"`
|
||||
// 端口状态: "listening", "failed: <error message>", ""
|
||||
PortStatus string `json:"port_status,omitempty" yaml:"-"`
|
||||
}
|
||||
|
||||
// IsEnabled 检查规则是否启用,默认为 true
|
||||
@@ -164,60 +132,6 @@ type ProxyConnectResult struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// PluginMetadata Plugin 元数据(协议层)
|
||||
type PluginMetadata struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Checksum string `json:"checksum"`
|
||||
Size int64 `json:"size"`
|
||||
Description string `json:"description,omitempty"`
|
||||
}
|
||||
|
||||
// PluginListRequest 请求可用 plugins
|
||||
type PluginListRequest struct {
|
||||
ClientVersion string `json:"client_version"`
|
||||
}
|
||||
|
||||
// PluginListResponse 返回可用 plugins
|
||||
type PluginListResponse struct {
|
||||
Plugins []PluginMetadata `json:"plugins"`
|
||||
}
|
||||
|
||||
// PluginDownloadRequest 请求下载 plugin
|
||||
type PluginDownloadRequest struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
}
|
||||
|
||||
// PluginDataChunk Plugin 二进制数据块
|
||||
type PluginDataChunk struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
ChunkIndex int `json:"chunk_index"`
|
||||
TotalChunks int `json:"total_chunks"`
|
||||
Data []byte `json:"data"`
|
||||
Checksum string `json:"checksum,omitempty"`
|
||||
}
|
||||
|
||||
// PluginReadyNotification Plugin 加载确认
|
||||
type PluginReadyNotification struct {
|
||||
Name string `json:"name"`
|
||||
Version string `json:"version"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// InstallPluginsRequest 安装插件请求
|
||||
type InstallPluginsRequest struct {
|
||||
Plugins []string `json:"plugins"` // 要安装的插件名称列表
|
||||
}
|
||||
|
||||
// PluginConfigSync 插件配置同步
|
||||
type PluginConfigSync struct {
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
Config map[string]string `json:"config"` // 配置内容
|
||||
}
|
||||
|
||||
// UDPPacket UDP 数据包
|
||||
type UDPPacket struct {
|
||||
RemotePort int `json:"remote_port"` // 服务端监听端口
|
||||
@@ -225,67 +139,6 @@ type UDPPacket struct {
|
||||
Data []byte `json:"data"` // UDP 数据
|
||||
}
|
||||
|
||||
// ClientPluginStartRequest 启动客户端插件请求
|
||||
type ClientPluginStartRequest struct {
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
RuleName string `json:"rule_name"` // 规则名称
|
||||
RemotePort int `json:"remote_port"` // 服务端监听端口
|
||||
Config map[string]string `json:"config"` // 插件配置
|
||||
}
|
||||
|
||||
// ClientPluginStopRequest 停止客户端插件请求
|
||||
type ClientPluginStopRequest struct {
|
||||
PluginID string `json:"plugin_id,omitempty"` // 插件ID(优先使用)
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
RuleName string `json:"rule_name"` // 规则名称
|
||||
}
|
||||
|
||||
// ClientPluginStatusResponse 客户端插件状态响应
|
||||
type ClientPluginStatusResponse struct {
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
RuleName string `json:"rule_name"` // 规则名称
|
||||
Running bool `json:"running"` // 是否运行中
|
||||
LocalAddr string `json:"local_addr"` // 本地监听地址
|
||||
Error string `json:"error"` // 错误信息
|
||||
}
|
||||
|
||||
// ClientPluginConnRequest 客户端插件连接请求
|
||||
type ClientPluginConnRequest struct {
|
||||
PluginID string `json:"plugin_id,omitempty"` // 插件ID(优先使用)
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
RuleName string `json:"rule_name"` // 规则名称
|
||||
}
|
||||
|
||||
// PluginStatusEntry 单个插件状态
|
||||
type PluginStatusEntry struct {
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
Running bool `json:"running"` // 是否运行中
|
||||
}
|
||||
|
||||
// PluginStatusQueryResponse 插件状态查询响应
|
||||
type PluginStatusQueryResponse struct {
|
||||
Plugins []PluginStatusEntry `json:"plugins"` // 所有插件状态
|
||||
}
|
||||
|
||||
// JSPluginInstallRequest JS 插件安装请求
|
||||
type JSPluginInstallRequest struct {
|
||||
PluginID string `json:"plugin_id"` // 插件实例唯一 ID
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
Source string `json:"source"` // JS 源码
|
||||
Signature string `json:"signature"` // 官方签名 (Base64)
|
||||
RuleName string `json:"rule_name"` // 规则名称
|
||||
RemotePort int `json:"remote_port"` // 服务端监听端口
|
||||
Config map[string]string `json:"config"` // 插件配置
|
||||
AutoStart bool `json:"auto_start"` // 是否自动启动
|
||||
}
|
||||
|
||||
// JSPluginInstallResult JS 插件安装结果
|
||||
type JSPluginInstallResult struct {
|
||||
PluginName string `json:"plugin_name"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// ClientRestartRequest 客户端重启请求
|
||||
type ClientRestartRequest struct {
|
||||
Reason string `json:"reason,omitempty"` // 重启原因
|
||||
@@ -297,23 +150,6 @@ type ClientRestartResponse struct {
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// PluginConfigUpdateRequest 插件配置更新请求
|
||||
type PluginConfigUpdateRequest struct {
|
||||
PluginID string `json:"plugin_id,omitempty"` // 插件ID(优先使用)
|
||||
PluginName string `json:"plugin_name"` // 插件名称
|
||||
RuleName string `json:"rule_name"` // 规则名称
|
||||
Config map[string]string `json:"config"` // 新配置
|
||||
Restart bool `json:"restart"` // 是否重启插件
|
||||
}
|
||||
|
||||
// PluginConfigUpdateResponse 插件配置更新响应
|
||||
type PluginConfigUpdateResponse struct {
|
||||
PluginName string `json:"plugin_name"`
|
||||
RuleName string `json:"rule_name"`
|
||||
Success bool `json:"success"`
|
||||
Error string `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
// UpdateCheckRequest 更新检查请求
|
||||
type UpdateCheckRequest struct {
|
||||
Component string `json:"component"` // "server" 或 "client"
|
||||
@@ -367,7 +203,7 @@ type LogEntry struct {
|
||||
Timestamp int64 `json:"ts"` // Unix 时间戳 (毫秒)
|
||||
Level string `json:"level"` // 日志级别: debug, info, warn, error
|
||||
Message string `json:"msg"` // 日志消息
|
||||
Source string `json:"src"` // 来源: client, plugin:<name>
|
||||
Source string `json:"src"` // 来源: client
|
||||
}
|
||||
|
||||
// LogData 日志数据
|
||||
@@ -382,25 +218,6 @@ type LogStopRequest struct {
|
||||
SessionID string `json:"session_id"` // 会话 ID
|
||||
}
|
||||
|
||||
// PluginAPIRequest 插件 API 请求
|
||||
type PluginAPIRequest struct {
|
||||
PluginID string `json:"plugin_id"` // 插件实例唯一 ID
|
||||
PluginName string `json:"plugin_name"` // 插件名称 (向后兼容)
|
||||
Method string `json:"method"` // HTTP 方法: GET, POST, PUT, DELETE
|
||||
Path string `json:"path"` // 路由路径
|
||||
Query string `json:"query"` // 查询参数
|
||||
Headers map[string]string `json:"headers"` // 请求头
|
||||
Body string `json:"body"` // 请求体
|
||||
}
|
||||
|
||||
// PluginAPIResponse 插件 API 响应
|
||||
type PluginAPIResponse struct {
|
||||
Status int `json:"status"` // HTTP 状态码
|
||||
Headers map[string]string `json:"headers"` // 响应头
|
||||
Body string `json:"body"` // 响应体
|
||||
Error string `json:"error"` // 错误信息
|
||||
}
|
||||
|
||||
// WriteMessage 写入消息到 writer
|
||||
func WriteMessage(w io.Writer, msg *Message) error {
|
||||
header := make([]byte, HeaderSize)
|
||||
|
||||
Reference in New Issue
Block a user