control.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. require "luci.ip"
  2. require "nixio.fs"
  3. require "luci.sys"
  4. local m, s, o
  5. m = Map("shadowsocksr")
  6. s = m:section(TypedSection, "access_control")
  7. s.anonymous = true
  8. -- Interface control
  9. s:tab("Interface", translate("Interface control"))
  10. o = s:taboption("Interface", DynamicList, "Interface", translate("Interface"))
  11. o.template = "cbi/network_netlist"
  12. o.widget = "checkbox"
  13. o.nocreate = true
  14. o.unspecified = true
  15. o.description = translate("Listen only on the given interface or, if unspecified, on all")
  16. -- Part of WAN
  17. s:tab("wan_ac", translate("WAN IP AC"))
  18. o = s:taboption("wan_ac", DynamicList, "wan_bp_ips", translate("WAN White List IP"))
  19. o.datatype = "ip4addr"
  20. o = s:taboption("wan_ac", DynamicList, "wan_fw_ips", translate("WAN Force Proxy IP"))
  21. o.datatype = "ip4addr"
  22. -- Part of LAN
  23. s:tab("lan_ac", translate("LAN IP AC"))
  24. o = s:taboption("lan_ac", ListValue, "lan_ac_mode", translate("LAN Access Control"))
  25. o:value("0", translate("Disable"))
  26. o:value("w", translate("Allow listed only"))
  27. o:value("b", translate("Allow all except listed"))
  28. o.rmempty = false
  29. o = s:taboption("lan_ac", DynamicList, "lan_ac_ips", translate("LAN Host List"))
  30. o.datatype = "ipaddr"
  31. luci.ip.neighbors({family = 4}, function(entry)
  32. if entry.reachable then
  33. o:value(entry.dest:string())
  34. end
  35. end)
  36. o:depends("lan_ac_mode", "w")
  37. o:depends("lan_ac_mode", "b")
  38. o = s:taboption("lan_ac", DynamicList, "lan_bp_ips", translate("LAN Bypassed Host List"))
  39. o.datatype = "ipaddr"
  40. luci.ip.neighbors({family = 4}, function(entry)
  41. if entry.reachable then
  42. o:value(entry.dest:string())
  43. end
  44. end)
  45. o = s:taboption("lan_ac", DynamicList, "lan_fp_ips", translate("LAN Force Proxy Host List"))
  46. o.datatype = "ipaddr"
  47. luci.ip.neighbors({family = 4}, function(entry)
  48. if entry.reachable then
  49. o:value(entry.dest:string())
  50. end
  51. end)
  52. o = s:taboption("lan_ac", DynamicList, "lan_gm_ips", translate("Game Mode Host List"))
  53. o.datatype = "ipaddr"
  54. luci.ip.neighbors({family = 4}, function(entry)
  55. if entry.reachable then
  56. o:value(entry.dest:string())
  57. end
  58. end)
  59. -- Part of Self
  60. -- s:tab("self_ac", translate("Router Self AC"))
  61. -- o = s:taboption("self_ac",ListValue, "router_proxy", translate("Router Self Proxy"))
  62. -- o:value("1", translatef("Normal Proxy"))
  63. -- o:value("0", translatef("Bypassed Proxy"))
  64. -- o:value("2", translatef("Forwarded Proxy"))
  65. -- o.rmempty = false
  66. s:tab("esc", translate("Bypass Domain List"))
  67. local escconf = "/etc/ssrplus/white.list"
  68. o = s:taboption("esc", TextValue, "escconf")
  69. o.rows = 13
  70. o.wrap = "off"
  71. o.rmempty = true
  72. o.cfgvalue = function(self, section)
  73. return nixio.fs.readfile(escconf) or ""
  74. end
  75. o.write = function(self, section, value)
  76. nixio.fs.writefile(escconf, value:gsub("\r\n", "\n"))
  77. end
  78. o.remove = function(self, section, value)
  79. nixio.fs.writefile(escconf, "")
  80. end
  81. s:tab("block", translate("Black Domain List"))
  82. local blockconf = "/etc/ssrplus/black.list"
  83. o = s:taboption("block", TextValue, "blockconf")
  84. o.rows = 13
  85. o.wrap = "off"
  86. o.rmempty = true
  87. o.cfgvalue = function(self, section)
  88. return nixio.fs.readfile(blockconf) or " "
  89. end
  90. o.write = function(self, section, value)
  91. nixio.fs.writefile(blockconf, value:gsub("\r\n", "\n"))
  92. end
  93. o.remove = function(self, section, value)
  94. nixio.fs.writefile(blockconf, "")
  95. end
  96. s:tab("denydomain", translate("Deny Domain List"))
  97. local denydomainconf = "/etc/ssrplus/deny.list"
  98. o = s:taboption("denydomain", TextValue, "denydomainconf")
  99. o.rows = 13
  100. o.wrap = "off"
  101. o.rmempty = true
  102. o.cfgvalue = function(self, section)
  103. return nixio.fs.readfile(denydomainconf) or " "
  104. end
  105. o.write = function(self, section, value)
  106. nixio.fs.writefile(denydomainconf, value:gsub("\r\n", "\n"))
  107. end
  108. o.remove = function(self, section, value)
  109. nixio.fs.writefile(denydomainconf, "")
  110. end
  111. s:tab("netflix", translate("Netflix Domain List"))
  112. local netflixconf = "/etc/ssrplus/netflix.list"
  113. o = s:taboption("netflix", TextValue, "netflixconf")
  114. o.rows = 13
  115. o.wrap = "off"
  116. o.rmempty = true
  117. o.cfgvalue = function(self, section)
  118. return nixio.fs.readfile(netflixconf) or " "
  119. end
  120. o.write = function(self, section, value)
  121. nixio.fs.writefile(netflixconf, value:gsub("\r\n", "\n"))
  122. end
  123. o.remove = function(self, section, value)
  124. nixio.fs.writefile(netflixconf, "")
  125. end
  126. if luci.sys.call('[ -f "/www/luci-static/resources/uci.js" ]') == 0 then
  127. m.apply_on_parse = true
  128. function m.on_apply(self)
  129. luci.sys.call("/etc/init.d/shadowsocksr reload > /dev/null 2>&1 &")
  130. end
  131. end
  132. return m