index.lua 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --[[
  2. LuCI - Lua Configuration Interface
  3. Copyright 2008 Steven Barth <steven@midlink.org>
  4. Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. $Id$
  10. ]]--
  11. module("luci.controller.admin.index", package.seeall)
  12. function index()
  13. local uci_state = luci.model.uci.cursor_state()
  14. local setup_mode = uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0") == "1"
  15. -- Disable gluon-luci-admin when setup mode is not enabled
  16. if not setup_mode then
  17. return
  18. end
  19. local root = node()
  20. if not root.lock then
  21. root.target = alias("admin")
  22. root.index = true
  23. end
  24. local page = entry({"admin"}, alias("admin", "index"), "Expert Mode", 10)
  25. page.sysauth = "root"
  26. if setup_mode then
  27. -- force root to be logged in when running in setup_mode
  28. page.sysauth_authenticator = function() return "root" end
  29. else
  30. page.sysauth_authenticator = "htmlauth"
  31. end
  32. page.index = true
  33. entry({"admin", "index"}, cbi("admin/remote"), "Remotezugriff", 1).ignoreindex = true
  34. if not setup_mode then
  35. entry({"admin", "logout"}, call("action_logout"), "Logout")
  36. end
  37. end
  38. function action_logout()
  39. local dsp = require "luci.dispatcher"
  40. local sauth = require "luci.sauth"
  41. if dsp.context.authsession then
  42. sauth.kill(dsp.context.authsession)
  43. dsp.context.urltoken.stok = nil
  44. end
  45. luci.http.header("Set-Cookie", "sysauth=; path=" .. dsp.build_url())
  46. luci.http.redirect(luci.dispatcher.build_url())
  47. end