model.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. }
  21. type Inbound struct {
  22. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  23. UserId int `json:"-"`
  24. Up int64 `json:"up" form:"up"`
  25. Down int64 `json:"down" form:"down"`
  26. Total int64 `json:"total" form:"total"`
  27. Remark string `json:"remark" form:"remark"`
  28. Enable bool `json:"enable" form:"enable"`
  29. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  30. ClientStats []xray.ClientTraffic `gorm:"foreignKey:InboundId;references:Id" json:"clientStats" form:"clientStats"`
  31. // config part
  32. Listen string `json:"listen" form:"listen"`
  33. Port int `json:"port" form:"port" gorm:"unique"`
  34. Protocol Protocol `json:"protocol" form:"protocol"`
  35. Settings string `json:"settings" form:"settings"`
  36. StreamSettings string `json:"streamSettings" form:"streamSettings"`
  37. Tag string `json:"tag" form:"tag" gorm:"unique"`
  38. Sniffing string `json:"sniffing" form:"sniffing"`
  39. }
  40. type InboundClientIps struct {
  41. Id int `json:"id" gorm:"primaryKey;autoIncrement"`
  42. ClientEmail string `json:"clientEmail" form:"clientEmail" gorm:"unique"`
  43. Ips string `json:"ips" form:"ips"`
  44. }
  45. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  46. listen := i.Listen
  47. if listen != "" {
  48. listen = fmt.Sprintf("\"%v\"", listen)
  49. }
  50. return &xray.InboundConfig{
  51. Listen: json_util.RawMessage(listen),
  52. Port: i.Port,
  53. Protocol: string(i.Protocol),
  54. Settings: json_util.RawMessage(i.Settings),
  55. StreamSettings: json_util.RawMessage(i.StreamSettings),
  56. Tag: i.Tag,
  57. Sniffing: json_util.RawMessage(i.Sniffing),
  58. }
  59. }
  60. type Setting struct {
  61. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  62. Key string `json:"key" form:"key"`
  63. Value string `json:"value" form:"value"`
  64. }
  65. type Client struct {
  66. ID string `json:"id"`
  67. Password string `json:"password"`
  68. Flow string `json:"flow"`
  69. AlterIds uint16 `json:"alterId"`
  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. }