933efb45f41aaa5b41813d61c006107afb087251
[project/luci.git] / modules / freifunk / luasrc / model / cbi / freifunk / profile.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2011-2012 Manuel Munz <freifunk at somakoma dot de>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10         httc://www.apache.org/licenses/LICENSE-2.0
11 ]]--
12
13 local uci = require "luci.model.uci".cursor()
14 local ipkg = require "luci.model.ipkg"
15 local community = uci:get("freifunk", "community", "name")
16 luci.i18n.loadc("freifunk")
17
18 if community == nil then
19         luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "profile_error"))
20         return
21 else
22         community = "profile_" .. community
23         m = Map(community, translate("Community settings"), translate("These are the settings of your local community."))
24         c = m:section(NamedSection, "profile", "community")
25
26         local name = c:option(Value, "name", "Name")
27         name.rmempty = false
28
29         local homepage = c:option(Value, "homepage", translate("Homepage"))
30
31         local cc = c:option(Value, "country", translate("Country code"))
32         function cc.cfgvalue(self, section)
33                 return uci:get(community, "wifi_device", "country")
34         end
35         function cc.write(self, sec, value)
36                 if value then
37                         uci:set(community, "wifi_device", "country", value)
38                         uci:save(community)
39                 end
40         end
41
42         local ssid = c:option(Value, "ssid", translate("ESSID"))
43         ssid.rmempty = false
44
45         local prefix = c:option(Value, "mesh_network", translate("Mesh prefix"))
46         prefix.datatype = "ip4addr"
47         prefix.rmempty = false
48
49         local splash_net = c:option(Value, "splash_network", translate("Network for client DHCP addresses"))
50         splash_net.datatype = "ip4addr"
51         splash_net.rmempty = false
52
53         local splash_prefix = c:option(Value, "splash_prefix", translate("Client network size"))
54         splash_prefix.datatype = "range(0,32)"
55         splash_prefix.rmempty = false
56
57         local ipv6 = c:option(Flag, "ipv6", translate("Enable IPv6"))
58         ipv6.rmempty = true
59
60         local ipv6_config = c:option(ListValue, "ipv6_config", translate("IPv6 Config"))
61         ipv6_config:depends("ipv6", 1)
62         ipv6_config:value("static")
63         if ipkg.installed ("auto-ipv6-ib") then
64                 ipv6_config:value("auto-ipv6-random")
65                 ipv6_config:value("auto-ipv6-fromv4")
66         end
67         ipv6_config.rmempty = true
68
69         local ipv6_prefix = c:option(Value, "ipv6_prefix", translate("IPv6 Prefix"), translate("IPv6 network in CIDR notation."))
70         ipv6_prefix:depends("ipv6", 1)
71         ipv6_prefix.datatype = "ip6addr"
72         ipv6_prefix.rmempty = true
73
74         local lat = c:option(Value, "latitude", translate("Latitude"))
75         lat.datatype = "range(-180, 180)"
76         lat.rmempty = false
77
78         local lon = c:option(Value, "longitude", translate("Longitude"))
79         lon.rmempty = false
80         return m
81 end