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")
21 local has_switch = false
23 uci:foreach("network", "switch",
30 local page = node("admin", "network")
31 page.target = alias("admin", "network", "network")
32 page.title = i18n("Network")
37 local page = node("admin", "network", "vlan")
38 page.target = cbi("admin_network/vlan")
39 page.title = i18n("Switch")
43 if has_wifi and has_wifi.size > 0 then
44 local page = entry({"admin", "network", "wireless"}, arcombine(template("admin_network/wifi_overview"), cbi("admin_network/wifi")), i18n("Wifi"), 15)
48 local page = entry({"admin", "network", "wireless_join"}, call("wifi_join"), nil, 16)
51 local page = entry({"admin", "network", "wireless_add"}, call("wifi_add"), nil, 16)
54 local page = entry({"admin", "network", "wireless_delete"}, call("wifi_delete"), nil, 16)
58 local page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), i18n("Interfaces"), 10)
62 local page = entry({"admin", "network", "add"}, cbi("admin_network/iface_add"), nil)
65 uci:foreach("network", "interface",
67 local ifc = section[".name"]
68 if ifc ~= "loopback" then
69 entry({"admin", "network", "network", ifc},
76 if nixio.fs.access("/etc/config/dhcp") then
77 local page = node("admin", "network", "dhcpleases")
78 page.target = cbi("admin_network/dhcpleases")
79 page.title = i18n("DHCP Leases")
83 local page = node("admin", "network", "hosts")
84 page.target = cbi("admin_network/hosts")
85 page.title = i18n("Hostnames")
88 local page = node("admin", "network", "routes")
89 page.target = cbi("admin_network/routes")
90 page.title = i18n("Static Routes")
96 local function param(x)
97 return luci.http.formvalue(x)
100 local function ptable(x)
102 return x and (type(x) ~= "table" and { x } or x) or {}
105 local dev = param("device")
106 local ssid = param("join")
109 local cancel = (param("cancel") or param("cbi.cancel")) and true or false
112 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless_join?device=" .. dev))
114 local cbi = require "luci.cbi"
115 local tpl = require "luci.template"
116 local map = luci.cbi.load("admin_network/wifi_add")[1]
118 if map:parse() ~= cbi.FORM_DONE then
125 luci.template.render("admin_network/wifi_join")
130 local dev = luci.http.formvalue("device")
131 local uci = require "luci.model.uci".cursor()
132 local wlm = require "luci.model.wireless"
137 local net = wlm:add_network({
145 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", dev, net:name()))
149 function wifi_delete(network)
150 local uci = require "luci.model.uci".cursor()
151 local wlm = require "luci.model.wireless"
154 wlm:del_network(network)
157 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))