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", "wireless_delete"}, call("wifi_delete"), nil, 16)
54 local page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), i18n("interfaces", "Schnittstellen"), 10)
58 local page = entry({"admin", "network", "add"}, cbi("admin_network/iface_add"), nil)
61 uci:foreach("network", "interface",
63 local ifc = section[".name"]
64 if ifc ~= "loopback" then
65 entry({"admin", "network", "network", ifc},
72 local page = node("admin", "network", "dhcp")
73 page.target = cbi("admin_network/dhcp")
79 {"admin", "network", "dhcp", "leases"},
80 cbi("admin_network/dhcpleases"),
84 local page = node("admin", "network", "hosts")
85 page.target = cbi("admin_network/hosts")
86 page.title = i18n("hostnames", "Hostnames")
89 local page = node("admin", "network", "routes")
90 page.target = cbi("admin_network/routes")
91 page.title = i18n("a_n_routes_static")
97 local function param(x)
98 return luci.http.formvalue(x)
101 local function ptable(x)
103 return x and (type(x) ~= "table" and { x } or x) or {}
106 local dev = param("device")
107 local ssid = param("join")
110 local wep = (tonumber(param("wep")) == 1)
111 local wpa = tonumber(param("wpa_version")) or 0
112 local channel = tonumber(param("channel"))
113 local mode = param("mode")
114 local bssid = param("bssid")
116 local confirm = (param("confirm") == "1")
117 local cancel = param("cancel") and true or false
119 if confirm and not cancel then
120 local fixed_bssid = (param("fixed_bssid") == "1")
121 local replace_net = (param("replace_net") == "1")
122 local autoconnect = (param("autoconnect") == "1")
123 local attach_intf = param("attach_intf")
125 local uci = require "luci.model.uci".cursor()
128 uci:delete_all("wireless", "wifi-iface")
133 mode = (mode == "Ad-Hoc" and "adhoc" or "sta"),
137 if attach_intf and uci:get("network", attach_intf) == "interface" then
138 -- target network already has a interface, make it a bridge
139 uci:set("network", attach_intf, "type", "bridge")
141 uci:commit("network")
143 wificonf.network = attach_intf
146 require "luci.sys".call("/sbin/ifup " .. attach_intf)
151 wificonf.bssid = bssid
155 wificonf.encryption = "wep"
156 wificonf.key = param("key")
158 wificonf.encryption = param("wpa_suite")
159 wificonf.key = param("key")
162 local s = uci:section("wireless", "wifi-iface", nil, wificonf)
163 uci:delete("wireless", dev, "disabled")
164 uci:set("wireless", dev, "channel", channel)
167 uci:commit("wireless")
170 require "luci.sys".call("/sbin/wifi")
173 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
175 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless_join?device=" .. dev))
177 luci.template.render("admin_network/wifi_join_settings")
180 luci.template.render("admin_network/wifi_join")
184 function wifi_delete(network)
185 local uci = require "luci.model.uci".cursor()
186 local wlm = require "luci.model.wireless"
189 wlm:del_network(network)
192 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))