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 |
3f706839
|
jim-p
|
system_reboot_sync(true);
|
64 |
916b6353
|
Viktor Gurov
|
break;
|
65 |
|
|
case 'Reboot':
|
66 |
|
|
system_reboot();
|
67 |
|
|
break;
|
68 |
|
|
default:
|
69 |
|
|
}
|
70 |
|
|
print('</pre></div>');
|
71 |
|
|
}
|
72 |
|
|
?>
|
73 |
|
|
|
74 |
|
|
<div id="countdown" class="text-center"></div>
|
75 |
|
|
|
76 |
|
|
<script type="text/javascript">
|
77 |
|
|
//<![CDATA[
|
78 |
|
|
events.push(function() {
|
79 |
|
|
|
80 |
|
|
var time = 0;
|
81 |
|
|
|
82 |
|
|
function checkonline() {
|
83 |
|
|
$.ajax({
|
84 |
|
|
url : "/index.php", // or other resource
|
85 |
|
|
type : "HEAD"
|
86 |
|
|
})
|
87 |
|
|
.done(function() {
|
88 |
|
|
window.location="/index.php";
|
89 |
|
|
});
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
function startCountdown() {
|
93 |
|
|
setInterval(function() {
|
94 |
|
|
if (time == "<?=$guitimeout?>") {
|
95 |
|
|
$('#countdown').html('<h4><?=sprintf(gettext('Rebooting%1$sPage will automatically reload in %2$s seconds'), "<br />", "<span id=\"secs\"></span>");?></h4>');
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
if (time > 0) {
|
99 |
|
|
$('#secs').html(time);
|
100 |
|
|
time--;
|
101 |
|
|
} else {
|
102 |
|
|
time = "<?=$guiretry?>";
|
103 |
|
|
$('#countdown').html('<h4><?=sprintf(gettext('Not yet ready%1$s Retrying in another %2$s seconds'), "<br />", "<span id=\"secs\"></span>");?></h4>');
|
104 |
|
|
$('#secs').html(time);
|
105 |
|
|
checkonline();
|
106 |
|
|
}
|
107 |
|
|
}, 1000);
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
time = "<?=$guitimeout?>";
|
111 |
|
|
startCountdown();
|
112 |
|
|
|
113 |
|
|
});
|
114 |
|
|
//]]>
|
115 |
|
|
</script>
|
116 |
|
|
<?php
|
117 |
|
|
else:
|
118 |
|
|
|
119 |
|
|
$form = new Form(false);
|
120 |
|
|
|
121 |
da77bc71
|
Viktor Gurov
|
$help = 'Select "Normal reboot" to reboot the system immediately';
|
122 |
a5a8e816
|
Viktor Gurov
|
$modeslist = ['Reboot' => 'Normal reboot'];
|
123 |
96d0cb2d
|
Viktor G
|
if (php_uname('m') != 'arm') {
|
124 |
a5a8e816
|
Viktor Gurov
|
$help .= ', "Reboot with Filesystem Check" to reboot and run filesystem check';
|
125 |
|
|
$modeslist += ['FSCKReboot' => 'Reboot with Filesystem Check'];
|
126 |
|
|
}
|
127 |
3f706839
|
jim-p
|
|
128 |
|
|
$help .= ', or "Reroot" to stop processes, remount disks and re-run startup sequence';
|
129 |
|
|
$modeslist += ['Reroot' => 'Reroot'];
|
130 |
|
|
|
131 |
916b6353
|
Viktor Gurov
|
$help .= '.';
|
132 |
|
|
|
133 |
|
|
$section = new Form_Section('Select reboot method');
|
134 |
|
|
|
135 |
|
|
$section->addInput(new Form_Select(
|
136 |
|
|
'rebootmode',
|
137 |
|
|
'*Reboot method',
|
138 |
|
|
$rebootmode,
|
139 |
|
|
$modeslist
|
140 |
|
|
))->setHelp($help);
|
141 |
|
|
|
142 |
|
|
$form->add($section);
|
143 |
|
|
|
144 |
|
|
$form->addGlobal(new Form_Button(
|
145 |
|
|
'Submit',
|
146 |
|
|
'Submit',
|
147 |
|
|
null,
|
148 |
|
|
'fa-wrench'
|
149 |
|
|
))->addClass('btn-primary');
|
150 |
|
|
|
151 |
|
|
print $form;
|
152 |
|
|
?>
|
153 |
|
|
|
154 |
|
|
<script type="text/javascript">
|
155 |
|
|
//<![CDATA[
|
156 |
|
|
events.push(function() {
|
157 |
|
|
//If we have been called with $_POST['override'] == "yes", then just reload the page to simulate the user clicking "Reboot"
|
158 |
|
|
if ( "<?=$_POST['override']?>" == "yes") {
|
159 |
|
|
$('form').submit();
|
160 |
|
|
}
|
161 |
|
|
});
|
162 |
|
|
//]]>
|
163 |
|
|
</script>
|
164 |
|
|
<?php
|
165 |
|
|
|
166 |
|
|
endif;
|
167 |
|
|
|
168 |
|
|
include("foot.inc");
|