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
20 local has_wifi = nixio.fs.stat("/etc/config/wireless")
22 local page = node("admin", "network")
23 page.target = alias("admin", "network", "network")
24 page.title = i18n("Network")
28 local page = node("admin", "network", "vlan")
29 page.target = cbi("admin_network/vlan")
30 page.title = i18n("Switch")
33 if has_wifi and has_wifi.size > 0 then
34 local page = entry({"admin", "network", "wireless"}, arcombine(template("admin_network/wifi_overview"), cbi("admin_network/wifi")), i18n("Wifi"), 15)
38 local page = entry({"admin", "network", "wireless_join"}, call("wifi_join"), nil, 16)
41 local page = entry({"admin", "network", "wireless_add"}, call("wifi_add"), nil, 16)
44 local page = entry({"admin", "network", "wireless_delete"}, call("wifi_delete"), nil, 16)
48 local page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), i18n("Interfaces"), 10)
52 local page = entry({"admin", "network", "add"}, cbi("admin_network/iface_add"), nil)
55 uci:foreach("network", "interface",
57 local ifc = section[".name"]
58 if ifc ~= "loopback" then
59 entry({"admin", "network", "network", ifc},
66 if nixio.fs.access("/etc/config/dhcp") then
67 local page = node("admin", "network", "dhcpleases")
68 page.target = cbi("admin_network/dhcpleases")
69 page.title = i18n("DHCP Leases")
73 local page = node("admin", "network", "hosts")
74 page.target = cbi("admin_network/hosts")
75 page.title = i18n("Hostnames")
78 local page = node("admin", "network", "routes")
79 page.target = cbi("admin_network/routes")
80 page.title = i18n("Static Routes")
86 local function param(x)
87 return luci.http.formvalue(x)
90 local function ptable(x)
92 return x and (type(x) ~= "table" and { x } or x) or {}
95 local dev = param("device")
96 local ssid = param("join")
99 local cancel = (param("cancel") or param("cbi.cancel")) and true or false
102 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless_join?device=" .. dev))
104 local cbi = require "luci.cbi"
105 local tpl = require "luci.template"
106 local map = luci.cbi.load("admin_network/wifi_add")[1]
108 if map:parse() ~= cbi.FORM_DONE then
115 luci.template.render("admin_network/wifi_join")
120 local dev = luci.http.formvalue("device")
121 local uci = require "luci.model.uci".cursor()
122 local wlm = require "luci.model.wireless"
127 local net = wlm:add_network({
135 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", dev, net:name()))
139 function wifi_delete(network)
140 local uci = require "luci.model.uci".cursor()
141 local wlm = require "luci.model.wireless"
144 wlm:del_network(network)
147 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))