/**
  * Checks if the current IP is blocked.
  *
  * @since 2.0.0
  */
 public function ip_check()
 {
     if (!is_user_logged_in() && zerospam_is_blocked(zerospam_get_ip())) {
         do_action('zero_spam_ip_blocked');
         die(__($this->settings['blocked_ip_msg'], 'zerospam'));
     }
 }
Exemple #2
0
 /**
  * Uses wp_ajax_(action).
  *
  * Get the blocked IP data.
  *
  * @since 2.0.0
  *
  * @link http://codex.wordpress.org/Plugin_API/Action_Reference/wp_ajax_(action)
  */
 public function wp_ajax_get_blocked_ip()
 {
     global $wpdb;
     check_ajax_referer('zero-spam', 'security');
     $ajax_nonce = wp_create_nonce('zero-spam');
     $ip = $_REQUEST['ip'];
     $data = zerospam_get_blocked_ip($ip);
     if ($data) {
         $data->is_blocked = zerospam_is_blocked($ip);
         $data->start_date_txt = date('l, F j, Y', strtotime($data->start_date));
         $data->end_date_txt = date('l, F j, Y', strtotime($data->end_date));
         echo json_encode((array) $data);
     }
     die;
 }
function zerospam_block_ip($args)
{
    global $wpdb;
    $table_name = $wpdb->prefix . 'zerospam_blocked_ips';
    $ip = isset($args['ip']) ? $args['ip'] : false;
    $type = isset($args['type']) ? $args['type'] : 'temporary';
    if ($ip) {
        // Check is IP has already been blocked.
        if (zerospam_is_blocked($ip)) {
            // Update existing record.
            $wpdb->update($table_name, array('type' => $type, 'start_date' => isset($args['start_date']) ? $args['start_date'] : null, 'end_date' => isset($args['end_date']) ? $args['end_date'] : null, 'reason' => $args['reason']), array('ip' => $ip), array('%s', '%s', '%s', '%s'), array('%s'));
        } else {
            // Insert new record.
            $insert = array('ip' => $ip, 'type' => $type);
            if ('temporary' == $type) {
                $insert['start_date'] = $args['start_date'];
                $insert['end_date'] = $args['end_date'];
            }
            if (isset($args['reason']) && $args['reason']) {
                $insert['reason'] = $args['reason'];
            }
            $wpdb->insert($table_name, $insert, array('%s', '%s', '%s', '%s', '%s'));
        }
    }
}
            echo $obj->page;
            ?>
 <i class="fa fa-external-link-square"></i></a>
						<?php 
        } else {
            ?>
							<?php 
            echo __('Unknown', 'zerospam');
            ?>
						<?php 
        }
        ?>
					</td>
					<td class="zero-spam__status">
						<?php 
        if (zerospam_is_blocked($obj->ip)) {
            ?>
						<span class="zero-spam__label zero-spam__bg--primary"><?php 
            echo __('Blocked', 'zerospam');
            ?>
</span>
						<?php 
        } else {
            ?>
						<span class="zero-spam__label zero-spam__bg--trinary"><?php 
            echo __('Unblocked', 'zerospam');
            ?>
</span>
						<?php 
        }
        ?>
        ?>
" id="row-<?php 
        echo esc_attr($data->zerospam_ip_id);
        ?>
">
							<td class="zero-spam__ip"><a href="http://ip-lookup.net/index.php?ip=<?php 
        echo esc_attr($data->ip);
        ?>
" target="_blank">
								<?php 
        echo $data->ip;
        ?>
 <i class="fa fa-external-link-square"></i></a></td>
							<td class="zero-spam__status">
								<?php 
        if (zerospam_is_blocked($data->ip)) {
            ?>
								<span class="zero-spam__label zero-spam__bg--primary"><?php 
            echo __('Blocked', 'zerospam');
            ?>
</span>
								<?php 
        } else {
            ?>
								<span class="zero-spam__label zero-spam__bg--trinary"><?php 
            echo __('Unblocked', 'zerospam');
            ?>
</span>
								<?php 
        }
        ?>