Project

General

Profile

Download (9.53 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-2021 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
		"dnsmasq" => gettext("DNS Forwarder"),
83
		"unbound" => gettext("DNS Resolver"),
84
		"dhcpd" => gettext("DHCP Server"),
85
		"dhcpdv6" => gettext("DHCPv6 Server"),
86
		"dyndnses" => gettext("Dynamic DNS"),
87
		"filter" => gettext("Firewall Rules"),
88
		"interfaces" => gettext("Interfaces"),
89
		"ipsec" => gettext("IPSEC"),
90
		"dnshaper" => gettext("Limiters"),
91
		"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
		"wol" => gettext("Wake-on-LAN")
104
		);
105

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

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

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

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

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

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

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

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

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

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

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

    
188
$section->addInput(new Form_Checkbox(
189
	'encrypt',
190
	'Encryption',
191
	'Encrypt this configuration file.',
192
	false
193
));
194

    
195
$section->addPassword(new Form_Input(
196
	'encrypt_password',
197
	'Password',
198
	'password',
199
	null
200
));
201

    
202
$group = new Form_Group('');
203
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
204
$group->add(new Form_Button(
205
	'download',
206
	'Download configuration as XML',
207
	null,
208
	'fa-download'
209
))->setAttribute('id')->addClass('btn-primary');
210

    
211
$section->add($group);
212
$form->add($section);
213

    
214
$section = new Form_Section('Restore Backup');
215

    
216
$section->addInput(new Form_StaticText(
217
	null,
218
	sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_label'])
219
));
220

    
221
$section->addInput(new Form_Select(
222
	'restorearea',
223
	'Restore area',
224
	'',
225
	build_area_list(true)
226
));
227

    
228
$section->addInput(new Form_Input(
229
	'conffile',
230
	'Configuration file',
231
	'file',
232
	null
233
));
234

    
235
$section->addInput(new Form_Checkbox(
236
	'decrypt',
237
	'Encryption',
238
	'Configuration file is encrypted.',
239
	false
240
));
241

    
242
$section->addInput(new Form_Input(
243
	'decrypt_password',
244
	'Password',
245
	'password',
246
	null,
247
	['placeholder' => 'Password']
248
));
249

    
250
$group = new Form_Group('');
251
// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
252
$group->add(new Form_Button(
253
	'restore',
254
	'Restore Configuration',
255
	null,
256
	'fa-undo'
257
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
258

    
259
$section->add($group);
260

    
261
$form->add($section);
262

    
263
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
264
	$section = new Form_Section('Package Functions');
265

    
266
	if ($config['installedpackages']['package'] != "") {
267
		$group = new Form_Group('');
268
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
269
		$group->add(new Form_Button(
270
			'reinstallpackages',
271
			'Reinstall Packages',
272
			null,
273
			'fa-retweet'
274
		))->setHelp('Click this button to reinstall all system packages.  This may take a while.')->addClass('btn-success')->setAttribute('id');
275

    
276
		$section->add($group);
277
	}
278

    
279
	if (is_subsystem_dirty("packagelock")) {
280
		$group = new Form_Group('');
281
		// Note: ID attribute of each element created is to be unique.  Not being used, suppressing it.
282
		$group->add(new Form_Button(
283
			'clearpackagelock',
284
			'Clear Package Lock',
285
			null,
286
			'fa-wrench'
287
		))->setHelp('Click this button to clear the package lock if a package fails to reinstall properly after an upgrade.')->addClass('btn-warning')->setAttribute('id');
288

    
289
		$section->add($group);
290
	}
291

    
292
	$form->add($section);
293
}
294

    
295
print($form);
296
?>
297
<script type="text/javascript">
298
//<![CDATA[
299
events.push(function() {
300

    
301
	// ------- Show/hide sections based on checkbox settings --------------------------------------
302

    
303
	function hideSections(hide) {
304
		hidePasswords();
305
	}
306

    
307
	function hidePasswords() {
308

    
309
		encryptHide = !($('input[name="encrypt"]').is(':checked'));
310
		decryptHide = !($('input[name="decrypt"]').is(':checked'));
311

    
312
		hideInput('encrypt_password', encryptHide);
313
		hideInput('decrypt_password', decryptHide);
314
	}
315

    
316
	// ---------- Click handlers ------------------------------------------------------------------
317

    
318
	$('input[name="encrypt"]').on('change', function() {
319
		hidePasswords();
320
	});
321

    
322
	$('input[name="decrypt"]').on('change', function() {
323
		hidePasswords();
324
	});
325

    
326
	$('#conffile').change(function () {
327
		if (document.getElementById("conffile").value) {
328
			$('.restore').prop('disabled', false);
329
		} else {
330
			$('.restore').prop('disabled', true);
331
		}
332
	});
333

    
334
	$('#backuparea').change(function () {
335
		if (document.getElementById("backuparea").value == 0) {
336
			disableInput('donotbackuprrd', false);
337
			disableInput('nopackages', false);
338
			disableInput('backupdata', false);
339
		} else {
340
			disableInput('donotbackuprrd', true);
341
			disableInput('nopackages', true);
342
			disableInput('backupdata', true);
343
			if (['captiveportal', 'dhcpd', 'dhcpdv6', 'voucher'].includes(document.getElementById("backuparea").value)) {
344
				disableInput('backupdata', false);
345
			}
346
		}
347
	});
348

    
349
	// ---------- On initial page load ------------------------------------------------------------
350

    
351
	hideSections();
352
	$('.restore').prop('disabled', true);
353
});
354
//]]>
355
</script>
356

    
357
<?php
358
include("foot.inc");
359

    
360
if (is_subsystem_dirty('restore')) {
361
	system_reboot();
362
}
(9-9/229)