function bps_email_alerts_log_file_options() { $SecurityLogEmailOptions = get_option('bulletproof_security_options_email'); $admin_email = get_option('admin_email'); $bps_option_name = 'bulletproof_security_options_email'; $bps_new_value_1 = $admin_email; $bps_new_value_2 = $admin_email; $bps_new_value_3 = ''; $bps_new_value_4 = ''; $bps_new_value_5 = 'lockoutOnly'; $bps_new_value_6 = '500KB'; $bps_new_value_7 = 'email'; $bps_new_value_8 = '500KB'; $bps_new_value_9 = 'email'; $BPS_Options = array('bps_send_email_to' => $bps_new_value_1, 'bps_send_email_from' => $bps_new_value_2, 'bps_send_email_cc' => $bps_new_value_3, 'bps_send_email_bcc' => $bps_new_value_4, 'bps_login_security_email' => $bps_new_value_5, 'bps_security_log_size' => $bps_new_value_6, 'bps_security_log_emailL' => $bps_new_value_7, 'bps_dbb_log_size' => $bps_new_value_8, 'bps_dbb_log_email' => $bps_new_value_9); if (!get_option($bps_option_name)) { foreach ($BPS_Options as $key => $value) { update_option('bulletproof_security_options_email', $BPS_Options); } } else { if (!$SecurityLogEmailOptions['bps_dbb_log_size'] && !$SecurityLogEmailOptions['bps_dbb_log_email']) { $BPS_Options = array('bps_send_email_to' => $SecurityLogEmailOptions['bps_send_email_to'], 'bps_send_email_from' => $SecurityLogEmailOptions['bps_send_email_from'], 'bps_send_email_cc' => $SecurityLogEmailOptions['bps_send_email_cc'], 'bps_send_email_bcc' => $SecurityLogEmailOptions['bps_send_email_bcc'], 'bps_login_security_email' => $SecurityLogEmailOptions['bps_login_security_email'], 'bps_security_log_size' => $SecurityLogEmailOptions['bps_security_log_size'], 'bps_security_log_emailL' => $SecurityLogEmailOptions['bps_security_log_emailL'], 'bps_dbb_log_size' => '500KB', 'bps_dbb_log_email' => 'email'); foreach ($BPS_Options as $key => $value) { update_option('bulletproof_security_options_email', $BPS_Options); } } } $bps_option_name_dbb = 'bulletproof_security_options_DBB_log'; $bps_new_value_dbb = bpsPro_DBB_LogLastMod_wp_secs(); $BPS_Options_dbb = array('bps_dbb_log_date_mod' => $bps_new_value_dbb); if (!get_option($bps_option_name_dbb)) { foreach ($BPS_Options_dbb as $key => $value) { update_option('bulletproof_security_options_DBB_log', $BPS_Options_dbb); } } }
function bpsSetupWizard() { if (isset($_POST['Submit-Setup-Wizard']) && current_user_can('manage_options')) { check_admin_referer('bps_setup_wizard'); set_time_limit(300); global $wpdb, $wp_version, $bps_version; $time_start = microtime(true); $Stable_name = $wpdb->prefix . "bpspro_seclog_ignore"; $Ltable_name = $wpdb->prefix . "bpspro_login_security"; $DBBtable_name = $wpdb->prefix . "bpspro_db_backup"; $successTextBegin = '<font color="green"><strong>'; $successMessage = __(' DB Table created Successfully!', 'bulletproof-security'); $successTextEnd = '</strong></font><br>'; $failTextBegin = '<font color="red"><strong>'; $failMessage = __('Error: Unable to create DB Table ', 'bulletproof-security'); $failTextEnd = '</strong></font><br>'; $bps_setup_wizard = 'bulletproof_security_options_wizard_free'; $BPS_Wizard = array('bps_wizard_free' => 'wizard'); if (!get_option($bps_setup_wizard)) { foreach ($BPS_Wizard as $key => $value) { update_option('bulletproof_security_options_wizard_free', $BPS_Wizard); } } else { foreach ($BPS_Wizard as $key => $value) { update_option('bulletproof_security_options_wizard_free', $BPS_Wizard); } } echo '<h3>' . __('BPS Setup Verification & Error Checks', 'bulletproof-security') . '</h3>'; echo '<div style="font-size:12px;margin:-10px 0px 10px 0px;font-weight:bold;">' . __('If you see all Green font messages displayed below, the Setup Wizard setup completed successfully.', 'bulletproof-security') . '<br>' . __('If you see any Red font or Blue font messages displayed below, click the Read Me help button above and read the "Notes" help section.', 'bulletproof-security') . '<br>' . __('Click the Read Me help button above for a list of recommended BPS Video Tutorials to watch.', 'bulletproof-security') . '</div>'; echo '<div id="Wizard-background" style="max-height:250px;width:85%;overflow:auto;margin-bottom:20px;padding:10px;border:2px solid black;background-color:#ffffe0;">'; echo '<span class="setup-wizard-checks-text">'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security Database Tables Setup', 'bulletproof-security') . '</div>'; echo '<div id="SWDBTables" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $Stable_name)) == $Stable_name) { echo $successTextBegin . $Stable_name . $successMessage . $successTextEnd; } else { echo $failTextBegin . $failMessage . $Stable_name . $failTextEnd; } if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $Ltable_name)) == $Ltable_name) { echo $successTextBegin . $Ltable_name . $successMessage . $successTextEnd; } else { echo $failTextBegin . $failMessage . $Ltable_name . $failTextEnd; } if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $DBBtable_name)) == $DBBtable_name) { echo $successTextBegin . $DBBtable_name . $successMessage . $successTextEnd; } else { echo $failTextBegin . $failMessage . $DBBtable_name . $failTextEnd; } echo '</p></div>'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security Core Folders Setup', 'bulletproof-security') . '</div>'; echo '<div id="SWFolders" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; $successMessage2 = __(' Folder created Successfully!', 'bulletproof-security'); $failMessage2 = __('Error: Unable to create Folder ', 'bulletproof-security'); if (is_dir(WP_CONTENT_DIR . '/bps-backup')) { echo $successTextBegin . WP_CONTENT_DIR . '/bps-backup' . $successMessage2 . $successTextEnd; } else { echo $failTextBegin . $failMessage2 . WP_CONTENT_DIR . '/bps-backup' . $failTextEnd; } if (is_dir(WP_CONTENT_DIR . '/bps-backup')) { echo $successTextBegin . WP_CONTENT_DIR . '/bps-backup/master-backups' . $successMessage2 . $successTextEnd; } else { echo $failTextBegin . $failMessage2 . WP_CONTENT_DIR . '/bps-backup/master-backups' . $failTextEnd; } if (is_dir(WP_CONTENT_DIR . '/bps-backup/logs')) { echo $successTextBegin . WP_CONTENT_DIR . '/bps-backup/logs' . $successMessage2 . $successTextEnd; } else { echo $failTextBegin . $failMessage2 . WP_CONTENT_DIR . '/bps-backup/logs' . $failTextEnd; } echo '</p></div>'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security Core Files Setup', 'bulletproof-security') . '</div>'; echo '<div id="SWFiles" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; $successMessage3 = __(' File created or updated Successfully!', 'bulletproof-security'); $failMessage3 = __('Error: Unable to create or update File ', 'bulletproof-security'); bpsSetupWizardCreateRootHtaccess(); bpsSetupWizardCreateWpadminHtaccess(); bpsSetupWizardCreateDefaultHtaccess(); $htaccess_dir = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess'; $secureHtaccess = $htaccess_dir . '/secure.htaccess'; $wpadminHtaccess = $htaccess_dir . '/wpadmin-secure.htaccess'; $defaultHtaccess = $htaccess_dir . '/default.htaccess'; if (is_writable($secureHtaccess)) { echo $successTextBegin . $secureHtaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $secureHtaccess . $failTextEnd; } if (is_writable($wpadminHtaccess)) { echo $successTextBegin . $wpadminHtaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $wpadminHtaccess . $failTextEnd; } if (is_writable($defaultHtaccess)) { echo $successTextBegin . $defaultHtaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $defaultHtaccess . $failTextEnd; } $bps_ARHtaccess = WP_CONTENT_DIR . '/bps-backup/.htaccess'; $bpsProDBBLogARQ = WP_CONTENT_DIR . '/bps-backup/logs/db_backup_log.txt'; $bpsProSecLogARQ = WP_CONTENT_DIR . '/bps-backup/logs/http_error_log.txt'; if (file_exists($bps_ARHtaccess)) { echo $successTextBegin . $bps_ARHtaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $bps_ARHtaccess . $failTextEnd; } if (file_exists($bpsProDBBLogARQ)) { echo $successTextBegin . $bpsProDBBLogARQ . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $bpsProDBBLogARQ . $failTextEnd; } if (file_exists($bpsProSecLogARQ)) { echo $successTextBegin . $bpsProSecLogARQ . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $bpsProSecLogARQ . $failTextEnd; } $bps_denyall_htaccess_renamed = WP_PLUGIN_DIR . '/bulletproof-security/admin/htaccess/.htaccess'; $security_log_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/security-log/.htaccess'; $system_info_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/system-info/.htaccess'; $login_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/login/.htaccess'; $MMode_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/maintenance/.htaccess'; $DBB_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/db-backup-security/.htaccess'; $core_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/core/.htaccess'; $wizard_denyall_htaccess = WP_PLUGIN_DIR . '/bulletproof-security/admin/wizard/.htaccess'; if (file_exists($bps_denyall_htaccess_renamed)) { echo $successTextBegin . $bps_denyall_htaccess_renamed . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $bps_denyall_htaccess_renamed . $failTextEnd; } if (file_exists($security_log_denyall_htaccess)) { echo $successTextBegin . $security_log_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $security_log_denyall_htaccess . $failTextEnd; } if (file_exists($system_info_denyall_htaccess)) { echo $successTextBegin . $system_info_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $system_info_denyall_htaccess . $failTextEnd; } if (file_exists($login_denyall_htaccess)) { echo $successTextBegin . $login_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $login_denyall_htaccess . $failTextEnd; } if (file_exists($MMode_denyall_htaccess)) { echo $successTextBegin . $MMode_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $MMode_denyall_htaccess . $failTextEnd; } if (file_exists($DBB_denyall_htaccess)) { echo $successTextBegin . $DBB_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $DBB_denyall_htaccess . $failTextEnd; } if (file_exists($core_denyall_htaccess)) { echo $successTextBegin . $core_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $core_denyall_htaccess . $failTextEnd; } if (file_exists($wizard_denyall_htaccess)) { echo $successTextBegin . $wizard_denyall_htaccess . $successMessage3 . $successTextEnd; } else { echo $failTextBegin . $failMessage3 . $wizard_denyall_htaccess . $failTextEnd; } echo '</p></div>'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security DB Backup Setup', 'bulletproof-security') . '</div>'; echo '<div id="DBBackup" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; bpsSetupWizard_dbbackup_folder_check(); $successMessage4 = __(' DB Option created or updated Successfully!', 'bulletproof-security'); $bps_option_name_dbb = 'bulletproof_security_options_DBB_log'; $bps_new_value_dbb = bpsPro_DBB_LogLastMod_wp_secs(); $BPS_Options_dbb = array('bps_dbb_log_date_mod' => $bps_new_value_dbb); if (!get_option($bps_option_name_dbb)) { update_option('bulletproof_security_options_DBB_log', $BPS_Options_dbb); echo $successTextBegin . $bps_option_name_dbb . $successMessage4 . $successTextEnd; } else { update_option('bulletproof_security_options_DBB_log', $BPS_Options_dbb); echo $successTextBegin . $bps_option_name_dbb . $successMessage4 . $successTextEnd; } echo '</p></div>'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security Security Log User Agent Filter Setup', 'bulletproof-security') . '</div>'; echo '<div id="SLuserAgentFilter" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; bpsSetupWizard_autoupdate_useragent_filters(); echo '</p></div>'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security Email Alerting & Log File Options Setup', 'bulletproof-security') . '</div>'; echo '<div id="SWSmonitor" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; $admin_email = get_option('admin_email'); $successMessage7 = __(' DB Option created or updated Successfully!', 'bulletproof-security'); $bps_option_name7 = 'bulletproof_security_options_email'; $bps_new_value7 = $admin_email; $bps_new_value7_1 = $admin_email; $bps_new_value7_2 = ''; $bps_new_value7_3 = ''; $bps_new_value7_4 = 'lockoutOnly'; $bps_new_value7_9 = '500KB'; $bps_new_value7_10 = 'email'; $bps_new_value7_18 = 'email'; $bps_new_value7_19 = '500KB'; $BPS_Options7 = array('bps_send_email_to' => $bps_new_value7, 'bps_send_email_from' => $bps_new_value7_1, 'bps_send_email_cc' => $bps_new_value7_2, 'bps_send_email_bcc' => $bps_new_value7_3, 'bps_login_security_email' => $bps_new_value7_4, 'bps_security_log_size' => $bps_new_value7_9, 'bps_security_log_emailL' => $bps_new_value7_10, 'bps_dbb_log_email' => $bps_new_value7_18, 'bps_dbb_log_size' => $bps_new_value7_19); if (!get_option($bps_option_name7)) { foreach ($BPS_Options7 as $key => $value) { update_option('bulletproof_security_options_email', $BPS_Options7); echo $successTextBegin . $key . $successMessage7 . $successTextEnd; } } else { $BPS_Email_Options = get_option('bulletproof_security_options_email'); $BPS_Options7 = array('bps_send_email_to' => $BPS_Email_Options['bps_send_email_to'], 'bps_send_email_from' => $BPS_Email_Options['bps_send_email_from'], 'bps_send_email_cc' => $BPS_Email_Options['bps_send_email_cc'], 'bps_send_email_bcc' => $BPS_Email_Options['bps_send_email_bcc'], 'bps_login_security_email' => $BPS_Email_Options['bps_login_security_email'], 'bps_security_log_size' => $BPS_Email_Options['bps_security_log_size'], 'bps_security_log_emailL' => $BPS_Email_Options['bps_security_log_emailL'], 'bps_dbb_log_email' => $BPS_Email_Options['bps_dbb_log_email'], 'bps_dbb_log_size' => $BPS_Email_Options['bps_dbb_log_size']); foreach ($BPS_Options7 as $key => $value) { update_option('bulletproof_security_options_email', $BPS_Options7); echo $successTextBegin . $key . $successMessage7 . $successTextEnd; } } echo '</p></div>'; echo '<div style="color:black;font-size:1.13em;font-weight:bold;margin-bottom:15px;">' . __('BulletProof Security Login Security & Monitoring Options Setup', 'bulletproof-security') . '</div>'; echo '<div id="SWLoginSecurity" style="border-top:3px solid #999999;margin-top:-10px;"><p>'; $successMessage8 = __(' DB Option created or updated Successfully!', 'bulletproof-security'); $bps_option_name8 = 'bulletproof_security_options_login_security'; $bps_new_value8 = '3'; $bps_new_value8_1 = '60'; $bps_new_value8_2 = '60'; $bps_new_value8_3 = ''; $bps_new_value8_4 = 'On'; $bps_new_value8_5 = 'logLockouts'; $bps_new_value8_6 = 'wpErrors'; $bps_new_value8_7 = 'On'; $bps_new_value8_8 = 'enable'; $bps_new_value8_9 = 'ascending'; $BPS_Options8 = array('bps_max_logins' => $bps_new_value8, 'bps_lockout_duration' => $bps_new_value8_1, 'bps_manual_lockout_duration' => $bps_new_value8_2, 'bps_max_db_rows_display' => $bps_new_value8_3, 'bps_login_security_OnOff' => $bps_new_value8_4, 'bps_login_security_logging' => $bps_new_value8_5, 'bps_login_security_errors' => $bps_new_value8_6, 'bps_login_security_remaining' => $bps_new_value8_7, 'bps_login_security_pw_reset' => $bps_new_value8_8, 'bps_login_security_sort' => $bps_new_value8_9); if (!get_option($bps_option_name8)) { foreach ($BPS_Options8 as $key => $value) { update_option('bulletproof_security_options_login_security', $BPS_Options8); echo $successTextBegin . $key . $successMessage8 . $successTextEnd; } } else { $BPS_LSM_Options = get_option('bulletproof_security_options_login_security'); $BPS_Options_lsm = array('bps_max_logins' => $BPS_LSM_Options['bps_max_logins'], 'bps_lockout_duration' => $BPS_LSM_Options['bps_lockout_duration'], 'bps_manual_lockout_duration' => $BPS_LSM_Options['bps_manual_lockout_duration'], 'bps_max_db_rows_display' => $BPS_LSM_Options['bps_max_db_rows_display'], 'bps_login_security_OnOff' => $BPS_LSM_Options['bps_login_security_OnOff'], 'bps_login_security_logging' => $BPS_LSM_Options['bps_login_security_logging'], 'bps_login_security_errors' => $BPS_LSM_Options['bps_login_security_errors'], 'bps_login_security_remaining' => $BPS_LSM_Options['bps_login_security_remaining'], 'bps_login_security_pw_reset' => $BPS_LSM_Options['bps_login_security_pw_reset'], 'bps_login_security_sort' => $BPS_LSM_Options['bps_login_security_sort']); foreach ($BPS_Options_lsm as $key => $value) { update_option('bulletproof_security_options_login_security', $BPS_Options_lsm); echo $successTextBegin . $key . $successMessage8 . $successTextEnd; } } // Custom Code - no echo/output: pre-save CC DB options for Custom Code Export|Import features ONLY if DB options do not exist bpsSetupWizardCustomCodePresave(); echo '</p></div>'; echo '</span>'; echo '<div id="message" class="updated" style="border:1px solid #999999;margin-left:70px;background-color:#ffffe0;"><p>'; $text = '<strong><font color="green">' . __('The Setup Wizard has completed BPS Setup.', 'bulletproof-security') . '<br>' . __('Check the "BPS Setup Verification & Error Checks" section below for any errors in Red Font.', 'bulletproof-security') . '</font></strong><br>'; echo $text; echo '</p></div>'; $time_end = microtime(true); $wizard_run_time = $time_end - $time_start; $wizard_time_display = '<strong>' . __('Setup Wizard Completion Time: ', 'bulletproof-security') . '</strong>' . round($wizard_run_time, 2) . ' Seconds'; echo '<div id="message" class="updated" style="border:1px solid #999999;margin-left:70px;background-color:#ffffe0;"><p>'; echo bpsPro_memory_resource_usage(); echo $wizard_time_display; echo '</p></div>'; echo '</div>'; } // end if (isset($_POST['Submit-Setup-Wizard']) }
function bpsPro_db_backup($db_backup, $tables, $job_name, $job_type, $email_zip) { global $wpdb; $time_start = microtime(true); if ($email_zip == 'Delete') { $email_zip_log = 'Yes & Delete'; } else { $email_zip_log = $email_zip; } if ($email_zip == 'EmailOnly') { $email_zip_log = 'Send Email Only'; } else { $email_zip_log = $email_zip; } $timeNow = time(); $gmt_offset = get_option('gmt_offset') * 3600; $timestamp = date_i18n(get_option('date_format'), strtotime("11/15-1976")) . ' ' . date_i18n(get_option('time_format'), $timeNow + $gmt_offset); $handle = fopen($db_backup, 'wb'); if ($handle) { fwrite($handle, "-- -------------------------------------------\n"); } fwrite($handle, "-- BulletProof Security DB Backup\n"); fwrite($handle, "-- Support: http://forum.ait-pro.com/\n"); fwrite($handle, "-- Backup Job Name: " . $job_name . "\n"); fwrite($handle, "-- DB Backup Job Type: " . $job_type . "\n"); fwrite($handle, "-- Email DB Backup: " . $email_zip_log . "\n"); fwrite($handle, "-- DB Backup Time: " . $timestamp . "\n"); fwrite($handle, "-- DB Name: " . DB_NAME . "\n"); fwrite($handle, "-- DB Table Prefix: " . $wpdb->base_prefix . "\n"); fwrite($handle, "-- Website URL: " . get_bloginfo('url') . "\n"); fwrite($handle, "-- WP ABSPATH: " . ABSPATH . "\n"); fwrite($handle, "-- -------------------------------------------\n\n"); fwrite($handle, "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n"); fwrite($handle, "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n"); fwrite($handle, "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n"); fwrite($handle, "/*!40101 SET NAMES " . DB_CHARSET . " */;\n"); fwrite($handle, "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n"); fwrite($handle, "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n"); fwrite($handle, "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n"); fwrite($handle, "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n\n"); if (!empty($tables)) { foreach ($tables as $table_array) { $table = current($table_array); $create = $wpdb->get_var("SHOW CREATE TABLE " . $table, 1); $myisam = strpos($create, 'MyISAM'); fwrite($handle, "--\n-- BEGIN Table " . $table . "\n--\n\nDROP TABLE IF EXISTS `" . $table . "`;\n/*!40101 SET @saved_cs_client = @@character_set_client */;\n/*!40101 SET character_set_client = '" . DB_CHARSET . "' */;\n" . $create . ";\n/*!40101 SET character_set_client = @saved_cs_client */;\n\n"); $data = $wpdb->get_results("SELECT * FROM `" . $table . "` LIMIT 1000", ARRAY_A); if (!empty($data)) { fwrite($handle, "LOCK TABLES `" . $table . "` WRITE;\n"); if (false !== $myisam) { fwrite($handle, "/*!40000 ALTER TABLE `" . $table . "` DISABLE KEYS */;\n\n"); } $offset = 0; do { foreach ($data as $entry) { foreach ($entry as $key => $value) { if (NULL === $value) { $entry[$key] = "NULL"; } elseif ("" === $value || false === $value) { $entry[$key] = "''"; } elseif (!is_numeric($value)) { $entry[$key] = "'" . esc_sql($value) . "'"; } } fwrite($handle, "INSERT INTO `" . $table . "` ( " . implode(", ", array_keys($entry)) . " )\n VALUES ( " . implode(", ", $entry) . " );\n"); } $offset += 1000; $data = $wpdb->get_results("SELECT * FROM `" . $table . "` LIMIT " . $offset . ",1000", ARRAY_A); } while (!empty($data)); fwrite($handle, "\n--\n-- END Table " . $table . "\n--\n"); if (false !== $myisam) { fwrite($handle, "\n/*!40000 ALTER TABLE `" . $table . "` ENABLE KEYS */;"); } fwrite($handle, "\nUNLOCK TABLES;\n\n"); } } } fwrite($handle, "/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;\n"); fwrite($handle, "/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;\n"); fwrite($handle, "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n"); fwrite($handle, "/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;\n"); fwrite($handle, "/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;\n"); fwrite($handle, "/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;\n"); fwrite($handle, "/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;\n"); fclose($handle); if (file_exists($db_backup)) { $DBBoptions = get_option('bulletproof_security_options_db_backup'); // Use ZipArchive if (class_exists('ZipArchive')) { $zip = new ZipArchive(); $filename = $DBBoptions['bps_db_backup_folder'] . '/' . date('Y-m-d-\\t\\i\\m\\e-g-i-s-a', $timeNow + $gmt_offset) . '.zip'; if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) { exit("Error: Cannot Open {$filename}\n"); } $zip->addFile($db_backup, DB_NAME . ".sql"); $zip->close(); @unlink($db_backup); } else { // Use PCLZip define('PCLZIP_TEMPORARY_DIR', $DBBoptions['bps_db_backup_folder'] . '/'); require_once ABSPATH . 'wp-admin/includes/class-pclzip.php'; if (ini_get('mbstring.func_overload') && function_exists('mb_internal_encoding')) { $previous_encoding = mb_internal_encoding(); mb_internal_encoding('ISO-8859-1'); } $filename = $DBBoptions['bps_db_backup_folder'] . '/' . date('Y-m-d-\\t\\i\\m\\e-g-i-s-a', $timeNow + $gmt_offset) . '.zip'; $archive = new PclZip($filename); $sql_filename = str_replace($DBBoptions['bps_db_backup_folder'] . '/', "", $db_backup); $db_backup = str_replace(array('\\', '//'), "/", $db_backup); $db_backup_folder = str_replace(DB_NAME . '.sql', "", $db_backup); $v_list = $archive->create($db_backup_folder . $sql_filename, PCLZIP_OPT_REMOVE_PATH, $db_backup_folder); @unlink($db_backup); } } $time_end = microtime(true); $backup_time = $time_end - $time_start; $backup_time_log = 'Backup Job Completion Time: ' . round($backup_time, 2) . ' Seconds'; $backup_time_display = '<strong>Backup Job Completion Time: </strong>' . round($backup_time, 2) . ' Seconds'; $bpsDBBLog = WP_CONTENT_DIR . '/bps-backup/logs/db_backup_log.txt'; echo '<div id="message" class="updated" style="border:1px solid #999999;margin-left:220px;background-color:#ffffe0;"><p>'; echo bpsPro_memory_resource_usage(); echo $backup_time_display; echo '</p></div>'; $log_contents = "\r\n" . '[Backup Job Logged: ' . $timestamp . ']' . "\r\n" . 'Backup Job Name: ' . $job_name . "\r\n" . 'Backup Job Type: ' . $job_type . "\r\n" . 'Email DB Backup: ' . $email_zip_log . "\r\n" . $backup_time_log . "\r\n" . bpsPro_memory_resource_usage_logging() . "\r\n" . 'Zip Backup File Name: ' . $filename . "\r\n"; if (is_writable($bpsDBBLog)) { if (!($handle = fopen($bpsDBBLog, 'a'))) { exit; } if (fwrite($handle, $log_contents) === FALSE) { exit; } fclose($handle); } $DBBLog_Options = array('bps_dbb_log_date_mod' => bpsPro_DBB_LogLastMod_wp_secs()); foreach ($DBBLog_Options as $key => $value) { update_option('bulletproof_security_options_DBB_log', $DBBLog_Options); } $DBB_Backup_Options = array('bps_db_backup' => $DBBoptions['bps_db_backup'], 'bps_db_backup_description' => $DBBoptions['bps_db_backup_description'], 'bps_db_backup_folder' => $DBBoptions['bps_db_backup_folder'], 'bps_db_backup_download_link' => $DBBoptions['bps_db_backup_download_link'], 'bps_db_backup_job_type' => $DBBoptions['bps_db_backup_job_type'], 'bps_db_backup_frequency' => $DBBoptions['bps_db_backup_frequency'], 'bps_db_backup_start_time_hour' => $DBBoptions['bps_db_backup_start_time_hour'], 'bps_db_backup_start_time_weekday' => $DBBoptions['bps_db_backup_start_time_weekday'], 'bps_db_backup_start_time_month_date' => $DBBoptions['bps_db_backup_start_time_month_date'], 'bps_db_backup_email_zip' => $DBBoptions['bps_db_backup_email_zip'], 'bps_db_backup_delete' => $DBBoptions['bps_db_backup_delete'], 'bps_db_backup_status_display' => $timestamp); foreach ($DBB_Backup_Options as $key => $value) { update_option('bulletproof_security_options_db_backup', $DBB_Backup_Options); } // Send Email last: attaching a large zip file may fail if ($job_type != 'Manual' || $email_zip != 'No') { $Email_options = get_option('bulletproof_security_options_email'); $bps_email_to = $Email_options['bps_send_email_to']; $bps_email_from = $Email_options['bps_send_email_from']; $bps_email_cc = $Email_options['bps_send_email_cc']; $bps_email_bcc = $Email_options['bps_send_email_bcc']; $justUrl = get_site_url(); if ($email_zip == 'EmailOnly') { $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: {$bps_email_from}" . "\r\n"; $headers .= "Cc: {$bps_email_cc}" . "\r\n"; $headers .= "Bcc: {$bps_email_bcc}" . "\r\n"; $subject = " BPS DB Backup Completed - {$timestamp} "; $message = '<p><font color="blue"><strong>DB Backup Has Completed For:</strong></font></p>'; $message .= '<p>Website: ' . $justUrl . '</p>'; $mailed = wp_mail($bps_email_to, $subject, $message, $headers); } if ($email_zip == 'Delete' || $email_zip == 'Yes') { $attachments = array($filename); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $headers .= "From: {$bps_email_from}" . "\r\n"; $headers .= "Cc: {$bps_email_cc}" . "\r\n"; $headers .= "Bcc: {$bps_email_bcc}" . "\r\n"; $subject = " BPS DB Backup Completed - {$timestamp} "; $message = '<p><font color="blue"><strong>DB Backup File is Attached For:</strong></font></p>'; $message .= '<p>Website: ' . $justUrl . '</p>'; $mailed = wp_mail($bps_email_to, $subject, $message, $headers, $attachments); } if (@$mailed && $email_zip == 'Delete') { unlink($filename); } } }