Project

General

Profile

Download (9.91 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_backup.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
 * Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
9
 * 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-backup-restore
30
##|*NAME=Diagnostics: Backup & Restore
31
##|*DESCR=Allow access to the 'Diagnostics: Backup & Restore' page.
32
##|*WARN=standard-warning-root
33
##|*MATCH=diag_backup.php*
34
##|-PRIV
35

    
36
/* Allow additional execution time 0 = no limit. */
37
ini_set('max_execution_time', '0');
38
ini_set('max_input_time', '0');
39

    
40
/* omit no-cache headers because it confuses IE with file downloads */
41
$omit_nocacheheaders = true;
42
require_once("guiconfig.inc");
43
require_once("backup.inc");
44

    
45
$rrddbpath = "/var/db/rrd";
46
$rrdtool = "/usr/bin/nice -n20 /usr/local/bin/rrdtool";
47

    
48
if ($_POST['apply']) {
49
	ob_flush();
50
	flush();
51
	clear_subsystem_dirty("restore");
52
	exit;
53
}
54

    
55
if ($_POST) {
56
	if ($_POST['reinstallpackages']) {
57
		header("Location: pkg_mgr_install.php?mode=reinstallall");
58
		exit;
59
	} else if ($_POST['clearpackagelock']) {
60
		clear_subsystem_dirty('packagelock');
61
		$savemsg = "Package lock cleared.";
62
	} else {
63
		$execpost_return = execPost($_POST, $_FILES);
64
		$input_errors = $execpost_return['input_errors'];
65
		$savemsg = $execpost_return['savemsg'];
66
	}
67

    
68
}
69

    
70
$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
function build_area_list($showall) {
76
	global $config;
77

    
78
	$areas = array(
79
		"aliases" => gettext("Aliases"),
80
		"captiveportal" => gettext("Captive Portal"),
81
		"voucher" => gettext("Captive Portal Vouchers"),
82
		"widgets" => gettext("Dashboard Widgets"),
83
		"dnsmasq" => gettext("DNS Forwarder"),
84
		"unbound" => gettext("DNS Resolver"),
85
		"dhcpd" => gettext("DHCP Server"),
86
		"dhcpdv6" => gettext("DHCPv6 Server"),
87
		"dyndnses" => gettext("Dynamic DNS"),
88
		"filter" => gettext("Firewall Rules"),
89
		"interfaces" => gettext("Interfaces"),
90
		"ipsec" => gettext("IPSEC"),
91
		"dnshaper" => gettext("Limiters"),
92
		"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
		"wol" => gettext("Wake-on-LAN")
105
		);
106

    
107
	$list = array("" => gettext("All"));
108

    
109
	if ($showall) {
110
		return($list + $areas);
111
	} else {
112
		foreach ($areas as $area => $areaname) {
113
			if ($area === "rrddata" || check_and_returnif_section_exists($area) == true) {
114
				$list[$area] = $areaname;
115
			}
116
		}
117

    
118
		return($list);
119
	}
120
}
121

    
122
$pgtitle = array(gettext("Diagnostics"), htmlspecialchars(gettext("Backup & Restore")), htmlspecialchars(gettext("Backup & Restore")));
123
$pglinks = array("", "@self", "@self");
124
include("head.inc");
125

    
126
if ($input_errors) {
127
	print_input_errors($input_errors);
128
}
129

    
130
if ($savemsg) {
131
	print_info_box($savemsg, 'success');
132
}
133

    
134
if (is_subsystem_dirty('restore')):
135
?>
136
	<br/>
137
	<form action="diag_reboot.php" method="post">
138
		<input name="Submit" type="hidden" value="Yes" />
139
		<?php print_info_box(gettext("The firewall configuration has been changed.") . "<br />" . gettext("The firewall is now rebooting.")); ?>
140
		<br />
141
	</form>
142
<?php
143
endif;
144

    
145
$tab_array = array();
146
$tab_array[] = array(htmlspecialchars(gettext("Backup & Restore")), true, "diag_backup.php");
147
$tab_array[] = array(gettext("Config History"), false, "diag_confbak.php");
148
display_top_tabs($tab_array);
149

    
150
$form = new Form(false);
151
$form->setMultipartEncoding();	// Allow file uploads
152

    
153
$section = new Form_Section('Backup Configuration');
154

    
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
$section->addInput(new Form_Checkbox(
177
	'backupdata',
178
	'Include extra data',
179
	'Backup extra data.',
180
	false
181
))->setHelp('Backup extra data files for some services.%1$s' .
182
	    '%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
	    '<div class="infoblock">', '<ul>', '<li>', '</li>', '</ul></div>'
187
);
188

    
189
$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
$section->addInput(new Form_Checkbox(
197
	'encrypt',
198
	'Encryption',
199
	'Encrypt this configuration file.',
200
	false
201
));
202

    
203
$section->addPassword(new Form_Input(
204
	'encrypt_password',
205
	'Password',
206
	'password',
207
	null
208
));
209

    
210
$group = new Form_Group('');
211
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
212
$group->add(new Form_Button(
213
	'download',
214
	'Download configuration as XML',
215
	null,
216
	'fa-download'
217
))->setAttribute('id')->addClass('btn-primary');
218

    
219
$section->add($group);
220
$form->add($section);
221

    
222
$section = new Form_Section('Restore Backup');
223

    
224
$section->addInput(new Form_StaticText(
225
	null,
226
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), g_get('product_label'))
227
));
228

    
229
$section->addInput(new Form_Select(
230
	'restorearea',
231
	'Restore area',
232
	'',
233
	build_area_list(true)
234
));
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
	'decrypt',
245
	'Encryption',
246
	'Configuration file is encrypted.',
247
	false
248
));
249

    
250
$section->addInput(new Form_Input(
251
	'decrypt_password',
252
	'Password',
253
	'password',
254
	null,
255
	['placeholder' => 'Password']
256
));
257

    
258
$group = new Form_Group('');
259
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
260
$group->add(new Form_Button(
261
	'restore',
262
	'Restore Configuration',
263
	null,
264
	'fa-undo'
265
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
266

    
267
$section->add($group);
268

    
269
$form->add($section);
270

    
271
$has_installed_packages = !empty(config_get_path('installedpackages/package', []));
272

    
273
if ($has_installed_packages || (is_subsystem_dirty("packagelock"))) {
274
	$section = new Form_Section('Package Functions');
275

    
276
	if ($has_installed_packages) {
277
		$group = new Form_Group('');
278
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
279
		$group->add(new Form_Button(
280
			'reinstallpackages',
281
			'Reinstall Packages',
282
			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

    
286
		$section->add($group);
287
	}
288

    
289
	if (is_subsystem_dirty("packagelock")) {
290
		$group = new Form_Group('');
291
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
292
		$group->add(new Form_Button(
293
			'clearpackagelock',
294
			'Clear Package Lock',
295
			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

    
299
		$section->add($group);
300
	}
301

    
302
	$form->add($section);
303
}
304

    
305
print($form);
306
?>
307
<script type="text/javascript">
308
//<![CDATA[
309
events.push(function() {
310

    
311
	// ------- Show/hide sections based on checkbox settings --------------------------------------
312

    
313
	function hideSections(hide) {
314
		hidePasswords();
315
	}
316

    
317
	function hidePasswords() {
318

    
319
		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
	// ---------- Click handlers ------------------------------------------------------------------
327

    
328
	$('input[name="encrypt"]').on('change', function() {
329
		hidePasswords();
330
	});
331

    
332
	$('input[name="decrypt"]').on('change', function() {
333
		hidePasswords();
334
	});
335

    
336
	$('#conffile').change(function () {
337
		if (document.getElementById("conffile").value) {
338
			$('.restore').prop('disabled', false);
339
		} else {
340
			$('.restore').prop('disabled', true);
341
		}
342
	});
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
			disableInput('backupssh', false);
350
		} else {
351
			disableInput('donotbackuprrd', true);
352
			disableInput('nopackages', true);
353
			disableInput('backupdata', true);
354
			disableInput('backupssh', true);
355
			if (['captiveportal', 'dhcpd', 'dhcpdv6', 'voucher'].includes(document.getElementById("backuparea").value)) {
356
				disableInput('backupdata', false);
357
			}
358
		}
359
	});
360

    
361
	// ---------- On initial page load ------------------------------------------------------------
362

    
363
	hideSections();
364
	$('.restore').prop('disabled', true);
365
});
366
//]]>
367
</script>
368

    
369
<?php
370
include("foot.inc");
371

    
372
if (is_subsystem_dirty('restore')) {
373
	print('<span style="display: none;">');
374
	system_reboot();
375
	print('</span>');
376
}
(9-9/228)