Beispiel #1
0
function BlackListedBase($url, $IP, $userid, $PROTO)
{
    $db_path = "/var/log/squid/ufdbgclient.black.db";
    $CONNECT = false;
    if (!is_file($db_path)) {
        if ($GLOBALS["DEBUG_BLACKLIST"]) {
            events("{$db_path} -> no such file");
        }
        return false;
    }
    $H = parse_url($url);
    $domain = $H["host"];
    if ($GLOBALS["DEBUG_BLACKLIST"]) {
        events("{$url} -> {$domain} PROTO: {$PROTO}");
    }
    reset_memory();
    if ($GLOBALS["SquidGuardIPWeb"] == null) {
        if ($GLOBALS["DEBUG_BLACKLIST"]) {
            events("http://127.0.0.1/ufdbguardd.php");
        }
        $GLOBALS["SquidGuardIPWeb"] = "http://127.0.0.1/ufdbguardd.php";
    }
    $urlenc = urlencode($url);
    if (preg_match("#([0-9\\.]+)#", $IP, $re)) {
        $IP = $re[1];
    }
    if ($userid == "-") {
        $userid = null;
    }
    $returned = "{$GLOBALS["SquidGuardIPWeb"]}?rule-id=0SquidGuardIPWeb=" . base64_encode($GLOBALS["SquidGuardIPWeb"]) . "&clientaddr={$IP}&clientname={$IP}&clientuser={$userid}" . "&clientgroup=global-blacklist&targetgroup=blacklist&url={$urlenc}";
    if ($PROTO == "CONNECT") {
        $CONNECT = true;
        if ($GLOBALS["SquidGuardWebUseExternalUri"] == 1) {
            $returned = $GLOBALS["SquidGuardWebExternalUriSSL"];
        } else {
            $returned = "https://{$GLOBALS["SquidGuardServerName"]}:{$GLOBALS["SquidGuardApacheSSLPort"]}/ufdbguardd.php?rule-id=0SquidGuardIPWeb=" . base64_encode("https://{$GLOBALS["SquidGuardServerName"]}:{$GLOBALS["SquidGuardApacheSSLPort"]}") . "&clientaddr={$IP}&clientname={$IP}&clientuser={$userid}" . "&clientgroup=global-blacklist&targetgroup=blacklist&url={$urlenc}";
        }
    }
    if (isset($GLOBALS["BlacklistedBase"][$domain])) {
        if ($GLOBALS["DEBUG_BLACKLIST"]) {
            events("BlackListedBase: {$domain} -> IN MEMORY [OK]");
        }
        if ($GLOBALS["BlacklistedBase"][$domain]) {
            if ($GLOBALS["DEBUG_BLACKLIST"]) {
                events("BlackListedBase: {$domain} -> MEM BLOCK");
            }
            ufdbgevents("blacklist", "global-blacklist");
            Output_results($returned, __FUNCTION__, __LINE__, $CONNECT);
            return true;
        } else {
            if ($GLOBALS["DEBUG_BLACKLIST"]) {
                events("BlackListedBase: {$domain} -> MEM [PASS]");
            }
            return false;
        }
    } else {
        if ($GLOBALS["DEBUG_BLACKLIST"]) {
            events("{$domain} -> MEMORY NOT BLACKLISTED");
        }
    }
    $db_con = dba_open($db_path, "r", "db4");
    if (!$db_con) {
        return false;
    }
    $mainkey = trim(dba_firstkey($db_con));
    while ($mainkey != false) {
        $val = 0;
        if (trim($mainkey) == null) {
            $mainkey = dba_nextkey($db_con);
            continue;
        }
        if ($GLOBALS["DEBUG_BLACKLIST"]) {
            events("BlackListedBase:Checking {$mainkey} -> {$domain}");
        }
        if (preg_match("#{$mainkey}#", $domain)) {
            $GLOBALS["BlacklistedBase"][$domain] = true;
            if ($GLOBALS["DEBUG_BLACKLIST"]) {
                events("BlackListedBase:  BLACKLIST MATCH {$mainkey} -> {$domain}");
            }
            ufdbgevents("blacklist", "global-blacklist");
            if ($GLOBALS["DEBUG_BLACKLIST"]) {
                events("Output_results({$returned})");
            }
            Output_results($returned, __FUNCTION__, __LINE__, $CONNECT);
            dba_close($db_con);
            return true;
        }
        $mainkey = dba_nextkey($db_con);
    }
    if ($GLOBALS["DEBUG_BLACKLIST"]) {
        events("{$domain} -> STAMP MEMORY TO FALSE");
    }
    $GLOBALS["BlacklistedBase"][$domain] = false;
    dba_close($db_con);
    return false;
}
Beispiel #2
0
function BlackListedBase($url,$IP,$userid){
	$db_path="/var/log/squid/ufdbgclient.black.db";
	
	if(!is_file($db_path)){
		if($GLOBALS["VERBOSE"]){events("$db_path -> no such file");}
		return false;
	}
	
	$H=parse_url($url);
	$domain=$H["host"];
	reset_memory();
	if($GLOBALS["SquidGuardIPWeb"]==null){
		$GLOBALS["SquidGuardIPWeb"]="http://127.0.0.1/exec.squidguard.php";
	}
	$urlenc=urlencode($url);
	if(preg_match("#([0-9\.]+)#", $IP,$re)){$IP=$re[1];}
	if($userid=="-"){$userid=null;}
	$returned="{$GLOBALS["SquidGuardIPWeb"]}?rule-id=0SquidGuardIPWeb=".
	base64_encode($GLOBALS["SquidGuardIPWeb"])."&clientaddr=$IP&clientname=$IP&clientuser=$userid".
	"&clientgroup=default&targetgroup=blacklist&url=$urlenc";

	if(isset($GLOBALS["BlacklistedBase"][$domain])){
		
		if($GLOBALS["BlacklistedBase"][$domain]){
			if($GLOBALS["VERBOSE"]){events("BlackListedBase: $domain -> MEM BLOCK"); }
			ufdbgevents("blacklist","default");
			Output_results($returned);
			return true;
		}else{
			if($GLOBALS["VERBOSE"]){events("BlackListedBase: $domain -> MEM PASS"); }
			return false;
		}
	}
	
	
	$db_con = dba_open($db_path, "r","db4");
	if(!$db_con){return false;}
	$mainkey=trim(dba_firstkey($db_con));
	
	while($mainkey !=false){
		$val=0;
	
	
		if(trim($mainkey)==null){
			$mainkey=dba_nextkey($db_con);
			continue;
		}
		
		if($GLOBALS["VERBOSE"]){events("BlackListedBase:Checking $mainkey -> $domain"); }
		if(preg_match("#$mainkey#", $domain)){
			$GLOBALS["BlacklistedBase"][$domain]=true;
			if($GLOBALS["VERBOSE"]){events("BlackListedBase:  BLACKLIST MATCH $mainkey -> $domain"); }
			ufdbgevents("blacklist","global-blacklist");
			Output_results($returned);
			dba_close($db_con);
			return true;
		}
	
		$mainkey=dba_nextkey($db_con);
	
	}
	$GLOBALS["BlacklistedBase"][$domain]=false;
	dba_close($db_con);
	return false;	
	
	
}