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