1
0

model.go 3.2 KB

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