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
|
'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
|
$section->addInput(new Form_Checkbox(
|
196
|
'encrypt',
|
197
|
'Encryption',
|
198
|
'Encrypt this configuration file.',
|
199
|
false
|
200
|
));
|
201
|
|
202
|
$section->addPassword(new Form_Input(
|
203
|
'encrypt_password',
|
204
|
'Password',
|
205
|
'password',
|
206
|
null
|
207
|
));
|
208
|
|
209
|
$group = new Form_Group('');
|
210
|
// Note: ID attribute of each element created is to be unique. Not being used, suppressing it.
|
211
|
$group->add(new Form_Button(
|
212
|
'download',
|
213
|
'Download configuration as XML',
|
214
|
null,
|
215
|
'fa-download'
|
216
|
))->setAttribute('id')->addClass('btn-primary');
|
217
|
|
218
|
$section->add($group);
|
219
|
$form->add($section);
|
220
|
|
221
|
$section = new Form_Section('Restore Backup');
|
222
|
|
223
|
$section->addInput(new Form_StaticText(
|
224
|
null,
|
225
|
sprintf(gettext("Open a %s configuration XML file and click the button below to restore the configuration."), $g['product_label'])
|
226
|
));
|
227
|
|
228
|
$section->addInput(new Form_Select(
|
229
|
'restorearea',
|
230
|
'Restore area',
|
231
|
'',
|
232
|
build_area_list(true)
|
233
|
));
|
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
|
'decrypt',
|
244
|
'Encryption',
|
245
|
'Configuration file is encrypted.',
|
246
|
false
|
247
|
));
|
248
|
|
249
|
$section->addInput(new Form_Input(
|
250
|
'decrypt_password',
|
251
|
'Password',
|
252
|
'password',
|
253
|
null,
|
254
|
['placeholder' => 'Password']
|
255
|
));
|
256
|
|
257
|
$group = new Form_Group('');
|
258
|
// Note: ID attribute of each element created is to be unique. Not being used, suppressing it.
|
259
|
$group->add(new Form_Button(
|
260
|
'restore',
|
261
|
'Restore Configuration',
|
262
|
null,
|
263
|
'fa-undo'
|
264
|
))->setHelp('The firewall will reboot after restoring the configuration.')->addClass('btn-danger restore')->setAttribute('id');
|
265
|
|
266
|
$section->add($group);
|
267
|
|
268
|
$form->add($section);
|
269
|
|
270
|
if (($config['installedpackages']['package'] != "") || (is_subsystem_dirty("packagelock"))) {
|
271
|
$section = new Form_Section('Package Functions');
|
272
|
|
273
|
if ($config['installedpackages']['package'] != "") {
|
274
|
$group = new Form_Group('');
|
275
|
// Note: ID attribute of each element created is to be unique. Not being used, suppressing it.
|
276
|
$group->add(new Form_Button(
|
277
|
'reinstallpackages',
|
278
|
'Reinstall Packages',
|
279
|
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
|
|
283
|
$section->add($group);
|
284
|
}
|
285
|
|
286
|
if (is_subsystem_dirty("packagelock")) {
|
287
|
$group = new Form_Group('');
|
288
|
// Note: ID attribute of each element created is to be unique. Not being used, suppressing it.
|
289
|
$group->add(new Form_Button(
|
290
|
'clearpackagelock',
|
291
|
'Clear Package Lock',
|
292
|
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
|
|
296
|
$section->add($group);
|
297
|
}
|
298
|
|
299
|
$form->add($section);
|
300
|
}
|
301
|
|
302
|
print($form);
|
303
|
?>
|
304
|
<script type="text/javascript">
|
305
|
//<![CDATA[
|
306
|
events.push(function() {
|
307
|
|
308
|
// ------- Show/hide sections based on checkbox settings --------------------------------------
|
309
|
|
310
|
function hideSections(hide) {
|
311
|
hidePasswords();
|
312
|
}
|
313
|
|
314
|
function hidePasswords() {
|
315
|
|
316
|
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
|
// ---------- Click handlers ------------------------------------------------------------------
|
324
|
|
325
|
$('input[name="encrypt"]').on('change', function() {
|
326
|
hidePasswords();
|
327
|
});
|
328
|
|
329
|
$('input[name="decrypt"]').on('change', function() {
|
330
|
hidePasswords();
|
331
|
});
|
332
|
|
333
|
$('#conffile').change(function () {
|
334
|
if (document.getElementById("conffile").value) {
|
335
|
$('.restore').prop('disabled', false);
|
336
|
} else {
|
337
|
$('.restore').prop('disabled', true);
|
338
|
}
|
339
|
});
|
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
|
disableInput('backupssh', false);
|
347
|
} else {
|
348
|
disableInput('donotbackuprrd', true);
|
349
|
disableInput('nopackages', true);
|
350
|
disableInput('backupdata', true);
|
351
|
disableInput('backupssh', true);
|
352
|
if (['captiveportal', 'dhcpd', 'dhcpdv6', 'voucher'].includes(document.getElementById("backuparea").value)) {
|
353
|
disableInput('backupdata', false);
|
354
|
}
|
355
|
}
|
356
|
});
|
357
|
|
358
|
// ---------- On initial page load ------------------------------------------------------------
|
359
|
|
360
|
hideSections();
|
361
|
$('.restore').prop('disabled', true);
|
362
|
});
|
363
|
//]]>
|
364
|
</script>
|
365
|
|
366
|
<?php
|
367
|
include("foot.inc");
|
368
|
|
369
|
if (is_subsystem_dirty('restore')) {
|
370
|
print('<span style="display: none;">');
|
371
|
system_reboot();
|
372
|
print('</span>');
|
373
|
}
|