From 31564b356d8caf82cf2a45e97bb4c998619944af Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 10:45:23 +0200 Subject: autoconfigbackup.- code style fixes - Update copyright header - Code style and whitespace fixes - Use platform_booting() - Replace backticks with shell_exec() --- config/autoconfigbackup/autoconfigbackup.inc | 292 ++++++++++++++------------- 1 file changed, 152 insertions(+), 140 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.inc b/config/autoconfigbackup/autoconfigbackup.inc index 7050aab6..dc69ab62 100644 --- a/config/autoconfigbackup/autoconfigbackup.inc +++ b/config/autoconfigbackup/autoconfigbackup.inc @@ -1,69 +1,74 @@ $post['passwordagain']) + if ($post['password'] <> $post['passwordagain']) { $input_errors[] = "Sorry, the entered portal.pfsense.org passwords do not match."; + } - if($post['crypto_password'] <> $post['crypto_password2']) + if ($post['crypto_password'] <> $post['crypto_password2']) { $input_errors[] = "Sorry, the entered encryption passwords do not match."; + } - if($post['testconnection']) { + if ($post['testconnection']) { $status = test_connection($post); - if($status) + if ($status) { $savemsg = "Connection to portal.pfsense.org was tested with no errors."; + } } - + // We do not need to store this value. unset($_POST['testconnection']); } @@ -73,8 +78,9 @@ function configure_proxy() { $ret = array(); if (!empty($config['system']['proxyurl'])) { $ret[CURLOPT_PROXY] = $config['system']['proxyurl']; - if (!empty($config['system']['proxyport'])) + if (!empty($config['system']['proxyport'])) { $ret[CURLOPT_PROXYPORT] = $config['system']['proxyport']; + } if (!empty($config['system']['proxyuser']) && !empty($config['system']['proxypass'])) { $ret[CURLOPT_PROXYAUTH] = CURLAUTH_ANY | CURLAUTH_ANYSAFE; $ret[CURLOPT_PROXYUSERPWD] = "{$config['system']['proxyuser']}:{$config['system']['proxypass']}"; @@ -86,27 +92,28 @@ function configure_proxy() { function test_connection($post) { global $savemsg, $config, $g; - /* do nothing when booting */ - if($g['booting']) + // Do nothing when booting + if (platform_booting()) { return; + } // Seperator used during client / server communications - $oper_sep = "\|\|"; + $oper_sep = "\|\|"; // Encryption password - $decrypt_password = $post['crypto_password']; + $decrypt_password = $post['crypto_password']; // Defined username - $username = $post['username']; + $username = $post['username']; // Defined password - $password = $post['password']; + $password = $post['password']; // Set hostname - $hostname = $config['system']['hostname'] . "." . $config['system']['domain']; + $hostname = $config['system']['hostname'] . "." . $config['system']['domain']; // URL to restore.php - $get_url = "https://portal.pfsense.org/pfSconfigbackups/restore.php"; + $get_url = "https://portal.pfsense.org/pfSconfigbackups/restore.php"; // Populate available backups $curl_session = curl_init(); @@ -124,29 +131,30 @@ function test_connection($post) { curl_setopt($curl_session, CURLOPT_POSTFIELDS, "action=showbackups&hostname={$hostname}"); $data = curl_exec($curl_session); - if (curl_errno($curl_session)) + if (curl_errno($curl_session)) { return("An error occurred " . curl_error($curl_session)); - else + } else { curl_close($curl_session); - + } return; } function upload_config($reasonm = "") { global $config, $g, $input_errors; - /* do nothing when booting */ - if($g['booting']) + // Do nothing when booting + if (platform_booting()) { return; + } /* - * pfSense upload config to pfSense.org script - * This file plugs into config.inc (/usr/local/pkg/parse_config) - * and runs every time the running firewall filter changes. - * + * pfSense upload config to pfSense.org script + * This file plugs into config.inc (/usr/local/pkg/parse_config) + * and runs every time the running firewall filter changes. + * */ - - if(file_exists("/tmp/acb_nooverwrite")) { + + if (file_exists("/tmp/acb_nooverwrite")) { unlink("/tmp/acb_nooverwrite"); $nooverwrite = "true"; } else { @@ -154,28 +162,30 @@ function upload_config($reasonm = "") { } // Define some needed variables - if(file_exists("/cf/conf/lastpfSbackup.txt")) + if (file_exists("/cf/conf/lastpfSbackup.txt")) { $last_backup_date = str_replace("\n", "", file_get_contents("/cf/conf/lastpfSbackup.txt")); - else + } else { $last_backup_date = ""; + } $last_config_change = $config['revision']['time']; - $hostname = $config['system']['hostname'] . "." . $config['system']['domain']; - if($reasonm) + $hostname = $config['system']['hostname'] . "." . $config['system']['domain']; + if ($reasonm) { $reason = $reasonm; - else - $reason = $config['revision']['description']; - $username = $config['installedpackages']['autoconfigbackup']['config'][0]['username']; - $password = $config['installedpackages']['autoconfigbackup']['config'][0]['password']; - $encryptpw = $config['installedpackages']['autoconfigbackup']['config'][0]['crypto_password']; + } else { + $reason = $config['revision']['description']; + } + $username = $config['installedpackages']['autoconfigbackup']['config'][0]['username']; + $password = $config['installedpackages']['autoconfigbackup']['config'][0]['password']; + $encryptpw = $config['installedpackages']['autoconfigbackup']['config'][0]['crypto_password']; // Define upload_url, must be present after other variable definitions due to username, password $upload_url = "https://portal.pfsense.org/pfSconfigbackups/backup.php"; - if(!$username or !$password or !$encryptpw) { - if(!file_exists("/cf/conf/autoconfigback.notice")) { - $notice_text = "Either the username, password or encryption password is not set for Automatic Configuration Backup. "; - $notice_text .= "Please correct this in Diagnostics -> AutoConfigBackup -> Settings."; + if (!$username or !$password or !$encryptpw) { + if (!file_exists("/cf/conf/autoconfigback.notice")) { + $notice_text = "Either the username, password or encryption password is not set for Automatic Configuration Backup."; + $notice_text .= " Please correct this in Diagnostics -> AutoConfigBackup -> Settings."; //log_error($notice_text); //file_notice("AutoConfigBackup", $notice_text, $notice_text, ""); conf_mount_rw(); @@ -184,81 +194,83 @@ function upload_config($reasonm = "") { } } else { /* If configuration has changed, upload to pfS */ - if($last_backup_date <> $last_config_change) { + if ($last_backup_date <> $last_config_change) { - // Mount RW (if needed) - conf_mount_rw(); + // Mount RW (if needed) + conf_mount_rw(); - $notice_text = "Beginning https://portal.pfsense.org configuration backup."; + $notice_text = "Beginning https://portal.pfsense.org configuration backup."; + log_error($notice_text); + update_filter_reload_status($notice_text); + + // Encrypt config.xml + $data = file_get_contents("/cf/conf/config.xml"); + $raw_config_sha256_hash = trim(shell_exec("/sbin/sha256 /cf/conf/config.xml | /usr/bin/awk '{ print $4 }'")); + $data = encrypt_data($data, $encryptpw); + tagfile_reformat($data, $data, "config.xml"); + + $post_fields = array( + 'reason' => urlencode((string)$reason), + 'hostname' => urlencode($hostname), + 'configxml' => urlencode($data), + 'nooverwrite' => urlencode($nooverwrite), + 'raw_config_sha256_hash' => urlencode($raw_config_sha256_hash) + ); + + // URL-ify the data for the POST + foreach ($post_fields as $key=>$value) { + $fields_string .= $key . '=' . $value . '&'; + } + rtrim($fields_string,'&'); + + // Check configuration into the ESF repo + $curl_session = curl_init(); + curl_setopt($curl_session, CURLOPT_URL, $upload_url); + curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}"))); + curl_setopt($curl_session, CURLOPT_POST, count($post_fields)); + curl_setopt($curl_session, CURLOPT_POSTFIELDS, $fields_string); + curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0); + curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 55); + curl_setopt($curl_session, CURLOPT_TIMEOUT, 30); + 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 (curl_errno($curl_session)) { + $fd = fopen("/tmp/backupdebug.txt", "w"); + fwrite($fd, $upload_url . "" . $fields_string . "\n\n"); + fwrite($fd, $data); + fwrite($fd, curl_error($curl_session)); + fclose($fd); + } else { + curl_close($curl_session); + } + + if (!strstr($data, "500")) { + $notice_text = "An error occurred while uploading your pfSense configuration to portal.pfsense.org"; + log_error($notice_text . " - " . $data); + file_notice("autoconfigurationbackup", $notice_text, $data, ""); + update_filter_reload_status($notice_text . " - " . $data); + } else { + // Update last pfS backup time + $fd = fopen("/cf/conf/lastpfSbackup.txt", "w"); + fwrite($fd, $config['revision']['time']); + fclose($fd); + $notice_text = "End of portal.pfsense.org configuration backup (success)."; log_error($notice_text); update_filter_reload_status($notice_text); + } - // Encrypt config.xml - $data = file_get_contents("/cf/conf/config.xml"); - $raw_config_sha256_hash = trim(`/sbin/sha256 /cf/conf/config.xml | awk '{ print $4 }'`); - $data = encrypt_data($data, $encryptpw); - tagfile_reformat($data, $data, "config.xml"); - - $post_fields = array( - 'reason' => urlencode((string)$reason), - 'hostname' => urlencode($hostname), - 'configxml' => urlencode($data), - 'nooverwrite' => urlencode($nooverwrite), - 'raw_config_sha256_hash' => urlencode($raw_config_sha256_hash) - ); - - //url-ify the data for the POST - foreach($post_fields as $key=>$value) - $fields_string .= $key.'='.$value.'&'; - rtrim($fields_string,'&'); - - // Check configuration into the ESF repo - $curl_session = curl_init(); - curl_setopt($curl_session, CURLOPT_URL, $upload_url); - curl_setopt($curl_session, CURLOPT_HTTPHEADER, array("Authorization: Basic " . base64_encode("{$username}:{$password}"))); - curl_setopt($curl_session, CURLOPT_POST, count($post_fields)); - curl_setopt($curl_session, CURLOPT_POSTFIELDS, $fields_string); - curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, 0); - curl_setopt($curl_session, CURLOPT_CONNECTTIMEOUT, 55); - curl_setopt($curl_session, CURLOPT_TIMEOUT, 30); - 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 (curl_errno($curl_session)) { - $fd = fopen("/tmp/backupdebug.txt", "w"); - fwrite($fd, $upload_url . "" . $fields_string . "\n\n"); - fwrite($fd, $data); - fwrite($fd, curl_error($curl_session)); - fclose($fd); - } else { - curl_close($curl_session); - } - - if(!strstr($data, "500")) { - $notice_text = "An error occurred while uploading your pfSense configuration to portal.pfsense.org"; - log_error($notice_text . " - " . $data); - file_notice("autoconfigurationbackup", $notice_text, $data, ""); - update_filter_reload_status($notice_text . " - " . $data); - } else { - // Update last pfS backup time - $fd = fopen("/cf/conf/lastpfSbackup.txt", "w"); - fwrite($fd, $config['revision']['time']); - fclose($fd); - $notice_text = "End of portal.pfsense.org configuration backup (success)."; - log_error($notice_text); - update_filter_reload_status($notice_text); - } - - // Mount image RO (if needed) - conf_mount_ro(); + // Mount image RO (if needed) + conf_mount_ro(); } else { - // debugging + // Debugging //log_error("No https://portal.pfsense.org backup required."); } - } + } } +?> -- cgit v1.2.3 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') 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 From 9597e97c029be127beff9eb8b30af6d306983415 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 13:48:26 +0200 Subject: autoconfigbackup.- code style fixes - Move custom_php_resync_config_command() function to autoconfigbackup.inc and give it an unique prefix - Also give a unique prefix to custom_php_validation_command() - Fix copyright header - Fix file permissions (no need for these to be executable) - Whitespace fixes --- config/autoconfigbackup/autoconfigbackup.xml | 112 +++++++++++++-------------- 1 file changed, 53 insertions(+), 59 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.xml b/config/autoconfigbackup/autoconfigbackup.xml index eb3f7545..dd83a9c7 100644 --- a/config/autoconfigbackup/autoconfigbackup.xml +++ b/config/autoconfigbackup/autoconfigbackup.xml @@ -3,41 +3,47 @@ - + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ +/* ====================================================================================== */ + ]]> - Automatically backs up your pfSense configuration. All contents are encrypted before being sent to the server. Requires Gold Subscription from https://portal.pfsense.org - pfSense Portal subscription + Automatically backs up your pfSense configuration. All contents are encrypted before being sent to the server. Requires Gold Subscription from https://portal.pfsense.org + pfSense Portal subscription AutoConfigBackup - 1.28 + 1.29 Diagnostics: Auto Configuration Backup Change /usr/local/pkg/autoconfigbackup.inc @@ -49,38 +55,31 @@ /autoconfigbackup.php - /usr/local/pkg/write_config/ - 0755 + /usr/local/pkg/write_config/ https://packages.pfsense.org/packages/config/autoconfigbackup/parse_config_upload.inc - /usr/local/www/ - 0755 + /usr/local/www/ https://packages.pfsense.org/packages/config/autoconfigbackup/autoconfigbackup.php - /usr/local/pkg/ - 0755 + /usr/local/pkg/ https://packages.pfsense.org/packages/config/autoconfigbackup/autoconfigbackup.inc - /etc/inc/ - 0755 + /etc/inc/ https://packages.pfsense.org/packages/config/autoconfigbackup/crypt_acb.php - /usr/local/www/ - 0755 + /usr/local/www/ https://packages.pfsense.org/packages/config/autoconfigbackup/autoconfigbackup_backup.php - /usr/local/pkg/write_config/ - 0755 + /usr/local/pkg/write_config/ https://packages.pfsense.org/packages/config/autoconfigbackup/parse_config_upload.php - /usr/local/www/ - 0755 + /usr/local/www/ https://packages.pfsense.org/packages/config/autoconfigbackup/autoconfigbackup_stats.php @@ -116,37 +115,32 @@ password - Enter Password again + Enter Password Again passwordagain password Encryption Password - This password will be used to encrypt config.xml before uploading. We recommend not setting this to the same thing as your portal.pfsense.org account. Keep record of this password in a safe place - without it, your configurations will be impossible to restore. + + not setting this to the same password as your portal.pfsense.org account.
+ Keep record of this password in a safe place - without it, your configurations will be impossible to restore. + ]]> +
crypto_password password
- Encryption Password again + Encryption Password Again Enter the encryption password again. crypto_password2 password - + - custom_php_validation_command($_POST, $input_errors); + acb_custom_php_validation_command($_POST, $input_errors); - "; - $savemsg .= "A configuration backup has been queued."; - ]]> + acb_custom_php_resync_config_command();
-- cgit v1.2.3 From 7b2165a1a055271cd05c2c4bc46d82e32d9a1d31 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 13:50:18 +0200 Subject: autoconfigbackup.- code style fixes - Move custom_php_resync_config_command() function from XML to autoconfigbackup.inc and give it an unique prefix - Also give an unique prefix to custom_php_validation_command() --- config/autoconfigbackup/autoconfigbackup.inc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.inc b/config/autoconfigbackup/autoconfigbackup.inc index dc69ab62..c7d4c97b 100644 --- a/config/autoconfigbackup/autoconfigbackup.inc +++ b/config/autoconfigbackup/autoconfigbackup.inc @@ -39,7 +39,7 @@ unlink_if_exists("/usr/local/pkg/parse_config/parse_config_upload.inc"); unlink_if_exists("/usr/local/pkg/parse_config/parse_config_upload.php"); // Ensures patches match -function custom_php_validation_command($post, &$input_errors) { +function acb_custom_php_validation_command($post, &$input_errors) { global $_POST, $savemsg, $config; if (!$post['username']) { @@ -73,6 +73,20 @@ function custom_php_validation_command($post, &$input_errors) { unset($_POST['testconnection']); } +function acb_custom_php_resync_config_command() { + conf_mount_rw(); + unlink_if_exists("/cf/conf/lastpfSbackup.txt"); + conf_mount_ro(); + if (!function_exists("filter_configure")) { + require_once("filter.inc"); + } + filter_configure(); + if ($savemsg) { + $savemsg .= "
"; + } + $savemsg .= "A configuration backup has been queued."; +} + function configure_proxy() { global $config; $ret = array(); -- cgit v1.2.3 From 64bedf7f5cd87c07ddbb424f72314b9e1c043080 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 14:04:53 +0200 Subject: autoconfigbackup - code style fixes - Fix copyright header - Code style and whitespace fixes - XHTML fixes --- .../autoconfigbackup/autoconfigbackup_backup.php | 156 ++++++++++----------- 1 file changed, 74 insertions(+), 82 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup_backup.php b/config/autoconfigbackup/autoconfigbackup_backup.php index 3c5ea423..ee08d170 100644 --- a/config/autoconfigbackup/autoconfigbackup_backup.php +++ b/config/autoconfigbackup/autoconfigbackup_backup.php @@ -1,128 +1,120 @@
{$pgtitle}

"; - if($savemsg) { + } + if ($savemsg) { print_info_box($savemsg); - } - if ($input_errors) + } + if ($input_errors) { print_input_errors($input_errors); - + } ?>
- - - - - -
-
-
- -
- +
+ + + +
+
+ +
+ + - - - - + +
+ + + + + + + + -
Enter the backup reason: + +
 
- - - - - - - - - - - -
- Enter the backup reason: - - -
-   -
- -
+
+
-
+
-- cgit v1.2.3 From 98fd03b224e043f635f449a1697734f7fd9797fb Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 14:48:15 +0200 Subject: autoconfigbackup - code style fixes - Fix copyright header - Code style and whitespace fixes - XHTML fixes - Replace deprecated split() with explode(); still one split() occurrence left - cannot be simply replaced with explode() since that changes the output and I have no clue what the code is supposed to do plus no way to test it without subscription account. --- config/autoconfigbackup/autoconfigbackup_stats.php | 203 ++++++++++----------- 1 file changed, 98 insertions(+), 105 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup_stats.php b/config/autoconfigbackup/autoconfigbackup_stats.php index 34d96eda..6c50dd52 100644 --- a/config/autoconfigbackup/autoconfigbackup_stats.php +++ b/config/autoconfigbackup/autoconfigbackup_stats.php @@ -1,98 +1,98 @@ @@ -100,57 +100,54 @@ include("head.inc");
{$pgtitle}

"; - if($savemsg) { + } + if ($savemsg) { print_info_box($savemsg); - } - if ($input_errors) + } + if ($input_errors) { print_input_errors($input_errors); - + } ?>
- - - - - -
-
-
- -
+ + + + + + + +
+
+ +
- - +"; echo "$('loading').innerHTML = '';"; echo ""; $total_backups = 0; - foreach($statvers as $cv): + foreach ($statvers as $cv): ?> - "; + if ($counter == 0) + echo ""; ?> - - - - - - -
- Loading, please wait... + Loading, please wait...
Hostname Backup count
+ - - - - - - - - + + + + + + + +
Sorry, we could not load the status information for the account ($username).
Sorry, we could not load the status information for the account ($username).
- Total - - -
+
Total 
-- cgit v1.2.3 From d04474f9b71b6e87262a2a0096d5199dde27792d Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 15:03:35 +0200 Subject: autoconfigbackup - code style fixes - Fix copyright header - Code style and whitespace fixes N.B.: This code produces "Fatal error: Cannot redeclare stripos()" on any PHP5+ version, really no idea why's it still here for which prehistoric pfS versions. Not touching it otherwise. --- config/autoconfigbackup/crypt_acb.php | 220 +++++++++++++++++----------------- 1 file changed, 110 insertions(+), 110 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/crypt_acb.php b/config/autoconfigbackup/crypt_acb.php index 9f897cb5..29d6a74f 100644 --- a/config/autoconfigbackup/crypt_acb.php +++ b/config/autoconfigbackup/crypt_acb.php @@ -1,135 +1,135 @@ array("pipe", "r"), - 1 => array("pipe", "w"), - 2 => array("pipe", "e")); - log_error("proc_open"); - $fp = proc_open($pspec, $dspec, $pipes); - if (!$fp) - return false; - log_error("writing to pipe[0]"); - fwrite($pipes[0], $data); - log_error("closing pipe[0]"); - fclose($pipes[0]); - - log_error("enter while()"); - - while (!feof($pipes[1])) { - $rslt .= fread($pipes[1], 8192); - } - - log_error("exit while()"); - - fclose($pipes[1]); - - proc_close($fp); - - return $rslt; + unlink_if_exists($file); + unlink_if_exists("{$file}.dec"); + unlink_if_exists("{$file}.enc"); + return $result; +} + +function crypt_dataA(& $data, $pass, $opt) { + log_error("entering crypt_data()"); + $pspec = "/usr/bin/openssl enc {$opt} -aes-256-cbc -k {$pass}"; + $dspec = array( 0 => array("pipe", "r"), + 1 => array("pipe", "w"), + 2 => array("pipe", "e")); + log_error("proc_open"); + $fp = proc_open($pspec, $dspec, $pipes); + if (!$fp) { + return false; } + log_error("writing to pipe[0]"); + fwrite($pipes[0], $data); + log_error("closing pipe[0]"); + fclose($pipes[0]); - function encrypt_data(& $data, $pass) { - return trim(base64_encode(crypt_data($data, $pass, "-e"))); - } + log_error("enter while()"); - function decrypt_data(& $data, $pass) { - return trim(crypt_data(base64_decode($data), $pass, "-d")); + while (!feof($pipes[1])) { + $rslt .= fread($pipes[1], 8192); } - function tagfile_reformat($in, & $out, $tag) { + log_error("exit while()"); + fclose($pipes[1]); + proc_close($fp); + return $rslt; +} - $out = "---- BEGIN {$tag} ----\n"; +function encrypt_data(& $data, $pass) { + return trim(base64_encode(crypt_data($data, $pass, "-e"))); +} - $size = 80; - $oset = 0; - while ($size >= 64) { - $line = substr($in, $oset, 64); - $out .= $line."\n"; - $size = strlen($line); - $oset += $size; - } +function decrypt_data(& $data, $pass) { + return trim(crypt_data(base64_decode($data), $pass, "-d")); +} - $out .= "---- END {$tag} ----"; +function tagfile_reformat($in, & $out, $tag) { - $out = trim($out); + $out = "---- BEGIN {$tag} ----\n"; - return true; + $size = 80; + $oset = 0; + while ($size >= 64) { + $line = substr($in, $oset, 64); + $out .= $line."\n"; + $size = strlen($line); + $oset += $size; } - function tagfile_deformat($in, & $out, $tag) { - - $btag_val = "---- BEGIN {$tag} ----"; - $etag_val = "---- END {$tag} ----"; + $out .= "---- END {$tag} ----"; - $btag_len = strlen($btag_val); - $etag_len = strlen($etag_val); + $out = trim($out); - $btag_pos = stripos($in, $btag_val); - $etag_pos = stripos($in, $etag_val); + return true; +} - if (($btag_pos === false) || ($etag_pos === false)) - return false; +function tagfile_deformat($in, &$out, $tag) { - $body_pos = $btag_pos + $btag_len; - $body_len = strlen($in); - $body_len -= strlen($btag_len); - $body_len -= strlen($etag_len); + $btag_val = "---- BEGIN {$tag} ----"; + $etag_val = "---- END {$tag} ----"; - $out = substr($in, $body_pos, $body_len); + $btag_len = strlen($btag_val); + $etag_len = strlen($etag_val); - $out = trim($out); + $btag_pos = stripos($in, $btag_val); + $etag_pos = stripos($in, $etag_val); - return true; - } - - function stripos($str,$needle) { - return strpos(strtolower($str), strtolower($needle)); + if (($btag_pos === false) || ($etag_pos === false)) { + return false; } + $body_pos = $btag_pos + $btag_len; + $body_len = strlen($in); + $body_len -= strlen($btag_len); + $body_len -= strlen($etag_len); + + $out = substr($in, $body_pos, $body_len); + + $out = trim($out); + + return true; +} + +function stripos($str, $needle) { + return strpos(strtolower($str), strtolower($needle)); +} + +?> -- cgit v1.2.3 From 3a80254b9a3d288f22f1325b245a50dbf13cd970 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 15:10:39 +0200 Subject: autoconfigbackup - code style fixes Missing whitespace. --- config/autoconfigbackup/parse_config_upload.inc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/parse_config_upload.inc b/config/autoconfigbackup/parse_config_upload.inc index ba0b48ce..46919138 100644 --- a/config/autoconfigbackup/parse_config_upload.inc +++ b/config/autoconfigbackup/parse_config_upload.inc @@ -1,7 +1,6 @@ Date: Sun, 23 Aug 2015 15:12:28 +0200 Subject: autoconfigbackup - code style fixes Missing whitespace. --- config/autoconfigbackup/parse_config_upload.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/parse_config_upload.php b/config/autoconfigbackup/parse_config_upload.php index ba0b48ce..46919138 100644 --- a/config/autoconfigbackup/parse_config_upload.php +++ b/config/autoconfigbackup/parse_config_upload.php @@ -1,7 +1,6 @@ Date: Sun, 23 Aug 2015 15:13:33 +0200 Subject: autoconfigbackup - code style fixes Missing whitespace --- config/autoconfigbackup/upload_config_filter.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/upload_config_filter.php b/config/autoconfigbackup/upload_config_filter.php index ba0b48ce..46919138 100644 --- a/config/autoconfigbackup/upload_config_filter.php +++ b/config/autoconfigbackup/upload_config_filter.php @@ -1,7 +1,6 @@ Date: Sun, 23 Aug 2015 15:16:56 +0200 Subject: Remove closing php tag again This was apparently removed intentionally in 653a43f for god knows what reason. Removing again. --- config/autoconfigbackup/autoconfigbackup.inc | 1 - 1 file changed, 1 deletion(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.inc b/config/autoconfigbackup/autoconfigbackup.inc index c7d4c97b..ef22a30f 100644 --- a/config/autoconfigbackup/autoconfigbackup.inc +++ b/config/autoconfigbackup/autoconfigbackup.inc @@ -287,4 +287,3 @@ function upload_config($reasonm = "") { } } -?> -- cgit v1.2.3 From 029c748b6d904b1cd61811d50f08eed66c99d879 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Sun, 23 Aug 2015 15:21:03 +0200 Subject: Remove closing php tag again This was apparently removed intentionally in 653a43f for god knows what reason. Removing again. --- config/autoconfigbackup/crypt_acb.php | 1 - 1 file changed, 1 deletion(-) (limited to 'config') diff --git a/config/autoconfigbackup/crypt_acb.php b/config/autoconfigbackup/crypt_acb.php index 29d6a74f..f057eb9d 100644 --- a/config/autoconfigbackup/crypt_acb.php +++ b/config/autoconfigbackup/crypt_acb.php @@ -132,4 +132,3 @@ function stripos($str, $needle) { return strpos(strtolower($str), strtolower($needle)); } -?> -- cgit v1.2.3 From c832ce3548177fcca2cc9967a5e343ce0de04145 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 24 Aug 2015 13:42:39 +0200 Subject: autoconfigbackup.inc Only remount if the file exists --- config/autoconfigbackup/autoconfigbackup.inc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.inc b/config/autoconfigbackup/autoconfigbackup.inc index ef22a30f..64a16101 100644 --- a/config/autoconfigbackup/autoconfigbackup.inc +++ b/config/autoconfigbackup/autoconfigbackup.inc @@ -74,9 +74,11 @@ function acb_custom_php_validation_command($post, &$input_errors) { } function acb_custom_php_resync_config_command() { - conf_mount_rw(); - unlink_if_exists("/cf/conf/lastpfSbackup.txt"); - conf_mount_ro(); + if (is_file("/cf/conf/lastpfSbackup.txt") { + conf_mount_rw(); + unlink("/cf/conf/lastpfSbackup.txt"); + conf_mount_ro(); + } if (!function_exists("filter_configure")) { require_once("filter.inc"); } -- cgit v1.2.3 From 91008d77d35ef87e54293e852622edd201392c85 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Wed, 16 Sep 2015 13:23:06 +0200 Subject: Use pfSense 2.1.x compatible boot check --- config/autoconfigbackup/autoconfigbackup.inc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.inc b/config/autoconfigbackup/autoconfigbackup.inc index 64a16101..ebd9dc08 100644 --- a/config/autoconfigbackup/autoconfigbackup.inc +++ b/config/autoconfigbackup/autoconfigbackup.inc @@ -74,7 +74,7 @@ function acb_custom_php_validation_command($post, &$input_errors) { } function acb_custom_php_resync_config_command() { - if (is_file("/cf/conf/lastpfSbackup.txt") { + if (is_file("/cf/conf/lastpfSbackup.txt")) { conf_mount_rw(); unlink("/cf/conf/lastpfSbackup.txt"); conf_mount_ro(); @@ -109,7 +109,11 @@ function test_connection($post) { global $savemsg, $config, $g; // Do nothing when booting - if (platform_booting()) { + if (function_exists("platform_booting")) { + if (platform_booting()) { + return; + } + } elseif ($g['booting']) { return; } -- cgit v1.2.3 From 6c7adfa8c26dbe33f15939638bd32b038e74a0e4 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Wed, 16 Sep 2015 13:54:43 +0200 Subject: make pgtitle consistent with the rest of the tabs --- config/autoconfigbackup/autoconfigbackup_stats.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup_stats.php b/config/autoconfigbackup/autoconfigbackup_stats.php index 6c50dd52..73dd54e2 100644 --- a/config/autoconfigbackup/autoconfigbackup_stats.php +++ b/config/autoconfigbackup/autoconfigbackup_stats.php @@ -92,7 +92,7 @@ if ($_REQUEST['delhostname']) { } } -$pgtitle = "Diagnostics: Auto Configuration Stats"; +$pgtitle = "Diagnostics: Auto Configuration Backup Stats"; include("head.inc"); ?> -- cgit v1.2.3 From 6e7c15537353cc2377da63c3f9078502bfa14682 Mon Sep 17 00:00:00 2001 From: doktornotor Date: Mon, 21 Sep 2015 13:57:41 +0200 Subject: Use pfSense 2.1.x compatible boot check --- config/autoconfigbackup/autoconfigbackup.inc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'config') diff --git a/config/autoconfigbackup/autoconfigbackup.inc b/config/autoconfigbackup/autoconfigbackup.inc index ebd9dc08..abfe1a28 100644 --- a/config/autoconfigbackup/autoconfigbackup.inc +++ b/config/autoconfigbackup/autoconfigbackup.inc @@ -163,7 +163,11 @@ function upload_config($reasonm = "") { global $config, $g, $input_errors; // Do nothing when booting - if (platform_booting()) { + if (function_exists("platform_booting")) { + if (platform_booting()) { + return; + } + } elseif ($g['booting']) { return; } -- cgit v1.2.3