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_delete"}, call("wifi_delete"), nil, 16)
45 local page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), i18n("Interfaces"), 10)
49 local page = entry({"admin", "network", "add"}, cbi("admin_network/iface_add"), nil)
52 uci:foreach("network", "interface",
54 local ifc = section[".name"]
55 if ifc ~= "loopback" then
56 entry({"admin", "network", "network", ifc},
63 if nixio.fs.access("/etc/config/dhcp") then
64 local page = node("admin", "network", "dhcpleases")
65 page.target = cbi("admin_network/dhcpleases")
66 page.title = i18n("DHCP Leases")
70 local page = node("admin", "network", "hosts")
71 page.target = cbi("admin_network/hosts")
72 page.title = i18n("Hostnames")
75 local page = node("admin", "network", "routes")
76 page.target = cbi("admin_network/routes")
77 page.title = i18n("Static Routes")
83 local function param(x)
84 return luci.http.formvalue(x)
87 local function ptable(x)
89 return x and (type(x) ~= "table" and { x } or x) or {}
92 local dev = param("device")
93 local ssid = param("join")
96 local cancel = (param("cancel") or param("cbi.cancel")) and true or false
99 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless_join?device=" .. dev))
101 local cbi = require "luci.cbi"
102 local tpl = require "luci.template"
103 local map = luci.cbi.load("admin_network/wifi_add")[1]
105 if map:parse() ~= cbi.FORM_DONE then
112 luci.template.render("admin_network/wifi_join")
116 function wifi_delete(network)
117 local uci = require "luci.model.uci".cursor()
118 local wlm = require "luci.model.wireless"
121 wlm:del_network(network)
124 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))