configuration_tab.lua 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. -- Copyright 2017 Dirk Brenken (dev@brenken.org)
  2. -- This is free software, licensed under the Apache License, Version 2.0
  3. local nxfs = require("nixio.fs")
  4. local util = require("luci.util")
  5. local uci_input = "/etc/config/dnscrypt-proxy"
  6. if not nxfs.access(uci_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. m = SimpleForm("input", nil)
  13. m:append(Template("dnscrypt-proxy/config_css"))
  14. m.submit = translate("Save")
  15. m.reset = false
  16. s = m:section(SimpleSection, nil,
  17. translate("This form allows you to modify the content of the main DNSCrypt-Proxy configuration file (/etc/config/dnscrypt-proxy)."))
  18. f = s:option(TextValue, "data")
  19. f.rows = 20
  20. f.rmempty = true
  21. function f.cfgvalue()
  22. return nxfs.readfile(uci_input) or ""
  23. end
  24. function f.write(self, section, data)
  25. return nxfs.writefile(uci_input, "\n" .. util.trim(data:gsub("\r\n", "\n")) .. "\n")
  26. end
  27. function s.handle(self, state, data)
  28. return true
  29. end
  30. return m