Esempio n. 1
0
 private function sanitize_datetime($prefix, $msg_timestamp, $msg_date, $msg_time)
 {
     $this->vars_to_skip_validate_matching_fields[] = "{$prefix}_date";
     $this->vars_to_skip_validate_matching_fields[] = "{$prefix}_hour";
     $this->vars_to_skip_validate_matching_fields[] = "{$prefix}_minute";
     $this->vars_to_skip_validate_matching_fields[] = "{$prefix}_meridiem";
     $this->vars_to_skip_validate_matching_fields[] = "{$prefix}_time";
     if (isset($this->settings[$prefix])) {
         $this->sanitize_setting('positive-int', $prefix, $msg_timestamp);
         return;
     }
     $valid_date = $this->sanitize_setting('date', "{$prefix}_date", $msg_date);
     if (isset($this->settings["{$prefix}_meridiem"])) {
         if ($this->sanitize_setting(array('am', 'pm'), "{$prefix}_meridiem", $msg_time)) {
             $meridiem = $this->settings["{$prefix}_meridiem"];
         } else {
             $meridiem = false;
         }
         $valid_hours = range(1, 12);
     } else {
         $meridiem = '';
         $valid_hours = range(0, 23);
     }
     $valid_hour = $this->sanitize_setting('positive-int', "{$prefix}_hour", $msg_time) && $this->sanitize_setting($valid_hours, "{$prefix}_hour", $msg_time);
     $valid_minute = $this->sanitize_setting('positive-int', "{$prefix}_minute", $msg_time) && $this->sanitize_setting(range(0, 59), "{$prefix}_minute", $msg_time);
     if ($valid_date && $valid_hour && $valid_minute && false !== $meridiem) {
         $datetime = $this->settings["{$prefix}_date"] . ' ';
         $datetime .= sprintf('%d:%02d %s', $this->settings["{$prefix}_hour"], $this->settings["{$prefix}_minute"], $meridiem);
         $datetime = trim($datetime);
         $timestamp = strtotime($datetime);
         if (false === $timestamp) {
             $id = $this->get_id();
             /* translators: 1: date input name, 2: time input name, 3: submitted date time */
             $this->add_error(new WP_Error("itsec-validator-{$id}-invalid-datetime", sprintf(__('The %1$s and %2$s values resulted in a date and time of <code>%3$s</code>, which was unable to be processed properly. This could be an issue with PHP or a server configuration issue.', 'better-wp-security'), $msg_date, $msg_time, $datetime)));
             $this->vars_to_skip_validate_matching_fields[] = $prefix;
         } else {
             $this->settings[$prefix] = intval($timestamp - ITSEC_Core::get_time_offset());
             $this->settings["{$prefix}_time"] = $timestamp - strtotime(date('Y-m-d', $timestamp));
             unset($this->settings["{$prefix}_date"]);
             unset($this->settings["{$prefix}_hour"]);
             unset($this->settings["{$prefix}_minute"]);
             unset($this->settings["{$prefix}_meridiem"]);
         }
     } else {
         $this->vars_to_skip_validate_matching_fields[] = $prefix;
     }
 }
Esempio n. 2
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 get_temp_whitelist()
 {
     $whitelist = get_site_option('itsec_temp_whitelist_ip', false);
     if (!is_array($whitelist)) {
         $whitelist = array();
     } else {
         if (isset($whitelist['ip'])) {
             // Update old format
             $whitelist = array($whitelist['ip'] => $whitelist['exp'] - ITSEC_Core::get_time_offset());
         } else {
             return $whitelist;
         }
     }
     update_site_option('itsec_temp_whitelist_ip', $whitelist);
     return $whitelist;
 }
Esempio n. 4
0
    protected function render_settings($form)
    {
        global $wp_locale;
        $settings = $form->get_options();
        $validator = ITSEC_Modules::get_validator($this->id);
        $types = $validator->get_valid_types();
        if (1 === $settings['start']) {
            $tomorrow = date('Y-m-d', current_time('timestamp') + DAY_IN_SECONDS);
            $new_start = strtotime("{$tomorrow} 1:00 am") - ITSEC_Core::get_time_offset();
            $form->set_option('start', $new_start);
        }
        if (1 === $settings['end']) {
            $tomorrow = date('Y-m-d', current_time('timestamp') + DAY_IN_SECONDS);
            $new_end = strtotime("{$tomorrow} 6:00 am") - ITSEC_Core::get_time_offset();
            $form->set_option('end', $new_end);
        }
        $date_format = get_option('date_format');
        $time_format = get_option('time_format');
        if (false !== strpos($time_format, 'G')) {
            for ($hour = 0; $hour < 24; $hour++) {
                $hours[$hour] = $hour;
            }
        } else {
            if (false !== strpos($time_format, 'H')) {
                for ($hour = 0; $hour < 24; $hour++) {
                    $hours[$hour] = sprintf('%02d', $hour);
                }
            } else {
                for ($hour = 1; $hour <= 12; $hour++) {
                    $hours[$hour] = $hour;
                }
                if (false !== strpos($time_format, 'A')) {
                    $am = $wp_locale->get_meridiem('AM');
                    $pm = $wp_locale->get_meridiem('PM');
                } else {
                    $am = $wp_locale->get_meridiem('am');
                    $pm = $wp_locale->get_meridiem('pm');
                }
                $meridiems = array('am' => $am, 'pm' => $pm);
            }
        }
        for ($minute = 0; $minute <= 59; $minute++) {
            $minutes[$minute] = sprintf('%02d', $minute);
        }
        $this->set_datetime_options($form, 'start', isset($meridiems));
        $this->set_datetime_options($form, 'end', isset($meridiems));
        /* translators: 1: date, 2: time */
        $datetime_format = _x('%1$s \\a\\t %2$s', 'Date and time format', 'better-wp-security');
        $datetime_format = sprintf($datetime_format, $date_format, $time_format);
        $current_datetime = date_i18n($datetime_format);
        ?>
	<p><?php 
        printf(__('Please note that according to your <a href="%s">WordPress Timezone settings</a> your current time is:', 'better-wp-security'), admin_url('options-general.php#timezone_string'));
        ?>
</p>
	<p class="current-date-time"><?php 
        echo $current_datetime;
        ?>
</p>
	<p><?php 
        printf(__('If this is incorrect, please update it on the <a href="%s">WordPress General Settings page</a> by selecting the appropriate time zone. Failure to set the correct timezone may result in unintended lockouts.', 'better-wp-security'), admin_url('options-general.php#timezone_string'));
        ?>
</p>
	<table class="form-table itsec-settings-section">
		<tr>
			<th scope="row"><label for="itsec-away-mode-type"><?php 
        _e('Type of Restriction', 'better-wp-security');
        ?>
</label></th>
			<td>
				<?php 
        $form->add_select('type', $types);
        ?>
				<br />
				<p class="description"><?php 
        _e('Select the type of restriction you would like to enable.', 'better-wp-security');
        ?>
</p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="itsec-away-mode-start_date"><?php 
        _e('Start Date', 'better-wp-security');
        ?>
</label></th>
			<td>
				<?php 
        $form->add_text('start_date');
        ?>
				<br />
				<p class="description"><?php 
        _e('Date when the admin dashboard should become unavailable.', 'better-wp-security');
        ?>
</p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="itsec-away-mode-start_hour"><?php 
        _e('Start Time', 'better-wp-security');
        ?>
</label></th>
			<td>
				<?php 
        $form->add_select('start_hour', $hours);
        ?>
				<?php 
        $form->add_select('start_minute', $minutes);
        ?>
				<?php 
        if (isset($meridiems)) {
            ?>
					<?php 
            $form->add_select('start_meridiem', $meridiems);
            ?>
				<?php 
        }
        ?>
				<br />
				<p class="description"><?php 
        _e('Time when the admin dashboard should become unavailable.', 'better-wp-security');
        ?>
</p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="itsec-away-mode-end_date"><?php 
        _e('End Date', 'better-wp-security');
        ?>
</label></th>
			<td>
				<?php 
        $form->add_text('end_date');
        ?>
				<br />
				<p class="description"><?php 
        _e('Date when the admin dashboard should become available again.', 'better-wp-security');
        ?>
</p>
			</td>
		</tr>
		<tr>
			<th scope="row"><label for="itsec-away-mode-end_hour"><?php 
        _e('End Time', 'better-wp-security');
        ?>
</label></th>
			<td>
				<?php 
        $form->add_select('end_hour', $hours);
        ?>
				<?php 
        $form->add_select('end_minute', $minutes);
        ?>
				<?php 
        if (isset($meridiems)) {
            ?>
					<?php 
            $form->add_select('end_meridiem', $meridiems);
            ?>
				<?php 
        }
        ?>
				<p class="description"><?php 
        _e('Time when the admin dashboard should become available again.', 'better-wp-security');
        ?>
</p>
			</td>
		</tr>
	</table>
<?php 
    }