status.lua 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. -- Copyright (C) 2017 yushi studio <[email protected]>
  2. -- Licensed to the public under the GNU General Public License v3.
  3. require "nixio.fs"
  4. require "luci.sys"
  5. require "luci.model.uci"
  6. local m, s, o
  7. local redir_run = 0
  8. local reudp_run = 0
  9. local sock5_run = 0
  10. local server_run = 0
  11. local kcptun_run = 0
  12. local tunnel_run = 0
  13. local gfw_count = 0
  14. local ad_count = 0
  15. local ip_count = 0
  16. local nfip_count = 0
  17. local Process_list = luci.sys.exec("busybox ps -w")
  18. local uci = require "luci.model.uci".cursor()
  19. -- html constants
  20. font_blue = [[<b style=color:green>]]
  21. style_blue = [[<b style=color:red>]]
  22. font_off = [[</b>]]
  23. bold_on = [[<strong>]]
  24. bold_off = [[</strong>]]
  25. local kcptun_version = translate("Unknown")
  26. local kcp_file = "/usr/bin/kcptun-client"
  27. if not nixio.fs.access(kcp_file) then
  28. kcptun_version = translate("Not exist")
  29. else
  30. if not nixio.fs.access(kcp_file, "rwx", "rx", "rx") then
  31. nixio.fs.chmod(kcp_file, 755)
  32. end
  33. kcptun_version = "<b>" ..luci.sys.exec(kcp_file .. " -v | awk '{printf $3}'") .. "</b>"
  34. if not kcptun_version or kcptun_version == "" then
  35. kcptun_version = translate("Unknown")
  36. end
  37. end
  38. if nixio.fs.access("/etc/ssrplus/gfw_list.conf") then
  39. gfw_count = tonumber(luci.sys.exec("cat /etc/ssrplus/gfw_list.conf | wc -l")) / 2
  40. end
  41. if nixio.fs.access("/etc/ssrplus/ad.conf") then
  42. ad_count = tonumber(luci.sys.exec("cat /etc/ssrplus/ad.conf | wc -l"))
  43. end
  44. if nixio.fs.access("/etc/ssrplus/china_ssr.txt") then
  45. ip_count = tonumber(luci.sys.exec("cat /etc/ssrplus/china_ssr.txt | wc -l"))
  46. end
  47. if nixio.fs.access("/etc/ssrplus/applechina.conf") then
  48. apple_count = tonumber(luci.sys.exec("cat /etc/ssrplus/applechina.conf | wc -l"))
  49. end
  50. if nixio.fs.access("/etc/ssrplus/netflixip.list") then
  51. nfip_count = tonumber(luci.sys.exec("cat /etc/ssrplus/netflixip.list | wc -l"))
  52. end
  53. if Process_list:find("udp.only.ssr.reudp") then
  54. reudp_run = 1
  55. end
  56. if Process_list:find("tcp.only.ssr.retcp") then
  57. redir_run = 1
  58. end
  59. if Process_list:find("tcp.udp.ssr.local") then
  60. sock5_run = 1
  61. end
  62. if Process_list:find("tcp.udp.ssr.retcp") then
  63. redir_run = 1
  64. reudp_run = 1
  65. end
  66. if Process_list:find("local.ssr.retcp") then
  67. redir_run = 1
  68. sock5_run = 1
  69. end
  70. if Process_list:find("local.udp.ssr.retcp") then
  71. reudp_run = 1
  72. redir_run = 1
  73. sock5_run = 1
  74. end
  75. if Process_list:find("kcptun.client") then
  76. kcptun_run = 1
  77. end
  78. if Process_list:find("ssr.server") then
  79. server_run = 1
  80. end
  81. if Process_list:find("ssrplus/bin/dns2tcp") or Process_list:find("ssrplus/bin/mosdns") or (Process_list:find("ssrplus.dns") and Process_list:find("dns2socks.127.0.0.1.*127.0.0.1.5335")) then
  82. pdnsd_run = 1
  83. end
  84. m = SimpleForm("Version")
  85. m.reset = false
  86. m.submit = false
  87. s = m:field(DummyValue, "redir_run", translate("Global Client"))
  88. s.rawhtml = true
  89. if redir_run == 1 then
  90. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  91. else
  92. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  93. end
  94. s = m:field(DummyValue, "reudp_run", translate("Game Mode UDP Relay"))
  95. s.rawhtml = true
  96. if reudp_run == 1 then
  97. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  98. else
  99. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  100. end
  101. if uci:get_first("shadowsocksr", 'global', 'pdnsd_enable', '0') ~= '0' then
  102. s = m:field(DummyValue, "pdnsd_run", translate("DNS Anti-pollution"))
  103. s.rawhtml = true
  104. if pdnsd_run == 1 then
  105. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  106. else
  107. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  108. end
  109. end
  110. s = m:field(DummyValue, "sock5_run", translate("Global SOCKS5 Proxy Server"))
  111. s.rawhtml = true
  112. if sock5_run == 1 then
  113. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  114. else
  115. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  116. end
  117. s = m:field(DummyValue, "server_run", translate("Local Servers"))
  118. s.rawhtml = true
  119. if server_run == 1 then
  120. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  121. else
  122. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  123. end
  124. if nixio.fs.access("/usr/bin/kcptun-client") then
  125. s = m:field(DummyValue, "kcp_version", translate("KcpTun Version"))
  126. s.rawhtml = true
  127. s.value = kcptun_version
  128. s = m:field(DummyValue, "kcptun_run", translate("KcpTun"))
  129. s.rawhtml = true
  130. if kcptun_run == 1 then
  131. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  132. else
  133. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  134. end
  135. end
  136. s = m:field(Button, "Restart", translate("Restart ShadowSocksR Plus+"))
  137. s.inputtitle = translate("Restart Service")
  138. s.inputstyle = "reload"
  139. s.write = function()
  140. luci.sys.call("/etc/init.d/shadowsocksr restart >/dev/null 2>&1 &")
  141. luci.http.redirect(luci.dispatcher.build_url("admin", "services", "shadowsocksr", "client"))
  142. end
  143. s = m:field(DummyValue, "google", translate("Google Connectivity"))
  144. s.value = translate("No Check")
  145. s.template = "shadowsocksr/check"
  146. s = m:field(DummyValue, "baidu", translate("Baidu Connectivity"))
  147. s.value = translate("No Check")
  148. s.template = "shadowsocksr/check"
  149. s = m:field(DummyValue, "gfw_data", translate("GFW List Data"))
  150. s.rawhtml = true
  151. s.template = "shadowsocksr/refresh"
  152. s.value = gfw_count .. " " .. translate("Records")
  153. s = m:field(DummyValue, "ip_data", translate("China IP Data"))
  154. s.rawhtml = true
  155. s.template = "shadowsocksr/refresh"
  156. s.value = ip_count .. " " .. translate("Records")
  157. if uci:get_first("shadowsocksr", 'global', 'apple_optimization', '0') ~= '0' then
  158. s = m:field(DummyValue, "apple_data", translate("Apple Domains Data"))
  159. s.rawhtml = true
  160. s.template = "shadowsocksr/refresh"
  161. s.value = apple_count .. " " .. translate("Records")
  162. end
  163. if uci:get_first("shadowsocksr", 'global', 'netflix_enable', '0') ~= '0' then
  164. s = m:field(DummyValue, "nfip_data", translate("Netflix IP Data"))
  165. s.rawhtml = true
  166. s.template = "shadowsocksr/refresh"
  167. s.value = nfip_count .. " " .. translate("Records")
  168. end
  169. if uci:get_first("shadowsocksr", 'global', 'adblock', '0') == '1' then
  170. s = m:field(DummyValue, "ad_data", translate("Advertising Data"))
  171. s.rawhtml = true
  172. s.template = "shadowsocksr/refresh"
  173. s.value = ad_count .. " " .. translate("Records")
  174. end
  175. s = m:field(DummyValue, "check_port", translate("Check Server Port"))
  176. s.template = "shadowsocksr/checkport"
  177. s.value = translate("No Check")
  178. return m