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)
84 page = entry({"admin", "wireless_deauth"}, post("wifi_deauth"), nil)
88 page = entry({"admin", "translations"}, call("action_translations"), nil)
92 entry({"admin", "logout"}, call("action_logout"), _("Logout"), 999)
95 function action_logout()
96 local dsp = require "luci.dispatcher"
97 local utl = require "luci.util"
98 local sid = dsp.context.authsession
101 utl.ubus("session", "destroy", { ubus_rpc_session = sid })
103 luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s" %{
104 '', 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
108 luci.http.redirect(dsp.build_url())
111 function action_translations(lang)
112 local i18n = require "luci.i18n"
113 local http = require "luci.http"
114 local fs = require "nixio".fs
116 if lang and #lang > 0 then
117 lang = i18n.setlanguage(lang)
119 local s = fs.stat("%s/base.%s.lmo" %{ i18n.i18ndir, lang })
121 http.header("Cache-Control", "public, max-age=31536000")
122 http.header("ETag", "%x-%x-%x" %{ s["ino"], s["size"], s["mtime"] })
127 http.prepare_content("application/javascript; charset=utf-8")
128 http.write("window.TR=")
129 http.write_json(i18n.dump())
133 function lease_status()
134 local s = require "luci.tools.status"
136 luci.http.prepare_content("application/json")
138 luci.http.write_json(s.dhcp_leases())
140 luci.http.write_json(s.dhcp6_leases())
144 function wifi_assoclist()
145 local s = require "luci.tools.status"
147 luci.http.prepare_content("application/json")
148 luci.http.write_json(s.wifi_assoclist())
151 function wifi_deauth()
152 local iface = luci.http.formvalue("iface")
153 local bssid = luci.http.formvalue("bssid")
155 if iface and bssid then
156 luci.util.ubus("hostapd.%s" % iface, "del_client", {
163 luci.http.status(200, "OK")