status.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 = 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/netflixip.list") then
  48. nfip_count = tonumber(luci.sys.exec("cat /etc/ssrplus/netflixip.list | wc -l"))
  49. end
  50. if Process_list:find("udp.only.ssr.reudp") then
  51. reudp_run = 1
  52. end
  53. if Process_list:find("tcp.only.ssr.retcp") then
  54. redir_run = 1
  55. end
  56. if Process_list:find("tcp.udp.ssr.local") then
  57. sock5_run = 1
  58. end
  59. if Process_list:find("tcp.udp.ssr.retcp") then
  60. redir_run = 1
  61. reudp_run = 1
  62. end
  63. if Process_list:find("local.ssr.retcp") then
  64. redir_run = 1
  65. sock5_run = 1
  66. end
  67. if Process_list:find("local.udp.ssr.retcp") then
  68. reudp_run = 1
  69. redir_run = 1
  70. sock5_run = 1
  71. end
  72. if Process_list:find("kcptun.client") then
  73. kcptun_run = 1
  74. end
  75. if Process_list:find("ssr.server") then
  76. server_run = 1
  77. end
  78. if Process_list:find("ssrplus/bin/pdnsd") or Process_list:find("ssrplus/bin/dns2tcp") or (Process_list:find("ssrplus.dns") and Process_list:find("dns2socks.127.0.0.1.*127.0.0.1.5335")) then
  79. pdnsd_run = 1
  80. end
  81. m = SimpleForm("Version")
  82. m.reset = false
  83. m.submit = false
  84. s = m:field(DummyValue, "redir_run", translate("Global Client"))
  85. s.rawhtml = true
  86. if redir_run == 1 then
  87. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  88. else
  89. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  90. end
  91. s = m:field(DummyValue, "reudp_run", translate("Game Mode UDP Relay"))
  92. s.rawhtml = true
  93. if reudp_run == 1 then
  94. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  95. else
  96. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  97. end
  98. if uci:get_first("shadowsocksr", 'global', 'pdnsd_enable', '0') ~= '0' then
  99. s = m:field(DummyValue, "pdnsd_run", translate("DNS Anti-pollution"))
  100. s.rawhtml = true
  101. if pdnsd_run == 1 then
  102. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  103. else
  104. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  105. end
  106. end
  107. s = m:field(DummyValue, "sock5_run", translate("Global SOCKS5 Proxy Server"))
  108. s.rawhtml = true
  109. if sock5_run == 1 then
  110. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  111. else
  112. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  113. end
  114. s = m:field(DummyValue, "server_run", translate("Local Servers"))
  115. s.rawhtml = true
  116. if server_run == 1 then
  117. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  118. else
  119. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  120. end
  121. if nixio.fs.access("/usr/bin/kcptun-client") then
  122. s = m:field(DummyValue, "kcp_version", translate("KcpTun Version"))
  123. s.rawhtml = true
  124. s.value = kcptun_version
  125. s = m:field(DummyValue, "kcptun_run", translate("KcpTun"))
  126. s.rawhtml = true
  127. if kcptun_run == 1 then
  128. s.value = font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  129. else
  130. s.value = style_blue .. bold_on .. translate("Not Running") .. bold_off .. font_off
  131. end
  132. end
  133. s = m:field(DummyValue, "google", translate("Google Connectivity"))
  134. s.value = translate("No Check")
  135. s.template = "shadowsocksr/check"
  136. s = m:field(DummyValue, "baidu", translate("Baidu Connectivity"))
  137. s.value = translate("No Check")
  138. s.template = "shadowsocksr/check"
  139. s = m:field(DummyValue, "gfw_data", translate("GFW List Data"))
  140. s.rawhtml = true
  141. s.template = "shadowsocksr/refresh"
  142. s.value = gfw_count .. " " .. translate("Records")
  143. s = m:field(DummyValue, "ip_data", translate("China IP Data"))
  144. s.rawhtml = true
  145. s.template = "shadowsocksr/refresh"
  146. s.value = ip_count .. " " .. translate("Records")
  147. if uci:get_first("shadowsocksr", 'global', 'netflix_enable', '0') ~= '0' then
  148. s = m:field(DummyValue, "nfip_data", translate("Netflix IP Data"))
  149. s.rawhtml = true
  150. s.template = "shadowsocksr/refresh"
  151. s.value = nfip_count .. " " .. translate("Records")
  152. end
  153. if uci:get_first("shadowsocksr", 'global', 'adblock', '0') == '1' then
  154. s = m:field(DummyValue, "ad_data", translate("Advertising Data"))
  155. s.rawhtml = true
  156. s.template = "shadowsocksr/refresh"
  157. s.value = ad_count .. " " .. translate("Records")
  158. end
  159. if uci:get_first("shadowsocksr", 'global', 'pdnsd_enable', '0') == '1' then
  160. s = m:field(DummyValue, "cache", translate("Reset pdnsd cache"))
  161. s.template = "shadowsocksr/cache"
  162. end
  163. s = m:field(DummyValue, "check_port", translate("Check Server Port"))
  164. s.template = "shadowsocksr/checkport"
  165. s.value = translate("No Check")
  166. return m