Project

General

Profile

Download (9.83 KB) Statistics
| Branch: | Tag: | Revision:
1 8ccc8f1a Scott Ullrich
<?php
2 5b237745 Scott Ullrich
/*
3 c5d81585 Renato Botelho
 * diag_backup.php
4 9da2cf1c Stephen Beaver
 *
5 c5d81585 Renato Botelho
 * part of pfSense (https://www.pfsense.org)
6 38809d47 Renato Botelho do Couto
 * Copyright (c) 2004-2013 BSD Perimeter
7
 * Copyright (c) 2013-2016 Electric Sheep Fencing
8 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
9 c5d81585 Renato Botelho
 * All rights reserved.
10 fd9ebcd5 Stephen Beaver
 *
11 c5d81585 Renato Botelho
 * originally based on m0n0wall (http://m0n0.ch/wall)
12
 * Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
13
 * All rights reserved.
14 fd9ebcd5 Stephen Beaver
 *
15 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 *
19 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
20 fd9ebcd5 Stephen Beaver
 *
21 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
27 5b237745 Scott Ullrich
28 6b07c15a Matthew Grooms
##|+PRIV
29 5d916fc7 Stephen Beaver
##|*IDENT=page-diagnostics-backup-restore
30 0f298138 k-paulius
##|*NAME=Diagnostics: Backup & Restore
31
##|*DESCR=Allow access to the 'Diagnostics: Backup & Restore' page.
32 57188e47 Phil Davis
##|*WARN=standard-warning-root
33 6b07c15a Matthew Grooms
##|*MATCH=diag_backup.php*
34
##|-PRIV
35
36 47d11b79 Mark Crane
/* Allow additional execution time 0 = no limit. */
37 3420028c Scott Ullrich
ini_set('max_execution_time', '0');
38
ini_set('max_input_time', '0');
39 47d11b79 Mark Crane
40 5b237745 Scott Ullrich
/* omit no-cache headers because it confuses IE with file downloads */
41
$omit_nocacheheaders = true;
42 c81ef6e2 Phil Davis
require_once("guiconfig.inc");
43 0ff4de47 Steve Beaver
require_once("backup.inc");
44 5b237745 Scott Ullrich
45 8bdb6879 Darren Embry
$rrddbpath = "/var/db/rrd";
46
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
47
48 da17d77e Ermal Lu?i
if ($_POST['apply']) {
49 73ed069b Renato Botelho
	ob_flush();
50
	flush();
51 c9a19238 Darren Embry
	clear_subsystem_dirty("restore");
52 73ed069b Renato Botelho
	exit;
53 da17d77e Ermal Lu?i
}
54
55 5b237745 Scott Ullrich
if ($_POST) {
56 0ff4de47 Steve Beaver
	if ($_POST['reinstallpackages']) {
57
		header("Location: pkg_mgr_install.php?mode=reinstallall");
58
		exit;
59 9a7e1c95 Phil Davis
	} else if ($_POST['clearpackagelock']) {
60 0ff4de47 Steve Beaver
		clear_subsystem_dirty('packagelock');
61
		$savemsg = "Package lock cleared.";
62
	} else {
63 1b75667c Viktor G
		$execpost_return = execPost($_POST, $_FILES);
64
		$input_errors = $execpost_return['input_errors'];
65
		$savemsg = $execpost_return['savemsg'];
66 5f601060 Phil Davis
	}
67 73ed069b Renato Botelho
68 5b237745 Scott Ullrich
}
69 6a1e6651 Bill Marquette
70 02e1170d Scott Ullrich
$id = rand() . '.' . time();
71
72
$mth = ini_get('upload_progress_meter.store_method');
73
$dir = ini_get('upload_progress_meter.file.filename_template');
74
75 a4af095c Renato Botelho
function build_area_list($showall) {
76
	global $config;
77 b63695db Scott Ullrich
78 0e834fc5 Stephen Beaver
	$areas = array(
79
		"aliases" => gettext("Aliases"),
80 a4af095c Renato Botelho
		"captiveportal" => gettext("Captive Portal"),
81
		"voucher" => gettext("Captive Portal Vouchers"),
82
		"dnsmasq" => gettext("DNS Forwarder"),
83
		"unbound" => gettext("DNS Resolver"),
84
		"dhcpd" => gettext("DHCP Server"),
85
		"dhcpdv6" => gettext("DHCPv6 Server"),
86 9185bfff Viktor G
		"dyndnses" => gettext("Dynamic DNS"),
87 a4af095c Renato Botelho
		"filter" => gettext("Firewall Rules"),
88
		"interfaces" => gettext("Interfaces"),
89
		"ipsec" => gettext("IPSEC"),
90 9185bfff Viktor G
		"dnshaper" => gettext("Limiters"),
91 a4af095c Renato Botelho
		"nat" => gettext("NAT"),
92
		"openvpn" => gettext("OpenVPN"),
93
		"installedpackages" => gettext("Package Manager"),
94
		"rrddata" => gettext("RRD Data"),
95
		"cron" => gettext("Scheduled Tasks"),
96
		"syslog" => gettext("Syslog"),
97
		"system" => gettext("System"),
98
		"staticroutes" => gettext("Static routes"),
99
		"sysctl" => gettext("System tunables"),
100
		"snmpd" => gettext("SNMP Server"),
101
		"shaper" => gettext("Traffic Shaper"),
102
		"vlans" => gettext("VLANS"),
103 7ca42d47 k-paulius
		"wol" => gettext("Wake-on-LAN")
104 a4af095c Renato Botelho
		);
105 0e834fc5 Stephen Beaver
106
	$list = array("" => gettext("All"));
107
108 288a2a0f Phil Davis
	if ($showall) {
109 0e834fc5 Stephen Beaver
		return($list + $areas);
110 288a2a0f Phil Davis
	} else {
111 a4af095c Renato Botelho
		foreach ($areas as $area => $areaname) {
112
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
113
				$list[$area] = $areaname;
114
			}
115
		}
116 8ff5ffcc Matthew Grooms
117 0e834fc5 Stephen Beaver
		return($list);
118 5f601060 Phil Davis
	}
119 8ff5ffcc Matthew Grooms
}
120
121 0f298138 k-paulius
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
122 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
123 b63695db Scott Ullrich
include("head.inc");
124
125 947141fd Phil Davis
if ($input_errors) {
126 a4af095c Renato Botelho
	print_input_errors($input_errors);
127 947141fd Phil Davis
}
128 0e834fc5 Stephen Beaver
129 947141fd Phil Davis
if ($savemsg) {
130 a4af095c Renato Botelho
	print_info_box($savemsg, 'success');
131 947141fd Phil Davis
}
132 0e834fc5 Stephen Beaver
133 a4af095c Renato Botelho
if (is_subsystem_dirty('restore')):
134 5b237745 Scott Ullrich
?>
135 a4af095c Renato Botelho
	<br/>
136 1af5edbf Stephen Beaver
	<form action="diag_reboot.php" method="post">
137 7d5b007c Sjon Hortensius
		<input name="Submit" type="hidden" value="Yes" />
138 f6aebbcc NewEraCracker
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
139 a4af095c Renato Botelho
		<br />
140 7d5b007c Sjon Hortensius
	</form>
141 0e834fc5 Stephen Beaver
<?php
142 a4af095c Renato Botelho
endif;
143
144
$tab_array = array();
145 0f298138 k-paulius
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
146 a4af095c Renato Botelho
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
147
display_top_tabs($tab_array);
148
149
$form = new Form(false);
150 3beeb66a Stephen Beaver
$form->setMultipartEncoding();	// Allow file uploads
151 a4af095c Renato Botelho
152 5f88f964 k-paulius
$section = new Form_Section('Backup Configuration');
153 a4af095c Renato Botelho
154
$section->addInput(new Form_Select(
155
	'backuparea',
156
	'Backup area',
157
	'',
158
	build_area_list(false)
159
));
160
161
$section->addInput(new Form_Checkbox(
162
	'nopackages',
163
	'Skip packages',
164
	'Do not backup package information.',
165
	false
166
));
167
168
$section->addInput(new Form_Checkbox(
169
	'donotbackuprrd',
170
	'Skip RRD data',
171
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
172
	true
173
));
174
175 35fa566c Viktor G
$section->addInput(new Form_Checkbox(
176
	'backupdata',
177
	'Include extra data',
178
	'Backup extra data.',
179 b3cc5117 Viktor G
	false
180 35fa566c Viktor G
))->setHelp('Backup extra data files for some services.%1$s' .
181 1b75667c Viktor G
	    '%2$s%3$sCaptive Portal - Captive Portal DB and UsedMACs DB%4$s' .
182
	    '%3$sCaptive Portal Vouchers - Used Vouchers DB%4$s' .
183
	    '%3$sDHCP Server - DHCP leases DB%4$s' .
184
	    '%3$sDHCPv6 Server - DHCPv6 leases DB%4$s%5$s',
185 35fa566c Viktor G
	    '<div class="infoblock">', '<ul>', '<li>', '</li>', '</ul></div>'
186
);
187
188 dc22e511 Viktor G
$section->addInput(new Form_Checkbox(
189
	'backupssh',
190
	'Backup SSH keys',
191
	'Backup SSH keys (otherwise clients would fail to recognize the host keys after restore)',
192
	true
193
));
194
195 a4af095c Renato Botelho
$section->addInput(new Form_Checkbox(
196
	'encrypt',
197
	'Encryption',
198
	'Encrypt this configuration file.',
199
	false
200 7c0f116b Jared Dillard
));
201 a4af095c Renato Botelho
202 06a1ba14 Viktor G
$section->addPassword(new Form_Input(
203 a4af095c Renato Botelho
	'encrypt_password',
204 c8b10b4c Stephen Beaver
	'Password',
205 a4af095c Renato Botelho
	'password',
206 c8b10b4c Stephen Beaver
	null
207 7c0f116b Jared Dillard
));
208 a4af095c Renato Botelho
209
$group = new Form_Group('');
210 1d80d714 NOYB
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
211 a4af095c Renato Botelho
$group->add(new Form_Button(
212 9a7e1c95 Phil Davis
	'download',
213 faab522f Renato Botelho
	'Download configuration as XML',
214 37676f4e jim-p
	null,
215
	'fa-download'
216
))->setAttribute('id')->addClass('btn-primary');
217 a4af095c Renato Botelho
218
$section->add($group);
219
$form->add($section);
220
221 5f88f964 k-paulius
$section = new Form_Section('Restore Backup');
222 a4af095c Renato Botelho
223
$section->addInput(new Form_StaticText(
224
	null,
225 c67c74dd Steve Beaver
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_label'])
226 a4af095c Renato Botelho
));
227
228
$section->addInput(new Form_Select(
229
	'restorearea',
230
	'Restore area',
231
	'',
232 ce3eca6e Phil Davis
	build_area_list(true)
233 a4af095c Renato Botelho
));
234
235
$section->addInput(new Form_Input(
236
	'conffile',
237
	'Configuration file',
238
	'file',
239
	null
240
));
241
242
$section->addInput(new Form_Checkbox(
243 7c0f116b Jared Dillard
	'decrypt',
244 a4af095c Renato Botelho
	'Encryption',
245 7c0f116b Jared Dillard
	'Configuration file is encrypted.',
246 a4af095c Renato Botelho
	false
247 7c0f116b Jared Dillard
));
248 a4af095c Renato Botelho
249 76d6d925 Stephen Beaver
$section->addInput(new Form_Input(
250 a4af095c Renato Botelho
	'decrypt_password',
251 c8b10b4c Stephen Beaver
	'Password',
252 a4af095c Renato Botelho
	'password',
253
	null,
254
	['placeholder' => 'Password']
255 7c0f116b Jared Dillard
));
256 a4af095c Renato Botelho
257
$group = new Form_Group('');
258 1d80d714 NOYB
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
259 a4af095c Renato Botelho
$group->add(new Form_Button(
260 9a7e1c95 Phil Davis
	'restore',
261 faab522f Renato Botelho
	'Restore Configuration',
262 37676f4e jim-p
	null,
263
	'fa-undo'
264
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
265 a4af095c Renato Botelho
266
$section->add($group);
267
268
$form->add($section);
269
270
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
271 5f88f964 k-paulius
	$section = new Form_Section('Package Functions');
272 0e834fc5 Stephen Beaver
273 a4af095c Renato Botelho
	if ($config['installedpackages']['package'] != "") {
274
		$group = new Form_Group('');
275 1d80d714 NOYB
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
276 a4af095c Renato Botelho
		$group->add(new Form_Button(
277 9a7e1c95 Phil Davis
			'reinstallpackages',
278 faab522f Renato Botelho
			'Reinstall Packages',
279 37676f4e jim-p
			null,
280
			'fa-retweet'
281
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
282 0e834fc5 Stephen Beaver
283 a4af095c Renato Botelho
		$section->add($group);
284 7eead1fc Darren Embry
	}
285 0e834fc5 Stephen Beaver
286 a4af095c Renato Botelho
	if (is_subsystem_dirty("packagelock")) {
287
		$group = new Form_Group('');
288 1d80d714 NOYB
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
289 a4af095c Renato Botelho
		$group->add(new Form_Button(
290 9a7e1c95 Phil Davis
			'clearpackagelock',
291 faab522f Renato Botelho
			'Clear Package Lock',
292 37676f4e jim-p
			null,
293
			'fa-wrench'
294
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
295 0e834fc5 Stephen Beaver
296 a4af095c Renato Botelho
		$section->add($group);
297
	}
298 0e834fc5 Stephen Beaver
299 a4af095c Renato Botelho
	$form->add($section);
300 a1003d57 Ermal Lu?i
}
301 a4af095c Renato Botelho
302
print($form);
303 7c0f116b Jared Dillard
?>
304
<script type="text/javascript">
305
//<![CDATA[
306 947141fd Phil Davis
events.push(function() {
307 7c0f116b Jared Dillard
308
	// ------- Show/hide sections based on checkbox settings --------------------------------------
309 0da0d43e Phil Davis
310 7c0f116b Jared Dillard
	function hideSections(hide) {
311
		hidePasswords();
312
	}
313
314
	function hidePasswords() {
315 3beeb66a Stephen Beaver
316 7c0f116b Jared Dillard
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
317
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
318
319
		hideInput('encrypt_password', encryptHide);
320
		hideInput('decrypt_password', decryptHide);
321
	}
322
323 ff59b884 Stephen Beaver
	// ---------- Click handlers ------------------------------------------------------------------
324 7c0f116b Jared Dillard
325
	$('input[name="encrypt"]').on('change', function() {
326
		hidePasswords();
327
	});
328
329
	$('input[name="decrypt"]').on('change', function() {
330
		hidePasswords();
331 3beeb66a Stephen Beaver
	});
332 7c0f116b Jared Dillard
333 947141fd Phil Davis
	$('#conffile').change(function () {
334 40f146c5 Phil Davis
		if (document.getElementById("conffile").value) {
335
			$('.restore').prop('disabled', false);
336
		} else {
337
			$('.restore').prop('disabled', true);
338
		}
339 35fa566c Viktor G
	});
340
341
	$('#backuparea').change(function () {
342
		if (document.getElementById("backuparea").value == 0) {
343
			disableInput('donotbackuprrd', false);
344
			disableInput('nopackages', false);
345
			disableInput('backupdata', false);
346 dc22e511 Viktor G
			disableInput('backupssh', false);
347 35fa566c Viktor G
		} else {
348
			disableInput('donotbackuprrd', true);
349
			disableInput('nopackages', true);
350
			disableInput('backupdata', true);
351 dc22e511 Viktor G
			disableInput('backupssh', true);
352 1b75667c Viktor G
			if (['captiveportal', 'dhcpd', 'dhcpdv6', 'voucher'].includes(document.getElementById("backuparea").value)) {
353 35fa566c Viktor G
				disableInput('backupdata', false);
354
			}
355
		}
356
	});
357
358 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
359
360 7c0f116b Jared Dillard
	hideSections();
361 ff59b884 Stephen Beaver
	$('.restore').prop('disabled', true);
362 7c0f116b Jared Dillard
});
363
//]]>
364
</script>
365
366
<?php
367 a4af095c Renato Botelho
include("foot.inc");
368 7a7f3af1 sullrich
369 5f601060 Phil Davis
if (is_subsystem_dirty('restore')) {
370 1fe2aa3e Viktor G
	print('<span style="display: none;">');
371 cf9a4467 jim-p
	system_reboot();
372 1fe2aa3e Viktor G
	print('</span>');
373 c9d46a8e Renato Botelho
}