model.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. Allocate string `json:"allocate" form:"allocate"`
  43. }
  44. type OutboundTraffics struct {
  45. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  46. Tag string `json:"tag" form:"tag" gorm:"unique"`
  47. Up int64 `json:"up" form:"up" gorm:"default:0"`
  48. Down int64 `json:"down" form:"down" gorm:"default:0"`
  49. Total int64 `json:"total" form:"total" gorm:"default:0"`
  50. }
  51. type InboundClientIps struct {
  52. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  53. ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
  54. Ips string `json:"ips" form:"ips"`
  55. }
  56. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  57. listen := i.Listen
  58. if listen != "" {
  59. listen = fmt.Sprintf("\"%v\"", listen)
  60. }
  61. return &xray.InboundConfig{
  62. Listen: json_util.RawMessage(listen),
  63. Port: i.Port,
  64. Protocol: string(i.Protocol),
  65. Settings: json_util.RawMessage(i.Settings),
  66. StreamSettings: json_util.RawMessage(i.StreamSettings),
  67. Tag: i.Tag,
  68. Sniffing: json_util.RawMessage(i.Sniffing),
  69. Allocate: json_util.RawMessage(i.Allocate),
  70. }
  71. }
  72. type Setting struct {
  73. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  74. Key string `json:"key" form:"key"`
  75. Value string `json:"value" form:"value"`
  76. }
  77. type Client struct {
  78. ID string `json:"id"`
  79. Security string `json:"security"`
  80. Password string `json:"password"`
  81. Flow string `json:"flow"`
  82. Email string `json:"email"`
  83. LimitIP int `json:"limitIp"`
  84. TotalGB int64 `json:"totalGB" form:"totalGB"`
  85. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  86. Enable bool `json:"enable" form:"enable"`
  87. TgID int64 `json:"tgId" form:"tgId"`
  88. SubID string `json:"subId" form:"subId"`
  89. Reset int `json:"reset" form:"reset"`
  90. }