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 fs = require("nixio.fs")
  4. local util = require("luci.util")
  5. local trminput = "/etc/config/travelmate"
  6. if not nixio.fs.access(trminput) 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("travelmate/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 travelmate configuration file (/etc/config/travelmate)."))
  18. f = s:option(TextValue, "data")
  19. f.rows = 20
  20. f.rmempty = true
  21. function f.cfgvalue()
  22. return nixio.fs.readfile(trminput) or ""
  23. end
  24. function f.write(self, section, data)
  25. return nixio.fs.writefile(trminput, "\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