- 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`.
61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package db
|
|
|
|
import "github.com/gotunnel/pkg/protocol"
|
|
|
|
// Client 客户端数据
|
|
type Client struct {
|
|
ID string `json:"id"`
|
|
Nickname string `json:"nickname,omitempty"`
|
|
Rules []protocol.ProxyRule `json:"rules"`
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// Store 统一存储接口
|
|
type Store interface {
|
|
ClientStore
|
|
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)
|
|
}
|
|
|
|
// InstallToken 安装token
|
|
type InstallToken struct {
|
|
Token string `json:"token"`
|
|
ClientID string `json:"client_id"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
Used bool `json:"used"`
|
|
}
|
|
|
|
// InstallTokenStore 安装token存储接口
|
|
type InstallTokenStore interface {
|
|
CreateInstallToken(token *InstallToken) error
|
|
GetInstallToken(token string) (*InstallToken, error)
|
|
MarkTokenUsed(token string) error
|
|
DeleteExpiredTokens(expireTime int64) error
|
|
}
|