modules: Make luci-base sufficient to use luci apps
[oweals/luci.git] / modules / luci-base / luasrc / controller / admin / index.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
4 module("luci.controller.admin.index", package.seeall)
5
6 function index()
7         function toplevel_page(page, preflookup, preftarget)
8                 if preflookup and preftarget then
9                         if lookup(preflookup) then
10                                 page.target = preftarget
11                         end
12                 end
13
14                 if not page.target then
15                         page.target = firstchild()
16                 end
17         end
18
19         local root = node()
20         if not root.target then
21                 root.target = alias("admin")
22                 root.index = true
23         end
24
25         local page   = node("admin")
26         page.title   = _("Administration")
27         page.order   = 10
28         page.sysauth = "root"
29         page.sysauth_authenticator = "htmlauth"
30         page.ucidata = true
31         page.index = true
32         toplevel_page(page, "admin/status/overview", alias("admin", "status"))
33
34         -- Empty menu tree to be populated by addons and modules
35
36         page = node("admin", "status")
37         page.title = _("Status")
38         page.order = 10
39         page.index = true
40         -- overview is from mod-admin-full
41         toplevel_page(page, "admin/status/overview", alias("admin", "status", "overview"))
42
43         page = node("admin", "system")
44         page.title = _("System")
45         page.order = 20
46         page.index = true
47         -- system/system is from mod-admin-full
48         toplevel_page(page, "admin/system/system", alias("admin", "system", "system")) 
49
50         -- Only used if applications add items
51         page = node("admin", "services")
52         page.title = _("Services")
53         page.order = 40
54         page.index = true
55         toplevel_page(page, false, false)
56
57         -- Even for mod-admin-full network just uses first submenu item as landing
58         page = node("admin", "network")
59         page.title = _("Network")
60         page.order = 50
61         page.index = true
62         toplevel_page(page, false, false)
63
64         -- Logout is last
65         entry({"admin", "logout"}, call("action_logout"), _("Logout"), 999)
66 end
67
68 function action_logout()
69         local dsp = require "luci.dispatcher"
70         local utl = require "luci.util"
71         local sid = dsp.context.authsession
72
73         if sid then
74                 utl.ubus("session", "destroy", { ubus_rpc_session = sid })
75
76                 luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
77                         sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
78                 })
79         end
80
81         luci.http.redirect(dsp.build_url())
82 end