status.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 uci = luci.model.uci.cursor()
  18. local shadowsocksr = "shadowsocksr"
  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/ssr/gfw_list.conf") then
  38. gfw_count = tonumber(luci.sys.exec("cat /etc/ssr/gfw_list.conf | wc -l"))/2
  39. end
  40. if nixio.fs.access("/etc/ssr/ad.conf") then
  41. ad_count = tonumber(luci.sys.exec("cat /etc/ssr/ad.conf | wc -l"))
  42. end
  43. if nixio.fs.access("/etc/ssr/china_ssr.txt") then
  44. ip_count = tonumber(luci.sys.exec("cat /etc/ssr/china_ssr.txt | wc -l"))
  45. end
  46. if nixio.fs.access("/etc/ssr/netflixip.list") then
  47. nfip_count = tonumber(luci.sys.exec("cat /etc/ssr/netflixip.list | wc -l"))
  48. end
  49. local icount=luci.sys.exec("busybox ps -w | grep ssr-reudp |grep -v grep| wc -l")
  50. if tonumber(icount)>0 then
  51. reudp_run=1
  52. else
  53. icount=luci.sys.exec("busybox ps -w | grep ssr-retcp |grep \"\\-u\"|grep -v grep| wc -l")
  54. if tonumber(icount)>0 then
  55. reudp_run=1
  56. end
  57. end
  58. if luci.sys.call("busybox ps -w | grep ssr-retcp | grep -v grep >/dev/null") == 0 then
  59. redir_run=1
  60. end
  61. if luci.sys.call("busybox ps -w | grep ssr-local | grep -v ssr-socksdns |grep -v grep >/dev/null") == 0 then
  62. sock5_run=1
  63. end
  64. if luci.sys.call("pidof kcptun-client >/dev/null") == 0 then
  65. kcptun_run=1
  66. end
  67. if luci.sys.call("busybox ps -w | grep ssr-server | grep -v grep >/dev/null") == 0 then
  68. server_run=1
  69. end
  70. -- if luci.sys.call("busybox ps -w | grep ssr-tunnel |grep -v grep >/dev/null") == 0 then
  71. -- tunnel_run=1
  72. -- end
  73. if luci.sys.call("pidof pdnsd >/dev/null") == 0 or (luci.sys.call("busybox ps -w | grep ssr-dns |grep -v grep >/dev/null") == 0 and luci.sys.call("pidof dns2socks >/dev/null") == 0)then
  74. pdnsd_run=1
  75. end
  76. m = SimpleForm("Version")
  77. m.reset = false
  78. m.submit = false
  79. s=m:field(DummyValue,"redir_run",translate("Global Client"))
  80. s.rawhtml = true
  81. if redir_run == 1 then
  82. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  83. else
  84. s.value = translate("Not Running")
  85. end
  86. s=m:field(DummyValue,"reudp_run",translate("Game Mode UDP Relay"))
  87. s.rawhtml = true
  88. if reudp_run == 1 then
  89. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  90. else
  91. s.value = translate("Not Running")
  92. end
  93. if uci:get_first(shadowsocksr, 'global', 'pdnsd_enable', '0') ~= '0' then
  94. s=m:field(DummyValue,"pdnsd_run",translate("DNS Anti-pollution"))
  95. s.rawhtml = true
  96. if pdnsd_run == 1 then
  97. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  98. else
  99. s.value = translate("Not Running")
  100. end
  101. end
  102. s=m:field(DummyValue,"sock5_run",translate("Global SOCKS5 Proxy Server"))
  103. s.rawhtml = true
  104. if sock5_run == 1 then
  105. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  106. else
  107. s.value = translate("Not Running")
  108. end
  109. s=m:field(DummyValue,"server_run",translate("Local Servers"))
  110. s.rawhtml = true
  111. if server_run == 1 then
  112. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  113. else
  114. s.value = translate("Not Running")
  115. end
  116. if nixio.fs.access("/usr/bin/kcptun-client") then
  117. s=m:field(DummyValue,"kcp_version",translate("KcpTun Version"))
  118. s.rawhtml = true
  119. s.value =kcptun_version
  120. s=m:field(DummyValue,"kcptun_run",translate("KcpTun"))
  121. s.rawhtml = true
  122. if kcptun_run == 1 then
  123. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  124. else
  125. s.value = translate("Not Running")
  126. end
  127. end
  128. s=m:field(DummyValue,"google",translate("Google Connectivity"))
  129. s.value = translate("No Check")
  130. s.template = "shadowsocksr/check"
  131. s=m:field(DummyValue,"baidu",translate("Baidu Connectivity"))
  132. s.value = translate("No Check")
  133. s.template = "shadowsocksr/check"
  134. s=m:field(DummyValue,"gfw_data",translate("GFW List Data"))
  135. s.rawhtml = true
  136. s.template = "shadowsocksr/refresh"
  137. s.value = gfw_count .. " " .. translate("Records")
  138. s=m:field(DummyValue,"ip_data",translate("China IP Data"))
  139. s.rawhtml = true
  140. s.template = "shadowsocksr/refresh"
  141. s.value = ip_count .. " " .. translate("Records")
  142. s=m:field(DummyValue,"nfip_data",translate("Netflix IP Data"))
  143. s.rawhtml = true
  144. s.template = "shadowsocksr/refresh"
  145. s.value = nfip_count .. " " .. translate("Records")
  146. if uci:get_first(shadowsocksr, 'global', 'adblock', '0') == '1' then
  147. s=m:field(DummyValue,"ad_data",translate("Advertising Data"))
  148. s.rawhtml = true
  149. s.template = "shadowsocksr/refresh"
  150. s.value = ad_count .. " " .. translate("Records")
  151. end
  152. s=m:field(DummyValue,"check_port",translate("Check Server Port"))
  153. s.template = "shadowsocksr/checkport"
  154. s.value =translate("No Check")
  155. return m