control.lua 3.8 KB

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