configuration_tab.lua 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- Copyright 2018 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 input = "/etc/config/banip"
  6. if not fs.access(input) then
  7. m = SimpleForm("error", nil, translate("Input file not found, please check your configuration."))
  8. m.reset = false
  9. m.submit = false
  10. return m
  11. end
  12. if fs.stat(input).size >= 102400 then
  13. m = SimpleForm("error", nil,
  14. translate("The file size is too large for online editing in LuCI (≥ 100 KB). ")
  15. .. translate("Please edit this file directly in a terminal session."))
  16. m.reset = false
  17. m.submit = false
  18. return m
  19. end
  20. m = SimpleForm("edit", nil)
  21. m:append(Template("banip/banip_css"))
  22. m.submit = translate("Save")
  23. m.reset = false
  24. s = m:section(SimpleSection, nil,
  25. translate("This form allows you to modify the content of the main banIP configuration file (/etc/config/banip)."))
  26. f = s:option(TextValue, "data")
  27. f.rows = 20
  28. f.rmempty = true
  29. function f.cfgvalue()
  30. return fs.readfile(input) or ""
  31. end
  32. function f.write(self, section, data)
  33. return fs.writefile(input, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
  34. end
  35. function f.remove(self, section, value)
  36. return fs.writefile(input, "")
  37. end
  38. function s.handle(self, state, data)
  39. return true
  40. end
  41. return m