model.go 2.9 KB

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