profile_expert.lua 902 B

1234567891011121314151617181920212223242526272829303132
  1. -- Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
  2. -- Licensed to the public under the Apache License 2.0.
  3. local fs = require "nixio.fs"
  4. local uci = require "luci.model.uci".cursor()
  5. local community = uci:get("freifunk", "community", "name")
  6. if community == nil then
  7. luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "profile_error"))
  8. return
  9. else
  10. community = "/etc/config/profile_" .. community
  11. f = SimpleForm("community", translate("Community profile"), translate("You can manually edit the selected community profile here."))
  12. t = f:field(TextValue, "cop")
  13. t.rmempty = true
  14. t.rows = 30
  15. function t.cfgvalue()
  16. return fs.readfile(community) or ""
  17. end
  18. function f.handle(self, state, data)
  19. if state == FORM_VALID then
  20. if data.cop then
  21. fs.writefile(community, data.cop:gsub("\r\n", "\n"))
  22. end
  23. end
  24. return true
  25. end
  26. return f
  27. end