3x-ui/database/model/model.go

101 lines
3.3 KiB
Go
Raw Normal View History

2023-02-09 22:18:06 +03:00
package model
import (
"fmt"
2023-02-09 22:18:06 +03:00
"x-ui/util/json_util"
"x-ui/xray"
)
type Protocol string
const (
VMESS Protocol = "vmess"
2023-02-09 22:18:06 +03:00
VLESS Protocol = "vless"
2024-05-28 16:16:29 +03:00
DOKODEMO Protocol = "dokodemo-door"
HTTP Protocol = "http"
2023-02-09 22:18:06 +03:00
Trojan Protocol = "trojan"
Shadowsocks Protocol = "shadowsocks"
2024-05-28 16:16:29 +03:00
Socks Protocol = "socks"
WireGuard Protocol = "wireguard"
2023-02-09 22:18:06 +03:00
)
type User struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username"`
Password string `json:"password"`
LoginSecret string `json:"loginSecret"`
2023-02-09 22:18:06 +03:00
}
type Inbound struct {
2023-02-18 15:37:32 +03:00
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
UserId int `json:"-"`
Up int64 `json:"up" form:"up"`
Down int64 `json:"down" form:"down"`
Total int64 `json:"total" form:"total"`
Remark string `json:"remark" form:"remark"`
Enable bool `json:"enable" form:"enable"`
ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"`
2023-02-09 22:18:06 +03:00
// config part
Listen string `json:"listen" form:"listen"`
Port int `json:"port" form:"port"`
2023-02-09 22:18:06 +03:00
Protocol Protocol `json:"protocol" form:"protocol"`
Settings string `json:"settings" form:"settings"`
StreamSettings string `json:"streamSettings" form:"streamSettings"`
Tag string `json:"tag" form:"tag" gorm:"unique"`
Sniffing string `json:"sniffing" form:"sniffing"`
}
type OutboundTraffics struct {
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
Tag string `json:"tag" form:"tag" gorm:"unique"`
Up int64 `json:"up" form:"up" gorm:"default:0"`
Down int64 `json:"down" form:"down" gorm:"default:0"`
Total int64 `json:"total" form:"total" gorm:"default:0"`
}
2023-02-28 22:54:29 +03:00
type InboundClientIps struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
2023-02-28 22:54:29 +03:00
ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
Ips string `json:"ips" form:"ips"`
2023-02-28 22:54:29 +03:00
}
2023-02-09 22:18:06 +03:00
func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
listen := i.Listen
if listen != "" {
listen = fmt.Sprintf("\"%v\"", listen)
}
return &xray.InboundConfig{
Listen: json_util.RawMessage(listen),
Port: i.Port,
Protocol: string(i.Protocol),
Settings: json_util.RawMessage(i.Settings),
StreamSettings: json_util.RawMessage(i.StreamSettings),
Tag: i.Tag,
Sniffing: json_util.RawMessage(i.Sniffing),
}
}
type Setting struct {
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
Key string `json:"key" form:"key"`
Value string `json:"value" form:"value"`
}
2023-02-18 15:37:32 +03:00
2023-02-09 22:18:06 +03:00
type Client struct {
2023-02-18 15:37:32 +03:00
ID string `json:"id"`
Security string `json:"security"`
2023-03-17 19:07:49 +03:00
Password string `json:"password"`
Flow string `json:"flow"`
2023-02-18 15:37:32 +03:00
Email string `json:"email"`
2023-02-28 22:54:29 +03:00
LimitIP int `json:"limitIp"`
2023-02-18 15:37:32 +03:00
TotalGB int64 `json:"totalGB" form:"totalGB"`
2023-02-09 22:18:06 +03:00
ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
2023-04-10 14:03:50 +03:00
Enable bool `json:"enable" form:"enable"`
2024-04-02 14:34:44 +03:00
TgID int64 `json:"tgId" form:"tgId"`
2023-04-10 14:03:50 +03:00
SubID string `json:"subId" form:"subId"`
2023-12-04 21:20:16 +03:00
Reset int `json:"reset" form:"reset"`
2023-02-18 15:37:32 +03:00
}