2 LuCI - Lua Configuration Interface
4 Copyright 2008 Steven Barth <steven@midlink.org>
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
10 http://www.apache.org/licenses/LICENSE-2.0
14 module("luci.controller.admin.network", package.seeall)
18 local uci = require("luci.model.uci").cursor()
19 local i18n = luci.i18n.translate
21 local page = node("admin", "network")
22 page.target = alias("admin", "network", "network")
23 page.title = i18n("network")
27 local page = node("admin", "network", "vlan")
28 page.target = cbi("admin_network/vlan")
29 page.title = i18n("a_n_switch")
32 local page = entry({"admin", "network", "wireless"}, arcombine(template("admin_network/wifi_overview"), cbi("admin_network/wifi")), i18n("wifi"), 15)
37 uci:foreach("wireless", "wifi-device",
39 local ifc = section[".name"]
40 entry({"admin", "network", "wireless", ifc},
42 ifc:upper()).i18n = "wifi"
46 local page = entry({"admin", "network", "wireless_join"}, call("wifi_join"), nil, 16)
50 local page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), i18n("interfaces", "Schnittstellen"), 10)
54 uci:foreach("network", "interface",
56 local ifc = section[".name"]
57 if ifc ~= "loopback" then
58 entry({"admin", "network", "network", ifc},
65 local page = node("admin", "network", "dhcp")
66 page.target = cbi("admin_network/dhcp")
72 {"admin", "network", "dhcp", "leases"},
73 cbi("admin_network/dhcpleases"),
77 local page = node("admin", "network", "hosts")
78 page.target = cbi("admin_network/hosts")
79 page.title = i18n("hostnames", "Hostnames")
82 local page = node("admin", "network", "routes")
83 page.target = cbi("admin_network/routes")
84 page.title = i18n("a_n_routes_static")
90 local function param(x)
91 return luci.http.formvalue(x)
94 local function ptable(x)
96 return x and (type(x) ~= "table" and { x } or x) or {}
99 local dev = param("device")
100 local ssid = param("join")
103 local wep = (tonumber(param("wep")) == 1)
104 local wpa = tonumber(param("wpa_version")) or 0
105 local channel = tonumber(param("channel"))
106 local mode = param("mode")
107 local bssid = param("bssid")
109 local confirm = (param("confirm") == "1")
110 local cancel = param("cancel") and true or false
112 if confirm and not cancel then
113 local fixed_bssid = (param("fixed_bssid") == "1")
114 local replace_net = (param("replace_net") == "1")
115 local autoconnect = (param("autoconnect") == "1")
116 local attach_intf = param("attach_intf")
118 local uci = require "luci.model.uci".cursor()
121 uci:delete_all("wireless", "wifi-iface")
126 mode = (mode == "Ad-Hoc" and "adhoc" or "sta"),
130 if attach_intf and uci:get("network", attach_intf, "ifname") then
131 -- target network already has a interface, make it a bridge
132 uci:set("network", attach_intf, "type", "bridge")
134 uci:commit("network")
137 require "luci.sys".call("/sbin/ifup " .. attach_intf)
142 wificonf.bssid = bssid
146 wificonf.encryption = "wep"
147 wificonf.key = param("key")
149 wificonf.encryption = param("wpa_suite")
150 wificonf.key = param("key")
153 uci:section("wireless", "wifi-iface", nil, wificonf)
154 uci:delete("wireless", dev, "disabled")
155 uci:set("wireless", dev, "channel", channel)
158 uci:commit("wireless")
161 require "luci.sys".call("/sbin/wifi")
164 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", dev))
166 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless_join?device=" .. dev))
168 luci.template.render("admin_network/wifi_join_settings")
171 luci.template.render("admin_network/wifi_join")