servers.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. -- Licensed to the public under the GNU General Public License v3.
  2. require "luci.http"
  3. require "luci.dispatcher"
  4. require "luci.model.uci"
  5. local m, s, o
  6. local uci = luci.model.uci.cursor()
  7. local server_count = 0
  8. uci:foreach("shadowsocksr", "servers", function(s)
  9. server_count = server_count + 1
  10. end)
  11. m = Map("shadowsocksr", translate("Servers subscription and manage"))
  12. -- Server Subscribe
  13. s = m:section(TypedSection, "server_subscribe")
  14. s.anonymous = true
  15. o = s:option(Flag, "auto_update", translate("Auto Update"))
  16. o.rmempty = false
  17. o.description = translate("Auto Update Server subscription, GFW list and CHN route")
  18. o = s:option(ListValue, "auto_update_week_time", translate("Update Time (Every Week)"))
  19. o:value('*', translate("Every Day"))
  20. o:value("1", translate("Every Monday"))
  21. o:value("2", translate("Every Tuesday"))
  22. o:value("3", translate("Every Wednesday"))
  23. o:value("4", translate("Every Thursday"))
  24. o:value("5", translate("Every Friday"))
  25. o:value("6", translate("Every Saturday"))
  26. o:value("0", translate("Every Sunday"))
  27. o.default = "*"
  28. o.rmempty = false
  29. o:depends("auto_update", "1")
  30. o = s:option(ListValue, "auto_update_day_time", translate("Update time (every day)"))
  31. for t = 0, 23 do
  32. o:value(t, t .. ":00")
  33. end
  34. o.default = 2
  35. o.rmempty = false
  36. o:depends("auto_update", "1")
  37. o = s:option(ListValue, "auto_update_min_time", translate("Update Interval (min)"))
  38. for i = 0, 59 do
  39. o:value(i, i .. ":00")
  40. end
  41. o.default = 30
  42. o.rmempty = false
  43. o:depends("auto_update", "1")
  44. o = s:option(DynamicList, "subscribe_url", translate("Subscribe URL"))
  45. o.rmempty = true
  46. o = s:option(Value, "filter_words", translate("Subscribe Filter Words"))
  47. o.rmempty = true
  48. o.description = translate("Filter Words splited by /")
  49. o = s:option(Value, "save_words", translate("Subscribe Save Words"))
  50. o.rmempty = true
  51. o.description = translate("Save Words splited by /")
  52. o = s:option(Button, "update_Sub", translate("Update Subscribe List"))
  53. o.inputstyle = "reload"
  54. o.description = translate("Update subscribe url list first")
  55. o.write = function()
  56. uci:commit("shadowsocksr")
  57. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "shadowsocksr", "servers"))
  58. end
  59. o = s:option(Flag, "switch", translate("Subscribe Default Auto-Switch"))
  60. o.rmempty = false
  61. o.description = translate("Subscribe new add server default Auto-Switch on")
  62. o.default = "1"
  63. o = s:option(Flag, "proxy", translate("Through proxy update"))
  64. o.rmempty = false
  65. o.description = translate("Through proxy update list, Not Recommended ")
  66. o = s:option(Button, "subscribe", translate("Update All Subscribe Servers"))
  67. o.rawhtml = true
  68. o.template = "shadowsocksr/subscribe"
  69. o = s:option(Button, "delete", translate("Delete All Subscribe Servers"))
  70. o.inputstyle = "reset"
  71. o.description = string.format(translate("Server Count") .. ": %d", server_count)
  72. o.write = function()
  73. uci:delete_all("shadowsocksr", "servers", function(s)
  74. if s.hashkey or s.isSubscribe then
  75. return true
  76. else
  77. return false
  78. end
  79. end)
  80. uci:save("shadowsocksr")
  81. uci:commit("shadowsocksr")
  82. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "shadowsocksr", "delete"))
  83. return
  84. end
  85. -- [[ Servers Manage ]]--
  86. s = m:section(TypedSection, "servers")
  87. s.anonymous = true
  88. s.addremove = true
  89. s.template = "cbi/tblsection"
  90. s.sortable = true
  91. s.extedit = luci.dispatcher.build_url("admin", "services", "shadowsocksr", "servers", "%s")
  92. function s.create(...)
  93. local sid = TypedSection.create(...)
  94. if sid then
  95. luci.http.redirect(s.extedit % sid)
  96. return
  97. end
  98. end
  99. o = s:option(DummyValue, "type", translate("Type"))
  100. function o.cfgvalue(self, section)
  101. return m:get(section, "v2ray_protocol") or Value.cfgvalue(self, section) or translate("None")
  102. end
  103. o = s:option(DummyValue, "alias", translate("Alias"))
  104. function o.cfgvalue(...)
  105. return Value.cfgvalue(...) or translate("None")
  106. end
  107. o = s:option(DummyValue, "server_port", translate("Server Port"))
  108. function o.cfgvalue(...)
  109. return Value.cfgvalue(...) or "N/A"
  110. end
  111. o = s:option(DummyValue, "server_port", translate("Socket Connected"))
  112. o.template = "shadowsocksr/socket"
  113. o.width = "10%"
  114. o.render = function(self, section, scope)
  115. self.transport = s:cfgvalue(section).transport
  116. if self.transport == 'ws' then
  117. self.ws_path = s:cfgvalue(section).ws_path
  118. self.tls = s:cfgvalue(section).tls
  119. end
  120. DummyValue.render(self, section, scope)
  121. end
  122. o = s:option(DummyValue, "server", translate("Ping Latency"))
  123. o.template = "shadowsocksr/ping"
  124. o.width = "10%"
  125. local global_server = uci:get_first('shadowsocksr', 'global', 'global_server')
  126. node = s:option(Button, "apply_node", translate("Apply"))
  127. node.inputstyle = "apply"
  128. node.render = function(self, section, scope)
  129. if section == global_server then
  130. self.title = translate("Reapply")
  131. else
  132. self.title = translate("Apply")
  133. end
  134. Button.render(self, section, scope)
  135. end
  136. node.write = function(self, section)
  137. uci:set("shadowsocksr", '@global[0]', 'global_server', section)
  138. uci:save("shadowsocksr")
  139. uci:commit("shadowsocksr")
  140. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "shadowsocksr", "restart"))
  141. end
  142. o = s:option(Flag, "switch_enable", translate("Auto Switch"))
  143. o.rmempty = false
  144. function o.cfgvalue(...)
  145. return Value.cfgvalue(...) or 1
  146. end
  147. m:append(Template("shadowsocksr/server_list"))
  148. return m