model.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package model
  2. import (
  3. "fmt"
  4. "x-ui/util/json_util"
  5. "x-ui/xray"
  6. )
  7. type Protocol string
  8. const (
  9. VMESS Protocol = "vmess"
  10. VLESS Protocol = "vless"
  11. Tunnel Protocol = "tunnel"
  12. HTTP Protocol = "http"
  13. Trojan Protocol = "trojan"
  14. Shadowsocks Protocol = "shadowsocks"
  15. Mixed Protocol = "mixed"
  16. WireGuard Protocol = "wireguard"
  17. )
  18. type User struct {
  19. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  20. Username string `json:"username"`
  21. Password string `json:"password"`
  22. }
  23. type Inbound struct {
  24. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  25. UserId int `json:"-"`
  26. Up int64 `json:"up" form:"up"`
  27. Down int64 `json:"down" form:"down"`
  28. Total int64 `json:"total" form:"total"`
  29. AllTime int64 `json:"allTime" form:"allTime" gorm:"default:0"`
  30. Remark string `json:"remark" form:"remark"`
  31. Enable bool `json:"enable" form:"enable" gorm:"index:idx_enable_traffic_reset,priority:1"`
  32. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  33. TrafficReset string `json:"trafficReset" form:"trafficReset" gorm:"default:never;index:idx_enable_traffic_reset,priority:2"`
  34. LastTrafficResetTime int64 `json:"lastTrafficResetTime" form:"lastTrafficResetTime" gorm:"default:0"`
  35. ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"`
  36. // config part
  37. Listen string `json:"listen" form:"listen"`
  38. Port int `json:"port" form:"port"`
  39. Protocol Protocol `json:"protocol" form:"protocol"`
  40. Settings string `json:"settings" form:"settings"`
  41. StreamSettings string `json:"streamSettings" form:"streamSettings"`
  42. Tag string `json:"tag" form:"tag" gorm:"unique"`
  43. Sniffing string `json:"sniffing" form:"sniffing"`
  44. }
  45. type OutboundTraffics struct {
  46. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  47. Tag string `json:"tag" form:"tag" gorm:"unique"`
  48. Up int64 `json:"up" form:"up" gorm:"default:0"`
  49. Down int64 `json:"down" form:"down" gorm:"default:0"`
  50. Total int64 `json:"total" form:"total" gorm:"default:0"`
  51. }
  52. type InboundClientIps struct {
  53. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  54. ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
  55. Ips string `json:"ips" form:"ips"`
  56. }
  57. type HistoryOfSeeders struct {
  58. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  59. SeederName string `json:"seederName"`
  60. }
  61. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  62. listen := i.Listen
  63. if listen != "" {
  64. listen = fmt.Sprintf("\"%v\"", listen)
  65. }
  66. return &xray.InboundConfig{
  67. Listen: json_util.RawMessage(listen),
  68. Port: i.Port,
  69. Protocol: string(i.Protocol),
  70. Settings: json_util.RawMessage(i.Settings),
  71. StreamSettings: json_util.RawMessage(i.StreamSettings),
  72. Tag: i.Tag,
  73. Sniffing: json_util.RawMessage(i.Sniffing),
  74. }
  75. }
  76. type Setting struct {
  77. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  78. Key string `json:"key" form:"key"`
  79. Value string `json:"value" form:"value"`
  80. }
  81. type Client struct {
  82. ID string `json:"id"`
  83. Security string `json:"security"`
  84. Password string `json:"password"`
  85. Flow string `json:"flow"`
  86. Email string `json:"email"`
  87. LimitIP int `json:"limitIp"`
  88. TotalGB int64 `json:"totalGB" form:"totalGB"`
  89. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  90. Enable bool `json:"enable" form:"enable"`
  91. TgID int64 `json:"tgId" form:"tgId"`
  92. SubID string `json:"subId" form:"subId"`
  93. Comment string `json:"comment" form:"comment"`
  94. Reset int `json:"reset" form:"reset"`
  95. CreatedAt int64 `json:"created_at,omitempty"`
  96. UpdatedAt int64 `json:"updated_at,omitempty"`
  97. }
  98. type VLESSSettings struct {
  99. Clients []Client `json:"clients"`
  100. Decryption string `json:"decryption"`
  101. Encryption string `json:"encryption"`
  102. Fallbacks []any `json:"fallbacks"`
  103. }