Пример #1
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_ssl');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['frontend'] = isset($itsec_bwps_options['ssl_frontend']) ? intval($itsec_bwps_options['ssl_frontend']) : 0;
             update_site_option('itsec_ssl', $current_options);
             ITSEC_Response::regenerate_wp_config();
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_ssl');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // If anything in this module is being used activate it, otherwise deactivate it
             $activate = false;
             foreach ($current_options as $on) {
                 if ($on) {
                     $activate = true;
                     break;
                 }
             }
             if ($activate) {
                 ITSEC_Modules::activate('ssl');
             } else {
                 ITSEC_Modules::deactivate('ssl');
             }
             // remove 'enabled' which isn't used in the new module
             unset($current_options['enabled']);
             ITSEC_Modules::set_settings('ssl', $current_options);
         }
     }
 }
Пример #2
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_backup');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['backup_enabled']) && $itsec_bwps_options['backup_enabled'] == 1 ? true : false;
             $current_options['interval'] = isset($itsec_bwps_options['backup_interval']) ? intval($itsec_bwps_options['backup_interval']) : 1;
             update_site_option('itsec_backup', $current_options);
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_backup');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // Make sure the new module is properly activated or deactivated
             if ($current_options['enabled']) {
                 ITSEC_Modules::activate('backup');
             } else {
                 ITSEC_Modules::deactivate('backup');
             }
             if (isset($current_options['location']) && !is_dir($current_options['location'])) {
                 unset($current_options['location']);
             }
             $options = ITSEC_Modules::get_defaults('backup');
             foreach ($options as $name => $value) {
                 if (isset($current_options[$name])) {
                     $options[$name] = $current_options[$name];
                 }
             }
             ITSEC_Modules::set_settings('backup', $options);
         }
     }
 }
Пример #3
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_global');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // log_type used to be 0 for database, 1 for file, 2 for both
             switch ($current_options['log_type']) {
                 case 2:
                     $current_options['log_type'] = 'both';
                     break;
                 case 1:
                     $current_options['log_type'] = 'file';
                     break;
                 default:
                     $current_options['log_type'] = 'database';
             }
             if (isset($current_options['log_location']) && !is_dir($current_options['log_location'])) {
                 unset($current_options['log_location']);
             }
             if (isset($current_options['nginx_file']) && !is_dir(dirname($current_options['nginx_file']))) {
                 unset($current_options['nginx_file']);
             }
             $settings = ITSEC_Modules::get_defaults('global');
             foreach ($settings as $index => $setting) {
                 if (isset($current_options[$index])) {
                     $settings[$index] = $current_options[$index];
                 }
             }
             ITSEC_Modules::set_settings('global', $settings);
         }
     }
 }
Пример #4
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_brute_force');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['ll_enabled']) && $itsec_bwps_options['ll_enabled'] == 1 ? true : false;
             $current_options['max_attempts_host'] = isset($itsec_bwps_options['ll_maxattemptshost']) ? intval($itsec_bwps_options['ll_maxattemptshost']) : 5;
             $current_options['max_attempts_user'] = isset($itsec_bwps_options['ll_maxattemptsuser']) ? intval($itsec_bwps_options['ll_maxattemptsuser']) : 10;
             $current_options['check_period'] = isset($itsec_bwps_options['ll_checkinterval']) ? intval($itsec_bwps_options['ll_checkinterval']) : 5;
             update_site_option('itsec_brute_force', $current_options);
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_brute_force');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // Make sure the new module is properly activated or deactivated
             if ($current_options['enabled']) {
                 ITSEC_Modules::activate('brute-force');
             } else {
                 ITSEC_Modules::deactivate('brute-force');
             }
             // remove 'enabled' which isn't use in the new module
             unset($current_options['enabled']);
             ITSEC_Modules::set_settings('brute-force', $current_options);
         }
     }
 }
Пример #5
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_ipcheck');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             $settings = ITSEC_Modules::get_defaults('network-brute-force');
             if (isset($current_options['api_ban'])) {
                 $settings['enable_ban'] = $current_options['api_ban'];
             }
             // Make sure the new module is properly activated or deactivated
             if ($settings['enable_ban']) {
                 ITSEC_Modules::activate('network-brute-force');
             } else {
                 ITSEC_Modules::deactivate('network-brute-force');
             }
             if (!empty($current_options['api_key'])) {
                 $settings['api_key'] = $current_options['api_key'];
                 // Don't ask users to sign up if they already have
                 $settings['api_nag'] = false;
             }
             if (!empty($current_options['api_s'])) {
                 $settings['api_secret'] = $current_options['api_s'];
             }
             if (!empty($current_options['optin'])) {
                 $settings['updates_optin'] = $current_options['optin'];
             }
             ITSEC_Modules::set_settings('network-brute-force', $settings);
         }
     }
 }
Пример #6
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_four_oh_four');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['id_enabled']) && $itsec_bwps_options['id_enabled'] == 1 ? true : false;
             $current_options['check_period'] = isset($itsec_bwps_options['id_checkinterval']) ? intval($itsec_bwps_options['id_checkinterval']) : 5;
             $current_options['error_threshold'] = isset($itsec_bwps_options['id_threshold']) ? intval($itsec_bwps_options['id_threshold']) : 20;
             if (isset($itsec_bwps_options['id_whitelist']) && !is_array($itsec_bwps_options['id_whitelist']) && strlen($itsec_bwps_options['id_whitelist']) > 1) {
                 $current_options['white_list'] .= explode(PHP_EOL, $itsec_bwps_options['id_whitelist']);
             }
             update_site_option('itsec_four_oh_four', $current_options);
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_four_oh_four');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // Make sure the new module is properly activated or deactivated
             if ($current_options['enabled']) {
                 ITSEC_Modules::activate('404-detection');
             } else {
                 ITSEC_Modules::deactivate('404-detection');
             }
             // remove 'enabled' which isn't use in the new module
             unset($current_options['enabled']);
             ITSEC_Modules::set_settings('404-detection', $current_options);
         }
     }
 }
Пример #7
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_strong_passwords');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['st_enablepassword']) && $itsec_bwps_options['st_enablepassword'] == 1 ? true : false;
             $current_options['roll'] = isset($itsec_bwps_options['st_passrole']) ? $itsec_bwps_options['st_passrole'] : 'administrator';
             update_site_option('itsec_strong_passwords', $current_options);
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_strong_passwords');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // Make sure the new module is properly activated or deactivated
             if ($current_options['enabled']) {
                 ITSEC_Modules::activate('strong-passwords');
             } else {
                 ITSEC_Modules::deactivate('strong-passwords');
             }
             $settings = array('role' => $current_options['roll']);
             ITSEC_Modules::set_settings('strong-passwords', $settings);
         }
     }
 }
Пример #8
0
 public function handle_form_post($data)
 {
     $retval = ITSEC_Modules::set_settings($this->id, $data);
     if ($retval['saved']) {
         if ($retval['old_settings']['show_error_codes'] !== $retval['new_settings']['show_error_codes']) {
             ITSEC_Response::add_js_function_call('itsec_change_show_error_codes', array((bool) $retval['new_settings']['show_error_codes']));
         }
         if ($retval['old_settings']['write_files'] !== $retval['new_settings']['write_files']) {
             ITSEC_Response::add_js_function_call('itsec_change_write_files', array((bool) $retval['new_settings']['write_files']));
         }
     }
 }
Пример #9
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')));
             }
         }
     }
 }
Пример #10
0
 /**
  * Execute module upgrade
  *
  * @since 4.0
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         ITSEC_Lib::create_database_tables();
         $current_options = get_site_option('itsec_tweaks');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['protect_files'] = isset($itsec_bwps_options['st_ht_files']) && $itsec_bwps_options['st_ht_files'] == 1 ? true : false;
             $current_options['directory_browsing'] = isset($itsec_bwps_options['st_ht_browsing']) && $itsec_bwps_options['st_ht_browsing'] == 1 ? true : false;
             $current_options['request_methods'] = isset($itsec_bwps_options['st_ht_request']) && $itsec_bwps_options['st_ht_request'] == 1 ? true : false;
             $current_options['suspicious_query_strings'] = isset($itsec_bwps_options['st_ht_query']) && $itsec_bwps_options['st_ht_query'] == 1 ? true : false;
             $current_options['non_english_characters'] = isset($itsec_bwps_options['st_ht_foreign']) && $itsec_bwps_options['st_ht_foreign'] == 1 ? true : false;
             $current_options['long_url_strings'] = isset($itsec_bwps_options['st_longurl']) && $itsec_bwps_options['st_longurl'] == 1 ? true : false;
             $current_options['write_permissions'] = isset($itsec_bwps_options['st_fileperm']) && $itsec_bwps_options['st_fileperm'] == 1 ? true : false;
             update_site_option('itsec_tweaks', $current_options);
             ITSEC_Response::regenerate_server_config();
             ITSEC_Response::regenerate_wp_config();
         }
     }
     if ($itsec_old_version < 4035) {
         ITSEC_Response::regenerate_server_config();
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_tweaks');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             $new_module_settings = ITSEC_Modules::get_settings('system-tweaks');
             // Reduce to only settings in new module
             $current_options = array_intersect_key($current_options, $new_module_settings);
             // Use new module settings as defaults for any missing settings
             $current_options = array_merge($new_module_settings, $current_options);
             // If anything in this module is being used activate it, otherwise deactivate it
             $activate = false;
             foreach ($current_options as $on) {
                 if ($on) {
                     $activate = true;
                     break;
                 }
             }
             if ($activate) {
                 ITSEC_Modules::activate('system-tweaks');
             } else {
                 ITSEC_Modules::deactivate('system-tweaks');
             }
             ITSEC_Modules::set_settings('system-tweaks', $current_options);
         }
     }
 }
Пример #11
0
 public function execute_file_check($scheduled_call = true, $return_data = false)
 {
     global $itsec_logger, $itsec_globals;
     if (false === $this->running) {
         $this->running = true;
         $send_email = true;
         ITSEC_Lib::set_minimum_memory_limit('256M');
         $itsec_files = ITSEC_Core::get_itsec_files();
         if ($itsec_files->get_file_lock('file_change', 300)) {
             //make sure it isn't already running
             define('ITSEC_DOING_FILE_CHECK', true);
             //figure out what chunk we're on
             if (isset($this->settings['split']) && true === $this->settings['split']) {
                 if (isset($this->settings['last_chunk']) && false !== $this->settings['last_chunk'] && $this->settings['last_chunk'] < 6) {
                     $chunk = $this->settings['last_chunk'] + 1;
                 } else {
                     $chunk = 0;
                 }
             } else {
                 $chunk = false;
             }
             if (false !== $chunk) {
                 $db_field = 'itsec_local_file_list_' . $chunk;
             } else {
                 $db_field = 'itsec_local_file_list';
             }
             //set base memory
             $memory_used = @memory_get_peak_usage();
             $logged_files = get_site_option($db_field);
             //if there are no old files old file list is an empty array
             if (false === $logged_files) {
                 $send_email = false;
                 $logged_files = array();
                 if (is_multisite()) {
                     add_site_option($db_field, $logged_files);
                 } else {
                     add_option($db_field, $logged_files, '', 'no');
                 }
             }
             do_action('itsec-file-change-start-scan');
             $current_files = $this->scan_files('', $scheduled_call, $chunk);
             //scan current files
             do_action('itsec-file-change-end-scan');
             $files_added = @array_diff_assoc($current_files, $logged_files);
             //files added
             $files_removed = @array_diff_assoc($logged_files, $current_files);
             //files deleted
             $current_minus_added = @array_diff_key($current_files, $files_added);
             //remove all added files from current filelist
             $logged_minus_deleted = @array_diff_key($logged_files, $files_removed);
             //remove all deleted files from old file list
             $files_changed = array();
             //array of changed files
             do_action('itsec-file-change-start-hash-comparisons');
             //compare file hashes and mod dates
             foreach ($current_minus_added as $current_file => $current_attr) {
                 if (array_key_exists($current_file, $logged_minus_deleted)) {
                     //if attributes differ added to changed files array
                     if (isset($current_attr['mod_date']) && 0 != strcmp($current_attr['mod_date'], $logged_minus_deleted[$current_file]['mod_date']) || 0 != strcmp($current_attr['d'], $logged_minus_deleted[$current_file]['d']) || (isset($current_attr['hash']) && 0 != strcmp($current_attr['hash'], $logged_minus_deleted[$current_file]['hash']) || 0 != strcmp($current_attr['h'], $logged_minus_deleted[$current_file]['h']))) {
                         $remote_check = apply_filters('itsec_process_changed_file', true, $current_file, $current_attr['h']);
                         //hook to run actions on a changed file at time of discovery
                         if (true === $remote_check) {
                             //don't list the file if it matches the WordPress.org hash
                             $files_changed[$current_file]['h'] = isset($current_attr['hash']) ? $current_attr['hash'] : $current_attr['h'];
                             $files_changed[$current_file]['d'] = isset($current_attr['mod_date']) ? $current_attr['mod_date'] : $current_attr['d'];
                         }
                     }
                 }
             }
             //get count of changes
             $files_added_count = sizeof($files_added);
             $files_deleted_count = sizeof($files_removed);
             $files_changed_count = sizeof($files_changed);
             if (0 < $files_added_count) {
                 $files_added = apply_filters('itsec_process_added_files', $files_added);
                 //hook to run actions on all files added
                 $files_added_count = sizeof($files_added);
             }
             if (0 < $files_deleted_count) {
                 do_action('itsec_process_removed_files', $files_removed);
                 //hook to run actions on all files removed
             }
             do_action('itsec-file-change-end-hash-comparisons');
             //create single array of all changes
             $full_change_list = array('added' => $files_added, 'removed' => $files_removed, 'changed' => $files_changed);
             $this->settings['latest_changes'] = array('added' => count($files_added), 'removed' => count($files_removed), 'changed' => count($files_changed));
             update_site_option($db_field, $current_files);
             //Cleanup variables when we're done with them
             unset($files_added);
             unset($files_removed);
             unset($files_changed);
             unset($current_files);
             $this->settings['last_run'] = $itsec_globals['current_time'];
             $this->settings['last_chunk'] = $chunk;
             ITSEC_Modules::set_settings('file-change', $this->settings);
             //get new max memory
             $check_memory = @memory_get_peak_usage();
             if ($check_memory > $memory_used) {
                 $memory_used = $check_memory - $memory_used;
             }
             $full_change_list['memory'] = round($memory_used / 1000000, 2);
             $itsec_logger->log_event('file_change', 8, $full_change_list);
             if (true === $send_email && false !== $scheduled_call && isset($this->settings['email']) && true === $this->settings['email'] && (0 < $files_added_count || 0 < $files_changed_count || 0 < $files_deleted_count)) {
                 $email_details = array($files_added_count, $files_deleted_count, $files_changed_count, $full_change_list);
                 $this->send_notification_email($email_details);
             }
             if (function_exists('get_current_screen') && (!isset(get_current_screen()->id) || false === strpos(get_current_screen()->id, 'security_page_toplevel_page_itsec_logs')) && isset($this->settings['notify_admin']) && true === $this->settings['notify_admin']) {
                 ITSEC_Modules::set_setting('file-change', 'show_warning', true);
             }
             $itsec_files->release_file_lock('file_change');
             if ($files_added_count > 0 || $files_changed_count > 0 || $files_deleted_count > 0) {
                 $this->running = false;
                 //There were changes found
                 if ($return_data) {
                     return $full_change_list;
                 } else {
                     return true;
                 }
             } else {
                 $this->running = false;
                 return false;
                 //No changes were found
             }
         }
         $this->running = false;
         return -1;
         //An error occured
     }
     return -1;
 }
Пример #12
0
 /**
  * Process form input.
  *
  * This function should be left as-is in subclasses unless specific processing is required.
  *
  * @access public
  *
  * @param array $data Array of form inputs to be processed and stored.
  */
 public function handle_form_post($data)
 {
     ITSEC_Modules::set_settings($this->id, $data);
 }
Пример #13
0
 /**
  * Execute module upgrade
  *
  * @since 4.0
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         ITSEC_Lib::create_database_tables();
         $current_options = get_site_option('itsec_tweaks');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['wlwmanifest_header'] = isset($itsec_bwps_options['st_manifest']) && $itsec_bwps_options['st_manifest'] == 1 ? true : false;
             $current_options['edituri_header'] = isset($itsec_bwps_options['st_edituri']) && $itsec_bwps_options['st_edituri'] == 1 ? true : false;
             $current_options['comment_spam'] = isset($itsec_bwps_options['st_comment']) && $itsec_bwps_options['st_comment'] == 1 ? true : false;
             $current_options['login_errors'] = isset($itsec_bwps_options['st_loginerror']) && $itsec_bwps_options['st_loginerror'] == 1 ? true : false;
             update_site_option('itsec_tweaks', $current_options);
             ITSEC_Response::regenerate_server_config();
             ITSEC_Response::regenerate_wp_config();
         }
     }
     if ($itsec_old_version < 4035) {
         ITSEC_Response::regenerate_server_config();
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_tweaks');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             $new_module_settings = ITSEC_Modules::get_settings('wordpress-tweaks');
             // Reduce to only settings in new module
             $current_options = array_intersect_key($current_options, $new_module_settings);
             // Use new module settings as defaults for any missing settings
             $current_options = array_merge($new_module_settings, $current_options);
             // If anything in this module is being used activate it, otherwise deactivate it
             $activate = false;
             foreach ($current_options as $setting => $on) {
                 // False is actually "enabled" for blocking xmlrpc multiauth
                 if ('allow_xmlrpc_multiauth' !== $setting && $on || 'allow_xmlrpc_multiauth' === $setting && !$on) {
                     $activate = true;
                     break;
                 }
             }
             if ($activate) {
                 ITSEC_Modules::activate('wordpress-tweaks');
             } else {
                 ITSEC_Modules::deactivate('wordpress-tweaks');
             }
             ITSEC_Modules::set_settings('wordpress-tweaks', $current_options);
         }
     }
 }
Пример #14
0
 /**
  * Execute module upgrade
  *
  * @since 4.0
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         ITSEC_Lib::create_database_tables();
         $current_options = get_site_option('itsec_tweaks');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['theme_updates'] = isset($itsec_bwps_options['st_themenot']) && $itsec_bwps_options['st_themenot'] == 1 ? true : false;
             $current_options['plugin_updates'] = isset($itsec_bwps_options['st_pluginnot']) && $itsec_bwps_options['st_pluginnot'] == 1 ? true : false;
             $current_options['core_updates'] = isset($itsec_bwps_options['st_corenot']) && $itsec_bwps_options['st_corenot'] == 1 ? true : false;
             update_site_option('itsec_tweaks', $current_options);
             ITSEC_Response::regenerate_server_config();
             ITSEC_Response::regenerate_wp_config();
         }
     }
     if ($itsec_old_version < 4035) {
         ITSEC_Response::regenerate_server_config();
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_tweaks');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             $new_module_settings = ITSEC_Modules::get_settings('multisite-tweaks');
             // Reduce to only settings in new module
             $current_options = array_intersect_key($current_options, $new_module_settings);
             // Use new module settings as defaults for any missing settings
             $current_options = array_merge($new_module_settings, $current_options);
             // If anything in this module is being used activate it, otherwise deactivate it
             $activate = false;
             foreach ($current_options as $on) {
                 if ($on) {
                     $activate = true;
                     break;
                 }
             }
             if ($activate) {
                 ITSEC_Modules::activate('multisite-tweaks');
             } else {
                 ITSEC_Modules::deactivate('multisite-tweaks');
             }
             ITSEC_Modules::set_settings('multisite-tweaks', $current_options);
         }
     }
 }
Пример #15
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_hide_backend');
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['hb_enabled']) && $itsec_bwps_options['hb_enabled'] == 1 ? true : false;
             $current_options['register'] = isset($itsec_bwps_options['hb_register']) ? sanitize_text_field($itsec_bwps_options['hb_register']) : 'wp-register.php';
             if ($current_options['enabled'] === true) {
                 $current_options['show-tooltip'] = true;
                 set_site_transient('ITSEC_SHOW_HIDE_BACKEND_TOOLTIP', true, 600);
             } else {
                 $current_options['show-tooltip'] = false;
             }
             $forbidden_slugs = array('admin', 'login', 'wp-login.php', 'dashboard', 'wp-admin', '');
             if (isset($itsec_bwps_options['hb_login']) && !in_array(trim($itsec_bwps_options['hb_login']), $forbidden_slugs)) {
                 $current_options['slug'] = $itsec_bwps_options['hb_login'];
                 set_site_transient('ITSEC_SHOW_HIDE_BACKEND_TOOLTIP', true, 600);
             } else {
                 $current_options['enabled'] = false;
                 set_site_transient('ITSEC_SHOW_HIDE_BACKEND_TOOLTIP', true, 600);
             }
             update_site_option('itsec_hide_backend', $current_options);
             ITSEC_Response::regenerate_server_config();
         }
     }
     if ($itsec_old_version < 4027) {
         $current_options = get_site_option('itsec_hide_backend');
         if (isset($current_options['enabled']) && $current_options['enabled'] === true) {
             $config_file = ITSEC_Lib::get_htaccess();
             //Make sure we can write to the file
             $perms = substr(sprintf('%o', @fileperms($config_file)), -4);
             @chmod($config_file, 0664);
             add_action('admin_init', array($this, 'flush_rewrite_rules'));
             //reset file permissions if we changed them
             if ($perms == '0444') {
                 @chmod($config_file, 0444);
             }
             ITSEC_Response::regenerate_server_config();
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_hide_backend');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // remove 'show-tooltip' which is old and not used in the new module
             unset($current_options['show-tooltip']);
             ITSEC_Modules::set_settings('hide-backend', $current_options);
         }
     }
 }
Пример #16
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>');
         }
     }
 }
Пример #17
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options;
         $current_options = get_site_option('itsec_file_change');
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['id_fileenabled']) && $itsec_bwps_options['id_fileenabled'] == 1 ? true : false;
             $current_options['email'] = isset($itsec_bwps_options['id_fileemailnotify']) && $itsec_bwps_options['id_fileemailnotify'] == 0 ? false : true;
             $current_options['notify_admin'] = isset($itsec_bwps_options['id_filedisplayerror']) && $itsec_bwps_options['id_filedisplayerror'] == 0 ? false : true;
             $current_options['method'] = isset($itsec_bwps_options['id_fileincex']) && $itsec_bwps_options['id_fileincex'] == 0 ? false : true;
             if (isset($itsec_bwps_options['id_specialfile']) && !is_array($itsec_bwps_options['id_specialfile']) && strlen($itsec_bwps_options['id_specialfile']) > 1) {
                 $current_options['file_list'] .= explode(PHP_EOL, $itsec_bwps_options['id_specialfile']);
             }
             update_site_option('itsec_file_change', $current_options);
         }
     }
     if ($itsec_old_version < 4028) {
         if (!is_multisite()) {
             $options = array('itsec_local_file_list', 'itsec_local_file_list_0', 'itsec_local_file_list_1', 'itsec_local_file_list_2', 'itsec_local_file_list_3', 'itsec_local_file_list_4', 'itsec_local_file_list_5', 'itsec_local_file_list_6');
             foreach ($options as $option) {
                 $list = get_site_option($option);
                 if ($list !== false) {
                     delete_site_option($option);
                     add_option($option, $list, '', 'no');
                 }
             }
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_file_change');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options)) {
             // Make sure the new module is properly activated or deactivated
             if ($current_options['enabled']) {
                 ITSEC_Modules::activate('file-change');
             } else {
                 ITSEC_Modules::deactivate('file-change');
             }
             // remove 'enabled' which isn't use in the new module
             unset($current_options['enabled']);
             // This used to be boolean. Attempt to migrate to new string, falling back to default
             if (!is_array($current_options['method'])) {
                 $current_options['method'] = $current_options['method'] ? 'exclude' : 'include';
             } elseif (!in_array($current_options['method'], array('include', 'exclude'))) {
                 $current_options['method'] = 'exclude';
             }
             ITSEC_Modules::set_settings('file-change', $current_options);
         }
     }
 }
Пример #18
0
 /**
  * Execute module upgrade
  *
  * @return void
  */
 public function execute_upgrade($itsec_old_version)
 {
     if ($itsec_old_version < 4000) {
         global $itsec_bwps_options, $itsec_globals;
         $current_options = get_site_option('itsec_away_mode');
         $current_time = $itsec_globals['current_time'];
         // Don't do anything if settings haven't already been set, defaults exist in the module system and we prefer to use those
         if (false !== $current_options) {
             $current_options['enabled'] = isset($itsec_bwps_options['am_enabled']) && $itsec_bwps_options['am_enabled'] == 1 ? true : false;
             $current_options['type'] = isset($itsec_bwps_options['am_type']) && $itsec_bwps_options['am_type'] == 1 ? 1 : 2;
             if (isset($itsec_bwps_options['am_startdate']) && isset($itsec_bwps_options['am_starttime'])) {
                 $current_options['start'] = strtotime(date('Y-m-d', $itsec_bwps_options['am_startdate'])) + intval($itsec_bwps_options['am_starttime']);
             } elseif (isset($current_options['am_starttime']) && $current_options['type'] == 1) {
                 $current_options['start'] = strtotime(date('Y-m-d', $current_time)) + intval($itsec_bwps_options['am_starttime']);
             } else {
                 $current_options['enabled'] = false;
                 //didn't have the whole start picture so disable
             }
             if (isset($itsec_bwps_options['am_enddate']) && isset($itsec_bwps_options['am_endtime'])) {
                 $current_options['end'] = strtotime(date('Y-m-d', $itsec_bwps_options['am_enddate'])) + intval($itsec_bwps_options['am_endtime']);
             } elseif (isset($itsec_bwps_options['am_endtime']) && $itsec_bwps_options['type'] == 1) {
                 $current_options['end'] = strtotime(date('Y-m-d', $current_time)) + intval($itsec_bwps_options['am_endtime']);
             } else {
                 $current_options['enabled'] = false;
                 //didn't have the whole start picture so disable
             }
             update_site_option('itsec_away_mode', $current_options);
             $away_file = ITSEC_Core::get_storage_dir() . '/itsec_away.confg';
             //override file
             if ($current_options['enabled'] === true && !file_exists($away_file)) {
                 @file_put_contents($away_file, 'true');
             } else {
                 @unlink($away_file);
             }
         }
     }
     if ($itsec_old_version < 4041) {
         $current_options = get_site_option('itsec_away_mode');
         $current_override_options = get_site_option('itsec_away_mode_sync_override');
         // If there are no current options, go with the new defaults by not saving anything
         if (is_array($current_options) || is_array($current_override_options)) {
             $settings = ITSEC_Modules::get_defaults('away-mode');
             $original_settings = $settings;
             if (is_array($current_options)) {
                 $settings['type'] = 1 == $current_options['type'] ? 'daily' : 'one-time';
                 $settings['start'] = intval($current_options['start'] - ITSEC_Core::get_time_offset());
                 $settings['start_time'] = $current_options['start'] - strtotime(date('Y-m-d', $current_options['start']));
                 $settings['end'] = intval($current_options['end'] - ITSEC_Core::get_time_offset());
                 $settings['end_time'] = $current_options['end'] - strtotime(date('Y-m-d', $current_options['end']));
             }
             if (is_array($current_override_options)) {
                 $settings['override_type'] = $current_override_options['intention'];
                 $settings['override_end'] = $current_override_options['expires'];
             }
             ITSEC_Modules::set_settings('away-mode', $settings);
             if (isset($current_options['enabled']) && $current_options['enabled']) {
                 ITSEC_Modules::activate('away-mode');
             } else {
                 ITSEC_Modules::deactivate('away-mode');
             }
         }
     }
 }
 public function run($arguments)
 {
     $arguments = Ithemes_Sync_Functions::merge_defaults($arguments, $this->default_arguments);
     $details = ITSEC_Away_Mode::is_active(true);
     $settings = ITSEC_Modules::get_settings('away-mode');
     $defaults = ITSEC_Modules::get_defaults('away-mode');
     $errors = array();
     if ('activate' === $arguments['intention']) {
         if ($details['active']) {
             $action = 'stayed-active';
             $success = true;
         } else {
             if ($details['override_active'] && 'deactivate' === $details['override_type']) {
                 $action = 'removed-deactivate-override';
                 $settings['override_type'] = $defaults['override_type'];
                 $settings['override_end'] = $defaults['override_end'];
             } else {
                 if (false === $details['next']) {
                     $action = 'denied-activate';
                     $errors[] = new WP_Error('itsec-sync-verb-itsec-override-away-mode-cannot-override-activate-expired-one-time', __('iThemes Security received a request to modify the override behavior of the Away Mode module. However, the request is invalid as the module is configured for a one-time lockout that occurred in the past. Allowing an activate override would result in an unending Away Mode lockout.', 'better-wp-security'));
                     $success = false;
                 } else {
                     $action = 'added-activate-override';
                     $settings['override_type'] = 'activate';
                     $settings['override_end'] = ITSEC_Core::get_current_time() + $details['next'];
                 }
             }
         }
     } else {
         if ('deactivate' === $arguments['intention']) {
             if (!$details['active']) {
                 $action = 'stayed-inactive';
                 $success = true;
             } else {
                 if ($details['override_active'] && 'activate' === $details['override_type']) {
                     $action = 'removed-activate-override';
                     $settings['override_type'] = $defaults['override_type'];
                     $settings['override_end'] = $defaults['override_end'];
                 } else {
                     $action = 'added-deactivate-override';
                     $settings['override_type'] = 'deactivate';
                     $settings['override_end'] = ITSEC_Core::get_current_time() + $details['remaining'];
                 }
             }
         } else {
             if (empty($arguments['intention'])) {
                 $action = 'missing-intention';
                 $errors[] = new WP_Error('itsec-sync-verb-itsec-override-away-mode-missing-intention', __('iThemes Security received a request to modify the override behavior of the Away Mode module. However, the request is invalid as the required "intention" argument is missing.', 'better-wp-security'));
                 $success = false;
             } else {
                 $action = 'unknown-intention';
                 $errors[] = new WP_Error('itsec-sync-verb-itsec-override-away-mode-unknown-intention', sprintf(__('iThemes Security received a request to modify the override behavior of the Away Mode module. However, the request is invalid as the required "intention" argument is set to an unrecognized value: "".', 'better-wp-security'), $arguments['intention']));
                 $success = false;
             }
         }
     }
     if (!isset($success)) {
         ITSEC_Core::set_interactive(false);
         $results = ITSEC_Modules::set_settings('away-mode', $settings);
         if ($results['saved']) {
             $success = true;
         } else {
             $errors = $results['errors'];
             $success = false;
         }
     }
     if ($success) {
         $status = "{$arguments['intention']}d";
     } else {
         $status = 'error';
     }
     $response = array('api' => '1', 'status' => $status, 'action' => $action, 'errors' => $errors, 'details' => ITSEC_Away_Mode::is_active(true));
     return $response;
 }