model.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. func (i *Inbound) GenXrayInboundConfig() *xray.InboundConfig {
  41. listen := i.Listen
  42. if listen != "" {
  43. listen = fmt.Sprintf("\"%v\"", listen)
  44. }
  45. return &xray.InboundConfig{
  46. Listen: json_util.RawMessage(listen),
  47. Port: i.Port,
  48. Protocol: string(i.Protocol),
  49. Settings: json_util.RawMessage(i.Settings),
  50. StreamSettings: json_util.RawMessage(i.StreamSettings),
  51. Tag: i.Tag,
  52. Sniffing: json_util.RawMessage(i.Sniffing),
  53. }
  54. }
  55. type Setting struct {
  56. Id int `json:"id" form:"id" gorm:"primaryKey;autoIncrement"`
  57. Key string `json:"key" form:"key"`
  58. Value string `json:"value" form:"value"`
  59. }
  60. type Client struct {
  61. ID string `json:"id"`
  62. AlterIds uint16 `json:"alterId"`
  63. Email string `json:"email"`
  64. Security string `json:"security"`
  65. TotalGB int64 `json:"totalGB" form:"totalGB"`
  66. ExpiryTime int64 `json:"expiryTime" form:"expiryTime"`
  67. }