control.lua 4.1 KB

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