Merge pull request #509 from neheb/master
[project/luci.git] / modules / luci-mod-admin-full / 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         local root = node()
8         if not root.target then
9                 root.target = alias("admin")
10                 root.index = true
11         end
12
13         local page   = node("admin")
14         page.target  = firstchild()
15         page.title   = _("Administration")
16         page.order   = 10
17         page.sysauth = "root"
18         page.sysauth_authenticator = "htmlauth"
19         page.ucidata = true
20         page.index = true
21
22         -- Empty services menu to be populated by addons
23         entry({"admin", "services"}, firstchild(), _("Services"), 40).index = true
24
25         entry({"admin", "logout"}, call("action_logout"), _("Logout"), 90)
26 end
27
28 function action_logout()
29         local dsp = require "luci.dispatcher"
30         local utl = require "luci.util"
31         local sid = dsp.context.authsession
32
33         if sid then
34                 utl.ubus("session", "destroy", { ubus_rpc_session = sid })
35
36                 luci.http.header("Set-Cookie", "sysauth=%s; expires=%s; path=%s/" %{
37                         sid, 'Thu, 01 Jan 1970 01:00:00 GMT', dsp.build_url()
38                 })
39         end
40
41         luci.http.redirect(dsp.build_url())
42 end