public function run($arguments) { $away = ITSEC_Away_Mode::check_away(NULL, true); if ($away !== false && $away > 0) { $away_enabled = true; $next = $away; } elseif ($away !== false) { $away_enabled = false; $next = absint($away); } return array('api' => '0', 'enabled' => $away_enabled, 'next' => $next); }
public function run($arguments) { $details = ITSEC_Away_Mode::is_active(true); $response = array('api' => '1', 'enabled' => $details['active'], 'next' => $details['next'], 'details' => $details); // For backwards compatibility with the api version 0 functionality, the next value represents either next or // remaining depending on the context. The context when this occurs is when away mode is either active or has // an active override, but not both. if ($details['active'] xor $details['override_active']) { $response['next'] = $details['remaining']; } return $response; }
public function run($arguments) { global $itsec_globals; $current_status = ITSEC_Away_Mode::check_away(null, true); $intention = sanitize_text_field($arguments['intention']); $saved_options = get_site_option('itsec_away_mode_sync_override'); $saved_intention = isset($saved_options['intention']) ? $saved_options['intention'] : false; switch ($intention) { case 'activate': //process activation if ($saved_intention === false && $current_status < 0) { //option doesn't already exist $success = add_site_option('itsec_away_mode_sync_override', array('intention' => $intention, 'expires' => $itsec_globals['current_time'] + absint($current_status))); } elseif ($saved_intention == 'deactivate') { //allready tried to override $success = delete_site_option('itsec_away_mode_sync_override'); } break; case 'deactivate': //process deactivation if ($saved_intention === false && $current_status > 0) { $success = add_site_option('itsec_away_mode_sync_override', array('intention' => $intention, 'expires' => $itsec_globals['current_time'] + absint($current_status))); } elseif ($saved_intention == 'activate') { $success = delete_site_option('itsec_away_mode_sync_override'); } break; default: //invalid intention $success = false; break; } if ($success === false) { $status = 'error'; } else { $status = $intention . 'd'; } return array('api' => '0', 'status' => $status); }
<?php // Set up Away Mode Admin require_once 'class-itsec-away-mode-admin.php'; $itsec_away_mode_admin = new ITSEC_Away_Mode_Admin(); $itsec_away_mode_admin->run(ITSEC_Core::get_instance()); // Set up Away Mode Frontend require_once 'class-itsec-away-mode.php'; $itsec_away_mode = new ITSEC_Away_Mode(); $itsec_away_mode->run();
/** * Check if away mode is active * * @since 4.4 * * @param array $input [NULL] Input of options to check if calling from form * @param bool $remaining will return the number of seconds remaining * @param bool $override Whether or not we're calculating override values * * @return mixed true if locked out else false or times until next condition (negative until lockout, positive until release) */ public static function check_away($input = null, $remaining = false, $override = false) { global $itsec_globals; ITSEC_Lib::clear_caches(); //lets try to make sure nothing is storing a bad time $form = true; $has_away_file = @file_exists($itsec_globals['ithemes_dir'] . '/itsec_away.confg'); $status = false; //assume they're not locked out to start //Normal usage check if ($input === null) { //if we didn't provide input to check we need to get it $form = false; $input = get_site_option('itsec_away_mode'); } if ($form === false && !isset($input['enabled']) || !isset($input['type']) || !isset($input['start']) || !isset($input['end']) || !$has_away_file) { return false; //if we don't have complete settings don't lock them out } $current_time = $itsec_globals['current_time']; //use current time $enabled = isset($input['enabled']) ? $input['enabled'] : $form; $test_type = $input['type']; $test_start = $input['start']; $test_end = $input['end']; if ($test_type === 1) { //daily $test_start -= strtotime(date('Y-m-d', $test_start)); $test_end -= strtotime(date('Y-m-d', $test_end)); $day_seconds = $current_time - strtotime(date('Y-m-d', $current_time)); if ($test_start === $test_end) { $status = false; } if ($test_start < $test_end) { //same day if ($test_start <= $day_seconds && $test_end >= $day_seconds && $enabled === true) { $status = $test_end - $day_seconds; } } else { //overnight if (($test_start < $day_seconds || $test_end > $day_seconds) && $enabled === true) { if ($day_seconds >= $test_start) { $status = 86400 - $day_seconds + $test_end; } else { $status = $test_end - $day_seconds; } } } } else { if ($test_start !== $test_end && $test_start <= $current_time && $test_end >= $current_time && $enabled === true) { //one time $status = $test_end - $current_time; } } //they are allowed to log in if ($status === false) { if ($test_type === 1) { if ($day_seconds > $test_start) { //actually starts tomorrow $status = -(86400 + $test_start - $day_seconds); } else { //starts today $status = -($test_start - $day_seconds); } } else { $status = -($test_start - $current_time); if ($status > 0) { if ($form === false && isset($input['enabled']) && $input['enabled'] === true) { //disable away mode if one-time is in the past $input['enabled'] = false; update_site_option('itsec_away_mode', $input); } $status = 0; } } } if ($override === false) { //work in an override from sync $override_option = get_site_option('itsec_away_mode_sync_override'); $override = $override_option['intention']; $expires = $override_option['expires']; if ($expires < $itsec_globals['current_time']) { delete_site_option('itsec_away_mode_sync_override'); } else { if ($override === 'activate') { if ($status <= 0) { //not currently locked out $input['start'] = $current_time - 1; $status = ITSEC_Away_Mode::check_away($input, true, true); } else { delete_site_option('itsec_away_mode_sync_override'); } } elseif ($override === 'deactivate') { if ($status > 0) { //currently locked out $input['end'] = $current_time - 1; $status = ITSEC_Away_Mode::check_away($input, true, true); } else { delete_site_option('itsec_away_mode_sync_override'); } } } } if ($remaining === true) { return $status; } else { if ($status > 0 && $status !== false) { return true; } } return false; //always default to NOT locking folks out }
/** * Sanitize and validate input * * @param Array $input array of input fields * * @return Array Sanitized array */ public function sanitize_module_input($input) { //process away mode settings $input['enabled'] = isset($input['enabled']) && intval($input['enabled'] == 1) ? true : false; $input['type'] = isset($input['type']) && intval($input['type'] == 1) ? 1 : 2; if (!isset($input['away_start']) && !isset($input['start'])) { $input['start'] = $this->settings['start']; } elseif (!isset($input['away_start']) && isset($input['start'])) { $input['start'] = intval($input['start']); } else { $input['start'] = strtotime($input['away_start']['date'] . ' ' . $input['away_start']['hour'] . ':' . $input['away_start']['minute'] . ' ' . $input['away_start']['sel']); unset($input['away_start']); } if (!isset($input['away_end']) && !isset($input['end'])) { $input['end'] = $this->settings['end']; } elseif (!isset($input['away_end']) && isset($input['end'])) { $input['end'] = intval($input['end']); } else { $input['end'] = strtotime($input['away_end']['date'] . ' ' . $input['away_end']['hour'] . ':' . $input['away_end']['minute'] . ' ' . $input['away_end']['sel']); unset($input['away_end']); } if ($input['enabled'] === true && $input['start'] === 1 && $input['end'] === 1) { $input['enabled'] = false; } if (!class_exists('ITSEC_Away_Mode')) { require dirname(__FILE__) . '/class-itsec-away-mode.php'; } if ($input['enabled'] === true && ITSEC_Away_Mode::check_away($input) === true) { $input['enabled'] = false; //disable away mode $type = 'error'; $message = __('Invalid away mode time listed. The time entered would lock you out of your site now. Please try again.', 'better-wp-security'); add_settings_error('itsec', esc_attr('settings_updated'), $message, $type); } if ($input['enabled'] === true && $input['type'] === 2 && $input['end'] < $input['start']) { $input['enabled'] = false; //disable away mode $type = 'error'; $message = __('Invalid away mode time listed. The start time selected is after the end time selected.', 'better-wp-security'); add_settings_error('itsec', esc_attr('settings_updated'), $message, $type); } if ($input['enabled'] === true && $input['type'] === 2 && $input['end'] < current_time('timestamp')) { $input['enabled'] = false; //disable away mode $type = 'error'; $message = __('Invalid away mode time listed. The period selected already ended.', 'better-wp-security'); add_settings_error('itsec', esc_attr('settings_updated'), $message, $type); } if ($input['enabled'] === true && !file_exists($this->away_file)) { @file_put_contents($this->away_file, 'true'); } elseif ($input['enabled'] === false) { @unlink($this->away_file); } //process other settings if (is_multisite()) { if (isset($type)) { $error_handler = new WP_Error(); $error_handler->add($type, $message); $this->core->show_network_admin_notice($error_handler); } else { $this->core->show_network_admin_notice(false); } $this->settings = $input; } return $input; }
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; }