model.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. DOKODEMO Protocol = "dokodemo-door"
  12. HTTP Protocol = "http"
  13. Trojan Protocol = "trojan"
  14. Shadowsocks Protocol = "shadowsocks"
  15. Socks Protocol = "socks"
  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. LoginSecret string `json:"loginSecret"`
  23. }
  24. type Inbound struct {
  25. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  26. UserId int `json:"-"`
  27. Up int64 `json:"up" form:"up"`
  28. Down int64 `json:"down" form:"down"`
  29. Total int64 `json:"total" form:"total"`
  30. Remark string `json:"remark" form:"remark"`
  31. Enable bool `json:"enable" form:"enable"`
  32. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  33. ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"`
  34. // config part
  35. Listen string `json:"listen" form:"listen"`
  36. Port int `json:"port" form:"port"`
  37. Protocol Protocol `json:"protocol" form:"protocol"`
  38. Settings string `json:"settings" form:"settings"`
  39. StreamSettings string `json:"streamSettings" form:"streamSettings"`
  40. Tag string `json:"tag" form:"tag" gorm:"unique"`
  41. Sniffing string `json:"sniffing" form:"sniffing"`
  42. }
  43. type OutboundTraffics struct {
  44. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  45. Tag string `json:"tag" form:"tag" gorm:"unique"`
  46. Up int64 `json:"up" form:"up" gorm:"default:0"`
  47. Down int64 `json:"down" form:"down" gorm:"default:0"`
  48. Total int64 `json:"total" form:"total" gorm:"default:0"`
  49. }
  50. type InboundClientIps struct {
  51. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  52. ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
  53. Ips string `json:"ips" form:"ips"`
  54. }
  55. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  56. listen := i.Listen
  57. if listen != "" {
  58. listen = fmt.Sprintf("\"%v\"", listen)
  59. }
  60. return &xray.InboundConfig{
  61. Listen: json_util.RawMessage(listen),
  62. Port: i.Port,
  63. Protocol: string(i.Protocol),
  64. Settings: json_util.RawMessage(i.Settings),
  65. StreamSettings: json_util.RawMessage(i.StreamSettings),
  66. Tag: i.Tag,
  67. Sniffing: json_util.RawMessage(i.Sniffing),
  68. }
  69. }
  70. type Setting struct {
  71. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  72. Key string `json:"key" form:"key"`
  73. Value string `json:"value" form:"value"`
  74. }
  75. type Client struct {
  76. ID string `json:"id"`
  77. Security string `json:"security"`
  78. Password string `json:"password"`
  79. Flow string `json:"flow"`
  80. Email string `json:"email"`
  81. LimitIP int `json:"limitIp"`
  82. TotalGB int64 `json:"totalGB" form:"totalGB"`
  83. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  84. Enable bool `json:"enable" form:"enable"`
  85. TgID int64 `json:"tgId" form:"tgId"`
  86. SubID string `json:"subId" form:"subId"`
  87. Reset int `json:"reset" form:"reset"`
  88. }