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

104 lines
3.5 KiB
Go
Raw Normal View History

2023-02-09 19:18:06 +00:00
package model
import (
"fmt"
2023-02-09 19:18:06 +00:00
"x-ui/util/json_util"
"x-ui/xray"
)
type Protocol string
const (
VMESS Protocol = "vmess"
2023-02-09 19:18:06 +00:00
VLESS Protocol = "vless"
2024-05-28 13:16:29 +00:00
DOKODEMO Protocol = "dokodemo-door"
HTTP Protocol = "http"
2023-02-09 19:18:06 +00:00
Trojan Protocol = "trojan"
Shadowsocks Protocol = "shadowsocks"
2024-05-28 13:16:29 +00:00
Socks Protocol = "socks"
WireGuard Protocol = "wireguard"
2023-02-09 19:18:06 +00: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 19:18:06 +00:00
}
type Inbound struct {
2023-02-18 12:37:32 +00:00
Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
UserId int `json:"-"`
2023-02-18 12:37:32 +00:00
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 19:18:06 +00:00
// config part
Listen string `json:"listen" form:"listen"`
Port int `json:"port" form:"port"`
2023-02-09 19:18:06 +00: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"`
2024-09-16 09:41:21 +00:00
Allocate string `json:"allocate" form:"allocate"`
2023-02-09 19:18:06 +00:00
}
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 19:54:29 +00:00
type InboundClientIps struct {
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
2023-02-28 19:54:29 +00:00
ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
Ips string `json:"ips" form:"ips"`
2023-02-28 19:54:29 +00:00
}
2023-02-09 19:18:06 +00: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),
2024-09-16 09:41:21 +00:00
Allocate: json_util.RawMessage(i.Allocate),
2023-02-09 19:18:06 +00:00
}
}
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 12:37:32 +00:00
2023-02-09 19:18:06 +00:00
type Client struct {
2023-02-18 12:37:32 +00:00
ID string `json:"id"`
Security string `json:"security"`
2023-03-17 16:07:49 +00:00
Password string `json:"password"`
Flow string `json:"flow"`
2023-02-18 12:37:32 +00:00
Email string `json:"email"`
2023-02-28 19:54:29 +00:00
LimitIP int `json:"limitIp"`
2023-02-18 12:37:32 +00:00
TotalGB int64 `json:"totalGB" form:"totalGB"`
2023-02-09 19:18:06 +00:00
ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
2023-04-10 11:03:50 +00:00
Enable bool `json:"enable" form:"enable"`
2024-04-02 11:34:44 +00:00
TgID int64 `json:"tgId" form:"tgId"`
2023-04-10 11:03:50 +00:00
SubID string `json:"subId" form:"subId"`
Comment string `json:"comment" form:"comment"`
2023-12-04 18:20:16 +00:00
Reset int `json:"reset" form:"reset"`
2023-02-18 12:37:32 +00:00
}