Пример #1
0
    protected function render_settings($form)
    {
        ?>
	<div class="itsec-warning-message"><?php 
        printf(__('<span>Warning:</span> The changes made by this tool could cause compatibility issues with some plugins, themes, or customizations. Ensure that you <a href="%s">create a database backup</a> before using this tool.', 'better-wp-security'), esc_url(ITSEC_Core::get_backup_creation_page_url()));
        ?>
</div>
	
	<table class="form-table itsec-settings-section">
		<?php 
        if (username_exists('admin')) {
            ?>
			<tr>
				<th scope="row"><label for="itsec-admin-user-new_username"><?php 
            _e('New Admin Username', 'better-wp-security');
            ?>
</label></th>
				<td>
					<?php 
            $form->add_text('new_username', array('class' => 'code'));
            ?>
					<br />
					<p class="description"><?php 
            _e('Enter a new username to replace "admin." Please note that if you are logged in as admin you will have to log in again.', 'better-wp-security');
            ?>
</p>
				</td>
			</tr>
		<?php 
        }
        ?>
		<?php 
        if (ITSEC_Lib::user_id_exists(1)) {
            ?>
			<tr>
				<th scope="row"><label for="itsec-admin-user-change_id"><?php 
            _e('Change User ID 1', 'better-wp-security');
            ?>
</label></th>
				<td>
					<?php 
            $form->add_checkbox('change_id');
            ?>
					<label for="itsec-admin-user-change_id"><?php 
            _e('Change the ID of the user with ID 1.', 'better-wp-security');
            ?>
</label>
				</td>
			</tr>
		<?php 
        }
        ?>
	</table>
<?php 
    }
    /**
     * Render the settings metabox
     *
     * @since 4.0
     *
     * @return void
     */
    public function metabox_admin_user_settings()
    {
        $this->settings = username_exists('admin') || ITSEC_Lib::user_id_exists(1) ? false : true;
        if ($this->settings === true) {
            echo '<p>' . __('It looks like you have already removed the admin user. No further action is necessary.', 'it-l10n-ithemes-security-pro') . '</p>';
        } else {
            echo '<p>' . __('This feature will improve the security of your WordPress installation by removing common user attributes that can be used to target your site.', 'it-l10n-ithemes-security-pro') . '</p>';
            echo sprintf('<div class="itsec-warning-message"><span>%s: </span><a href="?page=toplevel_page_itsec-backup">%s</a> %s</div>', __('WARNING', 'it-l10n-ithemes-security-pro'), __('Backup your database', 'it-l10n-ithemes-security-pro'), __('before changing the admin user.', 'it-l10n-ithemes-security-pro'));
            echo sprintf('<div class="itsec-notice-message"><span>%s: </span> %s </div>', __('Notice', 'it-l10n-ithemes-security-pro'), __('Changing the admin username or id of user 1 will log you out of your site requiring you to log back in again.', 'it-l10n-ithemes-security-pro'));
            ?>

			<form method="post" action="?page=toplevel_page_itsec_advanced&settings-updated=true"
			      class="itsec-form">

				<?php 
            wp_nonce_field('ITSEC_admin_save', 'wp_nonce');
            ?>

				<table class="form-table">
					<tr valign="top">
						<th scope="row" class="settinglabel">
							<label
								for="itsec_enable_admin_user"><?php 
            _e('Enable Change Admin User', 'it-l10n-ithemes-security-pro');
            ?>
</label>
						</th>
						<td class="settingfield">
							<?php 
            //username field
            ?>
							<input type="checkbox" id="itsec_enable_admin_user" name="itsec_enable_admin_user"
							       value="true"/>

							<p class="description"><?php 
            _e('Check this box to enable admin user renaming.', 'it-l10n-ithemes-security-pro');
            ?>
</p>
						</td>
					</tr>

					<?php 
            if (username_exists('admin')) {
                ?>
						<tr valign="top" id="admin_user_username_field">
							<th scope="row" class="settinglabel">
								<label
									for="itsec_admin_user_username"><?php 
                _e('New Admin Username', 'it-l10n-ithemes-security-pro');
                ?>
</label>
							</th>
							<td class="settingfield">
								<?php 
                //username field
                ?>
								<input name="itsec_admin_user_username" id="itsec_admin_user_username" value=""
								       type="text"><br/>

								<p class="description"><?php 
                _e('Enter a new username to replace "admin." Please note that if you are logged in as admin you will have to log in again.', 'it-l10n-ithemes-security-pro');
                ?>
</p>
							</td>
						</tr>
					<?php 
            }
            ?>
					<?php 
            if (ITSEC_Lib::user_id_exists(1)) {
                ?>
						<tr valign="top" id="admin_user_id_field">
							<th scope="row" class="settinglabel">
								<label
									for="itsec_admin_user_id"><?php 
                _e('Change User ID 1', 'it-l10n-ithemes-security-pro');
                ?>
</label>
							</th>
							<td class="settingfield">
								<?php 
                //username field
                ?>
								<input type="checkbox" id="itsec_admin_user_id" name="itsec_admin_user_id" value="1"/>

								<p class="description"><?php 
                _e('Change the ID of the user with ID 1.', 'it-l10n-ithemes-security-pro');
                ?>
</p>
							</td>
						</tr>
					<?php 
            }
            ?>
				</table>
				<p class="submit">
					<input type="submit" class="button-primary"
					       value="<?php 
            _e('Save Admin User', 'it-l10n-ithemes-security-pro');
            ?>
"/>
				</p>
			</form>

		<?php 
        }
    }
Пример #3
0
 /**
  * Locks out given user or host
  *
  * @since 4.0
  *
  * @param  string $type     The type of lockout (for user reference)
  * @param  string $reason   Reason for lockout, for notifications
  * @param  string $host     Host to lock out
  * @param  int    $user     user id to lockout
  * @param string  $username username to lockout
  *
  * @return void
  */
 private function lockout($type, $reason, $host = NULL, $user = NULL, $username = NULL)
 {
     global $wpdb, $itsec_logger, $itsec_globals, $itsec_files;
     $host_expiration = NULL;
     $user_expiration = NULL;
     $username = sanitize_text_field(trim($username));
     if ($itsec_files->get_file_lock('lockout_' . $host . $user . $username)) {
         //Do we have a good host to lock out or not
         if ($host != NULL && $this->is_ip_whitelisted(sanitize_text_field($host)) === false && ITSEC_Lib::validates_ip_address($host) === true) {
             $good_host = sanitize_text_field($host);
         } else {
             $good_host = false;
         }
         //Do we have a valid user to lockout or not
         if ($user !== NULL && ITSEC_Lib::user_id_exists(intval($user)) === true) {
             $good_user = intval($user);
         } else {
             $good_user = false;
         }
         //Do we have a valid username to lockout or not
         if ($username !== NULL && $username != '') {
             $good_username = $username;
         } else {
             $good_username = false;
         }
         $blacklist_host = false;
         //assume we're not permanently blcking the host
         //Sanitize the data for later
         $type = sanitize_text_field($type);
         $reason = sanitize_text_field($reason);
         //handle a permanent host ban (if needed)
         if ($itsec_globals['settings']['blacklist'] === true && $good_host !== false) {
             //permanent blacklist
             $blacklist_period = isset($itsec_globals['settings']['blacklist_period']) ? $itsec_globals['settings']['blacklist_period'] * 24 * 60 * 60 : 604800;
             $host_count = 1 + $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->base_prefix . "itsec_lockouts` WHERE `lockout_expire_gmt` > '%s' AND `lockout_host`='%s';", date('Y-m-d H:i:s', $itsec_globals['current_time_gmt'] - $blacklist_period), $host));
             if ($host_count >= $itsec_globals['settings']['blacklist_count'] && isset($itsec_globals['settings']['write_files']) && $itsec_globals['settings']['write_files'] === true) {
                 $host_expiration = false;
                 if (!class_exists('ITSEC_Ban_Users')) {
                     require trailingslashit($itsec_globals['plugin_dir']) . 'modules/free/ban-users/class-itsec-ban-users.php';
                 }
                 ITSEC_Ban_Users::insert_ip(sanitize_text_field($host));
                 //Send it to the Ban Users module for banning
                 $blacklist_host = true;
                 //flag it so we don't do a temp ban as well
             }
         }
         //We have temp bans to perform
         if ($good_host !== false || $good_user !== false || $good_username || $good_username !== false) {
             if ($this->is_ip_whitelisted(sanitize_text_field($host))) {
                 $whitelisted = true;
                 $expiration = date('Y-m-d H:i:s', 1);
                 $expiration_gmt = date('Y-m-d H:i:s', 1);
             } else {
                 $whitelisted = false;
                 $exp_seconds = intval($itsec_globals['settings']['lockout_period']) * 60;
                 $expiration = date('Y-m-d H:i:s', $itsec_globals['current_time'] + $exp_seconds);
                 $expiration_gmt = date('Y-m-d H:i:s', $itsec_globals['current_time_gmt'] + $exp_seconds);
             }
             if ($good_host !== false && $blacklist_host === false) {
                 //temp lockout host
                 $host_expiration = $expiration;
                 $wpdb->insert($wpdb->base_prefix . 'itsec_lockouts', array('lockout_type' => $type, 'lockout_start' => date('Y-m-d H:i:s', $itsec_globals['current_time']), 'lockout_start_gmt' => date('Y-m-d H:i:s', $itsec_globals['current_time_gmt']), 'lockout_expire' => $expiration, 'lockout_expire_gmt' => $expiration_gmt, 'lockout_host' => sanitize_text_field($host), 'lockout_user' => ''));
                 $itsec_logger->log_event(__('lockout', 'it-l10n-better-wp-security'), 10, array('expires' => $expiration, 'expires_gmt' => $expiration_gmt, 'type' => $type), sanitize_text_field($host));
             }
             if ($good_user !== false) {
                 //blacklist host and temp lockout user
                 $user_expiration = $expiration;
                 $wpdb->insert($wpdb->base_prefix . 'itsec_lockouts', array('lockout_type' => $type, 'lockout_start' => date('Y-m-d H:i:s', $itsec_globals['current_time']), 'lockout_start_gmt' => date('Y-m-d H:i:s', $itsec_globals['current_time_gmt']), 'lockout_expire' => $expiration, 'lockout_expire_gmt' => $expiration_gmt, 'lockout_host' => '', 'lockout_user' => intval($user)));
                 if ($whitelisted === false) {
                     $itsec_logger->log_event('lockout', 10, array('expires' => $expiration, 'expires_gmt' => $expiration_gmt, 'type' => $type), '', '', intval($user));
                 } else {
                     $itsec_logger->log_event('lockout', 10, array(__('White Listed', 'it-l10n-better-wp-security'), 'type' => $type), '', '', intval($user));
                 }
             }
             if ($good_username !== false) {
                 //blacklist host and temp lockout username
                 $user_expiration = $expiration;
                 $wpdb->insert($wpdb->base_prefix . 'itsec_lockouts', array('lockout_type' => $type, 'lockout_start' => date('Y-m-d H:i:s', $itsec_globals['current_time']), 'lockout_start_gmt' => date('Y-m-d H:i:s', $itsec_globals['current_time_gmt']), 'lockout_expire' => $expiration, 'lockout_expire_gmt' => $expiration_gmt, 'lockout_host' => '', 'lockout_username' => $username));
                 if ($whitelisted === false) {
                     $itsec_logger->log_event('lockout', 10, array('expires' => $expiration, 'expires_gmt' => $expiration_gmt, 'type' => $type), '', '', $username);
                 } else {
                     $itsec_logger->log_event('lockout', 10, array(__('White Listed', 'it-l10n-better-wp-security'), 'type' => $type), '', '', $username);
                 }
             }
             if ($whitelisted === false) {
                 if ($itsec_globals['settings']['email_notifications'] === true) {
                     //send email notifications
                     $this->send_lockout_email($good_host, $good_user, $good_username, $host_expiration, $user_expiration, $reason);
                 }
                 if ($good_host !== false) {
                     $itsec_files->release_file_lock('lockout_' . $host . $user . $username);
                     $this->execute_lock();
                 } else {
                     $itsec_files->release_file_lock('lockout_' . $host . $user . $username);
                     $this->execute_lock(true);
                 }
             }
         }
         $itsec_files->release_file_lock('lockout_' . $host . $user . $username);
     }
 }
 /**
  * Prepare data for table
  *
  * @return void
  */
 public function prepare_items()
 {
     global $itsec_logger;
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     $items = $itsec_logger->get_events('user_logging');
     $table_data = array();
     $count = 0;
     foreach ($items as $item) {
         //loop through and group 404s
         $log_data = maybe_unserialize($item['log_data']);
         $table_data[$count]['time'] = sanitize_text_field($item['log_date']);
         $table_data[$count]['host'] = sanitize_text_field($item['log_host']);
         if (strlen(trim(sanitize_text_field($item['log_username']))) > 0) {
             $table_data[$count]['user'] = sanitize_text_field($item['log_username']);
         } elseif (intval($item['log_user']) > 0 && ITSEC_Lib::user_id_exists($item['log_user'])) {
             $user = get_user_by('id', $item['log_user']);
             $table_data[$count]['user'] = $user->data->user_login;
         } else {
             $table_data[$count]['user'] = '';
         }
         $table_data[$count]['action'] = sanitize_text_field($log_data['action']);
         if (isset($log_data['post'])) {
             $table_data[$count]['post_id'] = sanitize_text_field($log_data['post']);
         } else {
             $table_data[$count]['post_id'] = '';
         }
         $count++;
     }
     usort($table_data, array($this, 'sortrows'));
     $per_page = 50;
     //20 items per page
     $current_page = $this->get_pagenum();
     $total_items = count($table_data);
     $table_data = array_slice($table_data, ($current_page - 1) * $per_page, $per_page);
     $this->items = $table_data;
     $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page)));
 }
 public function release_lockout()
 {
     global $wpdb, $itsec_globals;
     if (!class_exists('ITSEC_Lib')) {
         require trailingslashit($itsec_globals['plugin_dir']) . '/core/class-itsec-lib.php';
     }
     $lockout_ids = $_POST['lockout_ids'];
     if (!is_array($lockout_ids)) {
         $lockout_ids = array();
     }
     $type = 'updated';
     $message = __('The selected lockouts have been cleared.', 'better-wp-security');
     foreach ($lockout_ids as $value) {
         $wpdb->update($wpdb->base_prefix . 'itsec_lockouts', array('lockout_active' => 0), array('lockout_id' => intval($value)));
     }
     ITSEC_Lib::clear_caches();
     if (!is_multisite()) {
         if (!function_exists('add_settings_error')) {
             require_once ABSPATH . '/wp-admin/includes/template.php';
         }
         add_settings_error('itsec', esc_attr('settings_updated'), $message, $type);
     }
     $site_status = array('username_admin_exists' => username_exists('admin') ? 1 : 0, 'user_id1_exists' => ITSEC_Lib::user_id_exists(1) ? 1 : 0, 'backup' => $this->backup_status(), 'permalink_structure' => get_option('permalink_structure'), 'is_multisite' => is_multisite() ? 1 : 0, 'users_can_register' => get_site_option('users_can_register') ? 1 : 0, 'force_ssl_login' => defined('FORCE_SSL_LOGIN') && FORCE_SSL_LOGIN === true ? 1 : 0, 'force_ssl_admin' => defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN === true ? 1 : 0, 'server_nginx' => 'nginx' === ITSEC_Lib::get_server() ? 1 : 0, 'lockouts_host' => $this->get_lockouts('host', true), 'lockouts_user' => $this->get_lockouts('user', true), 'lockouts_username' => $this->get_lockouts('username', true));
     return array('result' => 'success', 'site_status' => $site_status);
 }
 /**
  * Locks out given user or host
  *
  * @since 4.0
  *
  * @param  string $type     The type of lockout (for user reference)
  * @param  string $reason   Reason for lockout, for notifications
  * @param  string $host     Host to lock out
  * @param  int    $user     user id to lockout
  * @param string  $username username to lockout
  *
  * @return void
  */
 private function lockout($type, $reason, $host = null, $user = null, $username = null)
 {
     global $wpdb, $itsec_logger, $itsec_globals;
     $itsec_files = ITSEC_Core::get_itsec_files();
     $host_expiration = null;
     $user_expiration = null;
     $username = sanitize_text_field(trim($username));
     if ($itsec_files->get_file_lock('lockout_' . $host . $user . $username)) {
         //Do we have a good host to lock out or not
         if (!is_null($host) && ITSEC_Lib::is_ip_whitelisted(sanitize_text_field($host)) === false && ITSEC_Lib_IP_Tools::validate($host)) {
             $good_host = sanitize_text_field($host);
         } else {
             $good_host = false;
         }
         //Do we have a valid user to lockout or not
         if ($user !== null && ITSEC_Lib::user_id_exists(intval($user)) === true) {
             $good_user = intval($user);
         } else {
             $good_user = false;
         }
         //Do we have a valid username to lockout or not
         if ($username !== null && $username != '') {
             $good_username = $username;
         } else {
             $good_username = false;
         }
         $blacklist_host = false;
         //assume we're not permanently blcking the host
         //Sanitize the data for later
         $type = sanitize_text_field($type);
         $reason = sanitize_text_field($reason);
         //handle a permanent host ban (if needed)
         if (ITSEC_Modules::get_setting('global', 'blacklist') && $good_host !== false) {
             //permanent blacklist
             $blacklist_period = ITSEC_Modules::get_setting('global', 'blacklist_period', 7);
             $blacklist_seconds = $blacklist_period * DAY_IN_SECONDS;
             $host_count = 1 + $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . $wpdb->base_prefix . "itsec_lockouts` WHERE `lockout_expire_gmt` > '%s' AND `lockout_host`='%s';", date('Y-m-d H:i:s', $itsec_globals['current_time_gmt'] - $blacklist_seconds), $host));
             if ($host_count >= ITSEC_Modules::get_setting('global', 'blacklist_count') && ITSEC_Files::can_write_to_files()) {
                 $host_expiration = false;
                 $this->blacklist_ip(sanitize_text_field($host));
                 $blacklist_host = true;
                 //flag it so we don't do a temp ban as well
             }
         }
         //We have temp bans to perform
         if ($good_host !== false || $good_user !== false || $good_username || $good_username !== false) {
             if (ITSEC_Lib::is_ip_whitelisted(sanitize_text_field($host))) {
                 $whitelisted = true;
                 $expiration = date('Y-m-d H:i:s', 1);
                 $expiration_gmt = date('Y-m-d H:i:s', 1);
             } else {
                 $whitelisted = false;
                 $exp_seconds = ITSEC_Modules::get_setting('global', 'lockout_period') * MINUTE_IN_SECONDS;
                 $expiration = date('Y-m-d H:i:s', $itsec_globals['current_time'] + $exp_seconds);
                 $expiration_gmt = date('Y-m-d H:i:s', $itsec_globals['current_time_gmt'] + $exp_seconds);
             }
             if ($good_host !== false && $blacklist_host === false) {
                 //temp lockout host
                 $host_expiration = $expiration;
                 $wpdb->insert($wpdb->base_prefix . 'itsec_lockouts', array('lockout_type' => $type, 'lockout_start' => date('Y-m-d H:i:s', $itsec_globals['current_time']), 'lockout_start_gmt' => date('Y-m-d H:i:s', $itsec_globals['current_time_gmt']), 'lockout_expire' => $expiration, 'lockout_expire_gmt' => $expiration_gmt, 'lockout_host' => sanitize_text_field($host)));
                 $itsec_logger->log_event('lockout', 10, array('expires' => $expiration, 'expires_gmt' => $expiration_gmt, 'type' => $type), sanitize_text_field($host));
             }
             if ($good_user !== false) {
                 //blacklist host and temp lockout user
                 $user_expiration = $expiration;
                 $wpdb->insert($wpdb->base_prefix . 'itsec_lockouts', array('lockout_type' => $type, 'lockout_start' => date('Y-m-d H:i:s', $itsec_globals['current_time']), 'lockout_start_gmt' => date('Y-m-d H:i:s', $itsec_globals['current_time_gmt']), 'lockout_expire' => $expiration, 'lockout_expire_gmt' => $expiration_gmt, 'lockout_host' => '', 'lockout_user' => intval($user)));
                 if ($whitelisted === false) {
                     $itsec_logger->log_event('lockout', 10, array('expires' => $expiration, 'expires_gmt' => $expiration_gmt, 'type' => $type), '', '', intval($user));
                 } else {
                     $itsec_logger->log_event('lockout', 10, array(__('White Listed', 'better-wp-security'), 'type' => $type), '', '', intval($user));
                 }
             }
             if ($good_username !== false) {
                 //blacklist host and temp lockout username
                 $user_expiration = $expiration;
                 $wpdb->insert($wpdb->base_prefix . 'itsec_lockouts', array('lockout_type' => $type, 'lockout_start' => date('Y-m-d H:i:s', $itsec_globals['current_time']), 'lockout_start_gmt' => date('Y-m-d H:i:s', $itsec_globals['current_time_gmt']), 'lockout_expire' => $expiration, 'lockout_expire_gmt' => $expiration_gmt, 'lockout_host' => '', 'lockout_username' => $username));
                 if ($whitelisted === false) {
                     $itsec_logger->log_event('lockout', 10, array('expires' => $expiration, 'expires_gmt' => $expiration_gmt, 'type' => $type), '', '', $username);
                 } else {
                     $itsec_logger->log_event('lockout', 10, array(__('White Listed', 'better-wp-security'), 'type' => $type), '', '', $username);
                 }
             }
             if ($whitelisted === false) {
                 if (ITSEC_Modules::get_setting('global', 'email_notifications')) {
                     //send email notifications
                     $this->send_lockout_email($good_host, $good_user, $good_username, $host_expiration, $user_expiration, $reason);
                 }
                 if ($good_host !== false) {
                     $itsec_files->release_file_lock('lockout_' . $host . $user . $username);
                     $this->execute_lock();
                 } else {
                     $itsec_files->release_file_lock('lockout_' . $host . $user . $username);
                     $this->execute_lock(true);
                 }
             }
         }
         $itsec_files->release_file_lock('lockout_' . $host . $user . $username);
     }
 }
 public function run($arguments)
 {
     global $itsec_logger;
     $items = $itsec_logger->get_events('malware');
     $scan_count = 0;
     $report_count = 0;
     $total_count = 0;
     $return_array = array();
     $return_array['reports'] = array();
     $return_array['scans'] = array();
     $end = false;
     foreach ($items as $item) {
         //loop through and group 404s
         if ($end === true) {
             break;
         }
         $log_data = maybe_unserialize($item['log_data']);
         $action = isset($log_data['type']) ? sanitize_text_field($log_data['type']) : '';
         $good_item = true;
         if ($action == 'Malware Scan Report') {
             $array = 'reports';
             $count = $report_count;
         } elseif ($action == 'Malware Scan Requested') {
             $array = 'scans';
             $count = $scan_count;
         } else {
             $good_item = false;
         }
         if ($good_item === true) {
             $return_array[$array][$count]['time'] = sanitize_text_field($item['log_date']);
             $return_array[$array][$count]['host'] = sanitize_text_field($item['log_host']);
             if (strlen(trim(sanitize_text_field($item['log_username']))) > 0) {
                 $return_array[$array][$count]['user'] = sanitize_text_field($item['log_username']);
             } elseif (intval($item['log_user']) > 0 && ITSEC_Lib::user_id_exists($item['log_user'])) {
                 $user = get_user_by('id', $item['log_user']);
                 $return_array[$array][$count]['user'] = $user->data->user_login;
             } else {
                 $return_array[$array][$count]['user'] = '';
             }
             if (isset($log_data['resource'])) {
                 $return_array[$array][$count]['report'] = array('resource' => $log_data['resource']);
             }
             if (isset($log_data['report'])) {
                 $return_array[$array][$count]['report']['results'] = $log_data['report'];
             }
             if ($action == 'Malware Scan Report') {
                 $report_count++;
             } elseif ($action == 'Malware Scan Requested') {
                 $scan_count++;
             }
         }
         if (isset($arguments['count'])) {
             $count = absint($arguments['count']);
         } else {
             $count = 10;
         }
         if ($count > 0) {
             $count = $count - 1;
             if (isset($arguments['type'])) {
                 $type = sanitize_text_field($arguments['type']);
             } else {
                 $type = 'all';
             }
             switch ($type) {
                 case 'reports':
                     if ($report_count == $count) {
                         $end = true;
                     }
                     break;
                 case 'scans':
                     if ($scan_count == $count) {
                         $end = true;
                     }
                     break;
                 default:
                     if ($total_count == $count - 1) {
                         $end = true;
                     }
                     break;
             }
         }
         $total_count++;
     }
     if (isset($arguments['type'])) {
         switch ($arguments['type']) {
             case 'reports':
                 return $return_array['reports'];
                 break;
             case 'scans':
                 return $return_array['scans'];
                 break;
             default:
                 break;
         }
     }
     return $return_array;
 }
	/**
	 * Prepare data for table
	 *
	 * @return void
	 */
	public function prepare_items() {
		global $itsec_logger, $wpdb;

		$columns               = $this->get_columns();
		$hidden                = array();
		$this->_column_headers = array( $columns, $hidden, false );
		$per_page              = 20;
		$current_page          = $this->get_pagenum();
		$total_items           = $wpdb->get_var( "SELECT COUNT(*) FROM `" . $wpdb->base_prefix . "itsec_log` WHERE `log_type`='malware'" );

		$items = $itsec_logger->get_events( 'malware', array(), $per_page, ( ( $current_page - 1 ) * $per_page ), 'log_date' );

		$table_data = array();

		$count = 0;

		foreach ( $items as $item ) { //loop through and group 404s

			$log_data = maybe_unserialize( $item['log_data'] );

			$table_data[$count]['time'] = sanitize_text_field( $item['log_date'] );
			$table_data[$count]['host'] = sanitize_text_field( $item['log_host'] );

			if ( strlen( trim( sanitize_text_field( $item['log_username'] ) ) ) > 0 ) {

				$table_data[$count]['user'] = sanitize_text_field( $item['log_username'] );

			} elseif ( intval( $item['log_user'] ) > 0 && ITSEC_Lib::user_id_exists( $item['log_user'] ) ) {

				$user = get_user_by( 'id', $item['log_user'] );

				$table_data[$count]['user'] = $user->data->user_login;

			} else {

				$table_data[$count]['user'] = '';

			}

			$table_data[$count]['action'] = ( is_array( $log_data ) && isset( $log_data['type'] ) ) ? sanitize_text_field( $log_data['type'] ) : __( 'Malware Scan Report', 'it-l10n-ithemes-security-pro' );
			
			if ( is_wp_error( $log_data ) ) {
				$table_data[$count]['results'] = 'error';
				$table_data[$count]['data'] = $log_data;
			} else if ( isset( $log_data['SCAN']['SITE'] ) ) {
				// New log data from Sucuri scan.
				
				if (
					empty( $log_data['SYSTEM']['WARN'] ) &&
					empty( $log_data['MALWARE']['WARN'] ) &&
					empty( $log_data['BLACKLIST']['WARN'] )
				) {
					$table_data[$count]['results'] = 'clean';
				} else {
					$table_data[$count]['results'] = 'warn';
				}
				
				$table_data[$count]['data'] = $log_data;
			} else {
				// Legacy log data from VirusTotal scan.

				if ( isset( $log_data['resource'] ) ) {

					$table_data[$count]['report'] = array(
						'resource' => $log_data['resource'],
					);

				} else {

					$table_data[$count]['report'] = array();

				}

				if ( isset( $log_data['report'] ) ) {
					$table_data[$count]['report']['results'] = $log_data['report'];
				}

			}

			$table_data[$count]['count'] = $count;

			$count ++;

		}

//		usort( $table_data, array( $this, 'sortrows' ) );

		$this->items = $table_data;

		$this->set_pagination_args(
			array(
				'total_items' => $total_items,
				'per_page'    => $per_page,
				'total_pages' => ceil( $total_items / $per_page )
			)
		);
	}