Project

General

Profile

Download (4.33 KB) Statistics
| Branch: | Tag: | Revision:
1 916b6353 Viktor Gurov
<?php
2
/*
3
 * diag_reboot.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f585441 Luiz Souza
 * Copyright (c) 2014-2021 Rubicon Communications, LLC (Netgate)
9 916b6353 Viktor Gurov
 * All rights reserved.
10
 *
11
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14
 *
15
 * Licensed under the Apache License, Version 2.0 (the "License");
16
 * you may not use this file except in compliance with the License.
17
 * You may obtain a copy of the License at
18
 *
19
 * http://www.apache.org/licenses/LICENSE-2.0
20
 *
21
 * Unless required by applicable law or agreed to in writing, software
22
 * distributed under the License is distributed on an "AS IS" BASIS,
23
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
 * See the License for the specific language governing permissions and
25
 * limitations under the License.
26
 */
27
28
##|+PRIV
29
##|*IDENT=page-diagnostics-rebootsystem
30
##|*NAME=Diagnostics: Reboot System
31
##|*DESCR=Allow access to the 'Diagnostics: Reboot System' page.
32
##|*MATCH=diag_reboot.php*
33
##|-PRIV
34
35
// Set DEBUG to true to prevent the system_reboot() function from being called
36
define("DEBUG", false);
37
38
require_once("guiconfig.inc");
39
require_once("functions.inc");
40
require_once("captiveportal.inc");
41
42
$guitimeout = 90;	// Seconds to wait before reloading the page after reboot
43
$guiretry = 20;		// Seconds to try again if $guitimeout was not long enough
44
45
$pgtitle = array(gettext("Diagnostics"), gettext("Reboot"));
46 a5a8e816 Viktor Gurov
$platform = system_identify_specific_platform();
47 916b6353 Viktor Gurov
include("head.inc");
48
49
if (($_SERVER['REQUEST_METHOD'] == 'POST') && (empty($_POST['override']) ||
50
    ($_POST['override'] != "yes"))):
51
	if (DEBUG) {
52
		print_info_box(gettext("Not actually rebooting (DEBUG is set true)."), 'success');
53
	} else {
54
		print('<div><pre>');
55
		switch ($_POST['rebootmode']) {
56
			case 'FSCKReboot':
57 96d0cb2d Viktor G
				if (php_uname('m') != 'arm') {
58 a5a8e816 Viktor Gurov
					mwexec('/sbin/nextboot -e "pfsense.fsck.force=5"');
59
					system_reboot();
60
				}
61 916b6353 Viktor Gurov
				break;
62
			case 'Reroot':
63
				if (!is_module_loaded("zfs.ko")) {
64
					system_reboot_sync(true);
65
				}
66
				break;
67
			case 'Reboot':
68
				system_reboot();
69
				break;
70
			default:
71
		}
72
		print('</pre></div>');
73
	}
74
?>
75
76
<div id="countdown" class="text-center"></div>
77
78
<script type="text/javascript">
79
//<![CDATA[
80
events.push(function() {
81
82
	var time = 0;
83
84
	function checkonline() {
85
		$.ajax({
86
			url	 : "/index.php", // or other resource
87
			type : "HEAD"
88
		})
89
		.done(function() {
90
			window.location="/index.php";
91
		});
92
	}
93
94
	function startCountdown() {
95
		setInterval(function() {
96
			if (time == "<?=$guitimeout?>") {
97
				$('#countdown').html('<h4><?=sprintf(gettext('Rebooting%1$sPage will automatically reload in %2$s seconds'), "<br />", "<span id=\"secs\"></span>");?></h4>');
98
			}
99
100
			if (time > 0) {
101
				$('#secs').html(time);
102
				time--;
103
			} else {
104
				time = "<?=$guiretry?>";
105
				$('#countdown').html('<h4><?=sprintf(gettext('Not yet ready%1$s Retrying in another %2$s seconds'), "<br />", "<span id=\"secs\"></span>");?></h4>');
106
				$('#secs').html(time);
107
				checkonline();
108
			}
109
		}, 1000);
110
	}
111
112
	time = "<?=$guitimeout?>";
113
	startCountdown();
114
115
});
116
//]]>
117
</script>
118
<?php
119
else:
120
121
$form = new Form(false);
122
123 da77bc71 Viktor Gurov
$help = 'Select "Normal reboot" to reboot the system immediately';
124 a5a8e816 Viktor Gurov
$modeslist = ['Reboot' => 'Normal reboot'];
125 96d0cb2d Viktor G
if (php_uname('m') != 'arm') {
126 a5a8e816 Viktor Gurov
        $help .= ', "Reboot with Filesystem Check" to reboot and run filesystem check';
127
        $modeslist += ['FSCKReboot' => 'Reboot with Filesystem Check'];
128
        }
129 916b6353 Viktor Gurov
if (!is_module_loaded("zfs.ko")) {
130
	$help .= ' or "Reroot" to stop processes, remount disks and re-run startup sequence';
131
	$modeslist += ['Reroot' => 'Reroot'];
132
	} 
133
$help .= '.';
134
135
$section = new Form_Section('Select reboot method');
136
137
$section->addInput(new Form_Select(
138
        'rebootmode',
139
        '*Reboot method',
140
        $rebootmode,
141
        $modeslist
142
))->setHelp($help);
143
144
$form->add($section);
145
146
$form->addGlobal(new Form_Button(
147
        'Submit',
148
        'Submit',
149
        null,
150
        'fa-wrench'
151
))->addClass('btn-primary');
152
153
print $form;
154
?>
155
156
<script type="text/javascript">
157
//<![CDATA[
158
events.push(function() {
159
	//If we have been called with $_POST['override'] == "yes", then just reload the page to simulate the user clicking "Reboot"
160
	if ( "<?=$_POST['override']?>" == "yes") {
161
		$('form').submit();
162
	}
163
});
164
//]]>
165
</script>
166
<?php
167
168
endif;
169
170
include("foot.inc");