diff options
Diffstat (limited to 'modules/luci-mod-freifunk/luasrc/model')
5 files changed, 283 insertions, 0 deletions
diff --git a/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/basics.lua b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/basics.lua new file mode 100644 index 0000000000..8987b1cb46 --- /dev/null +++ b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/basics.lua @@ -0,0 +1,104 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2011 Manuel Munz <freifunk at somakoma de> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 +]] + +local fs = require "luci.fs" +local util = require "luci.util" +local uci = require "luci.model.uci".cursor() +local profiles = "/etc/config/profile_" + +m = Map("freifunk", translate ("Community")) +c = m:section(NamedSection, "community", "public", nil, translate("These are the basic settings for your local wireless community. These settings define the default values for the wizard and DO NOT affect the actual configuration of the router.")) + +community = c:option(ListValue, "name", translate ("Community")) +community.rmempty = false + +local list = { } +local list = fs.glob(profiles .. "*") + +for k,v in ipairs(list) do + local name = uci:get_first(v, "community", "name") or "?" + local n = string.gsub(v, profiles, "") + community:value(n, name) +end + + +n = Map("system", translate("Basic system settings")) +function n.on_after_commit(self) + luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "basics")) +end + +b = n:section(TypedSection, "system") +b.anonymous = true + +hn = b:option(Value, "hostname", translate("Hostname")) +hn.rmempty = false +hn.datatype = "hostname" + +loc = b:option(Value, "location", translate("Location")) +loc.rmempty = false +loc.datatype = "minlength(1)" + +lat = b:option(Value, "latitude", translate("Latitude"), translate("e.g.") .. " 48.12345") +lat.datatype = "float" +lat.rmempty = false + +lon = b:option(Value, "longitude", translate("Longitude"), translate("e.g.") .. " 10.12345") +lon.datatype = "float" +lon.rmempty = false + +--[[ +Opens an OpenStreetMap iframe or popup +Makes use of resources/OSMLatLon.htm and htdocs/resources/osm.js +]]-- + +local class = util.class +local ff = uci:get("freifunk", "community", "name") or "" +local co = "profile_" .. ff + +local deflat = uci:get_first("system", "system", "latitude") or uci:get_first(co, "community", "latitude") or 52 +local deflon = uci:get_first("system", "system", "longitude") or uci:get_first(co, "community", "longitude") or 10 +local zoom = 12 +if ( deflat == 52 and deflon == 10 ) then + zoom = 4 +end + +OpenStreetMapLonLat = luci.util.class(AbstractValue) + +function OpenStreetMapLonLat.__init__(self, ...) + AbstractValue.__init__(self, ...) + self.template = "cbi/osmll_value" + self.latfield = nil + self.lonfield = nil + self.centerlat = "" + self.centerlon = "" + self.zoom = "0" + self.width = "100%" --popups will ignore the %-symbol, "100%" is interpreted as "100" + self.height = "600" + self.popup = false + self.displaytext="OpenStreetMap" --text on button, that loads and displays the OSMap + self.hidetext="X" -- text on button, that hides OSMap +end + + osm = b:option(OpenStreetMapLonLat, "latlon", translate("Find your coordinates with OpenStreetMap"), translate("Select your location with a mouse click on the map. The map will only show up if you are connected to the Internet.")) + osm.latfield = "latitude" + osm.lonfield = "longitude" + osm.centerlat = uci:get_first("system", "system", "latitude") or deflat + osm.centerlon = uci:get_first("system", "system", "longitude") or deflon + osm.zoom = zoom + osm.width = "100%" + osm.height = "600" + osm.popup = false + osm.displaytext=translate("Show OpenStreetMap") + osm.hidetext=translate("Hide OpenStreetMap") + +return m, n diff --git a/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/contact.lua b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/contact.lua new file mode 100644 index 0000000000..30e94a3e96 --- /dev/null +++ b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/contact.lua @@ -0,0 +1,25 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth <steven@midlink.org> +Copyright 2011 Manuel Munz <freifunk at somakoma dot de> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 +]]-- + +m = Map("freifunk", translate("Contact"), translate("Please fill in your contact details below.")) + +c = m:section(NamedSection, "contact", "public", "") + +c:option(Value, "nickname", translate("Nickname")) +c:option(Value, "name", translate("Realname")) +c:option(DynamicList, "homepage", translate("Homepage")) +c:option(Value, "mail", translate("E-Mail")) +c:option(Value, "phone", translate("Phone")) +c:option(TextValue, "note", translate("Notice")).rows = 10 + +return m diff --git a/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/profile.lua b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/profile.lua new file mode 100644 index 0000000000..c9bd23ed61 --- /dev/null +++ b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/profile.lua @@ -0,0 +1,83 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2011-2012 Manuel Munz <freifunk at somakoma dot de> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + httc://www.apache.org/licenses/LICENSE-2.0 +]]-- + +local uci = require "luci.model.uci".cursor() +local ipkg = require "luci.model.ipkg" +local community = uci:get("freifunk", "community", "name") + +if community == nil then + luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "profile_error")) + return +else + community = "profile_" .. community + m = Map(community, translate("Community settings"), translate("These are the settings of your local community.")) + c = m:section(NamedSection, "profile", "community") + + local name = c:option(Value, "name", "Name") + name.rmempty = false + + local homepage = c:option(Value, "homepage", translate("Homepage")) + + local cc = c:option(Value, "country", translate("Country code")) + function cc.cfgvalue(self, section) + return uci:get(community, "wifi_device", "country") + end + function cc.write(self, sec, value) + if value then + uci:set(community, "wifi_device", "country", value) + uci:save(community) + end + end + + local ssid = c:option(Value, "ssid", translate("ESSID")) + ssid.rmempty = false + + local prefix = c:option(Value, "mesh_network", translate("Mesh prefix")) + prefix.datatype = "ip4addr" + prefix.rmempty = false + + local splash_net = c:option(Value, "splash_network", translate("Network for client DHCP addresses")) + splash_net.datatype = "ip4addr" + splash_net.rmempty = false + + local splash_prefix = c:option(Value, "splash_prefix", translate("Client network size")) + splash_prefix.datatype = "range(0,32)" + splash_prefix.rmempty = false + + local ipv6 = c:option(Flag, "ipv6", translate("Enable IPv6")) + ipv6.rmempty = true + + local ipv6_config = c:option(ListValue, "ipv6_config", translate("IPv6 Config")) + ipv6_config:depends("ipv6", 1) + ipv6_config:value("static") + if ipkg.installed ("auto-ipv6-ib") then + ipv6_config:value("auto-ipv6-random") + ipv6_config:value("auto-ipv6-fromv4") + end + ipv6_config.rmempty = true + + local ipv6_prefix = c:option(Value, "ipv6_prefix", translate("IPv6 Prefix"), translate("IPv6 network in CIDR notation.")) + ipv6_prefix:depends("ipv6", 1) + ipv6_prefix.datatype = "ip6addr" + ipv6_prefix.rmempty = true + + local vap = c:option(Flag, "vap", translate("VAP"), translate("Enable a virtual access point (VAP) by default if possible.")) + vap.rmempty = true + + local lat = c:option(Value, "latitude", translate("Latitude")) + lat.datatype = "range(-180, 180)" + lat.rmempty = false + + local lon = c:option(Value, "longitude", translate("Longitude")) + lon.rmempty = false + return m +end diff --git a/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/profile_expert.lua b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/profile_expert.lua new file mode 100644 index 0000000000..0d890e1df6 --- /dev/null +++ b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/profile_expert.lua @@ -0,0 +1,41 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2011 Manuel Munz <freifunk at somakoma dot de> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + httc://www.apache.org/licenses/LICENSE-2.0 +]]-- + +local fs = require "nixio.fs" +local uci = require "luci.model.uci".cursor() +local community = uci:get("freifunk", "community", "name") + +if community == nil then + luci.http.redirect(luci.dispatcher.build_url("admin", "freifunk", "profile_error")) + return +else + community = "/etc/config/profile_" .. community + f = SimpleForm("community", translate("Community profile"), translate("You can manually edit the selected community profile here.")) + + t = f:field(TextValue, "cop") + t.rmempty = true + t.rows = 30 + function t.cfgvalue() + return fs.readfile(community) or "" + end + + function f.handle(self, state, data) + if state == FORM_VALID then + if data.cop then + fs.writefile(community, data.cop:gsub("\r\n", "\n")) + end + end + return true + end + return f +end + diff --git a/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/user_index.lua b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/user_index.lua new file mode 100644 index 0000000000..fe1d8fe7ed --- /dev/null +++ b/modules/luci-mod-freifunk/luasrc/model/cbi/freifunk/user_index.lua @@ -0,0 +1,30 @@ +local fs = require "nixio.fs" +local file = "/www/luci-static/index_user.html" + +m = Map("freifunk", translate("Edit index page"), translate("You can display additional content on the public index page by inserting valid XHTML in the form below.<br />Headlines should be enclosed between <h2> and </h2>.")) + +s = m:section(NamedSection, "community", "public", "") +s.anonymous = true + +di = s:option(Flag, "DefaultText", translate("Disable default content"), translate("If selected then the default content element is not shown.")) +di.enabled = "disabled" +di.disabled = "enabled" +di.rmempty = false + +t = s:option(TextValue, "_text") +t.rmempty = true +t.rows = 20 + +function t.cfgvalue() + return fs.readfile(file) or "" +end + +function t.write(self, section, value) + return fs.writefile(file, value) +end + +function t.remove(self, section) + return fs.unlink(file) +end + +return m |