gluon-packages/gluon/gluon-config-mode/files/usr/lib/lua/luci/controller/gluon-config-mode/index.lua

84 lines
2.4 KiB
Lua
Raw Normal View History

2013-09-28 23:18:36 +02:00
--[[
Copyright 2013 Nils Schneider <nils@nilsschneider.net>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
$Id$
]]--
module("luci.controller.gluon-config-mode.index", package.seeall)
2013-09-28 23:18:36 +02:00
local site = require 'gluon.site_config'
2013-09-28 23:18:36 +02:00
local meshvpn_name = "mesh_vpn"
2013-09-28 23:18:36 +02:00
function index()
local uci_state = luci.model.uci.cursor_state()
if uci_state:get_first("gluon-config-mode", "wizard", "running", "0") == "1" then
2013-09-28 23:18:36 +02:00
local root = node()
if not root.target then
root.target = alias("gluon-config-mode")
2013-09-28 23:18:36 +02:00
root.index = true
end
page = node()
page.lock = true
page.target = alias("gluon-config-mode")
2013-09-28 23:18:36 +02:00
page.subindex = true
page.index = false
page = node("gluon-config-mode")
page.title = _("Wizard")
page.target = alias("gluon-config-mode", "wizard")
2013-09-28 23:18:36 +02:00
page.order = 5
page.setuser = "root"
page.setgroup = "root"
page.index = true
entry({"gluon-config-mode", "wizard"}, form("gluon-config-mode/wizard")).index = true
entry({"gluon-config-mode", "reboot"}, call("action_reboot"))
2013-09-28 23:18:36 +02:00
end
end
function action_reboot()
local configmode = require "luci.tools.gluon-config-mode"
2013-09-28 23:18:36 +02:00
local pubkey
local uci = luci.model.uci.cursor()
local meshvpn_enabled = uci:get("fastd", meshvpn_name, "enabled", "0")
local sysconfig = require 'gluon.sysconfig'
2013-09-28 23:18:36 +02:00
if meshvpn_enabled == "1" then
pubkey = configmode.get_fastd_pubkey(meshvpn_name)
end
uci:set("gluon-config-mode", uci:get_first("gluon-config-mode", "wizard"), "configured", "1")
uci:save("gluon-config-mode")
uci:commit("gluon-config-mode")
2013-09-28 23:18:36 +02:00
local hostname = uci:get_first("system", "system", "hostname")
if nixio.fork() ~= 0 then
luci.template.render("gluon-config-mode/reboot",
{luci=luci, pubkey=pubkey, hostname=hostname, site=site, sysconfig=sysconfig})
else
debug.setfenv(io.stdout, debug.getfenv(io.open '/dev/null'))
io.stdout:close()
-- Sleep a little so the browser can fetch everything required to
-- display the reboot page, then reboot the device.
nixio.nanosleep(2)
-- Run reboot with popen so it gets its own std filehandles.
io.popen("reboot")
-- Prevent any further execution in this child.
os.exit()
end
2013-09-28 23:18:36 +02:00
end