modules/admin-full: switch static lease page to /etc/config/dhcp, add better labels...
[project/luci.git] / modules / admin-full / luasrc / controller / admin / network.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
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
9
10         http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14 module("luci.controller.admin.network", package.seeall)
15
16 function index()
17         require("luci.i18n")
18         local uci = require("luci.model.uci").cursor()
19         local i18n = luci.i18n.translate
20
21         local page  = node("admin", "network")
22         page.target = alias("admin", "network", "network")
23         page.title  = i18n("Network")
24         page.order  = 50
25         page.index  = true
26
27         local page  = node("admin", "network", "vlan")
28         page.target = cbi("admin_network/vlan")
29         page.title  = i18n("Switch")
30         page.order  = 20
31
32         local page = entry({"admin", "network", "wireless"}, arcombine(template("admin_network/wifi_overview"), cbi("admin_network/wifi")), i18n("Wifi"), 15)
33         page.leaf = true
34         page.subindex = true
35
36         local page = entry({"admin", "network", "wireless_join"}, call("wifi_join"), nil, 16)
37         page.leaf = true
38
39         local page = entry({"admin", "network", "wireless_delete"}, call("wifi_delete"), nil, 16)
40         page.leaf = true
41
42         local page = entry({"admin", "network", "network"}, arcombine(cbi("admin_network/network"), cbi("admin_network/ifaces")), i18n("Interfaces"), 10)
43         page.leaf   = true
44         page.subindex = true
45
46         local page = entry({"admin", "network", "add"}, cbi("admin_network/iface_add"), nil)
47         page.leaf = true
48
49         uci:foreach("network", "interface",
50                 function (section)
51                         local ifc = section[".name"]
52                         if ifc ~= "loopback" then
53                                 entry({"admin", "network", "network", ifc},
54                                  true,
55                                  ifc:upper())
56                         end
57                 end
58         )
59
60         local page  = node("admin", "network", "dhcp")
61         page.target = cbi("admin_network/dhcp")
62         page.title  = "DHCP"
63         page.order  = 30
64         page.subindex = true
65
66         entry(
67          {"admin", "network", "dhcp", "leases"},
68          cbi("admin_network/dhcpleases"),
69          i18n("Leases")
70         )
71
72         local page  = node("admin", "network", "hosts")
73         page.target = cbi("admin_network/hosts")
74         page.title  = i18n("Hostnames")
75         page.order  = 40
76
77         local page  = node("admin", "network", "routes")
78         page.target = cbi("admin_network/routes")
79         page.title  = i18n("Static Routes")
80         page.order  = 50
81
82 end
83
84 function wifi_join()
85         local function param(x)
86                 return luci.http.formvalue(x)
87         end
88
89         local function ptable(x)
90                 x = param(x)
91                 return x and (type(x) ~= "table" and { x } or x) or {}
92         end
93
94         local dev  = param("device")
95         local ssid = param("join")
96
97         if dev and ssid then
98                 local cancel  = (param("cancel") or param("cbi.cancel")) and true or false
99
100                 if cancel then
101                         luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless_join?device=" .. dev))
102                 else
103                         local cbi = require "luci.cbi"
104                         local tpl = require "luci.template"
105                         local map = luci.cbi.load("admin_network/wifi_add")[1]
106
107                         if map:parse() ~= cbi.FORM_DONE then
108                                 tpl.render("header")
109                                 map:render()
110                                 tpl.render("footer")
111                         end
112                 end
113         else
114                 luci.template.render("admin_network/wifi_join")
115         end
116 end
117
118 function wifi_delete(network)
119         local uci = require "luci.model.uci".cursor()
120         local wlm = require "luci.model.wireless"
121
122         wlm.init(uci)
123         wlm:del_network(network)
124
125         uci:save("wireless")
126         luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
127 end