status.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. -- Copyright (C) 2017 yushi studio <[email protected]>
  2. -- Licensed to the public under the GNU General Public License v3.
  3. local m, s, o
  4. local redir_run=0
  5. local reudp_run=0
  6. local sock5_run=0
  7. local server_run=0
  8. local kcptun_run=0
  9. local tunnel_run=0
  10. local gfw_count=0
  11. local ad_count=0
  12. local ip_count=0
  13. local nfip_count=0
  14. local uci = luci.model.uci.cursor()
  15. local shadowsocksr = "shadowsocksr"
  16. -- html constants
  17. font_blue = [[<font color="green">]]
  18. font_off = [[</font>]]
  19. bold_on = [[<strong>]]
  20. bold_off = [[</strong>]]
  21. local fs = require "nixio.fs"
  22. local sys = require "luci.sys"
  23. local kcptun_version=translate("Unknown")
  24. local kcp_file="/usr/bin/kcptun-client"
  25. if not fs.access(kcp_file) then
  26. kcptun_version=translate("Not exist")
  27. else
  28. if not fs.access(kcp_file, "rwx", "rx", "rx") then
  29. fs.chmod(kcp_file, 755)
  30. end
  31. kcptun_version=sys.exec(kcp_file .. " -v | awk '{printf $3}'")
  32. if not kcptun_version or kcptun_version == "" then
  33. kcptun_version = translate("Unknown")
  34. end
  35. end
  36. if nixio.fs.access("/etc/dnsmasq.ssr/gfw_list.conf") then
  37. gfw_count = tonumber(sys.exec("cat /etc/dnsmasq.ssr/gfw_list.conf | wc -l"))/2
  38. end
  39. if nixio.fs.access("/etc/dnsmasq.ssr/ad.conf") then
  40. ad_count = tonumber(sys.exec("cat /etc/dnsmasq.ssr/ad.conf | wc -l"))
  41. end
  42. if nixio.fs.access("/etc/china_ssr.txt") then
  43. ip_count = tonumber(sys.exec("cat /etc/china_ssr.txt | wc -l"))
  44. end
  45. if nixio.fs.access("/etc/config/netflixip.list") then
  46. nfip_count = tonumber(sys.exec("cat /etc/config/netflixip.list | wc -l"))
  47. end
  48. local icount=sys.exec("busybox ps -w | grep ssr-reudp |grep -v grep| wc -l")
  49. if tonumber(icount)>0 then
  50. reudp_run=1
  51. else
  52. icount=sys.exec("busybox ps -w | grep ssr-retcp |grep \"\\-u\"|grep -v grep| wc -l")
  53. if tonumber(icount)>0 then
  54. reudp_run=1
  55. end
  56. end
  57. if luci.sys.call("busybox ps -w | grep ssr-retcp | grep -v grep >/dev/null") == 0 then
  58. redir_run=1
  59. end
  60. if luci.sys.call("busybox ps -w | grep ssr-local | grep -v ssr-socksdns |grep -v grep >/dev/null") == 0 then
  61. sock5_run=1
  62. end
  63. if luci.sys.call("pidof kcptun-client >/dev/null") == 0 then
  64. kcptun_run=1
  65. end
  66. if luci.sys.call("busybox ps -w | grep ssr-server | grep -v grep >/dev/null") == 0 then
  67. server_run=1
  68. end
  69. if luci.sys.call("busybox ps -w | grep ssr-tunnel |grep -v grep >/dev/null") == 0 then
  70. tunnel_run=1
  71. end
  72. 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
  73. pdnsd_run=1
  74. end
  75. m = SimpleForm("Version")
  76. m.reset = false
  77. m.submit = false
  78. s=m:field(DummyValue,"redir_run",translate("Global Client"))
  79. s.rawhtml = true
  80. if redir_run == 1 then
  81. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  82. else
  83. s.value = translate("Not Running")
  84. end
  85. s=m:field(DummyValue,"reudp_run",translate("Game Mode UDP Relay"))
  86. s.rawhtml = true
  87. if reudp_run == 1 then
  88. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  89. else
  90. s.value = translate("Not Running")
  91. end
  92. if uci:get_first(shadowsocksr, 'global', 'pdnsd_enable', '0') ~= '0' then
  93. s=m:field(DummyValue,"pdnsd_run",translate("DNS Anti-pollution"))
  94. s.rawhtml = true
  95. if pdnsd_run == 1 then
  96. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  97. else
  98. s.value = translate("Not Running")
  99. end
  100. end
  101. s=m:field(DummyValue,"sock5_run",translate("Global SOCKS5 Proxy Server"))
  102. s.rawhtml = true
  103. if sock5_run == 1 then
  104. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  105. else
  106. s.value = translate("Not Running")
  107. end
  108. s=m:field(DummyValue,"server_run",translate("Local Servers"))
  109. s.rawhtml = true
  110. if server_run == 1 then
  111. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  112. else
  113. s.value = translate("Not Running")
  114. end
  115. if nixio.fs.access("/usr/bin/kcptun-client") then
  116. s=m:field(DummyValue,"kcp_version",translate("KcpTun Version"))
  117. s.rawhtml = true
  118. s.value =kcptun_version
  119. s=m:field(DummyValue,"kcptun_run",translate("KcpTun"))
  120. s.rawhtml = true
  121. if kcptun_run == 1 then
  122. s.value =font_blue .. bold_on .. translate("Running") .. bold_off .. font_off
  123. else
  124. s.value = translate("Not Running")
  125. end
  126. end
  127. s=m:field(DummyValue,"google",translate("Google Connectivity"))
  128. s.value = translate("No Check")
  129. s.template = "shadowsocksr/check"
  130. s=m:field(DummyValue,"baidu",translate("Baidu Connectivity"))
  131. s.value = translate("No Check")
  132. s.template = "shadowsocksr/check"
  133. s=m:field(DummyValue,"gfw_data",translate("GFW List Data"))
  134. s.rawhtml = true
  135. s.template = "shadowsocksr/refresh"
  136. s.value = gfw_count .. " " .. translate("Records")
  137. s=m:field(DummyValue,"ip_data",translate("China IP Data"))
  138. s.rawhtml = true
  139. s.template = "shadowsocksr/refresh"
  140. s.value = ip_count .. " " .. translate("Records")
  141. s=m:field(DummyValue,"nfip_data",translate("Netflix IP Data"))
  142. s.rawhtml = true
  143. s.template = "shadowsocksr/refresh"
  144. s.value = nfip_count .. " " .. translate("Records")
  145. if uci:get_first(shadowsocksr, 'global', 'adblock', '0') == '1' then
  146. s=m:field(DummyValue,"ad_data",translate("Advertising Data"))
  147. s.rawhtml = true
  148. s.template = "shadowsocksr/refresh"
  149. s.value = ad_count .. " " .. translate("Records")
  150. end
  151. s=m:field(DummyValue,"check_port",translate("Check Server Port"))
  152. s.template = "shadowsocksr/checkport"
  153. s.value =translate("No Check")
  154. return m