static function backup_file_contents_to_db($src_file_path, $key_description) { global $wpdb, $aio_wp_security; $file_contents = AIOWPSecurity_Utility_File::get_file_contents($src_file_path); $payload = serialize($file_contents); $date_time = current_time('mysql'); $data = array('date_time' => $date_time, 'meta_key1' => $key_description, 'meta_value2' => $payload); //First check if a backup entry already exists in the global_meta table $aiowps_global_meta_tbl_name = AIOWPSEC_TBL_GLOBAL_META_DATA; $resultset = $wpdb->get_row("SELECT * FROM {$aiowps_global_meta_tbl_name} WHERE meta_key1 = '{$key_description}'", OBJECT); if ($resultset) { $where = array('meta_key1' => $key_description); $res = $wpdb->update($aiowps_global_meta_tbl_name, $data, $where); } else { $res = $wpdb->insert($aiowps_global_meta_tbl_name, $data); } if ($res === false) { $aio_wp_security->debug_logger->log_debug("AIOWPSecurity_Utility_File::backup_file_contents_to_db() - Unable to write entry to DB", 4); } return; }
function render_tab3() { global $aio_wp_security; if (isset($_POST['aiowps_restore_wp_config_button'])) { $nonce = $_REQUEST['_wpnonce']; if (!wp_verify_nonce($nonce, 'aiowpsec-restore-wp-config-nonce')) { $aio_wp_security->debug_logger->log_debug("Nonce check failed on wp-config file restore!", 4); die("Nonce check failed on wp-config file restore!"); } if (empty($_POST['aiowps_wp_config_file'])) { $this->show_msg_error(__('Please choose a wp-config.php file to restore from.', 'aiowpsecurity')); } else { //Let's copy the uploaded wp-config.php file into the active root file $new_wp_config_file_path = trim($_POST['aiowps_wp_config_file']); //Verify that file chosen is a wp-config.file $is_wp_config = $this->check_if_wp_config_contents($new_wp_config_file_path); if ($is_wp_config == 1) { $active_root_wp_config = AIOWPSecurity_Utility_File::get_wp_config_file_path(); if (!copy($new_wp_config_file_path, $active_root_wp_config)) { //Failed to make a backup copy $aio_wp_security->debug_logger->log_debug("wp-config.php - Restore from backed up wp-config operation failed!", 4); $this->show_msg_error(__('wp-config.php file restore failed. Please attempt to restore this file manually using FTP.', 'aiowpsecurity')); } else { $this->show_msg_updated(__('Your wp-config.php file has successfully been restored!', 'aiowpsecurity')); } } else { $aio_wp_security->debug_logger->log_debug("wp-config.php restore failed - Contents of restore file appear invalid!", 4); $this->show_msg_error(__('wp-config.php Restore operation failed! Please check the contents of the file you are trying to restore from.', 'aiowpsecurity')); } } } ?> <h2><?php _e('wp-config.php File Operations', 'aiowpsecurity'); ?> </h2> <div class="aio_blue_box"> <?php echo '<p>' . __('Your "wp-config.php" file is one of the most important in your WordPress installation. It is a primary configuration file and contains crucial things such as details of your database and other critical components.', 'aiowpsecurity') . ' <br />' . __('This feature allows you to backup and save your currently active wp-config.php file should you need to re-use the the backed up file in the future.', 'aiowpsecurity') . ' <br />' . __('You can also restore your site\'s wp-config.php settings using a backed up wp-config.php file.', 'aiowpsecurity') . ' </p>'; ?> </div> <?php if (AIOWPSecurity_Utility::is_multisite_install() && get_current_blog_id() != 1) { //Hide config settings if MS and not main site AIOWPSecurity_Utility::display_multisite_message(); } else { ?> <div class="postbox"> <h3><label for="title"><?php _e('Save the current wp-config.php file', 'aiowpsecurity'); ?> </label></h3> <div class="inside"> <form action="" method="POST"> <?php wp_nonce_field('aiowpsec-save-wp-config-nonce'); ?> <p class="description"><?php _e('Click the button below to backup and download the contents of the currently active wp-config.php file.', 'aiowpsecurity'); ?> </p> <input type="submit" name="aiowps_save_wp_config" value="<?php _e('Backup wp-config.php File', 'aiowpsecurity'); ?> " class="button-primary" /> </form> </div></div> <div class="postbox"> <h3><label for="title"><?php _e('Restore from a backed up wp-config file', 'aiowpsecurity'); ?> </label></h3> <div class="inside"> <form action="" method="POST"> <?php wp_nonce_field('aiowpsec-restore-wp-config-nonce'); ?> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('wp-config file to restore from', 'aiowpsecurity'); ?> :</th> <td> <input type="button" id="aiowps_wp_config_file_button" name="aiowps_wp_config_file_button" class="button rbutton" value="Select Your wp-config File" /> <input name="aiowps_wp_config_file" type="text" id="aiowps_wp_config_file" value="" size="80" /> <p class="description"> <?php _e('After selecting your file click the button below to restore your site using the backed up wp-config file (wp-config.php.backup.txt).', 'aiowpsecurity'); ?> </p> </td> </tr> </table> <input type="submit" name="aiowps_restore_wp_config_button" value="<?php _e('Restore wp-config File', 'aiowpsecurity'); ?> " class="button-primary" /> </form> </div></div> <div class="postbox"> <h3><label for="title"><?php _e('View Contents of the currently active wp-config.php file', 'aiowpsecurity'); ?> </label></h3> <div class="inside"> <?php $wp_config_file = AIOWPSecurity_Utility_File::get_wp_config_file_path(); $wp_config_contents = AIOWPSecurity_Utility_File::get_file_contents($wp_config_file); ?> <textarea class="aio_text_area_file_output aio_width_80 aio_spacer_10_tb" rows="20" readonly><?php echo $wp_config_contents; ?> </textarea> </div></div> <?php } //End if statement }
function render_tab4() { global $wpdb; $file_selected = isset($_POST["aiowps_log_file"]) ? $_POST["aiowps_log_file"] : ''; ?> <div class="postbox"> <h3 class="hndle"><label for="title"><?php _e('View Logs for All In WP Security & Firewall Plugin', 'all-in-one-wp-security-and-firewall'); ?> </label></h3> <div class="inside"> <form action="" method="POST"> <?php wp_nonce_field('aiowpsec-dashboard-logs-nonce'); ?> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Log File', 'all-in-one-wp-security-and-firewall'); ?> :</th> <td> <select id="aiowps_log_file" name="aiowps_log_file"> <option value=""><?php _e('--Select a file--', 'all-in-one-wp-security-and-firewall'); ?> </option> <option value="wp-security-log.txt" <?php selected($file_selected, 'wp-security-log.txt'); ?> >wp-security-log</option> <option value="wp-security-log-cron-job.txt" <?php selected($file_selected, 'wp-security-log-cron-job.txt'); ?> >wp-security-log-cron-job</option> </select> <span class="description"><?php _e('Select one of the log files to view the contents', 'all-in-one-wp-security-and-firewall'); ?> </span> </td> </tr> </table> <input type="submit" name="aiowps_view_logs" value="<?php _e('View Logs', 'all-in-one-wp-security-and-firewall'); ?> " class="button-primary" /> </form> </div></div> <?php if (isset($_POST['aiowps_view_logs'])) { $error = ''; $nonce = $_REQUEST['_wpnonce']; if (!wp_verify_nonce($nonce, 'aiowpsec-dashboard-logs-nonce')) { $aio_wp_security->debug_logger->log_debug("Nonce check failed on dashboard view logs!", 4); die("Nonce check failed on dashboard view logs!"); } if (!empty($file_selected)) { ?> <div class="postbox"> <h3 class="hndle"><label for="title"><?php echo __('Log File Contents For', 'all-in-one-wp-security-and-firewall') . ': ' . $file_selected; ?> </label></h3> <div class="inside"> <?php $aiowps_log_dir = AIO_WP_SECURITY_PATH . '/logs'; $log_file = $aiowps_log_dir . '/' . $file_selected; if (file_exists($log_file)) { $log_contents = AIOWPSecurity_Utility_File::get_file_contents($log_file); } else { $log_contents = ''; } if (empty($log_contents)) { $log_contents = $file_selected . ': ' . __('Log file is empty!', 'all-in-one-wp-security-and-firewall'); } ?> <textarea class="aio_text_area_file_output aio_half_width aio_spacer_10_tb" rows="15" readonly><?php echo $log_contents; ?> </textarea> </div> </div> <?php } } ?> <?php }