Example #1
0
function checkBan($board = false)
{
    global $config;
    if (!isset($_SERVER['REMOTE_ADDR'])) {
        // Server misconfiguration
        return;
    }
    if (event('check-ban', $board)) {
        return true;
    }
    $ips = array();
    $ips[] = $_SERVER['REMOTE_ADDR'];
    if ($config['proxy_check'] && isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
        $ips = array_merge($ips, explode(", ", $_SERVER['HTTP_X_FORWARDED_FOR']));
    }
    foreach ($ips as $ip) {
        $bans = Bans::find($_SERVER['REMOTE_ADDR'], $board, $config['show_modname']);
        foreach ($bans as &$ban) {
            if ($ban['expires'] && $ban['expires'] < time()) {
                Bans::delete($ban['id']);
                if ($config['require_ban_view'] && !$ban['seen']) {
                    if (!isset($_POST['json_response'])) {
                        displayBan($ban);
                    } else {
                        header('Content-Type: text/json');
                        die(json_encode(array('error' => true, 'banned' => true)));
                    }
                }
            } else {
                if (!isset($_POST['json_response'])) {
                    displayBan($ban);
                } else {
                    header('Content-Type: text/json');
                    die(json_encode(array('error' => true, 'banned' => true)));
                }
            }
        }
    }
    // I'm not sure where else to put this. It doesn't really matter where; it just needs to be called every
    // now and then to keep the ban list tidy.
    if ($config['cache']['enabled'] && ($last_time_purged = cache::get('purged_bans_last'))) {
        if (time() - $last_time_purged < $config['purge_bans']) {
            return;
        }
    }
    Bans::purge();
    if ($config['cache']['enabled']) {
        cache::set('purged_bans_last', time());
    }
}