Example #1
0
function xstart()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        return;
    }
    $TimeExec = $unix->file_time_min($pidtime);
    if ($TimeExec < 360) {
        return;
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    @file_put_contents($pidfile, getmypid());
    $php5 = $unix->LOCATE_PHP5_BIN();
    $q = new mysql_squid_builder();
    $q->CreateCategoryUrisTable("malware");
    $COUNT1 = $q->COUNT_ROWS("categoryuris_malware");
    vxvault();
    malwareurls_joxeankoret();
    clean_mx_de();
    $COUNT2 = $q->COUNT_ROWS("categoryuris_malware");
    $URLS_ADDED = $COUNT2 - $COUNT1;
    if ($URLS_ADDED > 0) {
        system("{$php5} /usr/share/artica-postfix/exec.squidguard.php --compile-category malware");
        squid_admin_mysql(2, "{$URLS_ADDED} malware URLs added", null, __FILE__, __LINE__);
    }
}
function updatev2_adblock()
{
    return;
    if (isset($GLOBALS[__FUNCTION__])) {
        return;
    }
    $GLOBALS[__FUNCTION__] = true;
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $main_artica_path = $GLOBALS["WORKDIR_LOCAL"];
    $unix = new unix();
    $users = new usersMenus();
    if (!$users->CORP_LICENSE) {
        if ($GLOBALS["VERBOSE"]) {
            echo "License error...\n";
        }
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        $TimeMn = $unix->file_time_min($timeFile);
        if ($TimeMn < 60) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$TimeMn}Mn require 60mn minimal (use --force if necessary)\n";
            }
            return;
        }
    }
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    updatev2_checkversion();
    $reload = false;
    $trackergzip = "{$main_artica_path}/category_tracker/tracker_expressions.gz";
    $trackerfinal = "{$main_artica_path}/category_tracker/expressions";
    $malwaregzip = "{$main_artica_path}/category_malware/categoryuris_malware.gz";
    $malwarecsv = "{$main_artica_path}/category_malware/categoryuris_malware.csv";
    $pubgzip = "{$main_artica_path}/category_publicite/publicite_expressions.gz";
    $pubfinal = "{$main_artica_path}/category_publicite/expressions";
    $phishgzip = "{$main_artica_path}/category_phishing/categoryuris_phishing.gz";
    $phishcsv = "{$main_artica_path}/category_phishing/categoryuris_phishing.csv";
    if ($GLOBALS["MIRROR"] == null) {
        return;
    }
    @unlink("{$pubgzip}");
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/publicite_expressions.gz");
    if (!$curl->GetFile($pubgzip)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pubgzip} failed to download {$curl->error}\n";
        }
        // ufdbguard_admin_events("UFDB::Fatal: $pubgzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        @unlink("{$pubgzip}");
    }
    @unlink($trackergzip);
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/tracker_expressions.gz");
    if (!$curl->GetFile($trackergzip)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$trackergzip} failed to download {$curl->error}\n";
        }
        // ufdbguard_admin_events("UFDB::Fatal: $trackergzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        @unlink($trackergzip);
    }
    @unlink($malwaregzip);
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/categoryuris_malware.gz");
    if (!$curl->GetFile($malwaregzip)) {
        // ufdbguard_admin_events("UFDB::Fatal: $malwaregzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        if ($GLOBALS["VERBOSE"]) {
            echo "{$malwaregzip} failed to download {$curl->error}\n";
        }
        @unlink($malwaregzip);
    }
    @unlink($phishgzip);
    $curl = new ccurl("{$GLOBALS["MIRROR"]}/categoryuris_phishing.gz");
    if (!$curl->GetFile($phishgzip)) {
        // ufdbguard_admin_events("UFDB::Fatal: $phishgzip failed to download $curl->error",__FUNCTION__,__FILE__,__LINE__,"ufbd-artica");
        if ($GLOBALS["VERBOSE"]) {
            echo "{$phishgzip} failed to download {$curl->error}\n";
        }
        @unlink($phishgzip);
    }
    $mdfile1 = md5_file($pubfinal);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pubfinal}({$mdfile1})\n";
    }
    if (is_file($pubgzip)) {
        $unix->uncompress($pubgzip, $pubfinal);
        $mdfile2 = md5_file($pubfinal);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pubfinal}({$mdfile2})\n";
        }
        if ($mdfile2 != $mdfile1) {
            $reload = true;
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pubgzip} no such file\n";
        }
    }
    $mdfile1 = md5_file($trackerfinal);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$trackerfinal} -1- ({$mdfile1})\n";
    }
    if (is_file($trackergzip)) {
        $unix->uncompress($trackergzip, $trackerfinal);
        $mdfile2 = md5_file($trackerfinal);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$trackerfinal} -2- ({$mdfile2})\n";
        }
        if ($mdfile1 != $mdfile2) {
            $reload = true;
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$trackergzip} no such file\n";
        }
    }
    if (is_file($malwaregzip)) {
        $uris = array();
        $q = new mysql_squid_builder();
        $unix->uncompress($malwaregzip, $malwarecsv);
        $handle = @fopen($malwarecsv, "r");
        $q->CreateCategoryUrisTable("malware");
        if ($handle) {
            $line = @fgets($handle);
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            $md5 = md5($line);
            $date = date("Y-m-d H:i:s");
            $url = mysql_escape_string2($line);
            $uris[] = "('{$md5}','{$date}','{$url}',1)";
        }
        if (count($uris) > 0) {
            $sql = "INSERT IGNORE INTO categoryuris_malware\n\t\t\t(zmd5,zDate,pattern,enabled) VALUES " . @implode(",", $uris);
            $q->QUERY_SQL($sql);
        }
    }
    if (is_file($phishgzip)) {
        $uris = array();
        $q = new mysql_squid_builder();
        $unix->uncompress($phishgzip, $phishcsv);
        $handle = @fopen($phishcsv, "r");
        $q->CreateCategoryUrisTable("phishing");
        if ($handle) {
            $line = @fgets($handle);
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            $md5 = md5($line);
            $date = date("Y-m-d H:i:s");
            $url = mysql_escape_string2($line);
            $uris[] = "('{$md5}','{$date}','{$url}',1)";
        }
        if (count($uris) > 0) {
            $sql = "INSERT IGNORE INTO categoryuris_phishing\n\t\t\t(zmd5,zDate,pattern,enabled) VALUES " . @implode(",", $uris);
            $q->QUERY_SQL($sql);
        }
    }
    if ($reload) {
        squid_admin_mysql(2, "Ask to reload the Web filtering service", "");
        shell_exec("/etc/init.d/ufdb reload");
    }
}
function query(){
	
	$category=null;
	$tpl=new templates();
	$also=$tpl->_ENGINE_parse_body("{also}");
	$MyPage=CurrentPageName();
	$q=new mysql_squid_builder();
	$nowebsites=$tpl->_ENGINE_parse_body("{no_saved_web_site_catz}");
	
	writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__);
	if($category==null){if($_GET["category"]<>null){$category=$_GET["category"];}}
	if($category==null){if($_POST["qtype"]<>null){$category=$_POST["qtype"];}}	
	
	
	if($_POST["query"]<>null){if($_GET["website"]<>null){$_POST["query"]=$_GET["website"];}}
	if($category==null){json_error_show("Please select a category first");}
	if($_POST["sortname"]=="sitename"){$_POST["sortname"]="zDate";$_POST["sortorder"]="desc";}
	
	writelogs("Category:$category",__FUNCTION__,__FILE__,__LINE__);
	$table="categoryuris_".$q->category_transform_name($category);
	$CategoriesCheckRightsWrite=CategoriesCheckRightsWrite();
	$q->CreateCategoryUrisTable(null,$table);
	$search='%';
	$page=1;
	$COUNT_ROWS=$q->COUNT_ROWS($table);
	
	if($COUNT_ROWS==0){json_error_show("no data",1);}
	
	if(isset($_POST["sortname"])){if($_POST["sortname"]<>null){$ORDER="ORDER BY {$_POST["sortname"]} {$_POST["sortorder"]}";}}	
	if (isset($_POST['page'])) {$page = $_POST['page'];}
	
	$searchstring=string_to_flexquery();
	
	
	if($searchstring<>null){
		$sql="SELECT COUNT(zmd5) as TCOUNT FROM `$table` WHERE 1 $searchstring";
		$ligne=mysql_fetch_array($q->QUERY_SQL($sql,"artica_backup"));
		$total = $ligne["TCOUNT"];
		
	}else{
		$total = $q->COUNT_ROWS($table);
	}
	
	if (isset($_POST['rp'])) {$rp = $_POST['rp'];}	
	

	
	$pageStart = ($page-1)*$rp;
	$limitSql = "LIMIT $pageStart, $rp";
	
	$sql="SELECT zDate,zmd5,pattern,enabled  FROM `$table` WHERE 1 $searchstring $ORDER $limitSql";	
	$results = $q->QUERY_SQL($sql);
	if(!$q->ok){json_error_show($q->mysql_error,1);}
	if(mysql_num_rows($results)==0){json_error_show("$nowebsites",1);}
	$disabled_text=$tpl->_ENGINE_parse_body("{disabled}");
	
	$data = array();
	$data['page'] = $page;
	$data['total'] = $total;
	$data['rows'] = array();
	
	
	
	while ($ligne = mysql_fetch_assoc($results)) {
		$delete=imgtootltip("delete-24.png","{delete}","DeleteCategorizedURI('{$ligne["zmd5"]}','$table')");

		$enabled=$ligne["enabled"];
		$color="color:black";
		if($enabled==0){
			$color="color:#B6ACAC";
			$added=$added."<div><i style='font-size:11px'>$disabled_text</i></div>";
			$moveAll="&nbsp;";
			$move="&nbsp;";
			
		}
		
$jscat="<a href=\"javascript:blur();\" 
		OnClick=\"javascript:Loadjs('squid.categorize.php?www={$ligne["pattern"]}');\"
		style='font-size:14px;text-decoration:underline;$color'>";	

if(!$CategoriesCheckRightsWrite){
	$jscat=null;
	$delete=null;
}
		
	$data['rows'][] = array(
		'id' => $ligne['zmd5'],
		'cell' => array("
		<span style='font-size:14px;$color'>{$ligne['zDate']}</span>",
		"<span style='font-size:14px;$color'>$jscat{$ligne['pattern']}</a></span>$added",$delete)
		);
	}
	
	
echo json_encode($data);	

	
}