luci-base: switch to ubus sessions
[project/luci.git] / modules / luci-mod-admin-mini / luasrc / controller / mini / index.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5 Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11         http://www.apache.org/licenses/LICENSE-2.0
12
13 $Id$
14 ]]--
15
16 module("luci.controller.mini.index", package.seeall)
17
18 function index()
19         local root = node()
20         if not root.lock then
21                 root.target = alias("mini")
22                 root.index = true
23         end
24         
25         entry({"about"}, template("about"))
26         
27         local page   = entry({"mini"}, alias("mini", "index"), _("Essentials"), 10)
28         page.sysauth = "root"
29         page.sysauth_authenticator = "htmlauth"
30         page.index = true
31         
32         entry({"mini", "index"}, alias("mini", "index", "index"), _("Overview"), 10).index = true
33         entry({"mini", "index", "index"}, form("mini/index"), _("General"), 1).ignoreindex = true
34         entry({"mini", "index", "luci"}, cbi("mini/luci", {autoapply=true}), _("Settings"), 10)
35         entry({"mini", "index", "logout"}, call("action_logout"), _("Logout"))
36 end
37
38 function action_logout()
39         local dsp = require "luci.dispatcher"
40         local utl = require "luci.util"
41         if dsp.context.authsession then
42                 utl.ubus("session", "destroy", {
43                         ubus_rpc_session = dsp.context.authsession
44                 })
45                 dsp.context.urltoken.stok = nil
46         end
47
48         luci.http.header("Set-Cookie", "sysauth=; path=" .. dsp.build_url())
49         luci.http.redirect(luci.dispatcher.build_url())
50 end