Exemple #1
0
function sfs_check_banned($user_data, &$cached_response = false)
{
    if (forum_get_setting('sfs_enabled', 'N')) {
        return false;
    }
    $request = array('f' => 'json');
    if (isset($user_data['IPADDRESS']) && strlen(trim($user_data['IPADDRESS'])) > 0) {
        $request['ip'] = ipv6_to_ipv4($user_data['IPADDRESS']);
    }
    if (!isset($user_data['UID']) || $user_data['UID'] > 0) {
        if (isset($user_data['LOGON']) && strlen(trim($user_data['LOGON'])) > 0) {
            $request['username'] = $user_data['LOGON'];
        }
        if (isset($user_data['EMAIL']) && strlen(trim($user_data['EMAIL'])) > 0) {
            $request['email'] = $user_data['EMAIL'];
        }
    }
    if (sizeof($request) < 2) {
        return false;
    }
    $ban_type_array = array('ip' => BAN_TYPE_IP, 'username' => BAN_TYPE_LOGON, 'email' => BAN_TYPE_EMAIL);
    $sfs_api_url_array = parse_url(forum_get_setting('sfs_api_url', null, 'http://www.stopforumspam.com/api'));
    $sfs_api_url_array['query'] = http_build_query($request, false, '&');
    $sfs_api_url = build_url_str($sfs_api_url_array);
    $sfs_api_url_md5 = md5($sfs_api_url);
    $min_confidence = forum_get_setting('sfs_min_confidence', null, 75);
    $response_confidence = 0;
    $cached_response = false;
    try {
        if (!($response = sfs_cache_get($sfs_api_url_md5, $cached_response))) {
            $curl = curl_init($sfs_api_url);
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 500);
            curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
            $response = json_decode(curl_exec($curl), true);
        }
        if (!isset($response['success']) || $response['success'] != 1) {
            return false;
        }
        if (!$cached_response) {
            sfs_cache_put($sfs_api_url_md5, $response);
        }
        foreach (array_keys($ban_type_array) as $key) {
            if (!isset($response[$key]['confidence'])) {
                continue;
            }
            $response_confidence += $response[$key]['confidence'];
        }
        $response_confidence = $response_confidence / (count($request) - 1);
    } catch (Exception $e) {
        return false;
    }
    return $response_confidence > $min_confidence;
}
Exemple #2
0
function sfs_check_banned($user_data, &$cached_response = false)
{
    if (forum_get_setting('sfs_enabled', 'N')) {
        return false;
    }
    $request = array('f' => 'json');
    if (isset($user_data['IPADDRESS']) && strlen(trim($user_data['IPADDRESS'])) > 0) {
        $request['ip'] = $user_data['IPADDRESS'];
    }
    if (!isset($user_data['UID']) || $user_data['UID'] > 0) {
        if (isset($user_data['LOGON']) && strlen(trim($user_data['LOGON'])) > 0) {
            $request['username'] = $user_data['LOGON'];
        }
        if (isset($user_data['EMAIL']) && strlen(trim($user_data['EMAIL'])) > 0) {
            $request['email'] = $user_data['EMAIL'];
        }
    }
    if (sizeof($request) < 2) {
        return false;
    }
    $ban_type_array = array('ip' => BAN_TYPE_IP, 'username' => BAN_TYPE_LOGON, 'email' => BAN_TYPE_EMAIL);
    $sfs_api_url_array = parse_url(forum_get_setting('sfs_api_url', null, 'http://www.stopforumspam.com/api'));
    $sfs_api_url_array['query'] = http_build_query($request, false, '&');
    $sfs_api_url = build_url_str($sfs_api_url_array);
    $sfs_api_url_md5 = md5($sfs_api_url);
    $min_confidence = forum_get_setting('sfs_min_confidence', null, 75);
    $response_confidence = 0;
    try {
        if (!($response = sfs_cache_get($sfs_api_url_md5, $cached_response))) {
            $context = stream_context_create(array('http' => array('timeout' => 1)));
            $response = json_decode(file_get_contents($sfs_api_url, null, $context), true);
        }
        sfs_cache_put($sfs_api_url_md5, $response);
        if (!isset($response['success']) || $response['success'] != 1) {
            return false;
        }
        foreach (array_keys($ban_type_array) as $key) {
            if (!isset($response[$key]['confidence'])) {
                continue;
            }
            $response_confidence += $response[$key]['confidence'];
        }
        $response_confidence = $response_confidence / (count($request) - 1);
    } catch (Exception $e) {
        return false;
    }
    return $response_confidence > $min_confidence;
}