From ce292d0387a8ce1a247ed6a02d132ead59c83de4 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 13:25:00 +0200 Subject: autoconfigbackup.- code style fixes - Fix copyright header - Code style and whitespace fixes - Replace deprecated split() with explode() - Replace backticks with shell_exec() - Some XHTML fixes --- config/autoconfigbackup/autoconfigbackup.php | 370 ++++++++++++++------------- 1 file changed, 188 insertions(+), 182 deletions(-) (limited to 'config/autoconfigbackup') diff --git a/config/autoconfigbackup/autoconfigbackup.php b/config/autoconfigbackup/autoconfigbackup.php index 52b3eca9..5bf40736 100644 --- a/config/autoconfigbackup/autoconfigbackup.php +++ b/config/autoconfigbackup/autoconfigbackup.php @@ -1,81 +1,86 @@ {$pgtitle}

"; - if($savemsg) { + } + if ($savemsg) { echo "
"; print_info_box($savemsg); - echo "
"; - } - if ($input_errors) + echo ""; + } + if ($input_errors) { print_input_errors($input_errors); - if($hostname <> $myhostname) - print_info_box("Warning! You are currently viewing an alternate host's backup history ($hostname)"); + } + if ($hostname <> $myhostname) { + print_info_box("Warning! You are currently viewing an alternate host's backup history ($hostname)"); + } ?> - - - - - + + + -"; echo "$('loading').innerHTML = '';"; - echo ""; - foreach($confvers as $cv): + echo ""; + foreach ($confvers as $cv): ?> - + - + "; - else - echo ""; + if ($counter == 0) { + echo ""; + } else { + echo ""; + } ?>
+ + - - +
- Loading, please wait... -

  + Loading, please wait... +

 
-
+ ?> +
"); $data = substr($out, 0, $pos); $data = $data . "\n"; @@ -219,12 +225,16 @@ function get_hostnames() { $fd = fopen("/tmp/config_restore.xml", "w"); fwrite($fd, $data); fclose($fd); - if(strlen($data) < 50) - $input_errors[] = "The decrypted config.xml is under 50 characters, something went wrong. Aborting."; - $ondisksha256 = trim(`/sbin/sha256 /tmp/config_restore.xml | awk '{ print $4 }'`); - if($sha256 != "0" && $sha256 != "") // we might not have a sha256 on file for older backups - if($ondisksha256 <> $sha256) + if (strlen($data) < 50) { + $input_errors[] = "The decrypted config.xml is under 50 characters, something went wrong. Aborting."; + } + $ondisksha256 = trim(shell_exec("/sbin/sha256 /tmp/config_restore.xml | /usr/bin/awk '{ print $4 }'")); + // We might not have a sha256 on file for older backups + if ($sha256 != "0" && $sha256 != "") { + if ($ondisksha256 <> $sha256) { $input_errors[] = "SHA256 values do not match, cannot restore. $ondisksha256 <> $sha256"; + } + } if (curl_errno($curl_session)) { /* If an error occured, log the error in /tmp/ */ $fd = fopen("/tmp/acb_restoredebug.txt", "w"); @@ -233,18 +243,18 @@ function get_hostnames() { fwrite($fd, curl_error($curl_session)); fclose($fd); } else { - curl_close($curl_session); + curl_close($curl_session); } - if(!$input_errors && $data) { + if (!$input_errors && $data) { conf_mount_rw(); - if(config_restore("/tmp/config_restore.xml") == 0) { + if (config_restore("/tmp/config_restore.xml") == 0) { $savemsg = "Successfully reverted the pfSense configuration to revision " . urldecode($_REQUEST['newver']) . "."; $savemsg .= << -
- Would you like to reboot? - - +
+ + Would you like to reboot? + +
EOF; } else { @@ -256,42 +266,43 @@ EOF; } unlink_if_exists("/tmp/config_restore.xml"); conf_mount_ro(); - } - if($_REQUEST['download']) { + } + if ($_REQUEST['download']) { // Phone home and obtain backups $curl_session = curl_init(); curl_setopt($curl_session, CURLOPT_URL, $get_url); curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}"))); - curl_setopt($curl_session, CURLOPT_POST, 3); - curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=restore" . - "&hostname=" . urlencode($hostname) . - "&revision=" . urlencode($_REQUEST['download'])); + curl_setopt($curl_session, CURLOPT_POST, 3); + curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=restore" . "&hostname=" . urlencode($hostname) . "&revision=" . urlencode($_REQUEST['download'])); curl_setopt($curl_session, CURLOPT_USERAGENT, $g['product_name'] . '/' . rtrim(file_get_contents("/etc/version"))); // Proxy curl_setopt_array($curl_session, configure_proxy()); $data = curl_exec($curl_session); - if (!tagfile_deformat($data, $data1, "config.xml")) + if (!tagfile_deformat($data, $data1, "config.xml")) { $input_errors[] = "The downloaded file does not appear to contain an encrypted pfSense configuration."; + } if ($input_errors) { print_input_errors($input_errors); } else { $ds = split("\+\+\+\+", $data); $revision = $_REQUEST['download']; $sha256sum = $ds[0]; - if($sha256sum == "0") + if ($sha256sum == "0") { $sha256sum = "None on file."; + } $data = $ds[1]; $configtype = "Encrypted"; - if (!tagfile_deformat($data, $data, "config.xml")) + if (!tagfile_deformat($data, $data, "config.xml")) { $input_errors[] = "The downloaded file does not appear to contain an encrypted pfSense configuration."; + } $data = htmlentities(decrypt_data($data, $decrypt_password)); - if(!strstr($data, "pfsense")) { - $data = "Could not decrypt. Different encryption key?"; + if (!strstr($data, "pfsense")) { + $data = "Could not decrypt. Different encryption key?"; $input_errors[] = "Could not decrypt config.xml"; } - echo "

Hostname

"; + echo "

Hostname

"; echo ""; echo "

Revision date/time

"; echo ""; @@ -304,20 +315,21 @@ EOF; echo "

Decrypted config.xml

"; echo ""; } - if(!$input_errors) - echo "

"; + if (!$input_errors) { + echo "
"; + } echo ""; echo "

"; require("fend.inc"); - exit; + exit; } // Populate available backups $curl_session = curl_init(); - curl_setopt($curl_session, CURLOPT_URL, $get_url); + curl_setopt($curl_session, CURLOPT_URL, $get_url); curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}"))); - curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl_session, CURLOPT_POST, 1); curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=showbackups&hostname={$hostname}"); @@ -333,97 +345,91 @@ EOF; fwrite($fd, curl_error($curl_session)); fclose($fd); } else { - curl_close($curl_session); + curl_close($curl_session); } // Loop through and create new confvers $data_split = split("\n", $data); $confvers = array(); - foreach($data_split as $ds) { + foreach ($data_split as $ds) { $ds_split = split($oper_sep, $ds); $tmp_array = array(); $tmp_array['username'] = $ds_split[0]; $tmp_array['reason'] = $ds_split[1]; $tmp_array['time'] = $ds_split[2]; - if($ds_split[2] && $ds_split[0]) + if ($ds_split[2] && $ds_split[0]) { $confvers[] = $tmp_array; + } } - if ($input_errors) + if ($input_errors) { print_input_errors($input_errors); + } ?>
-
- Hostname: - -
+
+ Hostname: + +
+
Date Configuration Change
- - - - - - - - - - + + + + + + + + + +
Sorry, we could not locate any backups at portal.pfsense.org for this hostname ({$hostname}).

Backups hosted currently for this hostname on portal.pfsense.org: {$counter}.
Sorry, we could not locate any backups at portal.pfsense.org for this hostname ({$hostname}).

Backups hosted currently for this hostname on portal.pfsense.org: {$counter}.
- - - -

- -    - - Hint:  - - - Click the + sign next to the revision you would like to restore. -

- - - - + + +
+   Hint: Click the + sign next to the revision you would like to restore. +
+ + -- cgit v1.2.3