From 1682dd8c5fac3fd787fc31943788aaed23b21edf Mon Sep 17 00:00:00 2001 From: CodeFetch Date: Sat, 7 Feb 2015 07:50:14 +0100 Subject: [PATCH] Adding WiFi settings to config mode making the private-wifi-page redundant Fix copy-paste-mistake Update wifi.lua Fixed bad ideas Beautifies notation I'm bored. --- .../lua/luci/controller/admin/privatewifi.lua | 5 - .../lua/luci/model/cbi/admin/privatewifi.lua | 63 ------- .../Makefile | 10 +- .../lib/lua/luci/controller/admin/wifi.lua | 5 + .../usr/lib/lua/luci/model/cbi/admin/wifi.lua | 175 ++++++++++++++++++ 5 files changed, 185 insertions(+), 73 deletions(-) delete mode 100644 gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/controller/admin/privatewifi.lua delete mode 100644 gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua rename gluon/{gluon-luci-private-wifi => gluon-luci-wifi}/Makefile (62%) create mode 100644 gluon/gluon-luci-wifi/files/usr/lib/lua/luci/controller/admin/wifi.lua create mode 100644 gluon/gluon-luci-wifi/files/usr/lib/lua/luci/model/cbi/admin/wifi.lua diff --git a/gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/controller/admin/privatewifi.lua b/gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/controller/admin/privatewifi.lua deleted file mode 100644 index 0b10b4e..0000000 --- a/gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/controller/admin/privatewifi.lua +++ /dev/null @@ -1,5 +0,0 @@ -module("luci.controller.admin.privatewifi", package.seeall) - -function index() - entry({"admin", "privatewifi"}, cbi("admin/privatewifi"), "Privates WLAN", 10) -end diff --git a/gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua b/gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua deleted file mode 100644 index b915731..0000000 --- a/gluon/gluon-luci-private-wifi/files/usr/lib/lua/luci/model/cbi/admin/privatewifi.lua +++ /dev/null @@ -1,63 +0,0 @@ -local f, s, o, ssid -local uci = luci.model.uci.cursor() -local config = 'wireless' - --- where to read the configuration from -local primary_iface = 'wan_radio0' -local ssid = uci:get(config, primary_iface, "ssid") - -f = SimpleForm("wifi", "Privates WLAN") -f.reset = false -f.template = "admin/expertmode" -f.submit = "Fertig" - -s = f:section(SimpleSection, nil, [[ -Dein Freifunk-Router kann ebenfalls die Reichweite deines privaten Netzes erweitern. -Hierfür wird der WAN-Port mit einem seperaten WLAN gebridged. -Diese Funktionalität ist völlig unabhängig von Freifunk. -Beachte, dass du nicht gleichzeitig das Meshen über den WAN Port aktiviert haben solltest. -]]) - -o = s:option(Flag, "enabled", "Aktiviert") -o.default = (ssid and not uci:get_bool(config, primary_iface, "disabled")) and o.enabled or o.disabled -o.rmempty = false - -o = s:option(Value, "ssid", "Name (SSID)") -o.default = ssid - -o = s:option(Value, "key", "Schlüssel", "8-63 Zeichen") -o.datatype = "wpakey" -o.default = uci:get(config, primary_iface, "key") - -function f.handle(self, state, data) - if state == FORM_VALID then - uci:foreach(config, "wifi-device", - function(s) - local device = s['.name'] - local name = "wan_" .. device - - if data.enabled == '1' then - -- set up WAN wifi-iface - local t = uci:get_all(config, name) or {} - - t.device = device - t.network = "wan" - t.mode = 'ap' - t.encryption = 'psk2' - t.ssid = data.ssid - t.key = data.key - t.disabled = "false" - - uci:section(config, "wifi-iface", name, t) - else - -- disable WAN wifi-iface - uci:set(config, name, "disabled", "true") - end - end) - - uci:save(config) - uci:commit(config) - end -end - -return f diff --git a/gluon/gluon-luci-private-wifi/Makefile b/gluon/gluon-luci-wifi/Makefile similarity index 62% rename from gluon/gluon-luci-private-wifi/Makefile rename to gluon/gluon-luci-wifi/Makefile index 0d5c461..b689ae1 100644 --- a/gluon/gluon-luci-private-wifi/Makefile +++ b/gluon/gluon-luci-wifi/Makefile @@ -1,6 +1,6 @@ include $(TOPDIR)/rules.mk -PKG_NAME:=gluon-luci-private-wifi +PKG_NAME:=gluon-luci-wifi PKG_VERSION:=0.1 PKG_RELEASE:=1 @@ -8,11 +8,11 @@ PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) include $(INCLUDE_DIR)/package.mk -define Package/gluon-luci-private-wifi +define Package/gluon-luci-wifi SECTION:=gluon CATEGORY:=Gluon DEPENDS:=+gluon-luci-admin - TITLE:=UI for activating a private WLAN + TITLE:=UI for WLAN configuration endef define Build/Prepare @@ -25,8 +25,8 @@ endef define Build/Compile endef -define Package/gluon-luci-private-wifi/install +define Package/gluon-luci-wifi/install $(CP) ./files/* $(1)/ endef -$(eval $(call BuildPackage,gluon-luci-private-wifi)) +$(eval $(call BuildPackage,gluon-luci-wifi)) diff --git a/gluon/gluon-luci-wifi/files/usr/lib/lua/luci/controller/admin/wifi.lua b/gluon/gluon-luci-wifi/files/usr/lib/lua/luci/controller/admin/wifi.lua new file mode 100644 index 0000000..11a1d18 --- /dev/null +++ b/gluon/gluon-luci-wifi/files/usr/lib/lua/luci/controller/admin/wifi.lua @@ -0,0 +1,5 @@ +module("luci.controller.admin.wifi", package.seeall) + +function index() + entry({"admin", "wifi"}, cbi("admin/wifi"), "WLAN", 10) +end diff --git a/gluon/gluon-luci-wifi/files/usr/lib/lua/luci/model/cbi/admin/wifi.lua b/gluon/gluon-luci-wifi/files/usr/lib/lua/luci/model/cbi/admin/wifi.lua new file mode 100644 index 0000000..3eb268c --- /dev/null +++ b/gluon/gluon-luci-wifi/files/usr/lib/lua/luci/model/cbi/admin/wifi.lua @@ -0,0 +1,175 @@ +local f, s, o +local config = "wireless" +local uci = luci.model.uci.cursor() +local radios24 = {} +local radios5 = {} +local primary_iface = 'wan_radio0' +local private_ssid = uci:get(config, primary_iface, "ssid") +local countries = {{"Belgien", "BE"}, {"Bolivien", "BO"}, {"Dänemark", "DK"}, {"Deutschland", "DE"}, {"Frankreich", "FR"}, {"Italien", "IT"}, {"Niederlande", "NL"}, {"Österreich", "AT"}, {"Polen", "PL"}, {"Schweden", "SE"}, {"Schweiz", "CH"}, {"Tschechische Republik", "CZ"}, {"USA", "US"}} + +-- look for wifi interfaces and add them to the specific array +uci:foreach(config, 'wifi-device', + function(s) + --get the hwmode to separate 2.4 GHz and 5 GHz radios + local hwmode = uci:get(config, s['.name'], 'hwmode') + if hwmode == '11g' or hwmode == '11ng' then --if 2.4 GHz + table.insert(radios24, s['.name']) + elseif hwmode == '11a' or hwmode == '11na' then --if 5 GHz + table.insert(radios5, s['.name']) + end + end +) +local radios_type = {{"2,4 GHz","24",radios24},{"5 GHz", "5", radios5}} +f = SimpleForm("wifi", "WLAN-Einstellungen") +f.reset = false +f.template = "admin/expertmode" +f.submit = "Speichern" + +s = f:section(SimpleSection, nil, [[ +In diesem Abschnitt hast du die Möglichkeit die SSID für das Clientnetzwerk zu ändern (nur für Profis!), die maximale Sendeleistung und Reichweite festzusetzen, +die SSIDs des Client- und des Mesh-Netzes zu de/aktivieren, die Region auszuwählen und die Preisgabe der Region in den Beacons abzuschalten (wird nicht empfohlen). +]]) +-- show options for 2.4/5 GHz devices +for i=1,#radios_type do + local rtype = radios_type[i] + if table.getn(rtype[3]) > 0 then + s = f:section(SimpleSection, rtype[1], nil) + for index, radio in ipairs(rtype[3]) do + -- ssid for client network + local ssid = uci:get(config, "client_" .. radio, "ssid") + if ssid then + o = s:option(Value, 'ssid' .. rtype[2] .. index, "AP-SSID") + o.default = ssid + o.rmempty = false + end + + -- tx power + o = s:option(Value, 'txpower' .. rtype[2] .. index, "Sendeleistung (in dBm)") + local txpower = uci:get(config, radio, "txpower") + if not txpower then txpower="30" end + o.default = txpower + o.datatype = "uinteger" + o.rmempty = false + + -- distance + o = s:option(Value, 'distance' .. rtype[2] .. index, "Reichweite (in Metern)") + local distance = uci:get(config, radio, "distance") + if not distance then distance="100" end + o.default = distance + o.datatype = "uinteger" + o.rmempty = false + + -- country code + o=s:option(ListValue, "country" .. rtype[2] .. index, "Region") + o.default=uci:get(config, radio, "country") + for i=1,#countries do o:value(countries[i][2],countries[i][1]) end + + -- IE in beacons + o = s:option(Flag, 'country_ie' .. rtype[2] .. index, "IE senden (empfohlen)") + local country_ie = uci:get(config, radio, "country_ie") + if not country_ie then country_ie="1" end + o.default = country_ie + o.rmempty = false + + -- client network switch + o = s:option(Flag, 'clientbox' .. rtype[2] .. index, "Client-Netz aktivieren") + o.default = (uci:get_bool(config, 'client_' .. radio, "disabled")) and o.disabled or o.enabled + o.rmempty = false + + -- mesh network switch + o = s:option(Flag, 'meshbox' .. rtype[2] .. index, "Mesh-Netz aktivieren") + o.default = (uci:get_bool(config, 'mesh_' .. radio, "disabled")) and o.disabled or o.enabled + o.rmempty = false + end + end +end + +-- show options for private wifi +s = f:section(SimpleSection, "Privates WLAN", [[ +Dein Freifunk-Router kann ebenfalls die Reichweite deines privaten Netzes erweitern. +Hierfür wird der WAN-Port mit einem separatem WLAN gebridged. +Diese Funktionalität ist völlig unabhängig von Freifunk. +Beachte, dass du nicht gleichzeitig das Meshen über den WAN Port aktiviert haben solltest. +]]) + +-- private wifi switch +o = s:option(Flag, "private_enabled", "Aktiviert") +o.default = (private_ssid and not uci:get_bool(config, primary_iface, "disabled")) and o.enabled or o.disabled +o.rmempty = false + +-- private wifi ssid +o = s:option(Value, "private_ssid", "Name (SSID)") +o.default = private_ssid + +-- private wifi key +o = s:option(Value, "private_key", "Schlüssel", "8-63 Zeichen") +o.datatype = "wpakey" +o.default = uci:get(config, primary_iface, "key") + +-- handle submitted changes +function f.handle(self, state, data) + if state == FORM_VALID then + for i=1,#radios_type do + local rtype = radios_type[i] + for index, radio in ipairs(rtype[3]) do + -- set client network ssid + uci:set(config, "client_" .. radio, "ssid", data["ssid" .. rtype[2] .. index]) + + -- set tx power + uci:set(config, radio, "txpower", data["txpower" .. rtype[2] .. index]) + + -- set country code + uci:set(config, radio, "country", data["country" .. rtype[2] .. index]) + + -- set distance + uci:set(config, radio, "distance", data["distance" .. rtype[2] .. index]) + + -- set IE in beacons + uci:set(config, radio, "country_ie", data["country_ie" .. rtype[2] .. index]) + + -- set client network switch + if data["clientbox" .. rtype[2] .. index] == '0' then + uci:set(config, 'client_' .. radio, "disabled", 'true') + else + uci:set(config, 'client_' .. radio, "disabled", 'false') + end + + -- set mesh network switch + if data["meshbox" .. rtype[2] .. index] == '0' then + uci:set(config, 'mesh_' .. radio, "disabled", 'true') + else + uci:set(config, 'mesh_' .. radio, "disabled", 'false') + end + + end + end + + uci:foreach(config, "wifi-device", + function(s) + local device = s['.name'] + local name = "wan_" .. device + if data.private_enabled == '1' then + -- set up WAN wifi-iface + local t = uci:get_all(config, name) or {} + t.device = device + t.network = "wan" + t.mode = 'ap' + t.encryption = 'psk2' + t.ssid = data.private_ssid + t.key = data.private_key + t.disabled = "false" + uci:section(config, "wifi-iface", name, t) + else + -- disable WAN wifi-iface + uci:set(config, name, "disabled", "true") + end + + end) + -- save and commit changes + uci:save(config) + uci:commit(config) + + end +end + +return f