whitelist_tab.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. -- Copyright 2017 Dirk Brenken (dev@brenken.org)
  2. -- This is free software, licensed under the Apache License, Version 2.0
  3. local fs = require("nixio.fs")
  4. local util = require("luci.util")
  5. local uci = require("uci")
  6. local adbinput = uci.get("adblock", "global", "adb_whitelist") or "/etc/adblock/adblock.whitelist"
  7. if not nixio.fs.access(adbinput) then
  8. m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
  9. m.reset = false
  10. m.submit = false
  11. return m
  12. end
  13. if nixio.fs.stat(adbinput).size > 524288 then
  14. m = SimpleForm("error", nil,
  15. translate("The file size is too large for online editing in LuCI (> 512 KB). ")
  16. .. translate("Please edit this file directly in a terminal session."))
  17. m.reset = false
  18. m.submit = false
  19. return m
  20. end
  21. m = SimpleForm("input", nil)
  22. m:append(Template("adblock/config_css"))
  23. m.submit = translate("Save")
  24. m.reset = false
  25. s = m:section(SimpleSection, nil,
  26. translatef("This form allows you to modify the content of the adblock whitelist (%s).<br />", adbinput)
  27. .. translate("Please add only one domain per line. Comments introduced with '#' are allowed - ip addresses, wildcards and regex are not."))
  28. f = s:option(TextValue, "data")
  29. f.datatype = "string"
  30. f.rows = 20
  31. f.rmempty = true
  32. function f.cfgvalue()
  33. return nixio.fs.readfile(adbinput) or ""
  34. end
  35. function f.write(self, section, data)
  36. return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
  37. end
  38. function s.handle(self, state, data)
  39. return true
  40. end
  41. return m