blacklist_tab.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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", "blacklist", "adb_src" or "/etc/adblock/adblock.blacklist")
  7. if not nixio.fs.access(adbinput) then
  8. m = SimpleForm("error", nil,
  9. translate("Input file not found, please check your configuration."))
  10. m.reset = false
  11. m.submit = false
  12. return m
  13. end
  14. if nixio.fs.stat(adbinput).size > 524288 then
  15. m = SimpleForm("error", nil,
  16. translate("The file size is too large for online editing in LuCI (> 512 KB). ")
  17. .. translate("Please edit this file directly in a terminal session."))
  18. m.reset = false
  19. m.submit = false
  20. return m
  21. end
  22. m = SimpleForm("input", nil)
  23. m:append(Template("adblock/config_css"))
  24. m.submit = translate("Save")
  25. m.reset = false
  26. s = m:section(SimpleSection, nil,
  27. translatef("This form allows you to modify the content of the adblock blacklist (%s).<br />", adbinput)
  28. .. translate("Please add only one domain per line. Comments introduced with '#' are allowed - ip addresses, wildcards and regex are not."))
  29. f = s:option(TextValue, "data")
  30. f.datatype = "string"
  31. f.rows = 20
  32. f.rmempty = true
  33. function f.cfgvalue()
  34. return nixio.fs.readfile(adbinput) or ""
  35. end
  36. function f.write(self, section, data)
  37. return nixio.fs.writefile(adbinput, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
  38. end
  39. function s.handle(self, state, data)
  40. return true
  41. end
  42. return m