diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2008-10-19 03:35:49 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2008-10-19 03:35:49 +0000 |
commit | f02375051357cdb963338d22bceabf08e1e451be (patch) | |
tree | 0c19d6a7b5e6f0ed4d9c50672ca9a0f9b76036e0 /packages | |
parent | e53d05fdf40e31ae3feb94807e6115058e42c13e (diff) | |
download | pfsense-packages-f02375051357cdb963338d22bceabf08e1e451be.tar.gz pfsense-packages-f02375051357cdb963338d22bceabf08e1e451be.tar.bz2 pfsense-packages-f02375051357cdb963338d22bceabf08e1e451be.zip |
* Move upload code to its own function
* Add a new script that will be called from parse_config plugins
Diffstat (limited to 'packages')
-rw-r--r-- | packages/autoconfigbackup/autoconfigbackup.inc | 116 | ||||
-rw-r--r-- | packages/autoconfigbackup/parse_config_upload.php | 5 | ||||
-rw-r--r-- | packages/autoconfigbackup/upload_config_filter.php | 112 |
3 files changed, 122 insertions, 111 deletions
diff --git a/packages/autoconfigbackup/autoconfigbackup.inc b/packages/autoconfigbackup/autoconfigbackup.inc index 271ca68f..0e014117 100644 --- a/packages/autoconfigbackup/autoconfigbackup.inc +++ b/packages/autoconfigbackup/autoconfigbackup.inc @@ -26,6 +26,10 @@ POSSIBILITY OF SUCH DAMAGE. */ +$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); +if(strstr($pfSversion, "1.2")) + require_once("crypt_acb.php"); + /* ensures patches match */ function custom_php_validation_command($post, $input_errors) { global $_POST, $savemsg, $config; @@ -84,4 +88,116 @@ function test_connection($post) { return; } +function upload_config() { + global $config, $g; + + /* + * pfSense upload config to pfSense.org script + * This file plugs into filter.inc (/usr/local/pkg/pf) + * and runs every time the running firewall filter changes. + * + * Written by Scott Ullrich + * (C) 2008 BSD Perimeter LLC + * + */ + + // Define some needed variables + if(!file_exists("/cf/conf/lastpfSbackup.txt")) { + conf_mount_rw(); + touch("/cf/conf/lastpfSbackup.txt"); + conf_mount_ro(); + } + + $last_backup_date = str_replace("\n", "", file_get_contents("/cf/conf/lastpfSbackup.txt")); + $last_config_change = $config['revision']['time']; + $hostname = $config['system']['hostname']; + $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://{$username}:{$password}@portal.pfsense.org/pfSconfigbackups/backup.php"; + + if(!$username or !$password or !$encryptpw) { + + $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, ""); + + } else { + /* If configuration has changed, upload to pfS */ + if($last_backup_date <> $last_config_change) { + + // Mount RW (if needed) + conf_mount_rw(); + // Lock config + config_lock(); + + $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"); + $data = encrypt_data($data, $encryptpw); + tagfile_reformat($data, $data, "config.xml"); + + $post_fields = array( + 'reason' => urlencode($reason), + 'hostname' => urlencode($hostname), + 'configxml' => urlencode($data) + ); + + //url-ify the data for the POST + foreach($post_fields as $key=>$value) + $fields_string .= $key.'='.$value.'&'; + rtrim($fields_string,'&'); + + // Check configuration into the BSDP repo + $curl_session = curl_init(); + curl_setopt($curl_session, CURLOPT_URL, $upload_url); + 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); + $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 occured 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); + } + + // Unlock config + config_unlock(); + // Mount image RO (if needed) + conf_mount_ro(); + + } else { + log_error("No https://portal.pfsense.org backup required."); + } + + } +} + ?>
\ No newline at end of file diff --git a/packages/autoconfigbackup/parse_config_upload.php b/packages/autoconfigbackup/parse_config_upload.php new file mode 100644 index 00000000..d5e6082a --- /dev/null +++ b/packages/autoconfigbackup/parse_config_upload.php @@ -0,0 +1,5 @@ +<?php + +upload_config(); + +?> diff --git a/packages/autoconfigbackup/upload_config_filter.php b/packages/autoconfigbackup/upload_config_filter.php index 2fd88f70..d5e6082a 100644 --- a/packages/autoconfigbackup/upload_config_filter.php +++ b/packages/autoconfigbackup/upload_config_filter.php @@ -1,115 +1,5 @@ <?php -$pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); -if(strstr($pfSversion, "1.2")) - require("crypt_acb.php"); - -/* - * pfSense upload config to pfSense.org script - * This file plugs into filter.inc (/usr/local/pkg/pf) - * and runs every time the running firewall filter changes. - * - * Written by Scott Ullrich - * (C) 2008 BSD Perimeter LLC - * - */ - -// Define some needed variables -if(!file_exists("/cf/conf/lastpfSbackup.txt")) { - conf_mount_rw(); - touch("/cf/conf/lastpfSbackup.txt"); - conf_mount_ro(); -} - -$last_backup_date = str_replace("\n", "", file_get_contents("/cf/conf/lastpfSbackup.txt")); -$last_config_change = $config['revision']['time']; -$hostname = $config['system']['hostname']; -$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://{$username}:{$password}@portal.pfsense.org/pfSconfigbackups/backup.php"; - -if(!$username or !$password or !$encryptpw) { - - $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, ""); - -} else { - /* If configuration has changed, upload to pfS */ - if($last_backup_date <> $last_config_change) { - - // Mount RW (if needed) - conf_mount_rw(); - // Lock config - config_lock(); - - $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"); - $data = encrypt_data($data, $encryptpw); - tagfile_reformat($data, $data, "config.xml"); - - $post_fields = array( - 'reason' => urlencode($reason), - 'hostname' => urlencode($hostname), - 'configxml' => urlencode($data) - ); - - //url-ify the data for the POST - foreach($post_fields as $key=>$value) - $fields_string .= $key.'='.$value.'&'; - rtrim($fields_string,'&'); - - // Check configuration into the BSDP repo - $curl_session = curl_init(); - curl_setopt($curl_session, CURLOPT_URL, $upload_url); - 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); - $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 occured 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); - } - - // Unlock config - config_unlock(); - // Mount image RO (if needed) - conf_mount_ro(); - - } else { - log_error("No https://portal.pfsense.org backup required."); - } - -} +upload_config(); ?> |