feat: implement VPN platform management and real protocol services
This commit is contained in:
commit
58c036c34c
45 files changed
+9244
No files matched your search
@@ -0,0 +1,117 @@
|
||||
// Package model 定义平台数据模型(GORM + SQLite)
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
// User 平台账号
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"uniqueIndex;size:64" json:"username"`
|
||||
Email string `gorm:"size:128" json:"email"`
|
||||
Password string `gorm:"size:128" json:"-"` // 仅本地用户保存 bcrypt 哈希
|
||||
Role string `gorm:"size:16;default:viewer" json:"role"` // admin / operator / viewer
|
||||
Source string `gorm:"size:16;default:local" json:"source"` // local / ldap
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// LDAPConfig LDAP 身份源配置。BindPassword 由 store.EncryptSecret 加密后保存。
|
||||
type LDAPConfig struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
URL string `gorm:"size:256" json:"url"`
|
||||
BindDN string `gorm:"size:256" json:"bind_dn"`
|
||||
BindPassword string `gorm:"type:text" json:"-"`
|
||||
BaseDN string `gorm:"size:256" json:"base_dn"`
|
||||
UserFilter string `gorm:"size:512" json:"user_filter"`
|
||||
UsernameAttribute string `gorm:"size:64" json:"username_attribute"`
|
||||
Enabled bool `gorm:"default:false" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// MFADevice 保存管理平台用户的 TOTP 密钥和备用码(均加密保存)。
|
||||
type MFADevice struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
UserID uint `gorm:"uniqueIndex" json:"user_id"`
|
||||
Secret string `gorm:"type:text" json:"-"`
|
||||
BackupCodes string `gorm:"type:text" json:"-"`
|
||||
Enabled bool `gorm:"default:false" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// VPNUser 是拨号身份,不等同于管理平台登录账号;可来自本地或 LDAP。
|
||||
type VPNUser struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
TunnelID uint `gorm:"index" json:"tunnel_id"`
|
||||
Username string `gorm:"size:128;uniqueIndex:idx_vpn_user" json:"username"`
|
||||
DisplayName string `gorm:"size:128" json:"display_name"`
|
||||
Email string `gorm:"size:128" json:"email"`
|
||||
Source string `gorm:"size:16;default:local" json:"source"` // local / ldap
|
||||
LDAPDN string `gorm:"size:512" json:"ldap_dn"`
|
||||
Password string `gorm:"size:128" json:"-"`
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
Certificate string `gorm:"size:128" json:"certificate"`
|
||||
RxBytes int64 `gorm:"default:0" json:"rx_bytes"`
|
||||
TxBytes int64 `gorm:"default:0" json:"tx_bytes"`
|
||||
LastSeenAt *time.Time `json:"last_seen_at"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Tunnel 专线实例(所有协议统一存储,协议参数存 Config JSON)
|
||||
type Tunnel struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"size:128;index" json:"name"`
|
||||
Protocol string `gorm:"size:32;index" json:"protocol"` // wireguard/ipsec/l2tp/frp/openvpn/custom:xxx
|
||||
Remark string `gorm:"size:512" json:"remark"`
|
||||
Config string `gorm:"type:text" json:"config"` // JSON,密钥字段加密存储
|
||||
Secrets string `gorm:"type:text" json:"-"` // AES-GCM 加密的敏感字段 JSON
|
||||
State string `gorm:"size:16;default:stopped" json:"state"` // running/stopped/error
|
||||
AutoStart bool `gorm:"default:false" json:"auto_start"`
|
||||
RxBytes int64 `gorm:"default:0" json:"rx_bytes"`
|
||||
TxBytes int64 `gorm:"default:0" json:"tx_bytes"`
|
||||
ExpireAt *time.Time `json:"expire_at"`
|
||||
NodeID *uint `json:"node_id"`
|
||||
Node *Node `json:"node,omitempty"`
|
||||
LastError string `gorm:"size:1024" json:"last_error"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Node 中继节点(本机为内置节点)
|
||||
type Node struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"size:128" json:"name"`
|
||||
Address string `gorm:"size:256" json:"address"` // 节点地址(API 或 SSH)
|
||||
Kind string `gorm:"size:32;default:local" json:"kind"` // local / remote
|
||||
Remark string `gorm:"size:512" json:"remark"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// Plugin 自定义协议插件(通过命令钩子实现 Protocol 契约)
|
||||
type Plugin struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"uniqueIndex;size:64" json:"name"` // 协议标识
|
||||
DisplayName string `gorm:"size:128" json:"display_name"`
|
||||
Description string `gorm:"size:512" json:"description"`
|
||||
// 命令钩子:平台将专线 Config JSON 通过 stdin 传入,插件按约定动作执行
|
||||
CreateHook string `gorm:"size:512" json:"create_hook"`
|
||||
StartHook string `gorm:"size:512" json:"start_hook"`
|
||||
StopHook string `gorm:"size:512" json:"stop_hook"`
|
||||
StatusHook string `gorm:"size:512" json:"status_hook"`
|
||||
ConfigHook string `gorm:"size:512" json:"config_hook"` // 生成客户端配置
|
||||
Enabled bool `gorm:"default:true" json:"enabled"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
|
||||
// AuditLog 操作审计
|
||||
type AuditLog struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"size:64" json:"username"`
|
||||
Action string `gorm:"size:64" json:"action"`
|
||||
Target string `gorm:"size:256" json:"target"`
|
||||
Detail string `gorm:"size:1024" json:"detail"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
}
|
||||
Reference in new issue
Block a user