Project

General

Profile

Download (4.25 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 402c98a2 Reid Linnemann
 * Copyright (c) 2014-2023 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 138f2dd0 Viktor G
global $g;
39
40 916b6353 Viktor Gurov
require_once("guiconfig.inc");
41
require_once("functions.inc");
42
require_once("captiveportal.inc");
43
44
$guitimeout = 90;	// Seconds to wait before reloading the page after reboot
45
$guiretry = 20;		// Seconds to try again if $guitimeout was not long enough
46
47
$pgtitle = array(gettext("Diagnostics"), gettext("Reboot"));
48 a5a8e816 Viktor Gurov
$platform = system_identify_specific_platform();
49 916b6353 Viktor Gurov
include("head.inc");
50
51 9b83e6fb Viktor G
if ($_SERVER['REQUEST_METHOD'] == 'POST'):
52 916b6353 Viktor Gurov
	if (DEBUG) {
53
		print_info_box(gettext("Not actually rebooting (DEBUG is set true)."), 'success');
54
	} else {
55
		print('<div><pre>');
56
		switch ($_POST['rebootmode']) {
57
			case 'FSCKReboot':
58 44144b37 Viktor G
				if ((php_uname('m') != 'arm') && !is_module_loaded("zfs.ko")) {
59 a5a8e816 Viktor Gurov
					mwexec('/sbin/nextboot -e "pfsense.fsck.force=5"');
60 2568e151 Christian McDonald
					notify_all_remote(sprintf(gettext("%s is rebooting for a filesystem check now."), g_get('product_label')));
61 a5a8e816 Viktor Gurov
					system_reboot();
62
				}
63 916b6353 Viktor Gurov
				break;
64
			case 'Reroot':
65 2568e151 Christian McDonald
				notify_all_remote(sprintf(gettext("%s is rerooting now."), g_get('product_label')));
66 3f706839 jim-p
				system_reboot_sync(true);
67 916b6353 Viktor Gurov
				break;
68
			case 'Reboot':
69 2568e151 Christian McDonald
				notify_all_remote(sprintf(gettext("%s is rebooting now."), g_get('product_label')));
70 916b6353 Viktor Gurov
				system_reboot();
71
				break;
72
			default:
73
		}
74
		print('</pre></div>');
75
	}
76
?>
77
78
<div id="countdown" class="text-center"></div>
79
80
<script type="text/javascript">
81
//<![CDATA[
82
events.push(function() {
83
84
	var time = 0;
85
86
	function checkonline() {
87
		$.ajax({
88
			url	 : "/index.php", // or other resource
89
			type : "HEAD"
90
		})
91
		.done(function() {
92
			window.location="/index.php";
93
		});
94
	}
95
96
	function startCountdown() {
97
		setInterval(function() {
98
			if (time == "<?=$guitimeout?>") {
99
				$('#countdown').html('<h4><?=sprintf(gettext('Rebooting%1$sPage will automatically reload in %2$s seconds'), "<br />", "<span id=\"secs\"></span>");?></h4>');
100
			}
101
102
			if (time > 0) {
103
				$('#secs').html(time);
104
				time--;
105
			} else {
106
				time = "<?=$guiretry?>";
107
				$('#countdown').html('<h4><?=sprintf(gettext('Not yet ready%1$s Retrying in another %2$s seconds'), "<br />", "<span id=\"secs\"></span>");?></h4>');
108
				$('#secs').html(time);
109
				checkonline();
110
			}
111
		}, 1000);
112
	}
113
114
	time = "<?=$guitimeout?>";
115
	startCountdown();
116
117
});
118
//]]>
119
</script>
120
<?php
121
else:
122
123
$form = new Form(false);
124
125 da77bc71 Viktor Gurov
$help = 'Select "Normal reboot" to reboot the system immediately';
126 a5a8e816 Viktor Gurov
$modeslist = ['Reboot' => 'Normal reboot'];
127 44144b37 Viktor G
if ((php_uname('m') != 'arm') && !is_module_loaded("zfs.ko")) {
128 a5a8e816 Viktor Gurov
        $help .= ', "Reboot with Filesystem Check" to reboot and run filesystem check';
129
        $modeslist += ['FSCKReboot' => 'Reboot with Filesystem Check'];
130 44144b37 Viktor G
}
131 3f706839 jim-p
132
$help .= ', or "Reroot" to stop processes, remount disks and re-run startup sequence';
133
$modeslist += ['Reroot' => 'Reroot'];
134
135 916b6353 Viktor Gurov
$help .= '.';
136
137
$section = new Form_Section('Select reboot method');
138
139
$section->addInput(new Form_Select(
140
        'rebootmode',
141
        '*Reboot method',
142
        $rebootmode,
143
        $modeslist
144
))->setHelp($help);
145
146
$form->add($section);
147
148
$form->addGlobal(new Form_Button(
149
        'Submit',
150
        'Submit',
151
        null,
152
        'fa-wrench'
153
))->addClass('btn-primary');
154
155
print $form;
156
157
endif;
158
159
include("foot.inc");