All checks were successful
Build Multi-Platform Binaries / build-frontend (push) Successful in 38s
Build Multi-Platform Binaries / build-binaries (amd64, linux, client, true) (push) Successful in 1m47s
Build Multi-Platform Binaries / build-binaries (amd64, darwin, server, false) (push) Successful in 1m48s
Build Multi-Platform Binaries / build-binaries (amd64, windows, client, true) (push) Successful in 1m29s
Build Multi-Platform Binaries / build-binaries (amd64, linux, server, true) (push) Successful in 1m53s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, client, true) (push) Successful in 1m14s
Build Multi-Platform Binaries / build-binaries (amd64, windows, server, true) (push) Successful in 1m40s
Build Multi-Platform Binaries / build-binaries (arm64, darwin, server, false) (push) Successful in 1m36s
Build Multi-Platform Binaries / build-binaries (arm, 7, linux, server, true) (push) Successful in 1m51s
Build Multi-Platform Binaries / build-binaries (arm64, linux, client, true) (push) Successful in 1m17s
Build Multi-Platform Binaries / build-binaries (arm64, linux, server, true) (push) Successful in 1m50s
Build Multi-Platform Binaries / build-binaries (arm64, windows, server, false) (push) Successful in 1m18s
- 在WebServer中添加TrafficStore存储接口 - 将Web配置从根级别移动到Server.Web子结构下 - 移除Web配置中的BindAddr字段并调整默认值逻辑 - 在前端HomeView中替换模拟流量数据显示真实统计数据 - 添加流量统计API接口(/traffic/stats和/traffic/hourly) - 实现SQLite数据库流量统计表创建和CRUD操作 - 在Relay包中添加带流量统计的数据转发功能 - 在设置页面添加服务器配置编辑和保存功能 - 创建流量统计处理器和相关数据模型定义
97 lines
3.4 KiB
Go
97 lines
3.4 KiB
Go
package db
|
|
|
|
import "github.com/gotunnel/pkg/protocol"
|
|
|
|
// ConfigField 配置字段定义
|
|
type ConfigField struct {
|
|
Key string `json:"key"`
|
|
Label string `json:"label"`
|
|
Type string `json:"type"`
|
|
Default string `json:"default,omitempty"`
|
|
Required bool `json:"required,omitempty"`
|
|
Options []string `json:"options,omitempty"`
|
|
Description string `json:"description,omitempty"`
|
|
}
|
|
|
|
// ClientPlugin 客户端已安装的插件
|
|
type ClientPlugin struct {
|
|
ID string `json:"id"` // 插件实例唯一 ID
|
|
Name string `json:"name"`
|
|
Version string `json:"version"`
|
|
Enabled bool `json:"enabled"`
|
|
Running bool `json:"running"` // 运行状态
|
|
Config map[string]string `json:"config,omitempty"` // 插件配置
|
|
RemotePort int `json:"remote_port,omitempty"` // 远程监听端口
|
|
ConfigSchema []ConfigField `json:"config_schema,omitempty"` // 配置模式
|
|
AuthEnabled bool `json:"auth_enabled,omitempty"` // 是否启用认证
|
|
AuthUsername string `json:"auth_username,omitempty"` // 认证用户名
|
|
AuthPassword string `json:"auth_password,omitempty"` // 认证密码
|
|
}
|
|
|
|
// Client 客户端数据
|
|
type Client struct {
|
|
ID string `json:"id"`
|
|
Nickname string `json:"nickname,omitempty"`
|
|
Rules []protocol.ProxyRule `json:"rules"`
|
|
Plugins []ClientPlugin `json:"plugins,omitempty"` // 已安装的插件
|
|
}
|
|
|
|
// JSPlugin JS 插件数据
|
|
type JSPlugin struct {
|
|
Name string `json:"name"`
|
|
Source string `json:"source"`
|
|
Signature string `json:"signature"` // 官方签名 (Base64)
|
|
Description string `json:"description"`
|
|
Author string `json:"author"`
|
|
Version string `json:"version,omitempty"`
|
|
AutoPush []string `json:"auto_push"`
|
|
Config map[string]string `json:"config"`
|
|
AutoStart bool `json:"auto_start"`
|
|
Enabled bool `json:"enabled"`
|
|
}
|
|
|
|
// ClientStore 客户端存储接口
|
|
type ClientStore interface {
|
|
GetAllClients() ([]Client, error)
|
|
GetClient(id string) (*Client, error)
|
|
CreateClient(c *Client) error
|
|
UpdateClient(c *Client) error
|
|
DeleteClient(id string) error
|
|
ClientExists(id string) (bool, error)
|
|
GetClientRules(id string) ([]protocol.ProxyRule, error)
|
|
Close() error
|
|
}
|
|
|
|
// JSPluginStore JS 插件存储接口
|
|
type JSPluginStore interface {
|
|
GetAllJSPlugins() ([]JSPlugin, error)
|
|
GetJSPlugin(name string) (*JSPlugin, error)
|
|
SaveJSPlugin(p *JSPlugin) error
|
|
DeleteJSPlugin(name string) error
|
|
SetJSPluginEnabled(name string, enabled bool) error
|
|
UpdateJSPluginConfig(name string, config map[string]string) error
|
|
}
|
|
|
|
// Store 统一存储接口
|
|
type Store interface {
|
|
ClientStore
|
|
JSPluginStore
|
|
TrafficStore
|
|
Close() error
|
|
}
|
|
|
|
// TrafficRecord 流量记录
|
|
type TrafficRecord struct {
|
|
Timestamp int64 `json:"timestamp"` // Unix 时间戳(小时级别)
|
|
Inbound int64 `json:"inbound"` // 入站流量(字节)
|
|
Outbound int64 `json:"outbound"` // 出站流量(字节)
|
|
}
|
|
|
|
// TrafficStore 流量存储接口
|
|
type TrafficStore interface {
|
|
AddTraffic(inbound, outbound int64) error
|
|
GetTotalTraffic() (inbound, outbound int64, err error)
|
|
Get24HourTraffic() (inbound, outbound int64, err error)
|
|
GetHourlyTraffic(hours int) ([]TrafficRecord, error)
|
|
}
|