コード例 #1
0
ファイル: settings-page.php プロジェクト: Garth619/Femi9
 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')));
             }
         }
     }
 }
 public static function regenerate_server_config($add_responses = true)
 {
     require_once ITSEC_Core::get_core_dir() . '/lib/class-itsec-lib-config-file.php';
     $result = ITSEC_Lib_Config_File::update_server_config();
     $success = !is_wp_error($result);
     $server = ITSEC_Lib_Utility::get_web_server();
     if ($add_responses) {
         if (is_wp_error($result)) {
             ITSEC_Response::add_error($result);
             $file = ITSEC_Lib_Config_File::get_server_config_file_path();
         } else {
             if ('nginx' === $server) {
                 ITSEC_Response::add_message(__('You must restart your NGINX server for the changes to take effect.', 'better-wp-security'));
             }
         }
     }
     return $success;
 }
コード例 #3
0
 private function handle_post()
 {
     if (!defined('DOING_AJAX') || !DOING_AJAX) {
         // Only process the nonce when the request is not an AJAX request as the AJAX handler has its own nonce check.
         ITSEC_Form::check_nonce('itsec-settings-page');
     }
     $post_data = ITSEC_Form::get_post_data();
     $saved = true;
     $js_function_calls = array();
     if (!empty($_POST['widget-id'])) {
         $id = $_POST['widget-id'];
         if (isset($post_data[$id]) && isset($this->widgets[$id])) {
             $widget = $this->widgets[$id];
             $widget->handle_form_post($post_data[$id]);
         }
     } else {
         if (!empty($_POST['module'])) {
             if (isset($this->modules[$_POST['module']])) {
                 $modules = array($_POST['module'] => $this->modules[$_POST['module']]);
             } else {
                 ITSEC_Response::add_error(new WP_Error('itsec-settings-save-unrecognized-module', sprintf(__('The supplied module (%s) is not recognized. The module settings could not be saved.', 'better-wp-security'), $_POST['module'])));
                 $modules = array();
             }
         } else {
             $modules = $this->modules;
         }
         foreach ($modules as $id => $module) {
             if (isset($post_data[$id])) {
                 $results = $module->handle_form_post($post_data[$id]);
             }
         }
         if (ITSEC_Response::is_success()) {
             if (ITSEC_Response::get_show_default_success_message()) {
                 ITSEC_Response::add_message(__('The settings saved successfully.', 'better-wp-security'));
             }
         } else {
             if (ITSEC_Response::get_show_default_error_message()) {
                 $error_count = ITSEC_Response::get_error_count();
                 if ($error_count > 0) {
                     ITSEC_Response::add_error(new WP_Error('itsec-settings-data-not-saved', _n('The settings could not be saved. Please correct the error above and try again.', 'The settings could not be saved. Please correct the errors above and try again.', $error_count, 'better-wp-security')));
                 } else {
                     ITSEC_Response::add_error(new WP_Error('itsec-settings-data-not-saved-missing-error', __('The settings could not be saved. Due to an unknown error. Please try refreshing the page and trying again.', 'better-wp-security')));
                 }
             }
         }
     }
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     ITSEC_Response::maybe_regenerate_wp_config();
     ITSEC_Response::maybe_regenerate_server_config();
     ITSEC_Response::maybe_do_force_logout();
     ITSEC_Response::maybe_do_redirect();
 }
コード例 #4
0
ファイル: settings-page.php プロジェクト: Garth619/Femi9
 public function handle_form_post($data)
 {
     require_once dirname(__FILE__) . '/utility.php';
     if (!empty($data['new_directory_name'])) {
         $results = ITSEC_Content_Directory_Utility::change_content_directory($data['new_directory_name']);
         if (is_wp_error($results)) {
             ITSEC_Response::add_error($results);
             ITSEC_Response::add_error(new WP_Error('itsec-content-directory-settings-page-unable-to-change-content-directory', __('Unable to change the content directory. If the above error cannot be fixed, you may need to manually change the content directory. Instructions on how to change the content directory manually can be found <a href="https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder">here</a>.', 'better-wp-security')));
             ITSEC_Response::set_success(false);
         } else {
             /* translators: 1: New directory name */
             ITSEC_Response::add_message(sprintf(__('The content directory was successfully changed to <code>%1$s</code>.', 'better-wp-security'), $results));
             ITSEC_Response::reload_module($this->id);
         }
     } else {
         if (isset($data['undo_change']) && 'yes' === $data['undo_change']) {
             $results = ITSEC_Content_Directory_Utility::change_content_directory('wp-content');
             if (is_wp_error($results)) {
                 ITSEC_Response::add_error($results);
                 ITSEC_Response::add_error(new WP_Error('itsec-content-directory-settings-page-unable-to-undo-content-directory-change', __('Unable to change the content directory back to <code>wp-content</code>. If the above error cannot be fixed, you may need to manually change the content directory. Instructions on how to change the content directory manually can be found <a href="https://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content_folder">here</a>.', 'better-wp-security')));
                 ITSEC_Response::set_success(false);
             } else {
                 /* translators: 1: New directory name */
                 ITSEC_Response::add_message(sprintf(__('The content directory was successfully changed back to <code>%1$s</code>.', 'better-wp-security'), $results));
                 ITSEC_Response::reload_module($this->id);
             }
         }
     }
 }
コード例 #5
0
 public static function set_settings($slug, $settings)
 {
     $self = self::get_instance();
     $settings_obj = self::get_settings_obj($slug);
     if (is_null($settings_obj) || !is_callable(array($settings_obj, 'set_all'))) {
         $error = new WP_Error('itsec-modules-invalid-settings-object', sprintf(__('Unable to find a valid settings object for %s. Settings were unable to be saved.', 'better-wp-security'), $slug));
         ITSEC_Response::add_error($error);
         return $error;
     }
     return $settings_obj->set_all($settings);
 }
コード例 #6
0
ファイル: scanner.php プロジェクト: Garth619/Femi9
 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>');
         }
     }
 }