2
0

uciedit.lua 1011 B

12345678910111213141516171819202122232425262728293031323334353637
  1. -- Copyright 2016 Eric Luehrsen <ericluehrsen@gmail.com>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local m6, s6, frm
  4. local filename = "/etc/config/unbound"
  5. local fs = require "nixio.fs"
  6. local ut = require "luci.util"
  7. m6 = SimpleForm("editing", nil)
  8. m6:append(Template("unbound/css-editing"))
  9. m6.submit = translate("Save")
  10. m6.reset = false
  11. s6 = m6:section(SimpleSection, "",
  12. translatef("Edit '" .. filename .. "' "
  13. .. "and recipes can be found in OpenWrt "
  14. .. "<a href=\"%s\" target=\"_blank\">Guides</a> "
  15. .. "and <a href=\"%s\" target=\"_blank\">Github</a>.",
  16. "https://openwrt.org/docs/guide-user/services/dns/unbound",
  17. "https://github.com/openwrt/packages/blob/master/net/unbound/files/README.md"))
  18. frm = s6:option(TextValue, "data")
  19. frm.datatype = "string"
  20. frm.rows = 20
  21. function frm.cfgvalue()
  22. return fs.readfile(filename) or ""
  23. end
  24. function frm.write(self, section, data)
  25. return fs.writefile(filename, ut.trim(data:gsub("\r\n", "\n")))
  26. end
  27. return m6