modules/admin-full: convert cbi maps to new network model

This commit is contained in:
Jo-Philipp Wich 2010-10-30 00:45:43 +00:00
parent ba84656d6e
commit 185eacba4b
3 changed files with 397 additions and 394 deletions

View file

@ -34,6 +34,11 @@ m:chain("wireless")
nw.init(m.uci) nw.init(m.uci)
fw.init(m.uci) fw.init(m.uci)
--function m.on_commit(map)
-- nw.init(map.uci)
-- fw.init(map.uci)
--end
s = m:section(NamedSection, arg[1], "interface", translate("Common Configuration")) s = m:section(NamedSection, arg[1], "interface", translate("Common Configuration"))
s.addremove = false s.addremove = false
@ -107,7 +112,15 @@ function ifname_single.write(self, s, val)
for _, i in ipairs(n:get_interfaces()) do for _, i in ipairs(n:get_interfaces()) do
n:del_interface(i) n:del_interface(i)
end end
n:add_interface(val)
for i in val:gmatch("%S+") do
n:add_interface(i)
-- if this is not a bridge, only assign first interface
if self.option == "ifname_single" then
break
end
end
end end
end end

View file

@ -14,7 +14,6 @@ $Id$
local wa = require "luci.tools.webadmin" local wa = require "luci.tools.webadmin"
local nw = require "luci.model.network" local nw = require "luci.model.network"
local ww = require "luci.model.wireless"
local fs = require "nixio.fs" local fs = require "nixio.fs"
arg[1] = arg[1] or "" arg[1] = arg[1] or ""
@ -31,19 +30,15 @@ m:chain("network")
local ifsection local ifsection
function m.on_commit(map) function m.on_commit(map)
nw.init(map.uci) local wnet = nw:get_wifinet(arg[2])
ww.init(map.uci)
local wnet = ww:get_network(arg[2])
if ifsection and wnet then if ifsection and wnet then
ifsection.section = wnet.sid ifsection.section = wnet.sid
end end
end end
nw.init(m.uci) nw.init(m.uci)
ww.init(m.uci)
local wnet = ww:get_network(arg[2]) local wnet = nw:get_wifinet(arg[2])
-- redirect to overview page if network does not exist anymore (e.g. after a revert) -- redirect to overview page if network does not exist anymore (e.g. after a revert)
if not wnet then if not wnet then
@ -51,7 +46,7 @@ if not wnet then
return return
end end
m.title = ww:get_i18n(wnet) m.title = wnet:get_i18n()
local iw = luci.sys.wifi.getiwinfo(arg[1]) local iw = luci.sys.wifi.getiwinfo(arg[1])
@ -276,40 +271,37 @@ end
----------------------- Interface ----------------------- ----------------------- Interface -----------------------
local wnet = ww:get_network(arg[2]) s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
ifsection = s
s.addremove = false
s.anonymous = true
s.defaults.device = arg[1]
if wnet then s:tab("general", translate("General Setup"))
s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration")) s:tab("encryption", translate("Wireless Security"))
ifsection = s s:tab("macfilter", translate("MAC-Filter"))
s.addremove = false s:tab("advanced", translate("Advanced Settings"))
s.anonymous = true
s.defaults.device = arg[1]
s:tab("general", translate("General Setup")) s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
s:tab("encryption", translate("Wireless Security"))
s:tab("macfilter", translate("MAC-Filter"))
s:tab("advanced", translate("Advanced Settings"))
s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>")) mode = s:taboption("general", ListValue, "mode", translate("Mode"))
mode.override_values = true
mode:value("ap", translate("Access Point"))
mode:value("sta", translate("Client"))
mode:value("adhoc", translate("Ad-Hoc"))
mode = s:taboption("general", ListValue, "mode", translate("Mode")) bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
mode.override_values = true
mode:value("ap", translate("Access Point"))
mode:value("sta", translate("Client"))
mode:value("adhoc", translate("Ad-Hoc"))
bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>")) network = s:taboption("general", Value, "network", translate("Network"),
network = s:taboption("general", Value, "network", translate("Network"),
translate("Choose the network you want to attach to this wireless interface. " .. translate("Choose the network you want to attach to this wireless interface. " ..
"Select <em>unspecified</em> to not attach any network or fill out the " .. "Select <em>unspecified</em> to not attach any network or fill out the " ..
"<em>create</em> field to define a new network.")) "<em>create</em> field to define a new network."))
network.rmempty = true network.rmempty = true
network.template = "cbi/network_netlist" network.template = "cbi/network_netlist"
network.widget = "radio" network.widget = "radio"
function network.write(self, section, value) function network.write(self, section, value)
local i = nw:get_interface(section) local i = nw:get_interface(section)
if i then if i then
if value == '-' then if value == '-' then
@ -329,11 +321,11 @@ if wnet then
end end
end end
end end
end end
-------------------- MAC80211 Interface ---------------------- -------------------- MAC80211 Interface ----------------------
if hwtype == "mac80211" then if hwtype == "mac80211" then
if fs.access("/usr/sbin/iw") then if fs.access("/usr/sbin/iw") then
mode:value("mesh", "802.11s") mode:value("mesh", "802.11s")
end end
@ -377,13 +369,13 @@ if wnet then
hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>")) hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
hidden:depends({mode="ap"}) hidden:depends({mode="ap"})
hidden:depends({mode="ap-wds"}) hidden:depends({mode="ap-wds"})
end end
-------------------- Madwifi Interface ---------------------- -------------------- Madwifi Interface ----------------------
if hwtype == "atheros" then if hwtype == "atheros" then
mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)")) mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
mode:value("monitor", translate("Monitor")) mode:value("monitor", translate("Monitor"))
mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")}) mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
@ -468,12 +460,12 @@ if wnet then
local probereq = s:taboption("advanced", Flag, "probereq", translate("Do not send probe responses")) local probereq = s:taboption("advanced", Flag, "probereq", translate("Do not send probe responses"))
probereq.enabled = "0" probereq.enabled = "0"
probereq.disabled = "1" probereq.disabled = "1"
end end
-------------------- Broadcom Interface ---------------------- -------------------- Broadcom Interface ----------------------
if hwtype == "broadcom" then if hwtype == "broadcom" then
mode:value("wds", translate("WDS")) mode:value("wds", translate("WDS"))
mode:value("monitor", translate("Monitor")) mode:value("monitor", translate("Monitor"))
@ -491,12 +483,12 @@ if wnet then
bssid:depends({mode="wds"}) bssid:depends({mode="wds"})
bssid:depends({mode="adhoc"}) bssid:depends({mode="adhoc"})
end end
----------------------- HostAP Interface --------------------- ----------------------- HostAP Interface ---------------------
if hwtype == "prism2" then if hwtype == "prism2" then
mode:value("wds", translate("WDS")) mode:value("wds", translate("WDS"))
mode:value("monitor", translate("Monitor")) mode:value("monitor", translate("Monitor"))
@ -518,27 +510,27 @@ if wnet then
s:taboption("advanced", Value, "rate", translate("Transmission Rate")) s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold")) s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold")) s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
end end
------------------- WiFI-Encryption ------------------- ------------------- WiFI-Encryption -------------------
encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption")) encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption"))
encr.override_values = true encr.override_values = true
encr.override_depends = true encr.override_depends = true
encr:depends({mode="ap"}) encr:depends({mode="ap"})
encr:depends({mode="sta"}) encr:depends({mode="sta"})
encr:depends({mode="adhoc"}) encr:depends({mode="adhoc"})
encr:depends({mode="ahdemo"}) encr:depends({mode="ahdemo"})
encr:depends({mode="ap-wds"}) encr:depends({mode="ap-wds"})
encr:depends({mode="sta-wds"}) encr:depends({mode="sta-wds"})
encr:depends({mode="mesh"}) encr:depends({mode="mesh"})
encr:value("none", "No Encryption") encr:value("none", "No Encryption")
encr:value("wep-open", translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}) encr:value("wep-open", translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
encr:value("wep-shared", translate("WEP Shared Key"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}) encr:value("wep-shared", translate("WEP Shared Key"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
local supplicant = fs.access("/usr/sbin/wpa_supplicant") local supplicant = fs.access("/usr/sbin/wpa_supplicant")
local hostapd = fs.access("/usr/sbin/hostapd") local hostapd = fs.access("/usr/sbin/hostapd")
@ -574,46 +566,47 @@ if wnet then
"and ad-hoc mode) to be installed." "and ad-hoc mode) to be installed."
) )
end end
elseif hwtype == "broadcom" then elseif hwtype == "broadcom" then
encr:value("psk", "WPA-PSK") encr:value("psk", "WPA-PSK")
encr:value("psk2", "WPA2-PSK") encr:value("psk2", "WPA2-PSK")
encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode") encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
end end
encr:depends("mode", "ap") encr:depends("mode", "ap")
encr:depends("mode", "sta") encr:depends("mode", "sta")
encr:depends("mode", "ap-wds") encr:depends("mode", "ap-wds")
encr:depends("mode", "sta-wds") encr:depends("mode", "sta-wds")
encr:depends("mode", "wds") encr:depends("mode", "wds")
server = s:taboption("encryption", Value, "server", translate("Radius-Server")) server = s:taboption("encryption", Value, "server", translate("Radius-Server"))
server:depends({mode="ap", encryption="wpa"}) server:depends({mode="ap", encryption="wpa"})
server:depends({mode="ap", encryption="wpa2"}) server:depends({mode="ap", encryption="wpa2"})
server:depends({mode="ap-wds", encryption="wpa"}) server:depends({mode="ap-wds", encryption="wpa"})
server:depends({mode="ap-wds", encryption="wpa2"}) server:depends({mode="ap-wds", encryption="wpa2"})
server.rmempty = true server.rmempty = true
port = s:taboption("encryption", Value, "port", translate("Radius-Port")) port = s:taboption("encryption", Value, "port", translate("Radius-Port"))
port:depends({mode="ap", encryption="wpa"}) port:depends({mode="ap", encryption="wpa"})
port:depends({mode="ap", encryption="wpa2"}) port:depends({mode="ap", encryption="wpa2"})
port:depends({mode="ap-wds", encryption="wpa"}) port:depends({mode="ap-wds", encryption="wpa"})
port:depends({mode="ap-wds", encryption="wpa2"}) port:depends({mode="ap-wds", encryption="wpa2"})
port.rmempty = true port.rmempty = true
key = s:taboption("encryption", Value, "key", translate("Key")) key = s:taboption("encryption", Value, "key", translate("Key"))
key:depends("encryption", "wep") key:depends("encryption", "wep-open")
key:depends("encryption", "psk") key:depends("encryption", "wep-shared")
key:depends("encryption", "psk2") key:depends("encryption", "psk")
key:depends("encryption", "psk+psk2") key:depends("encryption", "psk2")
key:depends("encryption", "psk-mixed") key:depends("encryption", "psk+psk2")
key:depends({mode="ap", encryption="wpa"}) key:depends("encryption", "psk-mixed")
key:depends({mode="ap", encryption="wpa2"}) key:depends({mode="ap", encryption="wpa"})
key:depends({mode="ap-wds", encryption="wpa"}) key:depends({mode="ap", encryption="wpa2"})
key:depends({mode="ap-wds", encryption="wpa2"}) key:depends({mode="ap-wds", encryption="wpa"})
key.rmempty = true key:depends({mode="ap-wds", encryption="wpa2"})
key.password = true key.rmempty = true
key.password = true
if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID")) nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"))
nasid:depends({mode="ap", encryption="wpa"}) nasid:depends({mode="ap", encryption="wpa"})
nasid:depends({mode="ap", encryption="wpa2"}) nasid:depends({mode="ap", encryption="wpa2"})
@ -663,7 +656,6 @@ if wnet then
password:depends({mode="sta", eap_type="peap", encryption="wpa"}) password:depends({mode="sta", eap_type="peap", encryption="wpa"})
password:depends({mode="sta", eap_type="ttls", encryption="wpa2"}) password:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
password:depends({mode="sta", eap_type="ttls", encryption="wpa"}) password:depends({mode="sta", eap_type="ttls", encryption="wpa"})
end
end end
return m return m

View file

@ -14,7 +14,6 @@ $Id$
local nw = require "luci.model.network" local nw = require "luci.model.network"
local fw = require "luci.model.firewall" local fw = require "luci.model.firewall"
local wl = require "luci.model.wireless"
local uci = require "luci.model.uci".cursor() local uci = require "luci.model.uci".cursor()
local http = require "luci.http" local http = require "luci.http"
@ -34,7 +33,6 @@ end
nw.init(uci) nw.init(uci)
fw.init(uci) fw.init(uci)
wl.init(uci)
m.hidden = { m.hidden = {
device = http.formvalue("device"), device = http.formvalue("device"),
@ -145,14 +143,15 @@ function attachnet.parse(self, section)
if not net then if not net then
self.error = { [section] = "missing" } self.error = { [section] = "missing" }
else else
local wdev = wl:get_device(m.hidden.device) local wdev = nw:get_wifidev(m.hidden.device)
wdev:disabled(false)
wdev:channel(m.hidden.channel) wdev:set("disabled", false)
wdev:set("channel", m.hidden.channel)
if replace:formvalue(section) then if replace:formvalue(section) then
local n local n
for _, n in ipairs(wdev:get_networks()) do for _, n in ipairs(wdev:get_wifinets()) do
wl:del_network(n:name()) wdev:del_wifinet(n)
end end
end end
@ -177,8 +176,7 @@ function attachnet.parse(self, section)
wconf.bssid = m.hidden.bssid wconf.bssid = m.hidden.bssid
end end
local wnet = wl:add_network(wconf) local wnet = wdev:add_wifinet(wconf)
if wnet then if wnet then
if zone then if zone then
fw:del_network(net:name()) fw:del_network(net:name())