status.lua 5.3 KB

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