index.lua 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.setuser = "root"
  28. page.setgroup = "root"
  29. page.index = true
  30. entry({"gluon-config-mode", "wizard"}, form("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 parts_dir = "/lib/gluon/config-mode/reboot/"
  43. local files = util.consume(fs.dir(parts_dir))
  44. table.sort(files)
  45. local parts = {}
  46. for _, entry in ipairs(files) do
  47. if entry:sub(1, 1) ~= '.' then
  48. local f = dofile(parts_dir .. '/' .. entry)
  49. if f ~= nil then
  50. table.insert(parts, f)
  51. end
  52. end
  53. end
  54. local hostname = uci:get_first("system", "system", "hostname")
  55. luci.template.render("gluon/config-mode/reboot",
  56. {
  57. parts = parts,
  58. hostname = hostname,
  59. escape = gluon_luci.escape,
  60. urlescape = gluon_luci.urlescape,
  61. }
  62. )
  63. if nixio.fork() == 0 then
  64. -- Replace stdout with /dev/null
  65. nixio.dup(nixio.open('/dev/null', 'w'), nixio.stdout)
  66. -- Sleep a little so the browser can fetch everything required to
  67. -- display the reboot page, then reboot the device.
  68. nixio.nanosleep(1)
  69. nixio.execp("reboot")
  70. end
  71. end