Example #1
0
 public function handle_ajax_request($data)
 {
     if ('one-time-scan' === $data['method']) {
         require_once dirname(__FILE__) . '/scanner.php';
         ITSEC_Response::set_response(ITSEC_File_Change_Scanner::run_scan(false));
     } else {
         if ('get-filetree-data' === $data['method']) {
             ITSEC_Response::set_response($this->get_filetree_data($data));
         }
     }
 }
Example #2
0
 public function handle_ajax_request($data)
 {
     global $itsec_globals;
     require_once dirname(__FILE__) . '/class-itsec-malware-scanner.php';
     require_once dirname(__FILE__) . '/class-itsec-malware-scan-results-template.php';
     if (!ITSEC_Core::current_user_can_manage()) {
         $results = new WP_Error('itsec-settings-malware-scan-insufficient-privileges', __('An error prevented the scan from completing as expected. The currently logged in user does not have sufficient permissions to run this scan. You may need to log out of the site and log back in.', 'better-wp-security'));
     } else {
         $results = ITSEC_Malware_Scanner::scan();
     }
     ITSEC_Response::set_response(ITSEC_Malware_Scan_Results_Template::get_html($results, true));
 }
Example #3
0
 public function handle_ajax_request($data)
 {
     if ('reset-api-key' === $data['method']) {
         $defaults = ITSEC_Modules::get_defaults($this->id);
         $results = ITSEC_Modules::set_settings($this->id, $defaults);
         ITSEC_Response::set_response($results['saved']);
         ITSEC_Response::add_errors($results['errors']);
         ITSEC_Response::add_messages($results['messages']);
         if ($results['saved']) {
             ITSEC_Response::reload_module($this->id);
         } else {
             if (empty($results['errors'])) {
                 ITSEC_Response::add_error(new WP_Error('itsec-network-brute-force-settings-page-handle-ajax-request-bad-response', __('An unknown error prevented the API key from being reset properly. An unrecognized response was received. Please wait a few minutes and try again.', 'better-wp-security')));
             }
         }
     }
 }
Example #4
0
 public function handle_ajax_request($data)
 {
     global $itsec_backup;
     if (!isset($itsec_backup)) {
         require_once 'class-itsec-backup.php';
         $itsec_backup = new ITSEC_Backup();
         $itsec_backup->run();
     }
     $result = $itsec_backup->do_backup(true);
     $message = '';
     if (is_wp_error($result)) {
         $errors = ITSEC_Response::get_error_strings($result);
         foreach ($errors as $error) {
             $message .= '<div class="error inline"><p><strong>' . $error . '</strong></p></div>';
         }
     } else {
         if (is_string($result)) {
             $message = '<div class="updated fade inline"><p><strong>' . $result . '</strong></p></div>';
         } else {
             $message = '<div class="error inline"><p><strong>' . sprintf(__('The backup request returned an unexpected response. It returned a response of type <code>%1$s</code>.', 'better-wp-security'), gettype($result)) . '</strong></p></div>';
         }
     }
     ITSEC_Response::set_response($message);
 }
 public function handle_ajax_request()
 {
     global $itsec_globals;
     if (WP_DEBUG) {
         ini_set('display_errors', 1);
     }
     $method = isset($_POST['method']) && is_string($_POST['method']) ? $_POST['method'] : '';
     $module = isset($_POST['module']) && is_string($_POST['module']) ? $_POST['module'] : '';
     if (false === check_ajax_referer('itsec-settings-nonce', 'nonce', false)) {
         ITSEC_Response::add_error(new WP_Error('itsec-settings-page-failed-nonce', __('A nonce security check failed, preventing the request from completing as expected. Please try reloading the page and trying again.', 'better-wp-security')));
     } else {
         if (!ITSEC_Core::current_user_can_manage()) {
             ITSEC_Response::add_error(new WP_Error('itsec-settings-page-insufficient-privileges', __('A permissions security check failed, preventing the request from completing as expected. The currently logged in user does not have sufficient permissions to make this request. Please try reloading the page and trying again.', 'better-wp-security')));
         } else {
             if (empty($method)) {
                 ITSEC_Response::add_error(new WP_Error('itsec-settings-page-missing-method', __('The server did not receive a valid request. The required "method" argument is missing. Please try again.', 'better-wp-security')));
             } else {
                 if ('save' === $method) {
                     $this->handle_post();
                 } else {
                     if (empty($module)) {
                         ITSEC_Response::add_error(new WP_Error('itsec-settings-page-missing-module', __('The server did not receive a valid request. The required "module" argument is missing. Please try again.', 'better-wp-security')));
                     } else {
                         if ('activate' === $method) {
                             ITSEC_Response::set_response(ITSEC_Modules::activate($module));
                         } else {
                             if ('deactivate' === $method) {
                                 ITSEC_Response::set_response(ITSEC_Modules::deactivate($module));
                             } else {
                                 if ('is_active' === $method) {
                                     ITSEC_Response::set_response(ITSEC_Modules::is_active($module));
                                 } else {
                                     if ('get_refreshed_module_settings' === $method) {
                                         ITSEC_Response::set_response($this->get_module_settings($module));
                                     } else {
                                         if ('get_refreshed_widget_settings' === $method) {
                                             ITSEC_Response::set_response($this->get_widget_settings($module));
                                         } else {
                                             if ('handle_module_request' === $method) {
                                                 if (isset($this->modules[$module])) {
                                                     if (isset($_POST['data'])) {
                                                         $returned_value = $this->modules[$module]->handle_ajax_request($_POST['data']);
                                                         if (!is_null($returned_value)) {
                                                             ITSEC_Response::set_response($returned_value);
                                                         }
                                                     } else {
                                                         ITSEC_Response::add_error(new WP_Error('itsec-settings-page-module-request-missing-data', __('The server did not receive a valid request. The required "data" argument for the module is missing. Please try again.', 'better-wp-security')));
                                                     }
                                                 } else {
                                                     ITSEC_Response::add_error(new WP_Error('itsec-settings-page-module-request-invalid-module', __("The server did not receive a valid request. The supplied module, \"{$module}\", does not exist. Please try again.", 'better-wp-security')));
                                                 }
                                             } else {
                                                 if ('handle_widget_request' === $method) {
                                                     if (isset($this->widgets[$module])) {
                                                         if (isset($_POST['data'])) {
                                                             $this->widgets[$module]->handle_ajax_request($_POST['data']);
                                                         } else {
                                                             ITSEC_Response::add_error(new WP_Error('itsec-settings-page-widget-request-missing-data', __('The server did not receive a valid request. The required "data" argument for the widget is missing. Please try again.', 'better-wp-security')));
                                                         }
                                                     } else {
                                                         ITSEC_Response::add_error(new WP_Error('itsec-settings-page-widget-request-invalid-widget', __("The server did not receive a valid request. The supplied widget, \"{$module}\", does not exist. Please try again.", 'better-wp-security')));
                                                     }
                                                 } else {
                                                     ITSEC_Response::add_error(new WP_Error('itsec-settings-page-unknown-method', __('The server did not receive a valid request. An unknown "method" argument was supplied. Please try again.', 'better-wp-security')));
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     ITSEC_Response::send_json();
 }
Example #6
0
 public static function activate_network_brute_force()
 {
     $settings = ITSEC_Modules::get_settings('network-brute-force');
     $settings['email'] = $_POST['data']['email'];
     $settings['updates_optin'] = $_POST['data']['updates_optin'];
     $settings['api_nag'] = false;
     $results = ITSEC_Modules::set_settings('network-brute-force', $settings);
     if (is_wp_error($results)) {
         ITSEC_Response::add_error($results);
     } else {
         if ($results['saved']) {
             ITSEC_Modules::activate('network-brute-force');
             ITSEC_Response::add_js_function_call('setModuleToActive', 'network-brute-force');
             ITSEC_Response::set_response('<p>' . __('Your site is now using Network Brute Force Protection.', 'better-wp-security') . '</p>');
         }
     }
 }