initial: ZeroTier-like P2P mesh VPN server with multi-tenant Web UI
This commit is contained in:
101
internal/model/models.go
Normal file
101
internal/model/models.go
Normal file
@@ -0,0 +1,101 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
Username string `gorm:"uniqueIndex;size:64" json:"username"`
|
||||
Password string `json:"-"`
|
||||
Role string `gorm:"default:user;size:16" json:"role"`
|
||||
Token string `json:"-"`
|
||||
QuotaNetworks int `gorm:"default:3" json:"quota_networks"`
|
||||
QuotaNodes int `gorm:"default:20" json:"quota_nodes"`
|
||||
}
|
||||
|
||||
func (u *User) IsAdmin() bool {
|
||||
return u.Role == "admin"
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
UserID uint `gorm:"index;not null" json:"user_id"`
|
||||
NetworkID uint32 `gorm:"uniqueIndex;not null" json:"network_id"`
|
||||
Name string `gorm:"size:128" json:"name"`
|
||||
IPRange string `gorm:"size:64" json:"ip_range"`
|
||||
IP6Range string `gorm:"size:64" json:"ip6_range"`
|
||||
MTU int `gorm:"default:2800" json:"mtu"`
|
||||
Multicast bool `gorm:"default:true" json:"multicast"`
|
||||
Private bool `gorm:"default:true" json:"private"`
|
||||
Members []NetworkMember `json:"members,omitempty"`
|
||||
}
|
||||
|
||||
type NetworkMember struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
NetworkID uint32 `gorm:"index;not null" json:"network_id"`
|
||||
NodeID string `gorm:"size:40;index;not null" json:"node_id"`
|
||||
IPAddress string `gorm:"size:64" json:"ip_address"`
|
||||
Authorized bool `gorm:"default:false" json:"authorized"`
|
||||
Label string `gorm:"size:128" json:"label"`
|
||||
}
|
||||
|
||||
type Node struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
||||
UserID uint `gorm:"index;not null" json:"user_id"`
|
||||
NodeID string `gorm:"uniqueIndex;size:40" json:"node_id"`
|
||||
PublicKey string `gorm:"size:128" json:"public_key"`
|
||||
Name string `gorm:"size:128" json:"name"`
|
||||
IPAddress string `gorm:"size:64" json:"ip_address"`
|
||||
Port int `json:"port"`
|
||||
Online bool `gorm:"default:false" json:"online"`
|
||||
LastSeen *time.Time `json:"last_seen"`
|
||||
Version string `gorm:"size:32" json:"version"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Key string `gorm:"uniqueIndex;size:128" json:"key"`
|
||||
Value string `gorm:"size:1024" json:"value"`
|
||||
}
|
||||
|
||||
type ApiLog struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
IP string `gorm:"size:64;index" json:"ip"`
|
||||
Method string `gorm:"size:10" json:"method"`
|
||||
Path string `gorm:"size:512;index" json:"path"`
|
||||
StatusCode int `json:"status_code"`
|
||||
Query string `gorm:"size:1024" json:"query"`
|
||||
UserAgent string `gorm:"size:512" json:"user_agent"`
|
||||
LatencyMs int64 `json:"latency_ms"`
|
||||
}
|
||||
|
||||
type ErrorLog struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
IP string `gorm:"size:64;index" json:"ip"`
|
||||
Method string `gorm:"size:10" json:"method"`
|
||||
Path string `gorm:"size:512;index" json:"path"`
|
||||
StatusCode int `json:"status_code"`
|
||||
Query string `gorm:"size:1024" json:"query"`
|
||||
UserAgent string `gorm:"size:512" json:"user_agent"`
|
||||
RequestBody string `gorm:"type:text" json:"request_body"`
|
||||
ResponseBody string `gorm:"type:text" json:"response_body"`
|
||||
LatencyMs int64 `json:"latency_ms"`
|
||||
}
|
||||
Reference in New Issue
Block a user