1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
4 module("luci.controller.admin.index", package.seeall)
7 function toplevel_page(page, preflookup, preftarget)
8 if preflookup and preftarget then
9 if lookup(preflookup) then
10 page.target = preftarget
14 if not page.target then
15 page.target = firstchild()
19 local uci = require("luci.model.uci").cursor()
22 if not root.target then
23 root.target = alias("admin")
27 local page = node("admin")
29 page.title = _("Administration")
32 page.sysauth_authenticator = "htmlauth"
35 page.target = firstnode()
37 -- Empty menu tree to be populated by addons and modules
39 page = node("admin", "status")
40 page.title = _("Status")
43 -- overview is from mod-admin-full
44 toplevel_page(page, "admin/status/overview", alias("admin", "status", "overview"))
46 page = node("admin", "system")
47 page.title = _("System")
50 -- system/system is from mod-admin-full
51 toplevel_page(page, "admin/system/system", alias("admin", "system", "system"))
53 -- Only used if applications add items
54 page = node("admin", "services")
55 page.title = _("Services")
58 toplevel_page(page, false, false)
60 -- Even for mod-admin-full network just uses first submenu item as landing
61 page = node("admin", "network")
62 page.title = _("Network")
65 toplevel_page(page, false, false)
67 if nixio.fs.access("/etc/config/dhcp") then
68 page = entry({"admin", "dhcplease_status"}, call("lease_status"), nil)
72 local has_wifi = false
74 uci:foreach("wireless", "wifi-device",
81 page = entry({"admin", "wireless_assoclist"}, call("wifi_assoclist"), nil)
86 entry({"admin", "logout"}, call("action_logout"), _("Logout"), 999)
89 function action_logout()
90 local dsp = require "luci.dispatcher"
91 local utl = require "luci.util"
92 local sid = dsp.context.authsession
95 utl.ubus("session", "destroy", { ubus_rpc_session = sid })
97 luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
98 sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
102 luci.http.redirect(dsp.build_url())
106 function lease_status()
107 local s = require "luci.tools.status"
109 luci.http.prepare_content("application/json")
111 luci.http.write_json(s.dhcp_leases())
113 luci.http.write_json(s.dhcp6_leases())
117 function wifi_assoclist()
118 local s = require "luci.tools.status"
120 luci.http.prepare_content("application/json")
121 luci.http.write_json(s.wifi_assoclist())