1
0

model.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }
  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. Remark string `json:"remark" form:"remark"`
  30. Enable bool `json:"enable" form:"enable"`
  31. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  32. ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"`
  33. // config part
  34. Listen string `json:"listen" form:"listen"`
  35. Port int `json:"port" form:"port"`
  36. Protocol Protocol `json:"protocol" form:"protocol"`
  37. Settings string `json:"settings" form:"settings"`
  38. StreamSettings string `json:"streamSettings" form:"streamSettings"`
  39. Tag string `json:"tag" form:"tag" gorm:"unique"`
  40. Sniffing string `json:"sniffing" form:"sniffing"`
  41. Allocate string `json:"allocate" form:"allocate"`
  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. type HistoryOfSeeders struct {
  56. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  57. SeederName string `json:"seederName"`
  58. }
  59. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  60. listen := i.Listen
  61. if listen != "" {
  62. listen = fmt.Sprintf("\"%v\"", listen)
  63. }
  64. return &xray.InboundConfig{
  65. Listen: json_util.RawMessage(listen),
  66. Port: i.Port,
  67. Protocol: string(i.Protocol),
  68. Settings: json_util.RawMessage(i.Settings),
  69. StreamSettings: json_util.RawMessage(i.StreamSettings),
  70. Tag: i.Tag,
  71. Sniffing: json_util.RawMessage(i.Sniffing),
  72. Allocate: json_util.RawMessage(i.Allocate),
  73. }
  74. }
  75. type Setting struct {
  76. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  77. Key string `json:"key" form:"key"`
  78. Value string `json:"value" form:"value"`
  79. }
  80. type Client struct {
  81. ID string `json:"id"`
  82. Security string `json:"security"`
  83. Password string `json:"password"`
  84. Flow string `json:"flow"`
  85. Email string `json:"email"`
  86. LimitIP int `json:"limitIp"`
  87. TotalGB int64 `json:"totalGB" form:"totalGB"`
  88. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  89. Enable bool `json:"enable" form:"enable"`
  90. TgID int64 `json:"tgId" form:"tgId"`
  91. SubID string `json:"subId" form:"subId"`
  92. Comment string `json:"comment" form:"comment"`
  93. Reset int `json:"reset" form:"reset"`
  94. }