<%#
Opennet Firmware

Copyright 2010 Rene Ejury <opennet@absorb.it>

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

-%>

<%
local uci = require "luci.model.uci"
local cursor = uci.cursor()
local reboot = luci.http.formvalue("reboot")
local reconfigure = luci.http.formvalue("reconfigure")
%>

<%+header%>
<h2><a id="content" name="content"><%:System Reboot%></a></h2>
<h3><%:Reboots the operating system of your device%></h3>
<%	if not reboot and not reconfigure then
%>		<form method="post" action="<%=REQUEST_URI%>">
		<div class="cbi-map">
			<fieldset class="cbi-section">
					<input class="cbi-button" type="submit" value="<%:Perform Reboot%>" title="<%:Perform Reboot%>" name="reboot" />
			</fieldset>
		</div>
		<div class="cbi-map">
			<fieldset class="cbi-section">
<%				cursor:set_confdir("/etc/config_presets")
                lan_ipaddr = cursor:get("on-core", "defaults", "lan_ipaddr")
				lan_netmask = cursor:get("on-core", "defaults", "lan_netmask")
				on_ipschema = cursor:get("on-core", "defaults", "on_ipschema")
				on_netmask = cursor:get("on-core", "defaults", "on_netmask")
				on_id = cursor:get("on-core", "defaults", "on_id_preset")
				on_ipaddr = luci.sys.exec(". /usr/bin/on-helper.sh; get_on_ip '"..on_id.."' '"..on_ipschema.."' '0'")

				print("<p>"..luci.i18n.stringf([[Remove current configuration and redetect and reconfigure device interfaces again. After reboot, local LAN-device will be at %s/%s. A probably disabled DHCP-Server on LAN will not be reenabled - you should do this by hand. Opennet devices (WLAN) will be configured to start with %s/%s and follow the rules for multiple interfaces. If this is not enough for you, you can try a complete reset at the <a href='%s/admin/system/flashops/'>system backup page</a>, but be aware that you will loose all keys and certs than too.]], lan_ipaddr, lan_netmask, on_ipaddr, on_netmask, controller).."</p>")
%>			
                <p><input class="cbi-button" type="submit" value="<%:Remove Configuration and Reboot%>" title="<%:Remove Configuration and Reboot%>" name="reconfigure" /></p>
            </fieldset>
		</div>
		</form>
<%- else
		if reconfigure then
			luci.sys.exec("rm /etc/config/network")
			luci.sys.exec("rm /etc/config/wireless")
		end
		luci.sys.reboot()
-%>		<p><%:Please wait: Device rebooting...%></p>
		<script type="text/javascript">setTimeout("<%=REQUEST_URI%>", 20000)</script>
<%- end -%>
<%+footer%>
