Project

General

Profile

Download (9.91 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 402c98a2 Reid Linnemann
 * Copyright (c) 2014-2023 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 ef16abd8 luckman212
		"widgets" => gettext("Dashboard Widgets"),
83 a4af095c Renato Botelho
		"dnsmasq" => gettext("DNS Forwarder"),
84
		"unbound" => gettext("DNS Resolver"),
85
		"dhcpd" => gettext("DHCP Server"),
86
		"dhcpdv6" => gettext("DHCPv6 Server"),
87 9185bfff Viktor G
		"dyndnses" => gettext("Dynamic DNS"),
88 a4af095c Renato Botelho
		"filter" => gettext("Firewall Rules"),
89
		"interfaces" => gettext("Interfaces"),
90
		"ipsec" => gettext("IPSEC"),
91 9185bfff Viktor G
		"dnshaper" => gettext("Limiters"),
92 a4af095c Renato Botelho
		"nat" => gettext("NAT"),
93
		"openvpn" => gettext("OpenVPN"),
94
		"installedpackages" => gettext("Package Manager"),
95
		"rrddata" => gettext("RRD Data"),
96
		"cron" => gettext("Scheduled Tasks"),
97
		"syslog" => gettext("Syslog"),
98
		"system" => gettext("System"),
99
		"staticroutes" => gettext("Static routes"),
100
		"sysctl" => gettext("System tunables"),
101
		"snmpd" => gettext("SNMP Server"),
102
		"shaper" => gettext("Traffic Shaper"),
103
		"vlans" => gettext("VLANS"),
104 7ca42d47 k-paulius
		"wol" => gettext("Wake-on-LAN")
105 a4af095c Renato Botelho
		);
106 0e834fc5 Stephen Beaver
107
	$list = array("" => gettext("All"));
108
109 288a2a0f Phil Davis
	if ($showall) {
110 0e834fc5 Stephen Beaver
		return($list + $areas);
111 288a2a0f Phil Davis
	} else {
112 a4af095c Renato Botelho
		foreach ($areas as $area => $areaname) {
113
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
114
				$list[$area] = $areaname;
115
			}
116
		}
117 8ff5ffcc Matthew Grooms
118 0e834fc5 Stephen Beaver
		return($list);
119 5f601060 Phil Davis
	}
120 8ff5ffcc Matthew Grooms
}
121
122 0f298138 k-paulius
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
123 edcd7535 Phil Davis
$pglinks = array("", "@self", "@self");
124 b63695db Scott Ullrich
include("head.inc");
125
126 947141fd Phil Davis
if ($input_errors) {
127 a4af095c Renato Botelho
	print_input_errors($input_errors);
128 947141fd Phil Davis
}
129 0e834fc5 Stephen Beaver
130 947141fd Phil Davis
if ($savemsg) {
131 a4af095c Renato Botelho
	print_info_box($savemsg, 'success');
132 947141fd Phil Davis
}
133 0e834fc5 Stephen Beaver
134 a4af095c Renato Botelho
if (is_subsystem_dirty('restore')):
135 5b237745 Scott Ullrich
?>
136 a4af095c Renato Botelho
	<br/>
137 1af5edbf Stephen Beaver
	<form action="diag_reboot.php" method="post">
138 7d5b007c Sjon Hortensius
		<input name="Submit" type="hidden" value="Yes" />
139 f6aebbcc NewEraCracker
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
140 a4af095c Renato Botelho
		<br />
141 7d5b007c Sjon Hortensius
	</form>
142 0e834fc5 Stephen Beaver
<?php
143 a4af095c Renato Botelho
endif;
144
145
$tab_array = array();
146 0f298138 k-paulius
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
147 a4af095c Renato Botelho
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
148
display_top_tabs($tab_array);
149
150
$form = new Form(false);
151 3beeb66a Stephen Beaver
$form->setMultipartEncoding();	// Allow file uploads
152 a4af095c Renato Botelho
153 5f88f964 k-paulius
$section = new Form_Section('Backup Configuration');
154 a4af095c Renato Botelho
155
$section->addInput(new Form_Select(
156
	'backuparea',
157
	'Backup area',
158
	'',
159
	build_area_list(false)
160
));
161
162
$section->addInput(new Form_Checkbox(
163
	'nopackages',
164
	'Skip packages',
165
	'Do not backup package information.',
166
	false
167
));
168
169
$section->addInput(new Form_Checkbox(
170
	'donotbackuprrd',
171
	'Skip RRD data',
172
	'Do not backup RRD data (NOTE: RRD Data can consume 4+ megabytes of config.xml space!)',
173
	true
174
));
175
176 35fa566c Viktor G
$section->addInput(new Form_Checkbox(
177
	'backupdata',
178
	'Include extra data',
179
	'Backup extra data.',
180 b3cc5117 Viktor G
	false
181 35fa566c Viktor G
))->setHelp('Backup extra data files for some services.%1$s' .
182 1b75667c Viktor G
	    '%2$s%3$sCaptive Portal - Captive Portal DB and UsedMACs DB%4$s' .
183
	    '%3$sCaptive Portal Vouchers - Used Vouchers DB%4$s' .
184
	    '%3$sDHCP Server - DHCP leases DB%4$s' .
185
	    '%3$sDHCPv6 Server - DHCPv6 leases DB%4$s%5$s',
186 35fa566c Viktor G
	    '<div class="infoblock">', '<ul>', '<li>', '</li>', '</ul></div>'
187
);
188
189 dc22e511 Viktor G
$section->addInput(new Form_Checkbox(
190
	'backupssh',
191
	'Backup SSH keys',
192
	'Backup SSH keys (otherwise clients would fail to recognize the host keys after restore)',
193
	true
194
));
195
196 a4af095c Renato Botelho
$section->addInput(new Form_Checkbox(
197
	'encrypt',
198
	'Encryption',
199
	'Encrypt this configuration file.',
200
	false
201 7c0f116b Jared Dillard
));
202 a4af095c Renato Botelho
203 06a1ba14 Viktor G
$section->addPassword(new Form_Input(
204 a4af095c Renato Botelho
	'encrypt_password',
205 c8b10b4c Stephen Beaver
	'Password',
206 a4af095c Renato Botelho
	'password',
207 c8b10b4c Stephen Beaver
	null
208 7c0f116b Jared Dillard
));
209 a4af095c Renato Botelho
210
$group = new Form_Group('');
211 1d80d714 NOYB
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
212 a4af095c Renato Botelho
$group->add(new Form_Button(
213 9a7e1c95 Phil Davis
	'download',
214 faab522f Renato Botelho
	'Download configuration as XML',
215 37676f4e jim-p
	null,
216
	'fa-download'
217
))->setAttribute('id')->addClass('btn-primary');
218 a4af095c Renato Botelho
219
$section->add($group);
220
$form->add($section);
221
222 5f88f964 k-paulius
$section = new Form_Section('Restore Backup');
223 a4af095c Renato Botelho
224
$section->addInput(new Form_StaticText(
225
	null,
226 2568e151 Christian McDonald
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), g_get('product_label'))
227 a4af095c Renato Botelho
));
228
229
$section->addInput(new Form_Select(
230
	'restorearea',
231
	'Restore area',
232
	'',
233 ce3eca6e Phil Davis
	build_area_list(true)
234 a4af095c Renato Botelho
));
235
236
$section->addInput(new Form_Input(
237
	'conffile',
238
	'Configuration file',
239
	'file',
240
	null
241
));
242
243
$section->addInput(new Form_Checkbox(
244 7c0f116b Jared Dillard
	'decrypt',
245 a4af095c Renato Botelho
	'Encryption',
246 7c0f116b Jared Dillard
	'Configuration file is encrypted.',
247 a4af095c Renato Botelho
	false
248 7c0f116b Jared Dillard
));
249 a4af095c Renato Botelho
250 76d6d925 Stephen Beaver
$section->addInput(new Form_Input(
251 a4af095c Renato Botelho
	'decrypt_password',
252 c8b10b4c Stephen Beaver
	'Password',
253 a4af095c Renato Botelho
	'password',
254
	null,
255
	['placeholder' => 'Password']
256 7c0f116b Jared Dillard
));
257 a4af095c Renato Botelho
258
$group = new Form_Group('');
259 1d80d714 NOYB
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
260 a4af095c Renato Botelho
$group->add(new Form_Button(
261 9a7e1c95 Phil Davis
	'restore',
262 faab522f Renato Botelho
	'Restore Configuration',
263 37676f4e jim-p
	null,
264
	'fa-undo'
265
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
266 a4af095c Renato Botelho
267
$section->add($group);
268
269
$form->add($section);
270
271 a7b25043 jim-p
$has_installed_packages = !empty(config_get_path('installedpackages/package', []));
272
273
if ($has_installed_packages || (is_subsystem_dirty("packagelock"))) {
274 5f88f964 k-paulius
	$section = new Form_Section('Package Functions');
275 0e834fc5 Stephen Beaver
276 a7b25043 jim-p
	if ($has_installed_packages) {
277 a4af095c Renato Botelho
		$group = new Form_Group('');
278 1d80d714 NOYB
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
279 a4af095c Renato Botelho
		$group->add(new Form_Button(
280 9a7e1c95 Phil Davis
			'reinstallpackages',
281 faab522f Renato Botelho
			'Reinstall Packages',
282 37676f4e jim-p
			null,
283
			'fa-retweet'
284
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
285 0e834fc5 Stephen Beaver
286 a4af095c Renato Botelho
		$section->add($group);
287 7eead1fc Darren Embry
	}
288 0e834fc5 Stephen Beaver
289 a4af095c Renato Botelho
	if (is_subsystem_dirty("packagelock")) {
290
		$group = new Form_Group('');
291 1d80d714 NOYB
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
292 a4af095c Renato Botelho
		$group->add(new Form_Button(
293 9a7e1c95 Phil Davis
			'clearpackagelock',
294 faab522f Renato Botelho
			'Clear Package Lock',
295 37676f4e jim-p
			null,
296
			'fa-wrench'
297
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
298 0e834fc5 Stephen Beaver
299 a4af095c Renato Botelho
		$section->add($group);
300
	}
301 0e834fc5 Stephen Beaver
302 a4af095c Renato Botelho
	$form->add($section);
303 a1003d57 Ermal Lu?i
}
304 a4af095c Renato Botelho
305
print($form);
306 7c0f116b Jared Dillard
?>
307
<script type="text/javascript">
308
//<![CDATA[
309 947141fd Phil Davis
events.push(function() {
310 7c0f116b Jared Dillard
311
	// ------- Show/hide sections based on checkbox settings --------------------------------------
312 0da0d43e Phil Davis
313 7c0f116b Jared Dillard
	function hideSections(hide) {
314
		hidePasswords();
315
	}
316
317
	function hidePasswords() {
318 3beeb66a Stephen Beaver
319 7c0f116b Jared Dillard
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
320
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
321
322
		hideInput('encrypt_password', encryptHide);
323
		hideInput('decrypt_password', decryptHide);
324
	}
325
326 ff59b884 Stephen Beaver
	// ---------- Click handlers ------------------------------------------------------------------
327 7c0f116b Jared Dillard
328
	$('input[name="encrypt"]').on('change', function() {
329
		hidePasswords();
330
	});
331
332
	$('input[name="decrypt"]').on('change', function() {
333
		hidePasswords();
334 3beeb66a Stephen Beaver
	});
335 7c0f116b Jared Dillard
336 947141fd Phil Davis
	$('#conffile').change(function () {
337 40f146c5 Phil Davis
		if (document.getElementById("conffile").value) {
338
			$('.restore').prop('disabled', false);
339
		} else {
340
			$('.restore').prop('disabled', true);
341
		}
342 35fa566c Viktor G
	});
343
344
	$('#backuparea').change(function () {
345
		if (document.getElementById("backuparea").value == 0) {
346
			disableInput('donotbackuprrd', false);
347
			disableInput('nopackages', false);
348
			disableInput('backupdata', false);
349 dc22e511 Viktor G
			disableInput('backupssh', false);
350 35fa566c Viktor G
		} else {
351
			disableInput('donotbackuprrd', true);
352
			disableInput('nopackages', true);
353
			disableInput('backupdata', true);
354 dc22e511 Viktor G
			disableInput('backupssh', true);
355 1b75667c Viktor G
			if (['captiveportal', 'dhcpd', 'dhcpdv6', 'voucher'].includes(document.getElementById("backuparea").value)) {
356 35fa566c Viktor G
				disableInput('backupdata', false);
357
			}
358
		}
359
	});
360
361 eef93144 Jared Dillard
	// ---------- On initial page load ------------------------------------------------------------
362
363 7c0f116b Jared Dillard
	hideSections();
364 ff59b884 Stephen Beaver
	$('.restore').prop('disabled', true);
365 7c0f116b Jared Dillard
});
366
//]]>
367
</script>
368
369
<?php
370 a4af095c Renato Botelho
include("foot.inc");
371 7a7f3af1 sullrich
372 5f601060 Phil Davis
if (is_subsystem_dirty('restore')) {
373 1fe2aa3e Viktor G
	print('<span style="display: none;">');
374 cf9a4467 jim-p
	system_reboot();
375 1fe2aa3e Viktor G
	print('</span>');
376 c9d46a8e Renato Botelho
}