index.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. --[[
  2. Copyright 2013 Nils Schneider <nils@nilsschneider.net>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. $Id$
  8. ]]--
  9. module("luci.controller.gluon-config-mode.index", package.seeall)
  10. function index()
  11. local uci_state = luci.model.uci.cursor_state()
  12. if uci_state:get_first("gluon-setup-mode", "setup_mode", "running", "0") == "1" then
  13. local root = node()
  14. if not root.target then
  15. root.target = alias("gluon-config-mode")
  16. root.index = true
  17. end
  18. page = node()
  19. page.lock = true
  20. page.target = alias("gluon-config-mode")
  21. page.subindex = true
  22. page.index = false
  23. page = node("gluon-config-mode")
  24. page.title = _("Wizard")
  25. page.target = alias("gluon-config-mode", "wizard")
  26. page.order = 5
  27. page.sysauth = "root"
  28. page.sysauth_authenticator = function() return "root" end
  29. page.index = true
  30. entry({"gluon-config-mode", "wizard"}, cbi("gluon-config-mode/wizard")).index = true
  31. entry({"gluon-config-mode", "reboot"}, call("action_reboot"))
  32. end
  33. end
  34. function action_reboot()
  35. local uci = luci.model.uci.cursor()
  36. uci:set("gluon-setup-mode", uci:get_first("gluon-setup-mode", "setup_mode"), "configured", "1")
  37. uci:save("gluon-setup-mode")
  38. uci:commit("gluon-setup-mode")
  39. local gluon_luci = require "gluon.luci"
  40. local fs = require "nixio.fs"
  41. local util = require "nixio.util"
  42. local pretty_hostname = require "pretty_hostname"
  43. local parts_dir = "/lib/gluon/config-mode/reboot/"
  44. local files = util.consume(fs.dir(parts_dir))
  45. table.sort(files)
  46. local parts = {}
  47. for _, entry in ipairs(files) do
  48. if entry:sub(1, 1) ~= '.' then
  49. local f = dofile(parts_dir .. '/' .. entry)
  50. if f ~= nil then
  51. table.insert(parts, f)
  52. end
  53. end
  54. end
  55. local hostname = pretty_hostname.get(uci)
  56. luci.template.render("gluon/config-mode/reboot",
  57. {
  58. parts = parts,
  59. hostname = hostname,
  60. escape = gluon_luci.escape,
  61. urlescape = gluon_luci.urlescape,
  62. }
  63. )
  64. if nixio.fork() == 0 then
  65. -- Replace stdout with /dev/null
  66. nixio.dup(nixio.open('/dev/null', 'w'), nixio.stdout)
  67. -- Sleep a little so the browser can fetch everything required to
  68. -- display the reboot page, then reboot the device.
  69. nixio.nanosleep(1)
  70. nixio.execp("reboot")
  71. end
  72. end