Exemplo n.º 1
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);
         }
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 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);
         }
     }
 }
Exemplo n.º 4
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')));
             }
         }
     }
 }
Exemplo n.º 5
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;
 }