77f8b59290
OpenVPN Web management console with multi-instance support, client cert issuance, traffic/connection auditing, certificate expiry reminders, auto backup/restore. Stack: - Backend: Go 1.21+ (Gin + JWT) - Frontend: Vue 3 + Element Plus + ECharts + Vite - Storage: JSON file (db.json) + filesystem (pki/, instances/, clients/, backups/) Features: - Multi-instance OpenVPN management (independent port/proto/subnet/PKI) - One-click client certificate issuance with .ovpn (embedded certs) - Certificate expiry reminders (30-day threshold) - Connection log parsing (status-version 3) - Auto backup/restore (tar.gz) - Audit log for all write operations - JWT auth (12h TTL) - One-line install.sh for Ubuntu/Debian/RHEL/Fedora
84 lines
3.4 KiB
Go
84 lines
3.4 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// Instance 一个 OpenVPN 服务端实例。
|
|
// 每个实例使用独立端口与 PKI,运行在自己的 server.conf 下,
|
|
// 由 systemd 单元(或后台进程)托管,本服务通过 management 接口与之通信。
|
|
type Instance struct {
|
|
ID string `json:"id"`
|
|
Name string `json:"name"` // 唯一名,作为目录名
|
|
Port int `json:"port"` // openvpn 监听端口
|
|
Proto string `json:"proto"` // udp / tcp
|
|
Dev string `json:"dev"` // tun / tap
|
|
Subnet string `json:"subnet"` // 客户端子网,如 10.8.0.0/24
|
|
Cipher string `json:"cipher"` // 加密算法
|
|
AuthDigest string `json:"auth_digest"` // 摘要算法
|
|
PushDNS string `json:"push_dns"` // push "dhcp-option DNS x.x.x.x"
|
|
PushRoutes string `json:"push_routes"` // 多行
|
|
Extra string `json:"extra"` // 用户追加配置
|
|
Status string `json:"status"` // running/stopped/error
|
|
PID int `json:"pid"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
// VPNUser 一个 OpenVPN 客户端用户。
|
|
// 证书从对应实例的 PKI 中签发,可下载 .ovpn 客户端配置。
|
|
type VPNUser struct {
|
|
ID string `json:"id"`
|
|
InstanceID string `json:"instance_id"`
|
|
Username string `json:"username"` // 证书 CN
|
|
RealName string `json:"real_name"` // 备注
|
|
Email string `json:"email"`
|
|
Enabled bool `json:"enabled"` // 是否启用, false 即吊销/禁用
|
|
StaticIP string `json:"static_ip"` // ccd 固定地址, 空表示动态
|
|
CreatedAt time.Time `json:"created_at"`
|
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
|
RevokedAt *time.Time `json:"revoked_at,omitempty"`
|
|
}
|
|
|
|
// AuditLog 操作审计日志
|
|
type AuditLog struct {
|
|
ID string `json:"id"`
|
|
Time time.Time `json:"time"`
|
|
User string `json:"user"` // 操作者(管理用户)
|
|
Action string `json:"action"` // create_instance, revoke_user, ...
|
|
Target string `json:"target"` // 目标对象
|
|
Result string `json:"result"` // ok / failed
|
|
Detail string `json:"detail"`
|
|
IP string `json:"ip"`
|
|
}
|
|
|
|
// ConnectionLog 来自 OpenVPN status 的实时/历史连接记录。
|
|
// 周期由 OpenVPN 自身写入 status.log,本服务周期性读取解析后入库。
|
|
type ConnectionLog struct {
|
|
InstanceID string `json:"instance_id"`
|
|
CommonName string `json:"common_name"`
|
|
RealIP string `json:"real_ip"` // 客户端公网 IP
|
|
VPNIP string `json:"vpn_ip"` // 分配的 VPN 内网 IP
|
|
BytesIn int64 `json:"bytes_in"`
|
|
BytesOut int64 `json:"bytes_out"`
|
|
ConnectedAt time.Time `json:"connected_at"`
|
|
DisconnectedAt *time.Time `json:"disconnected_at,omitempty"`
|
|
}
|
|
|
|
// Backup 一份备份归档
|
|
type Backup struct {
|
|
ID string `json:"id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
Size int64 `json:"size"`
|
|
Note string `json:"note"`
|
|
Filename string `json:"filename"`
|
|
Includes []string `json:"includes"`
|
|
}
|
|
|
|
// CertInfo 证书元数据(用于证书到期提醒)。
|
|
type CertInfo struct {
|
|
InstanceID string `json:"instance_id"`
|
|
Username string `json:"username"`
|
|
Subject string `json:"subject"`
|
|
NotBefore time.Time `json:"not_before"`
|
|
NotAfter time.Time `json:"not_after"`
|
|
DaysLeft int `json:"days_left"`
|
|
} |