Files
trihuy-russian/database/model/model.go
T

98 lines
3.2 KiB
Go
Raw Normal View History

2023-02-09 22:48:06 +03:30
package model
import (
"fmt"
2024-03-11 01:01:24 +03:30
2023-02-09 22:48:06 +03:30
"x-ui/util/json_util"
"x-ui/xray"
)
type Protocol string
const (
VMess Protocol = "vmess"
VLESS Protocol = "vless"
Dokodemo Protocol = "Dokodemo-door"
Http Protocol = "http"
Trojan Protocol = "trojan"
Shadowsocks Protocol = "shadowsocks"
)
type User struct {
2023-04-21 19:00:14 +03:30
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
Username string `json:"username"`
Password string `json:"password"`
LoginSecret string `json:"loginSecret"`
2023-02-09 22:48:06 +03:30
}
type Inbound struct {
2023-02-18 16:07:32 +03:30
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:48:06 +03:30
// config part
Listen string `json:"listen" form:"listen"`
Port int `json:"port" form:"port"`
2023-02-09 22:48:06 +03:30
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 23:24:29 +03:30
type InboundClientIps struct {
2023-04-09 23:13:18 +03:30
Id int `json:"id" gorm:"primaryKey;autoIncrement"`
2023-02-28 23:24:29 +03:30
ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
2023-04-09 23:13:18 +03:30
Ips string `json:"ips" form:"ips"`
2023-02-28 23:24:29 +03:30
}
2023-02-09 22:48:06 +03:30
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 16:07:32 +03:30
2023-02-09 22:48:06 +03:30
type Client struct {
2023-02-18 16:07:32 +03:30
ID string `json:"id"`
2023-03-17 19:37:49 +03:30
Password string `json:"password"`
Flow string `json:"flow"`
2023-02-18 16:07:32 +03:30
Email string `json:"email"`
2023-02-28 23:24:29 +03:30
LimitIP int `json:"limitIp"`
2023-02-18 16:07:32 +03:30
TotalGB int64 `json:"totalGB" form:"totalGB"`
2023-02-09 22:48:06 +03:30
ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
2023-04-10 14:33:50 +03:30
Enable bool `json:"enable" form:"enable"`
2024-04-02 15:04:44 +03:30
TgID int64 `json:"tgId" form:"tgId"`
2023-04-10 14:33:50 +03:30
SubID string `json:"subId" form:"subId"`
2023-12-04 19:20:16 +01:00
Reset int `json:"reset" form:"reset"`
2023-02-18 16:07:32 +03:30
}