예제 #1
0
파일: banip.php 프로젝트: erorus/newsstand
<?php

require_once __DIR__ . '/../incl/incl.php';
require_once __DIR__ . '/../incl/api.incl.php';
if (!isset($argv[1])) {
    DebugMessage("Enter IP to ban on command line.\n");
    exit(1);
}
$ip = trim($argv[1]);
if ($ip == false) {
    MCDelete(BANLIST_CACHEKEY);
    DebugMessage("Cleared banlist from memcache.\n");
    exit;
}
$ret = BanIP($ip);
if ($ret) {
    DebugMessage("{$ip} added to ban list.\n");
} else {
    if (IPIsBanned($ip)) {
        DebugMessage("{$ip} already on ban list.\n");
    } else {
        DebugMessage("{$ip} NOT added to ban list.\n");
    }
}
예제 #2
0
function BotCheck($returnReason = false)
{
    if (PHP_SAPI == 'cli' || !isset($_SERVER['REMOTE_ADDR'])) {
        return false;
    }
    $checked = $_SERVER['REMOTE_ADDR'];
    $reason = '';
    $banned = IPIsBanned($checked, $reason);
    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $filterOpts = array('default' => false, 'flags' => FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);
        $otherIPs = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 6);
        if (count($otherIPs) == 6) {
            array_pop($otherIPs);
        }
        while (count($otherIPs) && !$banned) {
            if ($otherIP = filter_var(trim(array_shift($otherIPs)), FILTER_VALIDATE_IP, $filterOpts)) {
                $banned |= IPIsBanned($checked = $otherIP, $reason);
            }
        }
    }
    if ($returnReason) {
        return ['isbanned' => $banned, 'ip' => $banned ? $checked : '', 'reason' => $banned ? $reason : ''];
    }
    if ($banned) {
        header('HTTP/1.1 403 Forbidden');
        exit;
    }
    $c = UserThrottleCount();
    if ($c > THROTTLE_MAXHITS * 2) {
        BanIP();
    } else {
        if ($c > THROTTLE_MAXHITS) {
            header('Expires: 0');
            json_return(array('captcha' => CaptchaDetails()));
        }
    }
}