1 |
054f0ed0
|
Steve Beaver
|
<?php
|
2 |
|
|
/*
|
3 |
587315d5
|
Steve Beaver
|
* services_acb.php
|
4 |
054f0ed0
|
Steve Beaver
|
*
|
5 |
|
|
* part of pfSense (https://www.pfsense.org)
|
6 |
|
|
* Copyright (c) 2008-2015 Rubicon Communications, LLC (Netgate)
|
7 |
|
|
* All rights reserved.
|
8 |
|
|
*
|
9 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
10 |
|
|
* you may not use this file except in compliance with the License.
|
11 |
|
|
* You may obtain a copy of the License at
|
12 |
|
|
*
|
13 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
14 |
|
|
*
|
15 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
16 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
17 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
18 |
|
|
* See the License for the specific language governing permissions and
|
19 |
|
|
* limitations under the License.
|
20 |
|
|
*/
|
21 |
18c1de41
|
jim-p
|
|
22 |
|
|
##|+PRIV
|
23 |
|
|
##|*IDENT=page-services-acb
|
24 |
|
|
##|*NAME=Services: Auto Config Backup: Restore
|
25 |
|
|
##|*DESCR=Restore from auto config backup.
|
26 |
|
|
##|*MATCH=services_acb.php*
|
27 |
|
|
##|-PRIV
|
28 |
|
|
|
29 |
054f0ed0
|
Steve Beaver
|
require("guiconfig.inc");
|
30 |
|
|
require("acb.inc");
|
31 |
|
|
|
32 |
|
|
// Separator used during client / server communications
|
33 |
|
|
$oper_sep = "\|\|";
|
34 |
|
|
$exp_sep = '||';
|
35 |
|
|
|
36 |
720ebd09
|
Steve Beaver
|
// $legacy is used to determine whether to work with the old "Gold" ACB system, or the
|
37 |
|
|
// current system
|
38 |
|
|
$legacy = false;
|
39 |
d33560e8
|
Steve Beaver
|
|
40 |
720ebd09
|
Steve Beaver
|
if (isset($_REQUEST['legacy'])) {
|
41 |
|
|
$legacy = true;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
054f0ed0
|
Steve Beaver
|
// Encryption password
|
45 |
720ebd09
|
Steve Beaver
|
if (!$legacy) {
|
46 |
|
|
$decrypt_password = $config['system']['acb']['encryption_password'];
|
47 |
|
|
} else {
|
48 |
|
|
$decrypt_password = $config['system']['acb']['gold_encryption_password'];
|
49 |
|
|
}
|
50 |
054f0ed0
|
Steve Beaver
|
|
51 |
|
|
// Defined username. Username must be sent lowercase. See Redmine #7127 and Netgate Redmine #163
|
52 |
|
|
$username = strtolower($config['system']['acb']['gold_username']);
|
53 |
720ebd09
|
Steve Beaver
|
$password = $config['system']['acb']['gold_password'];
|
54 |
054f0ed0
|
Steve Beaver
|
|
55 |
|
|
// URL to restore.php
|
56 |
|
|
$get_url = "https://portal.pfsense.org/pfSconfigbackups/restore.php";
|
57 |
|
|
|
58 |
|
|
// URL to stats
|
59 |
|
|
$stats_url = "https://portal.pfsense.org/pfSconfigbackups/showstats.php";
|
60 |
|
|
|
61 |
|
|
// URL to delete.php
|
62 |
|
|
$del_url = "https://portal.pfsense.org/pfSconfigbackups/delete.php";
|
63 |
|
|
|
64 |
|
|
// Set hostname
|
65 |
|
|
if ($_REQUEST['hostname']) {
|
66 |
|
|
$hostname = $_REQUEST['hostname'];
|
67 |
|
|
} else {
|
68 |
|
|
$hostname = $config['system']['hostname'] . "." . $config['system']['domain'];
|
69 |
|
|
}
|
70 |
|
|
|
71 |
|
|
// Hostname of local machine
|
72 |
|
|
$myhostname = $config['system']['hostname'] . "." . $config['system']['domain'];
|
73 |
|
|
|
74 |
|
|
if (!$decrypt_password) {
|
75 |
af0edce6
|
Steve Beaver
|
Header("Location: /services_acb_settings.php");
|
76 |
054f0ed0
|
Steve Beaver
|
exit;
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
if ($_REQUEST['savemsg']) {
|
80 |
|
|
$savemsg = htmlentities($_REQUEST['savemsg']);
|
81 |
|
|
}
|
82 |
|
|
|
83 |
|
|
if ($_REQUEST['download']) {
|
84 |
|
|
$pgtitle = array("Services", "Auto Configuration Backup", "Revision Information");
|
85 |
|
|
} else {
|
86 |
|
|
$pgtitle = array("Services", "Auto Configuration Backup", "Restore");
|
87 |
|
|
}
|
88 |
|
|
|
89 |
|
|
/* Set up time zones for conversion. See #5250 */
|
90 |
|
|
$acbtz = new DateTimeZone('America/Chicago');
|
91 |
|
|
$mytz = new DateTimeZone(date_default_timezone_get());
|
92 |
|
|
|
93 |
|
|
include("head.inc");
|
94 |
|
|
|
95 |
|
|
function get_hostnames() {
|
96 |
|
|
global $stats_url, $username, $password, $oper_sep, $config, $g, $exp_sep;
|
97 |
|
|
// Populate available backups
|
98 |
|
|
$curl_session = curl_init();
|
99 |
|
|
curl_setopt($curl_session, CURLOPT_URL, $stats_url);
|
100 |
|
|
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}")));
|
101 |
|
|
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 1);
|
102 |
|
|
curl_setopt($curl_session, CURLOPT_POST, 1);
|
103 |
|
|
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
|
104 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=showstats");
|
105 |
|
|
curl_setopt($curl_session, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version")));
|
106 |
|
|
// Proxy
|
107 |
|
|
curl_setopt_array($curl_session, configure_proxy());
|
108 |
|
|
|
109 |
|
|
$data = curl_exec($curl_session);
|
110 |
|
|
if (curl_errno($curl_session)) {
|
111 |
|
|
$fd = fopen("/tmp/acb_statsdebug.txt", "w");
|
112 |
|
|
fwrite($fd, $stats_url . "" . "action=showstats" . "\n\n");
|
113 |
|
|
fwrite($fd, $data);
|
114 |
|
|
fwrite($fd, curl_error($curl_session));
|
115 |
|
|
fclose($fd);
|
116 |
|
|
} else {
|
117 |
|
|
curl_close($curl_session);
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
// Loop through and create new confvers
|
121 |
|
|
$data_split = explode("\n", $data);
|
122 |
|
|
$statvers = array();
|
123 |
|
|
foreach ($data_split as $ds) {
|
124 |
|
|
$ds_split = explode($exp_sep, $ds);
|
125 |
|
|
if ($ds_split[0]) {
|
126 |
|
|
$statvers[] = $ds_split[0];
|
127 |
|
|
}
|
128 |
|
|
}
|
129 |
|
|
return $statvers;
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
if ($_REQUEST['rmver'] != "") {
|
133 |
|
|
$curl_session = curl_init();
|
134 |
|
|
if ($legacy) {
|
135 |
|
|
curl_setopt($curl_session, CURLOPT_URL, $del_url);
|
136 |
|
|
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}")));
|
137 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=delete" . "&hostname=" . urlencode($hostname) . "&revision=" . urlencode($_REQUEST['rmver']));
|
138 |
|
|
} else {
|
139 |
|
|
curl_setopt($curl_session, CURLOPT_URL, "https://acb.netgate.com/rmbkp");
|
140 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "userkey=" . $userkey .
|
141 |
|
|
"&revision=" . urlencode($_REQUEST['rmver']) .
|
142 |
|
|
"&version=" . $g['product_version'] .
|
143 |
|
|
"&uid=" . urlencode($uniqueID));
|
144 |
|
|
}
|
145 |
|
|
|
146 |
|
|
curl_setopt($curl_session, CURLOPT_POST, 3);
|
147 |
|
|
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 1);
|
148 |
|
|
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
|
149 |
|
|
curl_setopt($curl_session, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version")));
|
150 |
|
|
// Proxy
|
151 |
|
|
curl_setopt_array($curl_session, configure_proxy());
|
152 |
|
|
|
153 |
|
|
$data = curl_exec($curl_session);
|
154 |
|
|
if (curl_errno($curl_session)) {
|
155 |
|
|
$fd = fopen("/tmp/acb_deletedebug.txt", "w");
|
156 |
|
|
fwrite($fd, $get_url . "" . "action=delete&hostname=" . urlencode($hostname) . "&revision=" . urlencode($_REQUEST['rmver']) . "\n\n");
|
157 |
|
|
fwrite($fd, $data);
|
158 |
|
|
fwrite($fd, curl_error($curl_session));
|
159 |
|
|
fclose($fd);
|
160 |
|
|
$savemsg = "An error occurred while trying to remove the item from portal.pfsense.org.";
|
161 |
|
|
} else {
|
162 |
|
|
curl_close($curl_session);
|
163 |
|
|
$budate = new DateTime($_REQUEST['rmver'], $acbtz);
|
164 |
|
|
$budate->setTimezone($mytz);
|
165 |
|
|
$savemsg = "Backup revision " . htmlspecialchars($budate->format(DATE_RFC2822)) . " has been removed.";
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
if ($_REQUEST['newver'] != "") {
|
170 |
|
|
// Phone home and obtain backups
|
171 |
|
|
$curl_session = curl_init();
|
172 |
|
|
if ($legacy) {
|
173 |
|
|
curl_setopt($curl_session, CURLOPT_URL, $get_url);
|
174 |
|
|
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}")));
|
175 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=restore" . "&hostname=" . urlencode($hostname) . "&revision=" . urlencode($_REQUEST['newver']));
|
176 |
|
|
} else {
|
177 |
|
|
curl_setopt($curl_session, CURLOPT_URL, "https://acb.netgate.com/getbkp");
|
178 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "userkey=" . $userkey .
|
179 |
|
|
"&revision=" . urlencode($_REQUEST['newver']) .
|
180 |
|
|
"&version=" . $g['product_version'] .
|
181 |
|
|
"&uid=" . urlencode($uniqueID));
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
curl_setopt($curl_session, CURLOPT_POST, 3);
|
185 |
|
|
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 1);
|
186 |
|
|
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
|
187 |
|
|
curl_setopt($curl_session, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version")));
|
188 |
|
|
// Proxy
|
189 |
|
|
curl_setopt_array($curl_session, configure_proxy());
|
190 |
|
|
$data = curl_exec($curl_session);
|
191 |
|
|
$data_split = explode('++++', $data);
|
192 |
|
|
$sha256 = trim($data_split[0]);
|
193 |
|
|
$data = $data_split[1];
|
194 |
|
|
|
195 |
|
|
if (!tagfile_deformat($data, $data, "config.xml")) {
|
196 |
|
|
$input_errors[] = "The downloaded file does not appear to contain an encrypted pfSense configuration.";
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
$out = decrypt_data($data, $decrypt_password);
|
200 |
|
|
|
201 |
|
|
$pos = stripos($out, "</pfsense>");
|
202 |
|
|
$data = substr($out, 0, $pos);
|
203 |
|
|
$data = $data . "</pfsense>\n";
|
204 |
|
|
|
205 |
|
|
$fd = fopen("/tmp/config_restore.xml", "w");
|
206 |
|
|
fwrite($fd, $data);
|
207 |
|
|
fclose($fd);
|
208 |
|
|
|
209 |
|
|
if (strlen($data) < 50) {
|
210 |
|
|
$input_errors[] = "The decrypted config.xml is under 50 characters, something went wrong. Aborting.";
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
$ondisksha256 = trim(shell_exec("/sbin/sha256 /tmp/config_restore.xml | /usr/bin/awk '{ print $4 }'"));
|
214 |
|
|
// We might not have a sha256 on file for older backups
|
215 |
|
|
if ($sha256 != "0" && $sha256 != "") {
|
216 |
|
|
if ($ondisksha256 != $sha256) {
|
217 |
|
|
$input_errors[] = "SHA256 values do not match, cannot restore. $ondisksha256 != $sha256";
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
if (curl_errno($curl_session)) {
|
221 |
|
|
/* If an error occured, log the error in /tmp/ */
|
222 |
|
|
$fd = fopen("/tmp/acb_restoredebug.txt", "w");
|
223 |
|
|
fwrite($fd, $get_url . "" . "action=restore&hostname={$hostname}&revision=" . urlencode($_REQUEST['newver']) . "\n\n");
|
224 |
|
|
fwrite($fd, $data);
|
225 |
|
|
fwrite($fd, curl_error($curl_session));
|
226 |
|
|
fclose($fd);
|
227 |
|
|
} else {
|
228 |
|
|
curl_close($curl_session);
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
if (!$input_errors && $data) {
|
232 |
|
|
if (config_restore("/tmp/config_restore.xml") == 0) {
|
233 |
|
|
$savemsg = "Successfully reverted the pfSense configuration to revision " . urldecode($_REQUEST['newver']) . ".";
|
234 |
|
|
$savemsg .= <<<EOF
|
235 |
|
|
<br />
|
236 |
|
|
<form action="diag_reboot.php" method="post">
|
237 |
|
|
Reboot the firewall to full activate changes?
|
238 |
|
|
<input name="override" type="hidden" value="yes" />
|
239 |
|
|
<input name="Submit" type="submit" class="formbtn" value=" Yes " />
|
240 |
|
|
</form>
|
241 |
|
|
EOF;
|
242 |
|
|
} else {
|
243 |
|
|
$savemsg = "Unable to revert to the selected configuration.";
|
244 |
|
|
}
|
245 |
|
|
} else {
|
246 |
|
|
log_error("There was an error when restoring the AutoConfigBackup item");
|
247 |
|
|
}
|
248 |
|
|
unlink_if_exists("/tmp/config_restore.xml");
|
249 |
|
|
}
|
250 |
|
|
|
251 |
|
|
if ($_REQUEST['download']) {
|
252 |
|
|
// Phone home and obtain backups
|
253 |
|
|
$curl_session = curl_init();
|
254 |
|
|
|
255 |
|
|
if ($legacy) {
|
256 |
720ebd09
|
Steve Beaver
|
|
257 |
054f0ed0
|
Steve Beaver
|
curl_setopt($curl_session, CURLOPT_URL, $get_url);
|
258 |
|
|
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}")));
|
259 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=restore" .
|
260 |
|
|
"&hostname=" . urlencode($hostname) .
|
261 |
|
|
"&revision=" . urlencode($_REQUEST['download']) .
|
262 |
|
|
"&version=" . $g['product_version'] .
|
263 |
|
|
"&uid=" . urlencode($uniqueID));
|
264 |
|
|
} else {
|
265 |
|
|
curl_setopt($curl_session, CURLOPT_URL, "https://acb.netgate.com/getbkp");
|
266 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "userkey=" . $userkey . "&revision=" . urlencode($_REQUEST['download']));
|
267 |
|
|
}
|
268 |
|
|
|
269 |
|
|
curl_setopt($curl_session, CURLOPT_POST, 3);
|
270 |
|
|
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 1);
|
271 |
|
|
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
|
272 |
|
|
|
273 |
|
|
curl_setopt($curl_session, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version")));
|
274 |
|
|
// Proxy
|
275 |
|
|
curl_setopt_array($curl_session, configure_proxy());
|
276 |
|
|
$data = curl_exec($curl_session);
|
277 |
|
|
|
278 |
|
|
if (!tagfile_deformat($data, $data1, "config.xml")) {
|
279 |
|
|
if ($legacy) {
|
280 |
|
|
$input_errors[] = "The downloaded file does not appear to contain an encrypted pfSense configuration.";
|
281 |
|
|
} else {
|
282 |
|
|
$input_errors[] = "The downloaded file does not appear to contain an encrypted pfSense configuration.";
|
283 |
|
|
}
|
284 |
|
|
} else {
|
285 |
|
|
$ds = explode('++++', $data);
|
286 |
|
|
$revision = $_REQUEST['download'];
|
287 |
|
|
$sha256sum = $ds[0];
|
288 |
|
|
if ($sha256sum == "0") {
|
289 |
|
|
$sha256sum = "None on file.";
|
290 |
|
|
}
|
291 |
|
|
$data = $ds[1];
|
292 |
|
|
$configtype = "Encrypted";
|
293 |
|
|
if (!tagfile_deformat($data, $data, "config.xml")) {
|
294 |
|
|
$input_errors[] = "The downloaded file does not appear to contain an encrypted pfSense configuration.";
|
295 |
|
|
}
|
296 |
|
|
$data = decrypt_data($data, $decrypt_password);
|
297 |
|
|
if (!strstr($data, "pfsense")) {
|
298 |
|
|
$data = "Could not decrypt. Different encryption key?";
|
299 |
|
|
$input_errors[] = "Could not decrypt config.xml";
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
// $confvers must be populated viewing info but there were errors
|
305 |
|
|
if ( !($_REQUEST['download']) || $input_errors) {
|
306 |
|
|
// Populate available backups
|
307 |
|
|
$curl_session = curl_init();
|
308 |
|
|
|
309 |
|
|
if ($legacy) {
|
310 |
|
|
curl_setopt($curl_session, CURLOPT_URL, $get_url);
|
311 |
|
|
curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}")));
|
312 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=showbackups&hostname={$hostname}");
|
313 |
|
|
} else {
|
314 |
|
|
curl_setopt($curl_session, CURLOPT_URL, "https://acb.netgate.com/list");
|
315 |
|
|
curl_setopt($curl_session, CURLOPT_POSTFIELDS, "userkey=" . $userkey .
|
316 |
|
|
"&uid=eb6a4e6f76c10734b636" .
|
317 |
|
|
"&version=" . $g['product_version'] .
|
318 |
|
|
"&uid=" . urlencode($uniqueID));
|
319 |
|
|
}
|
320 |
|
|
|
321 |
|
|
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 1);
|
322 |
|
|
curl_setopt($curl_session, CURLOPT_POST, 1);
|
323 |
|
|
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1);
|
324 |
|
|
|
325 |
|
|
curl_setopt($curl_session, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version")));
|
326 |
|
|
// Proxy
|
327 |
|
|
curl_setopt_array($curl_session, configure_proxy());
|
328 |
|
|
|
329 |
|
|
$data = curl_exec($curl_session);
|
330 |
|
|
|
331 |
af0edce6
|
Steve Beaver
|
if (curl_errno($curl_session)) {
|
332 |
054f0ed0
|
Steve Beaver
|
$fd = fopen("/tmp/acb_backupdebug.txt", "w");
|
333 |
|
|
fwrite($fd, $get_url . "" . "action=showbackups" . "\n\n");
|
334 |
|
|
fwrite($fd, $data);
|
335 |
|
|
fwrite($fd, curl_error($curl_session));
|
336 |
|
|
fclose($fd);
|
337 |
|
|
} else {
|
338 |
|
|
curl_close($curl_session);
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
// Loop through and create new confvers
|
342 |
|
|
$data_split = explode("\n", $data);
|
343 |
|
|
|
344 |
|
|
$confvers = array();
|
345 |
|
|
|
346 |
|
|
foreach ($data_split as $ds) {
|
347 |
|
|
$ds_split = explode($exp_sep, $ds);
|
348 |
|
|
$tmp_array = array();
|
349 |
|
|
$tmp_array['username'] = $ds_split[0];
|
350 |
|
|
$tmp_array['reason'] = $ds_split[1];
|
351 |
|
|
$tmp_array['time'] = $ds_split[2];
|
352 |
|
|
|
353 |
|
|
/* Convert the time from server time to local. See #5250 */
|
354 |
|
|
$budate = new DateTime($tmp_array['time'], $acbtz);
|
355 |
|
|
$budate->setTimezone($mytz);
|
356 |
|
|
$tmp_array['localtime'] = $budate->format(DATE_RFC2822);
|
357 |
|
|
|
358 |
|
|
if ($ds_split[2] && $ds_split[0]) {
|
359 |
|
|
$confvers[] = $tmp_array;
|
360 |
|
|
}
|
361 |
|
|
}
|
362 |
|
|
}
|
363 |
|
|
|
364 |
|
|
if ($input_errors) {
|
365 |
|
|
print_input_errors($input_errors);
|
366 |
|
|
}
|
367 |
|
|
if ($savemsg) {
|
368 |
|
|
print_info_box($savemsg, 'success');
|
369 |
|
|
}
|
370 |
|
|
|
371 |
|
|
$tab_array = array();
|
372 |
587315d5
|
Steve Beaver
|
$tab_array[0] = array("Settings", false, "/services_acb_settings.php");
|
373 |
054f0ed0
|
Steve Beaver
|
if ($_REQUEST['download']) {
|
374 |
|
|
$active = false;
|
375 |
|
|
} else {
|
376 |
|
|
$active = true;
|
377 |
|
|
}
|
378 |
|
|
|
379 |
587315d5
|
Steve Beaver
|
$tab_array[1] = array("Restore", $active, "/services_acb.php");
|
380 |
|
|
|
381 |
054f0ed0
|
Steve Beaver
|
if ($_REQUEST['download']) {
|
382 |
ce77c104
|
jim-p
|
$tab_array[] = array("Revision", true, "/services_acb.php?download=" . htmlspecialchars($_REQUEST['download']));
|
383 |
054f0ed0
|
Steve Beaver
|
}
|
384 |
587315d5
|
Steve Beaver
|
|
385 |
|
|
$tab_array[] = array("Backup now", false, "/services_acb_backup.php");
|
386 |
054f0ed0
|
Steve Beaver
|
|
387 |
|
|
display_top_tabs($tab_array);
|
388 |
|
|
|
389 |
|
|
$hostnames = get_hostnames();
|
390 |
|
|
?>
|
391 |
|
|
|
392 |
|
|
<div id="loading">
|
393 |
|
|
<i class="fa fa-spinner fa-spin"></i> Loading, please wait...
|
394 |
|
|
</div>
|
395 |
|
|
|
396 |
|
|
|
397 |
|
|
<?php if ($_REQUEST['download'] && (!$input_errors)):
|
398 |
|
|
|
399 |
|
|
$form = new Form(false);
|
400 |
|
|
|
401 |
|
|
$section = new Form_Section('Backup Details');
|
402 |
|
|
|
403 |
|
|
if ($legacy) {
|
404 |
|
|
$section->addInput(new Form_Input(
|
405 |
|
|
'hostname',
|
406 |
|
|
'Hostname',
|
407 |
|
|
'text',
|
408 |
|
|
$hostname
|
409 |
|
|
))->setWidth(7)->setReadOnly();
|
410 |
|
|
}
|
411 |
|
|
|
412 |
|
|
$section->addInput(new Form_Input(
|
413 |
|
|
'download',
|
414 |
|
|
'Revision date/time',
|
415 |
|
|
'text',
|
416 |
|
|
$_REQUEST['download']
|
417 |
|
|
))->setWidth(7)->setReadOnly();
|
418 |
|
|
|
419 |
|
|
$section->addInput(new Form_Input(
|
420 |
|
|
'reason',
|
421 |
|
|
'Revision Reason',
|
422 |
|
|
'text',
|
423 |
|
|
$_REQUEST['reason']
|
424 |
|
|
))->setWidth(7)->setReadOnly();
|
425 |
|
|
|
426 |
|
|
$section->addInput(new Form_Input(
|
427 |
|
|
'shasum',
|
428 |
|
|
'SHA256 summary',
|
429 |
|
|
'text',
|
430 |
|
|
$sha256sum
|
431 |
|
|
))->setWidth(7)->setReadOnly();
|
432 |
|
|
|
433 |
|
|
$section->addInput(new Form_Textarea(
|
434 |
|
|
'config_xml',
|
435 |
|
|
'Encrypted config.xml',
|
436 |
|
|
$ds[1]
|
437 |
|
|
))->setWidth(7)->setAttribute("rows", "40")->setAttribute("wrap", "off");
|
438 |
|
|
|
439 |
|
|
$section->addInput(new Form_Textarea(
|
440 |
|
|
'dec_config_xml',
|
441 |
|
|
'Decrypted config.xml',
|
442 |
|
|
$data
|
443 |
|
|
))->setWidth(7)->setAttribute("rows", "40")->setAttribute("wrap", "off");
|
444 |
|
|
|
445 |
|
|
$form->add($section);
|
446 |
|
|
|
447 |
|
|
print($form);
|
448 |
|
|
|
449 |
|
|
?>
|
450 |
587315d5
|
Steve Beaver
|
<a class="btn btn-primary" title="<?=gettext('Restore this revision')?>" href="services_acb.php?newver=<?= urlencode($_REQUEST['download']) ?>" onclick="return confirm('<?=gettext("Are you sure you want to restore {$cv['localtime']}?")?>')"><i class="fa fa-undo"></i> Install this revision</a>
|
451 |
054f0ed0
|
Steve Beaver
|
|
452 |
|
|
<?php else:
|
453 |
|
|
|
454 |
f0fdd1ab
|
Steve Beaver
|
if (!$legacy) {
|
455 |
|
|
$section2 = new Form_Section('Device key');
|
456 |
|
|
$group = new Form_Group("Device key");
|
457 |
|
|
|
458 |
|
|
$group->add(new Form_Input(
|
459 |
|
|
'devkey',
|
460 |
|
|
'Device key',
|
461 |
|
|
'text',
|
462 |
|
|
$userkey
|
463 |
|
|
))->setWidth(7)->setHelp("ID used to identify this firewall (derived from the SSH public key.) " .
|
464 |
|
|
"See help below for more details. %sPlease make a safe copy of this ID value.%s If it is lost, your backups will" .
|
465 |
|
|
" be lost too!", "<strong>", "</strong>");
|
466 |
|
|
|
467 |
|
|
$group->add(new Form_Button(
|
468 |
|
|
'upduserkey',
|
469 |
|
|
'Submit',
|
470 |
|
|
null,
|
471 |
|
|
'fa-save'
|
472 |
|
|
))->addClass('btn-success btn-xs');
|
473 |
|
|
|
474 |
|
|
$group->add(new Form_Button(
|
475 |
|
|
'restore',
|
476 |
|
|
'Reset',
|
477 |
|
|
null,
|
478 |
|
|
'fa-refresh'
|
479 |
|
|
))->addClass('btn-info btn-xs');
|
480 |
|
|
|
481 |
|
|
$section2->add($group);
|
482 |
|
|
print($section2);
|
483 |
|
|
|
484 |
|
|
print('<div class="infoblock">');
|
485 |
|
|
print_info_box(gettext("The Device key listed above is derived from the SSH public key of the firewall. When a configuration is saved, it is identified by this value." .
|
486 |
|
|
" If you are restoring the configuration of another firewall, paste the Device key from that firewall into the Device ID field above and click \"Submit\"." .
|
487 |
|
|
" This will temporarily override the ID for this session."), 'info', false);
|
488 |
|
|
print('</div>');
|
489 |
|
|
}
|
490 |
|
|
|
491 |
054f0ed0
|
Steve Beaver
|
?>
|
492 |
|
|
<div class="panel panel-default">
|
493 |
|
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("Automatic Configuration Backups")?></h2></div>
|
494 |
|
|
<div class="panel-body">
|
495 |
|
|
<div class="table-responsive">
|
496 |
|
|
<?php if ($legacy) { ?>
|
497 |
|
|
<strong>Hostname:</strong>
|
498 |
587315d5
|
Steve Beaver
|
<select id="hostname" name="hostname" onchange="document.location='services_acb.php?hostname=' + this.value + '&legacy=true';">
|
499 |
054f0ed0
|
Steve Beaver
|
<?
|
500 |
|
|
$host_not_found = true;
|
501 |
|
|
foreach ($hostnames as $hn):
|
502 |
|
|
?>
|
503 |
|
|
<option value='<?=$hn?>' <? if ($hn == $hostname) {echo " selected=\"selected\""; $host_not_found = false;} ?>>
|
504 |
|
|
<?=$hn?>
|
505 |
|
|
</option>
|
506 |
|
|
<?endforeach?>
|
507 |
|
|
<? if ($host_not_found) { ?>
|
508 |
fe482ccc
|
jim-p
|
<option value='<?=urlencode($hostname)?>' SELECTED><?=htmlspecialchars($hostname)?></option>
|
509 |
054f0ed0
|
Steve Beaver
|
<? } ?>
|
510 |
|
|
</select>
|
511 |
|
|
<?php }
|
512 |
|
|
if ($legacy): ?>
|
513 |
|
|
<span class="pull-right"> </span>
|
514 |
|
|
<button id="nolegacy" class="btn btn-xs btn-warning pull-right" data-toggle="tooltip" title="<?=gettext('Exit the legacy backup system')?>">Exit legacy repository</button>
|
515 |
|
|
<?php else: ?>
|
516 |
|
|
<span class="pull-right"> </span>
|
517 |
|
|
<button id="legacy" class="btn btn-xs btn-success pull-right" data-toggle="tooltip" title="<?=gettext('Switch to the legacy backup system provided as part of the Gold program')?>">Use legacy "Gold" repository</button>
|
518 |
|
|
<?php endif; ?>
|
519 |
|
|
|
520 |
|
|
</div>
|
521 |
|
|
<div class="table-responsive">
|
522 |
|
|
<table class="table table-striped table-hover table-condensed" id="backups">
|
523 |
|
|
<thead>
|
524 |
|
|
<tr>
|
525 |
|
|
<th width="30%"><?=gettext("Date")?></th>
|
526 |
|
|
<th width="60%"><?=gettext("Configuration Change")?></th>
|
527 |
|
|
<th width="10%"><?=gettext("Actions")?></th>
|
528 |
|
|
</tr>
|
529 |
|
|
</thead>
|
530 |
|
|
<tbody>
|
531 |
|
|
|
532 |
|
|
<?php
|
533 |
|
|
$counter = 0;
|
534 |
|
|
foreach ($confvers as $cv):
|
535 |
|
|
?>
|
536 |
|
|
<tr>
|
537 |
|
|
<td><?= $cv['localtime']; ?></td>
|
538 |
|
|
<td><?= $cv['reason']; ?></td>
|
539 |
|
|
<td>
|
540 |
d33560e8
|
Steve Beaver
|
<a class="fa fa-undo" title="<?=gettext('Restore this revision')?>" href="services_acb.php?hostname=<?=urlencode($hostname)?>&userkey=<?=urlencode($userkey)?>&newver=<?=urlencode($cv['time'])?><?=($legacy ? "&legacy=true":"")?>" onclick="return confirm('<?=gettext("Are you sure you want to restore {$cv['localtime']}?")?>')"></a>
|
541 |
|
|
<a class="fa fa-download" title="<?=gettext('Show info')?>" href="services_acb.php?download=<?=urlencode($cv['time'])?>&hostname=<?=urlencode($hostname)?>&userkey=<?=urlencode($userkey)?>&reason=<?=urlencode($cv['reason'])?><?=($legacy ? "&legacy=true":"")?> "></a>
|
542 |
3fd4f32c
|
Steve Beaver
|
<?php
|
543 |
|
|
if ($userkey == $origkey) {
|
544 |
|
|
?>
|
545 |
|
|
<a class="fa fa-trash" title="<?=gettext('Delete config')?>" href="services_acb.php?hostname=<?=urlencode($hostname)?>&rmver=<?=urlencode($cv['time'])?><?=($legacy ? "&legacy=true":"")?>"></a>
|
546 |
|
|
<?php } ?>
|
547 |
054f0ed0
|
Steve Beaver
|
</td>
|
548 |
|
|
</tr>
|
549 |
|
|
<?php $counter++;
|
550 |
|
|
endforeach;
|
551 |
|
|
if ($counter == 0): ?>
|
552 |
|
|
<tr>
|
553 |
|
|
<td colspan="3" align="center" class="text-danger"><strong>
|
554 |
|
|
<?=gettext("No backups could be located for this device.")?>
|
555 |
|
|
</strong>
|
556 |
|
|
</td>
|
557 |
|
|
</tr>
|
558 |
|
|
<?php else: ?>
|
559 |
|
|
<tr>
|
560 |
|
|
<td colspan="3" align="center">
|
561 |
|
|
<?php if ($legacy) { ?>
|
562 |
|
|
<br /><?=gettext("Current count of hosted backups for this hostname on portal.pfsense.org")?> : <?= $counter ?>
|
563 |
|
|
<?php } else { ?>
|
564 |
|
|
<br /><?=gettext("Current count of hosted backups")?> : <?= $counter ?>
|
565 |
|
|
<?php } ?>
|
566 |
|
|
</td>
|
567 |
|
|
</tr>
|
568 |
|
|
<?php endif; ?>
|
569 |
|
|
</tbody>
|
570 |
|
|
</table>
|
571 |
|
|
</div>
|
572 |
|
|
</div>
|
573 |
|
|
</div>
|
574 |
|
|
<?php
|
575 |
|
|
|
576 |
|
|
endif; ?>
|
577 |
|
|
|
578 |
|
|
</form>
|
579 |
|
|
|
580 |
|
|
<div id="legacynotice" class="modal fade" role="dialog">
|
581 |
|
|
<div class="modal-dialog">
|
582 |
|
|
<div class="modal-content">
|
583 |
|
|
<div class="modal-body">
|
584 |
|
|
<?php
|
585 |
|
|
|
586 |
|
|
print(gettext("<p align=\"center\"><strong>pfSense© "Gold" configuration backup system access.</strong>
|
587 |
|
|
</p>
|
588 |
|
|
<p>The "Gold" backup system may be available to allow the retrieval of older backups</p>
|
589 |
|
|
<p>Note that because these backups were stored by hostname AND username, the configured username, hostname and password will be transmitted (via HTTPS) to the server. By clicking "OK"
|
590 |
|
|
you agree that you authorize this action. The backup data is encrypted (AES-256) and the encryption key is neither transmitted, nor known outside of the firewall</p>
|
591 |
|
|
</div>"));
|
592 |
|
|
?>
|
593 |
|
|
<div class="modal-footer">
|
594 |
|
|
<button type="button" class="btn btn-xs btn-default" data-dismiss="modal" aria-label="Close">
|
595 |
|
|
<span aria-hidden="true">Cancel</span>
|
596 |
|
|
</button>
|
597 |
|
|
<button id="legacyok" type="button" class="btn btn-xs btn-success" data-dismiss="modal" aria-label="Close">
|
598 |
|
|
<span aria-hidden="true">OK</span>
|
599 |
|
|
</button>
|
600 |
|
|
</div>
|
601 |
|
|
|
602 |
|
|
</div>
|
603 |
|
|
</div>
|
604 |
|
|
</div>
|
605 |
|
|
|
606 |
c3d2fce6
|
Steve Beaver
|
<?php
|
607 |
|
|
|
608 |
|
|
if ((strlen($username) == 0) || (strlen($password) == 0) ||
|
609 |
|
|
(strlen($config['system']['acb']['gold_encryption_password']) == 0) ||
|
610 |
|
|
($config['system']['acb']['gold_encryption_password'] == "********" )) {
|
611 |
|
|
$legacyready = "no";
|
612 |
|
|
} else {
|
613 |
|
|
$legacyready = "yes";
|
614 |
|
|
}
|
615 |
|
|
|
616 |
7ed7a9f0
|
Steve Beaver
|
$legacynotready = gettext("Please configure your \"Gold\" membership settings on the Settings page " .
|
617 |
af0edce6
|
Steve Beaver
|
"before accessing the legacy backup features");
|
618 |
c3d2fce6
|
Steve Beaver
|
?>
|
619 |
|
|
|
620 |
054f0ed0
|
Steve Beaver
|
<script type="text/javascript">
|
621 |
|
|
//<![CDATA[
|
622 |
|
|
events.push(function(){
|
623 |
|
|
$('#loading').hide();
|
624 |
|
|
|
625 |
68048497
|
Steve Beaver
|
// Show the acceptance modal if the user wants to use the legacy system
|
626 |
054f0ed0
|
Steve Beaver
|
$('#legacy').click(function() {
|
627 |
c3d2fce6
|
Steve Beaver
|
if ("<?=$legacyready?>" == "yes") {
|
628 |
|
|
$('#legacynotice').modal('show');
|
629 |
|
|
} else {
|
630 |
|
|
alert('<?=$legacynotready?>');
|
631 |
|
|
}
|
632 |
054f0ed0
|
Steve Beaver
|
});
|
633 |
|
|
|
634 |
|
|
// Redraw the page if they cancel
|
635 |
|
|
$('#nolegacy').click(function() {
|
636 |
587315d5
|
Steve Beaver
|
window.location.replace('/services_acb.php');
|
637 |
054f0ed0
|
Steve Beaver
|
});
|
638 |
|
|
|
639 |
|
|
// On clicking "OK", reload the page but with a POST parameter "legacy" set
|
640 |
|
|
$('#legacyok').click(function() {
|
641 |
|
|
var $form = $('<form>');
|
642 |
|
|
|
643 |
|
|
$form
|
644 |
|
|
.attr("method", "POST")
|
645 |
587315d5
|
Steve Beaver
|
.attr("action", '/services_acb.php')
|
646 |
054f0ed0
|
Steve Beaver
|
// The CSRF magic is required because we will be viewing the results of the POST
|
647 |
|
|
.append(
|
648 |
|
|
$("<input>")
|
649 |
|
|
.attr("type", "hidden")
|
650 |
|
|
.attr("name", "__csrf_magic")
|
651 |
|
|
.val(csrfMagicToken)
|
652 |
|
|
)
|
653 |
|
|
.append(
|
654 |
|
|
$("<input>")
|
655 |
|
|
.attr("type", "hidden")
|
656 |
|
|
.attr("name", 'legacy')
|
657 |
|
|
.val("Yes")
|
658 |
|
|
)
|
659 |
|
|
.appendTo('body')
|
660 |
|
|
.submit();
|
661 |
|
|
});
|
662 |
|
|
|
663 |
|
|
// On clicking Submit", reload the page but with a POST parameter "userkey" set
|
664 |
|
|
$('#upduserkey').click(function() {
|
665 |
|
|
var $form = $('<form>');
|
666 |
|
|
var newuserkey = $('#devkey').val();
|
667 |
|
|
|
668 |
|
|
$form
|
669 |
|
|
.attr("method", "POST")
|
670 |
587315d5
|
Steve Beaver
|
.attr("action", '/services_acb.php')
|
671 |
054f0ed0
|
Steve Beaver
|
// The CSRF magic is required because we will be viewing the results of the POST
|
672 |
|
|
.append(
|
673 |
|
|
$("<input>")
|
674 |
|
|
.attr("type", "hidden")
|
675 |
|
|
.attr("name", "__csrf_magic")
|
676 |
|
|
.val(csrfMagicToken)
|
677 |
|
|
)
|
678 |
|
|
.append(
|
679 |
|
|
$("<input>")
|
680 |
|
|
.attr("type", "hidden")
|
681 |
|
|
.attr("name", "userkey")
|
682 |
|
|
.val(newuserkey)
|
683 |
|
|
)
|
684 |
|
|
.appendTo('body')
|
685 |
|
|
.submit();
|
686 |
|
|
});
|
687 |
|
|
|
688 |
|
|
$('#restore').click(function() {
|
689 |
|
|
$('#devkey').val("<?=$origkey?>");
|
690 |
|
|
});
|
691 |
|
|
});
|
692 |
|
|
//]]>
|
693 |
|
|
</script>
|
694 |
|
|
|
695 |
|
|
<?php include("foot.inc"); ?>
|