proxy.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. class BaseProxy {
  2. constructor(proxyStats) {
  3. this.name = proxyStats.name
  4. if (proxyStats.conf != null) {
  5. this.encryption = proxyStats.conf.use_encryption
  6. this.compression = proxyStats.conf.use_compression
  7. } else {
  8. this.encryption = ''
  9. this.compression = ''
  10. }
  11. this.conns = proxyStats.cur_conns
  12. this.traffic_in = proxyStats.today_traffic_in
  13. this.traffic_out = proxyStats.today_traffic_out
  14. this.last_start_time = proxyStats.last_start_time
  15. this.last_close_time = proxyStats.last_close_time
  16. this.status = proxyStats.status
  17. }
  18. }
  19. class TcpProxy extends BaseProxy {
  20. constructor(proxyStats) {
  21. super(proxyStats)
  22. this.type = 'tcp'
  23. if (proxyStats.conf != null) {
  24. this.addr = ':' + proxyStats.conf.remote_port
  25. this.port = proxyStats.conf.remote_port
  26. } else {
  27. this.addr = ''
  28. this.port = ''
  29. }
  30. }
  31. }
  32. class UdpProxy extends BaseProxy {
  33. constructor(proxyStats) {
  34. super(proxyStats)
  35. this.type = 'udp'
  36. if (proxyStats.conf != null) {
  37. this.addr = ':' + proxyStats.conf.remote_port
  38. this.port = proxyStats.conf.remote_port
  39. } else {
  40. this.addr = ''
  41. this.port = ''
  42. }
  43. }
  44. }
  45. class HttpProxy extends BaseProxy {
  46. constructor(proxyStats, port, subdomain_host) {
  47. super(proxyStats)
  48. this.type = 'http'
  49. this.port = port
  50. if (proxyStats.conf != null) {
  51. this.custom_domains = proxyStats.conf.custom_domains
  52. this.host_header_rewrite = proxyStats.conf.host_header_rewrite
  53. this.locations = proxyStats.conf.locations
  54. if (proxyStats.conf.sub_domain !== '') {
  55. this.subdomain = proxyStats.conf.sub_domain + '.' + subdomain_host
  56. } else {
  57. this.subdomain = ''
  58. }
  59. } else {
  60. this.custom_domains = ''
  61. this.host_header_rewrite = ''
  62. this.subdomain = ''
  63. this.locations = ''
  64. }
  65. }
  66. }
  67. class HttpsProxy extends BaseProxy {
  68. constructor(proxyStats, port, subdomain_host) {
  69. super(proxyStats)
  70. this.type = 'https'
  71. this.port = port
  72. if (proxyStats.conf != null) {
  73. this.custom_domains = proxyStats.conf.custom_domains
  74. if (proxyStats.conf.sub_domain !== '') {
  75. this.subdomain = proxyStats.conf.sub_domain + '.' + subdomain_host
  76. } else {
  77. this.subdomain = ''
  78. }
  79. } else {
  80. this.custom_domains = ''
  81. this.subdomain = ''
  82. }
  83. }
  84. }
  85. class StcpProxy extends BaseProxy {
  86. constructor(proxyStats) {
  87. super(proxyStats)
  88. this.type = 'stcp'
  89. }
  90. }
  91. export { BaseProxy, TcpProxy, UdpProxy, HttpProxy, HttpsProxy, StcpProxy }