Esempio n. 1
0
function CICAPEnableSquidGuardSave()
{
    $q = new mysql_squid_builder();
    $sock = new sockets();
    $q->CheckTablesICAP();
    $sock->SET_INFO("CICAPEnableSquidGuard", $_POST["CICAPEnableSquidGuard"]);
    if ($_POST["CICAPEnableSquidGuard"] == 1) {
        $q->QUERY_SQL("UPDATE c_icap_services SET enabled=1,zOrder=3 WHERE ID=12");
    } else {
        $q->QUERY_SQL("UPDATE c_icap_services SET enabled=0 WHERE ID=12");
    }
}
Esempio n. 2
0
function CicapEnabled()
{
    $sock = new sockets();
    $q = new mysql_squid_builder();
    $q->CheckTablesICAP();
    $EnableClamavInCiCap = $sock->GET_INFO("EnableClamavInCiCap");
    if (!is_numeric($EnableClamavInCiCap)) {
        $EnableClamavInCiCap = 1;
    }
    if ($_POST["CicapEnabled"] == 1) {
        if ($EnableClamavInCiCap == 1) {
            $q->QUERY_SQL("UPDATE c_icap_services SET enabled=1,zOrder=1 WHERE ID=1");
            $q->QUERY_SQL("UPDATE c_icap_services SET enabled=1,zOrder=2 WHERE ID=2");
        }
    } else {
        $q->QUERY_SQL("UPDATE c_icap_services SET enabled=0 WHERE ID=1");
        $q->QUERY_SQL("UPDATE c_icap_services SET enabled=0 WHERE ID=2");
    }
    $sock->SET_INFO("CicapEnabled", $_POST["CicapEnabled"]);
}
Esempio n. 3
0
function enable_icap()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        echo basename(__FILE__) . ":Already executed pid {$pid}.. aborting the process\n";
        progress("{failed}", 110);
        return;
    }
    $sock = new sockets();
    $sock->SET_INFO("kavicapserverEnabled", 1);
    $MEM = $unix->MEM_TOTAL_INSTALLEE();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $sock->SET_INFO("kavicapserverEnabled", 0);
        if ($GLOBALS["OUTPUT"]) {
            echo "Not enough memory - {$MEM}\n";
        }
        progress("{failed}", 110);
        return;
    }
    $q = new mysql_squid_builder();
    progress("{verify_icap_center}", 10);
    $q->CheckTablesICAP();
    if ($q->COUNT_ROWS("c_icap_services") == 0) {
        progress("{verify_icap_center} {failed}", 110);
    }
    progress("{hooking_local_service}", 10);
    $q->QUERY_SQL("UPDATE c_icap_services SET `enabled`=1 WHERE ID=6");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        progress("{hooking_local_service} {failed}", 110);
    }
    $q->QUERY_SQL("UPDATE c_icap_services SET `enabled`=1 WHERE ID=5");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        progress("{hooking_local_service} {failed}", 110);
    }
    progress("{reloading} {APP_KAV4PROXY}", 20);
    build();
    system("/etc/init.d/kav4proxy reload");
    progress("{configuring} {APP_SQUID}", 50);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force --noverifcaches");
    progress("{restarting} {APP_SQUID}", 70);
    system("/etc/init.d/squid restart --force {$GLOBALS["SCRIPT_SUFFIX"]}");
    progress("{restarting} Artica-status", 80);
    system("/etc/init.d/artica-status restart --force");
    progress("{refresh} License", 90);
    $GLOBALS["FORCE"] = true;
    license_infos(true);
    progress("{success} {hooking_local_service}", 100);
}
Esempio n. 4
0
function search()
{
    $tpl = new templates();
    $MyPage = CurrentPageName();
    $q = new mysql_squid_builder();
    $STATUS_ARRAY[0] = "32-green-grey.png";
    $STATUS_ARRAY[1] = "32-green.png";
    $STATUS_ARRAY[2] = "32-red.png";
    $STATUS_ARRAY[3] = "warning32.png";
    $t = $_GET["t"];
    $search = '%';
    $table = "c_icap_services";
    $page = 1;
    $FORCE_FILTER = 1;
    $total = 0;
    if (isset($_GET["OnlyActive"])) {
        if ($_GET["OnlyActive"] == 1) {
            $FORCE_FILTER = "`enabled`=1";
        }
    }
    $q->CheckTablesICAP();
    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) {
        $search = $_POST["query"];
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER} {$searchstring}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    } else {
        $sql = "SELECT COUNT(*) as TCOUNT FROM `{$table}` WHERE {$FORCE_FILTER}";
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
        $total = $ligne["TCOUNT"];
    }
    if (isset($_POST['rp'])) {
        $rp = $_POST['rp'];
    }
    $pageStart = ($page - 1) * $rp;
    if (!is_numeric($rp)) {
        $rp = 50;
    }
    $limitSql = "LIMIT {$pageStart}, {$rp}";
    $sql = "SELECT *  FROM `{$table}` WHERE {$FORCE_FILTER} {$searchstring}  {$ORDER} {$limitSql}";
    $results = $q->QUERY_SQL($sql);
    writelogs($sql . " ==> " . mysql_num_rows($results) . " items", __FUNCTION__, __FILE__, __LINE__);
    $data = array();
    $data['page'] = $page;
    $data['total'] = $total + 1;
    $data['rows'] = array();
    if (!$q->ok) {
        json_error_show($q->mysql_error, 1);
    }
    $fontsize = 22;
    while ($ligne = mysql_fetch_assoc($results)) {
        $CountDeMembers = 0;
        $color = "black";
        if ($ligne["enabled"] == 0) {
            $color = "#8a8a8a";
        }
        $style = "style='font-size:{$fontsize}px;color:{$color};'";
        $delete = imgsimple("delete-32.png", null, "Loadjs('{$MyPage}?service-delete-js=yes&ID={$ligne["ID"]}&t={$t}');");
        $bypass = "******";
        $js = "<a href=\"javascript:blur();\" OnClick=\"javascript:Loadjs('{$MyPage}?service-js=yes&ID={$ligne["ID"]}&t={$t}');\"\n\t\tstyle='font-size:{$fontsize}px;color:{$color};text-decoration:underline'>";
        if ($ligne["ID"] < 20) {
            $delete = "&nbsp;";
        }
        $up = imgsimple("arrow-up-32.png", null, "Loadjs('{$MyPage}?move-item-js=yes&ID={$ligne["ID"]}&dir=0&t={$_GET["t"]}')");
        $down = imgsimple("arrow-down-32.png", null, "Loadjs('{$MyPage}?move-item-js=yes&ID={$ligne["ID"]}&dir=1&t={$_GET["t"]}')");
        if (intval($ligne["bypass"]) > 0) {
            $ligne["bypass"] = 1;
        }
        if ($ligne["bypass"] == 1) {
            $bypass = "******";
        }
        $data['rows'][] = array('id' => $ligne['ID'], 'cell' => array("<span {$style}>{$js}{$ligne["zOrder"]}</a></span>", "<span {$style}>{$js}{$ligne["service_name"]}</a></span>", "<span {$style}>{$js}{$ligne["ipaddr"]}:{$ligne["listenport"]}</span>", "<span {$style}>{$js}{$ligne["respmod"]}</span>", "<center {$style}>{$js}{$bypass}</center>", "<center {$style}>{$up}</center>", "<center {$style}>{$down}</center>", "<center {$style}>{$delete}</center>", "<center {$style}>" . imgsimple($STATUS_ARRAY[$ligne["status"]]) . "</center>"));
    }
    echo json_encode($data);
}
Esempio n. 5
0
function C_ICAP_CLIENTS($aspid = false)
{
    $unix = new unix();
    $PidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if (!$aspid) {
        $pid = $unix->get_pid_from_file($PidFile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $TimeMin = $unix->PROCCESS_TIME_MIN($pid);
            return;
        }
    }
    @file_put_contents($PidFile, getmypid());
    $cicap_client = $unix->find_program("c-icap-client");
    if (!is_file($cicap_client)) {
        return;
    }
    $q = new mysql_squid_builder();
    $q->QUERY_SQL("UPDATE c_icap_services SET `status`=0 WHERE `enabled`=0");
    $q->CheckTablesICAP();
    $sql = "SELECT * FROM c_icap_services WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    if (mysql_num_rows($results) == 0) {
        return;
    }
    $METHODS["reqmod_precache"] = "REQMOD";
    $METHODS["respmod_precache"] = "RESPMOD";
    while ($ligne = mysql_fetch_assoc($results)) {
        $service_name_text = $ligne["service_name"];
        $ID = $ligne["ID"];
        $addr = $ligne["ipaddr"];
        $port = $ligne["listenport"];
        $service = $ligne["icap_server"];
        $cmdline = "{$cicap_client} -i {$addr} -p {$port} -s {$service} -method {$METHODS[$ligne["respmod"]]} 2>&1";
        if ($GLOBALS["VERBOSE"]) {
            echo $cmdline . "\n";
        }
        $Mresults = array();
        $FINAL = true;
        exec($cmdline, $Mresults);
        echo @implode("\n", $Mresults);
        $HEADER_LOG = "{$addr}:{$port}/{$service} ({$METHODS[$ligne["respmod"]]})";
        $FOUND = false;
        while (list($index, $line) = each($Mresults)) {
            if (preg_match("#200 OK#i", $line)) {
                $FINAL = true;
                $FOUND = true;
                break;
            }
            if (preg_match("#404 Service not found#i", $line)) {
                $FINAL = false;
                $FOUND = true;
                break;
            }
            if (preg_match("#Failed to connect#i", $line)) {
                $FINAL = false;
                $FOUND = true;
                break;
            }
        }
        if (!$FOUND) {
            squid_admin_mysql(1, "Unknown ICAP {$service} for {$HEADER_LOG}", @implode("\n", $Mresults), __FILE__, __LINE__);
            $q->QUERY_SQL("UPDATE c_icap_services SET `status`=3 WHERE ID={$ID}");
            continue;
        }
        if (!$FINAL) {
            squid_admin_mysql(0, "ICAP {$service} FAILED for {$HEADER_LOG}", @implode("\n", $Mresults), __FILE__, __LINE__);
            $q->QUERY_SQL("UPDATE c_icap_services SET `status`=2 WHERE ID={$ID}");
            continue;
        }
        $q->QUERY_SQL("UPDATE c_icap_services SET `status`=1 WHERE ID={$ID}");
    }
}
Esempio n. 6
0
function checkdatabase()
{
    $f["webfilter_aclsdynamic"] = true;
    $f["webfilter_aclsdynlogs"] = true;
    $f["webfilter_assoc_groups"] = true;
    $f["webfilter_avwhitedoms"] = true;
    $f["webfilter_bannedexts"] = true;
    $f["webfilter_bannedextsdoms"] = true;
    $f["webfilter_blkcnt"] = true;
    $f["webfilter_blkgp"] = true;
    $f["webfilter_blklnk"] = true;
    $f["webfilter_blks"] = true;
    $f["webfilter_certs"] = true;
    $f["webfilter_dnsbl"] = true;
    $f["webfilter_group"] = true;
    $f["webfilter_members"] = true;
    $f["webfilter_rules"] = true;
    $f["webfilter_terms"] = true;
    $f["webfilter_termsassoc"] = true;
    $f["webfilter_termsg"] = true;
    $f["webfilter_ufdbexpr"] = true;
    $f["webfilter_ufdbexprassoc"] = true;
    $f["webfilter_updateev"] = true;
    $f["webfilters_backupeddbs"] = true;
    $f["webfilters_bigcatzlogs"] = true;
    $f["webfilters_blkwhlts"] = true;
    $f["webfilters_categories_caches"] = true;
    $f["webfilters_databases_disk"] = true;
    $f["webfilters_dbstats"] = true;
    $f["webfilters_dtimes_blks"] = true;
    $f["webfilters_dtimes_rules"] = true;
    $f["webfilters_ipaddr"] = true;
    $f["webfilters_nodes"] = true;
    $f["webfilters_quotas"] = true;
    $f["webfilters_rewriteitems"] = true;
    $f["webfilters_rewriterules"] = true;
    $f["webfilters_schedules"] = true;
    $f["webfilters_sqaclaccess"] = true;
    $f["webfilters_sqacllinks"] = true;
    $f["webfilters_sqacls"] = true;
    $f["webfilters_sqaclsports"] = true;
    $f["webfilters_sqgroups"] = true;
    $f["webfilters_sqitems"] = true;
    $f["webfilters_sqtimes_assoc"] = true;
    $f["webfilters_sqtimes_rules"] = true;
    $f["webfilters_thumbnails"] = true;
    $f["webfilters_updates"] = true;
    $f["webfilters_usersasks"] = true;
    $f["websites_caches_params"] = true;
    $q = new mysql_squid_builder();
    if (!$q->TestingConnection()) {
        echo "Starting......: " . date("H:i:s") . " [MYSQL]: Connection failed...\n";
        return;
    }
    $build = false;
    while (list($tablename, $DGRULE) = each($f)) {
        if (!$q->TABLE_EXISTS($tablename)) {
            echo "Starting......: " . date("H:i:s") . " [MYSQL]: Missing table `{$tablename}`\n";
            $build = true;
        }
    }
    if ($build) {
        echo "Starting......: " . date("H:i:s") . " [MYSQL]: Construct database\n";
        $q->CheckTables(null, true);
        $q->CheckTablesICAP();
    }
}
Esempio n. 7
0
function checktables()
{
    $q = new mysql_squid_builder();
    $q->CheckTables();
    $q->CheckTablesICAP();
}