function start()
{
    $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__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $PID = GET_PID();
    if ($unix->process_exists($PID)) {
        squid_admin_mysql(1, "Watchdog says that rsyslog is off, but exists [action=stamp-pid]", null, __FILE__, __LINE__);
        $SrcPid = intval(@file_get_contents("/var/run/rsyslogd.pid"));
        if ($SrcPid != $PID) {
            squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists (PID:{$PID}) [action=stamp-pid]", null, __FILE__, __LINE__);
            @file_put_contents("/var/run/rsyslogd.pid", $PID);
        } else {
            squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists [action=nothing]", null, __FILE__, __LINE__);
        }
        @unlink($pidfile);
        die(1);
    }
    squid_admin_mysql(0, "Syslog daemon is down [action=start]", null, __FILE__, __LINE__);
    system("/etc/init.d/rsyslog start");
    $squid = $unix->LOCATE_SQUID_BIN();
    if (is_file($squid)) {
        sleep(3);
        squid_admin_mysql(1, "Reloading proxy service after starting syslog daemon", null, __FILE__, __LINE__);
        system("{$squid} -f /etc/squid3/squid.conf -k reconfigure");
    }
}
function parse()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.pid";
    $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogDir");
    if ($GLOBALS["LogFileDeamonLogDir"] == null) {
        $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid/realtime-events";
    }
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pid} already executed since {$timepid}Mn\n";
        }
        if ($timepid < 14) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    $TimeExec = $unix->file_time_min($TimeFile);
    if (!$GLOBALS["FORCE"]) {
        if ($TimeExec < 20) {
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    parsedb("/var/log/squid");
    parsedb($GLOBALS["LogFileDeamonLogDir"]);
}
function scan_connections()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Artica Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded()) {
        system_admin_events("Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    $q = new mysql();
    $sql = "SELECT * FROM texttoldap";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (mysql_num_rows($results) == 0) {
        return;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        if (!connect($ligne)) {
            continue;
        }
        import($ligne);
        $ID = $ligne["ID"];
    }
}
function start()
{
    $unix = new unix();
    if (!$GLOBALS["VERBOSE"]) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid)) {
            writelogs("Already running pid {$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    $ldap = new clladp();
    $pattern = "(&(objectclass=userAccount))";
    $attr = array();
    $sr = @ldap_search($ldap->ldap_connection, "dc=organizations,{$ldap->suffix}", $pattern, $attr);
    $hash = ldap_get_entries($ldap->ldap_connection, $sr);
    $unix = new unix();
    $users_array = array();
    if (!is_array($hash)) {
        blackwhite_admin_mysql(0, "Unable to obtain users from LDAP server", $ldap->ldap_last_error, __FILE__, __LINE__);
        return;
    }
    for ($i = 0; $i < $hash["count"]; $i++) {
        $usersArray[$hash[$i]["uid"][0]] = true;
    }
    while (list($uid, $none) = each($usersArray)) {
        imapopen_White($uid);
        imapopen_black($uid);
    }
}
Exemple #5
0
function ParseAllcontacts()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if ($unix->file_time_min($pidtime) < 120) {
        return;
    }
    @file_put_contents($pidtime, time());
    $ldap = new clladp();
    $suffix = $ldap->suffix;
    $arr = array("uid");
    $sr = @ldap_search($ldap->ldap_connection, "dc=organizations,{$suffix}", '(objectclass=userAccount)', $arr);
    if ($sr) {
        $hash = ldap_get_entries($ldap->ldap_connection, $sr);
        for ($i = 0; $i < $hash["count"]; $i++) {
            ParseContacts($hash[$i]["uid"][0]);
            if (system_is_overloaded(dirname(__FILE__))) {
                $unix->send_email_events(basename(__FILE__) . " Overloaded aborting task", "Zarafa contacts importation has been canceled due to overloaded system", "mailbox");
                return;
            }
            sleep(1);
        }
    }
}
function xstart()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = @file_get_contents($pidfile);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pidtime}\n";
    }
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    if (!$GLOBALS["FORCE"]) {
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid} since {$time}mn\n";
            }
            die;
        }
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $timefile = $unix->file_time_min($pidtime);
    if ($GLOBALS["VERBOSE"]) {
        echo "Timelock:{$pidtime} {$timefile} Mn\n";
    }
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < 5) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timefile}mn require 5mn\n";
            }
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    if (!is_file("/home/ufdb/smtp-events/ACCESS_LOG")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "/home/ufdb/smtp-events/ACCESS_LOG no such file\n";
        }
    }
    $array = explode("\n", @file_get_contents("/home/ufdb/smtp-events/ACCESS_LOG"));
    @unlink("/home/ufdb/smtp-events/ACCESS_LOG");
    $body = array();
    $mmstp = new ufdb_msmtp();
    $Subject = count($array) . " Web filtering blocked event(s)";
    $body[] = "Return-Path: <{$mmstp->smtp_sender}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$mmstp->smtp_sender}";
    $body[] = "Subject: {$Subject}";
    $body[] = "To: {$mmstp->recipient}";
    $body[] = "";
    $body[] = "";
    $body[] = @implode("\r\n", $array);
    $body[] = "";
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$mmstp->Send($finalbody)) {
        squid_admin_mysql(0, "Unable to send notification {$Subject} to {$mmstp->recipient}", "{$Subject} to {$mmstp->recipient}\n------------------\n" . @implode("\n", $array) . "\n\t\tThe following error encountered\n" . $mmstp->logs . "\n", __FILE__, __LINE__);
    }
}
Exemple #7
0
function SingleDebug($ID)
{
    $q = new mysql();
    $q->BuildTables();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$ID}.pid";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidfile);
    $fetchmail = $unix->find_program("fetchmail");
    if ($unix->process_exists($pid)) {
        SingleDebugEvents("Task aborted", "This task is aborted, it already running PID {$pid}, please wait before executing a new task", $ID);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    SingleDebugEvents("Task executed", "Starting rule number {$ID}\nThis task is executed please wait before executing a new task", $ID);
    $fetch = new fetchmail();
    $output = array();
    $fetch = new fetchmail();
    $l[] = "set logfile /var/log/fetchmail-rule-{$ID}.log";
    $l[] = "set daemon {$fetch->FetchmailPoolingTime}";
    $l[] = "set postmaster \"{$fetch->FetchmailDaemonPostmaster}\"";
    $l[] = "set idfile \"/var/log/fetchmail.{$ID}.id\"";
    $l[] = "";
    $GLOBALS["SINGLE_DEBUG"] = true;
    BuildRules();
    $pattern = $GLOBALS["FETCHMAIL_RULES_ID"][$ID];
    $l[] = $pattern;
    @file_put_contents("/tmp/fetchmailrc.{$ID}", @implode("\n", $l));
    shell_exec("/bin/chmod 600 /tmp/fetchmailrc.{$ID}");
    $cmd = "{$fetchmail} -v -N -f /tmp/fetchmailrc.{$ID} --pidfile /tmp/fetcmailrc.{$ID}.pid 2>&1";
    exec($cmd, $output);
    SingleDebugEvents("Task finish with " . count($output) . " event(s)", @implode("\n", $output), $ID);
}
function start()
{
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    if ($unix->process_exists(@file_get_contents($pidfile), $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n";
        }
        system_admin_events("--> Already executed.. " . @file_get_contents($pidfile) . " aborting the process", __FUNCTION__, __FILE__, __LINE__, "zarafa");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $WordpressBackupParams = unserialize(base64_decode($sock->GET_INFO("WordpressBackupParams")));
    if (!isset($WordpressBackupParams["FTP_ENABLE"])) {
        $WordpressBackupParams["FTP_ENABLE"] = 0;
    }
    if (!isset($WordpressBackupParams["DEST"])) {
        $WordpressBackupParams["DEST"] = "/home/wordpress-backup";
    }
    if ($WordpressBackupParams["DEST"] == null) {
        $WordpressBackupParams["DEST"] = "/home/wordpress-backup";
    }
    ScanFreeWebs($WordpressBackupParams);
    $t = time();
    build_progress_fullback("{backup} FTP ?", 95);
    ftp_backup($WordpressBackupParams);
    sizes_backup();
    build_progress_fullback("{done}", 100);
}
Exemple #9
0
function applyAcls()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if ($unix->process_exists(@file_get_contents("{$pidfile}"))) {
        echo "Already process exists\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $sql = "SELECT `directory` FROM acl_directories";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            system_admin_events("Fatal,{$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "acls");
            echo $q->mysql_error . "\n";
            return;
        }
    }
    $count = mysql_num_rows($results);
    system_admin_events("INFO,acls {$count} items", __FUNCTION__, __FILE__, __LINE__, "acls");
    echo "Starting......: " . date("H:i:s") . " acls {$count} items\n";
    if ($count == 0) {
        return;
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        ApplySingleAcls($ligne["directory"]);
    }
    $setfacl_bin = $unix->find_program("setfacl");
    if (is_file($setfacl_bin)) {
        shell_exec("{$setfacl_bin} -b /tmp 2>&1");
    }
}
Exemple #10
0
function start()
{
    $sock = new sockets();
    $unix = new unix();
    @mkdir("/etc/artica-postfix/pids", 0755, true);
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        echo "SWAP: [INFO] Already running...\n";
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $sysctl = $unix->find_program("sysctl");
    $swapoff = $unix->find_program("swapoff");
    $swapon = $unix->find_program("swapon");
    $nohup = $unix->find_program("nohup");
    $DisableSWAPP = $sock->GET_INFO("DisableSWAPP");
    if (!is_numeric($DisableSWAPP)) {
        $DisableSWAPP = 0;
    }
    if ($DisableSWAPP == 0) {
        echo "SWAP: [INFO] swap is enabled, aborting\n";
        shell_exec("{$nohup} {$swapon} -a >/dev/null 2>&1 &");
        return;
    }
    echo "SWAP: [INFO] swap is disabled, hide swap usage...\n";
    shell_exec("{$sysctl} -w vm.swappiness=0 >/dev/null 2>&1");
    shell_exec("{$nohup} {$swapoff} -a >/dev/null 2>&1 &");
}
function build()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $sock = new sockets();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        die;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    @file_put_contents($pidfile, getmypid());
    progress("{get_system_informations}", 30);
    support_step1();
    progress("{APP_UFDBGUARD}", 40);
    $EnableUfdbGuard = intval($sock->EnableUfdbGuard());
    if ($EnableUfdbGuard == 1) {
        $ufdbguardd = $unix->find_program("ufdbguardd");
        if (is_file($ufdbguardd)) {
            shell_exec("{$php} /usr/share/artica-postfix/exec.squidguard.php --build --force --verbose >/usr/share/artica-postfix/ressources/support/build-ufdbguard.log 2>&1");
        }
    }
    progress("{get_all_logs}", 50);
    support_step2();
    progress("{get_all_logs}", 70);
    export_tables();
    progress("{compressing_package}", 90);
    support_step3();
    progress("{success}", 100);
}
function xstart()
{
    $unix = new unix();
    $sock = new sockets();
    $GLOBALS["CLASS_SOCKETS"] = $sock;
    $FORCED_TEXT = null;
    $NOTIFY = false;
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS_FULL.db";
    $pid = $unix->get_pid_from_file($pidfile);
    $GLOBALS["CLASS_UNIX"] = $unix;
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Already executed\n";
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($unix->file_time_min($pidTime) < 30) {
            return;
        }
    }
    $GLOBALS["MAIN_ARRAY"] = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS.db"));
    ArticaWebFilter();
    ArticaUfdb();
    @mkdir("/usr/share/artica-postfix/ressources/logs", 0755, true);
    @unlink($pidTime);
    @file_put_contents($pidTime, serialize($GLOBALS["MAIN_ARRAY"]));
    if ($GLOBALS["VERBOSE"]) {
        echo "Saving {$pidTime}\n";
    }
    @chmod($pidTime, 0755);
}
Exemple #13
0
function start_interface($eth)
{
    $unix = new unix();
    if (!isset($GLOBALS["SNORT_PATH"])) {
        $GLOBALS["SNORT_PATH"] = $unix->find_program("snort");
    }
    $pidpath = "/var/run/snort_{$eth}.pid";
    $pid = @file_get_contents($pidpath);
    if ($unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " Snort Daemon for Interface \"{$eth}\" Already running PID {$pid}\n";
        return;
    }
    $cmds[] = "{$GLOBALS["SNORT_PATH"]}";
    $cmds[] = "--create-pidfile";
    $cmds[] = "--pid-path /var/run/snort_{$eth}.pid";
    $cmds[] = "-m 027 -D -d -l /var/log/snort -u root -g root";
    $cmds[] = "-c /etc/snort/snort.conf -i {$eth}";
    $cmd = @implode(" ", $cmds);
    if ($GLOBALS["VERBOSE"]) {
        echo "\n\n" . $cmd . "\n\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = @file_get_contents($pidpath);
        if ($unix->process_exists($pid)) {
            echo "Starting......: " . date("H:i:s") . " Snort Daemon for Interface \"{$eth}\" success PID {$pid}\n";
            return;
        }
        sleep(1);
    }
    echo "Starting......: " . date("H:i:s") . " Snort Daemon for Interface \"{$eth}\" failed\n";
    echo "Starting......: " . date("H:i:s") . " Snort {$cmd}\n";
}
function purge()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtime = "/etc/artica-postfix/pids/exec.suricata.hourly.purge.time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded()) {
        return;
    }
    $timeExec = $unix->file_time_min($pidtime);
    if ($timeExec < 1440) {
        return;
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $q = new postgres_sql();
    $sock = new sockets();
    $SuricataPurge = intval($sock->GET_INFO("SuricataPurge"));
    if ($SuricataPurge == 0) {
        $SuricataPurge = 15;
    }
    $q->QUERY_SQL("DELETE FROM suricata_events WHERE zdate < NOW() - INTERVAL '{$SuricataPurge} days'");
}
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__);
    }
}
Exemple #16
0
function applyAcls()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if ($unix->process_exists(@file_get_contents("{$pidfile}"))) {
        echo "Already process exists\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $sql = "SELECT `directory` FROM acl_directories";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, 'artica_backup');
    if (!$q->ok) {
        if ($GLOBALS["VERBOSE"]) {
            echo $q->mysql_error . "\n";
            return;
        }
    }
    $count = mysql_num_rows($results);
    echo "Starting......: acls {$count} items\n";
    if ($count == 0) {
        return;
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        ApplySingleAcls($ligne["directory"]);
    }
}
function CheckCMDLine()
{
    $unix = new unix();
    $PID_FILE = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = $unix->get_pid_from_file($PID_FILE);
    if ($unix->process_exists($pid)) {
        return;
    }
    @file_put_contents($PID_FILE, getmypid());
    if (system_is_overloaded()) {
        die;
    }
    $sock = new sockets();
    $ips = unserialize(base64_decode($sock->GET_INFO("RBLCheckIPList")));
    if (count($ips) > 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo count($ips) . " elements to check\n";
        }
        if (is_array($ips)) {
            while (list($num, $ip) = each($ips)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$ip} element...\n";
                }
                ChecksDNSBL($ip, false, true);
            }
            ChecksDNSBL();
            return;
        }
    }
    ChecksDNSBL();
}
Exemple #18
0
function process_queue()
{
    $unix = new unix();
    $pgrep = $unix->find_program("pgrep");
    exec("pgrep -l -f \"exec.squid-tail-injector.php --squid-sql-proc\" 2>&1", $results);
    while (list($index, $ligne) = each($results)) {
        if (preg_match("#pgrep#", $ligne)) {
            continue;
        }
        if (preg_match("#^([0-9]+).*?\\s+([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)\$#", $ligne, $re)) {
            $pid = $re[1];
            if (!$unix->process_exists($pid)) {
                continue;
            }
            if (!is_dir("/proc/{$pid}")) {
                continue;
            }
            $ttl = $unix->PROCESS_UPTIME($pid);
            $day = strtotime("{$re[2]}-{$re[3]}-{$re[4]} {$re[5]}:00:00");
            $dayText = date("{l} {F} d H", $day) . "h";
            if ($ttl == null) {
                continue;
            }
            $ttl = str_replace("uptime=", "", $ttl);
            $array[$day] = array("TTL" => $ttl, "PID" => $pid, "day" => $dayText);
            continue;
        }
    }
    krsort($array);
    echo "<articadatascgi>" . base64_encode(serialize($array)) . "</articadatascgi>";
}
function restore($filename)
{
    $unix = new unix();
    $sock = new sockets();
    $TMP = $unix->FILE_TEMP();
    $filenameBase = basename($filename);
    if (!is_file($filename)) {
        echo "{$filename} no such file\n";
        build_progress("{failed}", 110);
    }
    $tmpf = $unix->FILE_TEMP();
    build_progress("{uncompress} {$filenameBase}", 10);
    if (!$unix->uncompress($filename, $tmpf)) {
        @unlink($filename);
        build_progress("{uncompress} {$filenameBase} {failed}", 110);
        return;
    }
    @unlink($filename);
    build_progress("{importing} {$tmpf}", 50);
    $q = new mysql_squid_builder();
    $nice = $unix->EXEC_NICE();
    $mysql = $unix->find_program("mysql");
    $gzip = $unix->find_program("gzip");
    $nohup = $unix->find_program("nohup");
    $echo = $unix->find_program("echo");
    $rm = $unix->find_program("rm");
    $php = $unix->LOCATE_PHP5_BIN();
    $sh[] = "#!/bin/sh";
    $sh[] = "{$echo} \"{$mysql} -> {$filenameBase}\"";
    $sh[] = "{$nice} {$mysql} {$q->MYSQL_CMDLINES} -f squidlogs < {$tmpf}";
    $sh[] = "{$rm} {$TMP}.sh";
    $sh[] = "\n";
    @file_put_contents("{$TMP}.sh", @implode("\n", $sh));
    @chmod("{$TMP}.sh", 0755);
    build_progress(10, "Starting restore {$filenameBase} - " . basename("{$TMP}.sh") . " ");
    system("{$nohup} {$TMP}.sh >{$TMP}.txt 2>&1 &");
    sleep(1);
    $PID = $unix->PIDOF_PATTERN("{$TMP}.sh");
    echo "Running PID {$PID}\n";
    while ($unix->process_exists($PID)) {
        build_progress(50, "Starting restoring {$filenameBase}");
        sleep(3);
        $PID = $unix->PIDOF_PATTERN("{$TMP}.sh");
        echo "Running PID {$PID}\n";
    }
    echo @file_get_contents("{$TMP}.txt") . "\n";
    @unlink("{$TMP}.sh");
    @unlink("{$TMP}.txt");
    build_progress(50, "{restore} {done} {$filenameBase}");
    build_progress(50, "{restore} Analyze Hourly tables");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.hours.php --force --verbose");
    build_progress(60, "{restore} Repair Hourly tables");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.hours.php --repair --force --verbose");
    build_progress(70, "{restore} Repair Table days");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.repair.php --tables-day --repair --force --verbose");
    build_progress(80, "{restore} Repair sums");
    system("{$php} /usr/share/artica-postfix/exec.squid.stats.totals.php --repair --force --verbose");
    build_progress(100, "{restore} Done");
}
function build_blacklists($aspid = false)
{
    $unix = new unix();
    $FINALARRAY = array();
    $f = array();
    $PidFile = "/etc/artica-postfix/pids/squid_build_blacklists.pid";
    $dbfile = "/var/log/squid/ufdbgclient.black.db";
    if ($aspid) {
        $pid = $unix->get_pid_from_file($PidFile);
        if ($pid != getmypid()) {
            if ($unix->process_exists($pid, basename(__FILE__))) {
                echo "Starting......: " . date("H:i:s") . " Blacklists: Another artica script running pid {$pid}, aborting ...\n";
                WriteToSyslogMail("build_blacklists():: Another artica script running pid {$pid}, aborting ...", basename(__FILE__));
                return;
            }
        }
    }
    @unlink($dbfile);
    try {
        echo "berekley_db:: Creating {$dbfile} database\n";
        $db_desttmp = @dba_open($dbfile, "c", "db4");
        @dba_close($db_desttmp);
    } catch (Exception $e) {
        $error = $e->getMessage();
        echo "berekley_db::FATAL ERROR {$error} on {$dbfile}\n";
        return;
    }
    $q = new mysql_squid_builder();
    $array = array();
    $db_con = @dba_open($dbfile, "c", "db4");
    $sql = "SELECT * FROM deny_websites";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo "Starting......: " . date("H:i:s") . " [ACLS]: {$q->mysql_error}\n";
        return;
    }
    @unlink("/etc/squid3/www-blacklists.db");
    while ($ligne = mysql_fetch_assoc($results)) {
        if ($ligne["items"] == null) {
            continue;
        }
        $item = $ligne["items"];
        $item = str_replace("/", "\\/", $item);
        $item = str_replace(".", "\\.", $item);
        $item = str_replace("*", ".*?", $item);
        @dba_replace($item, $item, $db_con);
        $array[] = $ligne["items"];
    }
    @dba_close($db_con);
    @file_put_contents("/var/log/squid/ufdbgclient.reload", "#");
    @chown("/var/log/squid/ufdbgclient.reload", "squid");
    @chgrp("/var/log/squid/ufdbgclient.reload", "squid");
    $acl = new squid_acls();
    $url_rewrite_program = $acl->clean_dstdomains($array);
    echo "Starting......: " . date("H:i:s") . " [ACLS]: " . count($url_rewrite_program) . " blacklisted webistes\n";
    @file_put_contents("/etc/squid3/www-blacklists.db", @implode("\n", $url_rewrite_program) . "\n");
    @chown("/etc/squid3/www-blacklists.db", "squid");
    @chgrp("/etc/squid3/www-blacklists.db", "squid");
}
Exemple #21
0
function iprulesDNS()
{
    $unix = new unix();
    $IPCHAIN = "dnsfilter";
    $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($unix->process_exists(@file_get_contents($pidfile), basename(__FILE__))) {
        echo "Starting......: " . date("H:i:s") . " iptables configurator already executed PID " . @file_get_contents($pidfile) . "\n";
        die;
    }
    $pid = getmypid();
    file_put_contents($pidfile, $pid);
    $sock = new sockets();
    $EnableIptablesDNS = $sock->GET_INFO("EnableIptablesDNS");
    if (!is_numeric($EnableIptablesDNS)) {
        $EnableIptablesDNS = 1;
    }
    if ($EnableIptablesDNS == 0) {
        $ip = new iptables_exec();
        if ($ip->is_chain_exists($IPCHAIN)) {
            shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}");
            shell_exec("{$GLOBALS["iptables"]} -X {$IPCHAIN}");
        }
        return;
    }
    $tmpfile = $unix->FILE_TEMP();
    $curl = new ccurl("https://raw.github.com/smurfmonitor/dns-iptables-rules/master/domain-blacklist.txt");
    $curl->NoHTTP_POST = true;
    if ($curl->GetFile($tmpfile)) {
        $size = @filesize($tmpfile);
        if ($size < 100) {
            $tmpfile = "/usr/share/artica-postfix/bin/install/iptables_defaults.txt";
        }
    }
    $ip = new iptables_exec();
    if (!$ip->is_chain_exists($IPCHAIN)) {
        echo "Adding chain {$IPCHAIN}\n";
        shell_exec("{$GLOBALS["iptables"]} -N {$IPCHAIN}");
        shell_exec("{$GLOBALS["iptables"]} -I INPUT -p udp --dport 53 -j {$IPCHAIN}");
    } else {
        echo "chain {$IPCHAIN} exists...\n";
    }
    shell_exec("{$GLOBALS["iptables"]} -F {$IPCHAIN}");
    shell_exec("{$GLOBALS["iptables"]} -A {$IPCHAIN} -j RETURN");
    $f = explode("\n", @file_get_contents($tmpfile));
    while (list($num, $ligne) = each($f)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        $ligne = str_replace("INPUT", $IPCHAIN, $ligne);
        $ligne = str_replace("iptables", $GLOBALS["iptables"], $ligne);
        $results = array();
        exec($ligne, $results);
        echo "{$ligne}\n";
        while (list($a, $b) = each($results)) {
            echo "{$b}\n";
        }
    }
}
function start_parse()
{
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading...\n";
    }
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        "echo Loading done...\n";
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if (!$GLOBALS["FORCE"]) {
        if ($pid < 100) {
            $pid = null;
        }
        $unix = new unix();
        if ($unix->process_exists($pid, basename(__FILE__))) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid}\n";
            }
            return;
        }
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < 10) {
            return;
        }
        $mypid = getmypid();
        @file_put_contents($pidfile, $mypid);
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $ldap = new clladp();
    if (!$ldap->IsKerbAuth()) {
        return;
    }
    $q = new mysql_squid_builder();
    $sql = "SELECT ID,GroupName FROM webfilters_sqgroups WHERE `enabled`=1 AND `GroupType`='proxy_auth_statad'";
    $results = $q->QUERY_SQL($sql);
    $REFRESH = false;
    $Count = mysql_num_rows($results);
    $UPDATED = array();
    while ($ligne = mysql_fetch_assoc($results)) {
        if (parse_object($ligne["ID"], $ligne["GroupName"])) {
            $UPDATED[] = $ligne["GroupName"];
            $REFRESH = true;
        }
    }
    if ($REFRESH) {
        squid_admin_mysql(1, "Reloading proxy service after updating " . count($UPDATED) . " Active Directory group(s)", @implode("\n", $UPDATED), __FILE__, __LINE__);
        $squid = $unix->LOCATE_SQUID_BIN();
        system("/etc/init.d/squid reload --force --script=exec.squid.static.ad.groups.php/" . __LINE__);
        $sock = new sockets();
        $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
        if ($EnableTransparent27 == 1) {
            system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
        }
    }
}
function start_hour()
{
    $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $unix = new unix();
    $sock = new sockets();
    if (system_is_overloaded(basename(__FILE__))) {
        return;
    }
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "{$pid} already executed since {$timepid}Mn\n";
        }
        if (!$GLOBALS["FORCE"]) {
            if ($timepid < 14) {
                return;
            }
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $hostname = $unix->hostname_g();
    $today = date("Y-m-d") . " 00:00:00";
    $postgres = new postgres_sql();
    $results = $postgres->QUERY_SQL("select date_trunc('H',zdate) + (round(extract('minute' from zdate)/15)*15) * '1 minute'::interval as time, sum(rx) as rx, sum(tx) as tx,eth from access_log WHERE proxyname='{$hostname}' AND zdate >'{$today}' group by time,eth");
    $c = 0;
    $f = array();
    while ($ligne = @pg_fetch_assoc($results)) {
        $time = $ligne["time"];
        $ETH = $ligne["eth"];
        if ($ETH == "lo") {
            continue;
        }
        $RX = $ligne["rx"];
        $TX = $ligne["tx"];
        $f[] = "('{$time}','{$ETH}','{$RX}','{$TX}')";
    }
    if (count($f) == 0) {
        return;
    }
    $q = new mysql();
    if ($q->TABLE_EXISTS("RXTX_HOUR", "artica_events")) {
        $q->QUERY_SQL("TRUNCATE TABLE `RXTX_HOUR`", "artica_events");
    }
    $sql = "CREATE TABLE IF NOT EXISTS `RXTX_HOUR`\n\t(`ZDATE` DATETIME,\n\t`RX` INT UNSIGNED NOT NULL DEFAULT 1,\n\t`TX` INT UNSIGNED NOT NULL DEFAULT 1,\n\t`ETH` VARCHAR(60),\n\tKEY `ZDATE`(`ZDATE`),\n\tKEY `RX`(`RX`),\n\tKEY `TX`(`TX`),\n\tKEY `ETH`(`ETH`) )  ENGINE = MYISAM;";
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        return;
    }
    $q->QUERY_SQL("INSERT IGNORE INTO RXTX_HOUR (ZDATE,ETH,RX,TX) VALUES " . @implode(",", $f), "artica_events");
    start_week();
}
function importActivedirectoryusers()
{
    $sock = new sockets();
    $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth");
    if (!is_numeric($EnableKerbAuth)) {
        $EnableKerbAuth = 0;
    }
    if ($EnableKerbAuth == 0) {
        return;
    }
    $unix = new unix();
    $user = new settings_inc();
    $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__))) {
        WriteMyLogs("Process {$pid} already exists", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        WriteMyLogs("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $TImeStamp = $unix->file_time_min($pidTime);
    if (!$GLOBALS["FORCE"]) {
        if ($TImeStamp < 20) {
            WriteMyLogs("Need 20mn, current={$TImeStamp}Mn executed by:{$GLOBALS["EXECUTOR"]} Params:{$GLOBALS["PARAMS"]}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $netbin = $unix->LOCATE_NET_BIN_PATH();
    $usermod = $unix->find_program("usermod");
    $chmod = $unix->find_program("chmod");
    if (!is_file($netbin)) {
        WriteMyLogs("net no such binary, aborting", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (is_dir("/var/run/samba/winbindd_privileged")) {
        shell_exec("{$usermod} -G winbindd_priv squid >/dev/null 2>&1");
        shell_exec("{$chmod} 0750 /var/run/samba/winbindd_privileged/ >/dev/null 2>&1");
    }
    $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos")));
    $domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]);
    $domain_lower = strtolower($array["WINDOWS_DNS_SUFFIX"]);
    $adminpassword = $array["WINDOWS_SERVER_PASS"];
    $adminpassword = $unix->shellEscapeChars($adminpassword);
    $adminname = $array["WINDOWS_SERVER_ADMIN"];
    $ad_server = $array["WINDOWS_SERVER_NETBIOSNAME"];
    $GLOBALS["AUTHCMD"] = " -U {$adminname}%{$adminpassword}";
    getNetInfos();
    if (!isset($GLOBALS["LDAP_HOST"])) {
        WriteMyLogs("Unable to get ldap infos, aborting", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    GetUsersArray();
}
function compile_destination($cacheid)
{
    $unix = new unix();
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".compile_destination." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (!is_numeric($cacheid)) {
        build_progress("Error Destination ID is not set", 110);
        return;
    }
    if ($cacheid == 0) {
        build_progress("Error Destination ID is Zero", 110);
        return;
    }
    $q = new mysql_squid_builder();
    $sql = "SELECT servername FROM reverse_www WHERE cache_peer_id={$cacheid}";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        build_progress("Error MySQL error", 110);
        echo $q->mysql_error;
        return;
    }
    $count = mysql_num_rows($results);
    if ($count == 0) {
        echo "{$sql}\n";
        build_progress("Error no destination for ID {$cacheid}", 110);
        return;
    }
    build_progress("{$count} Destination(s)", 5);
    $c = 0;
    $php = $unix->LOCATE_PHP5_BIN();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $c++;
        $prc = $c / $count;
        $prc = $prc * 100;
        if ($prc > 90) {
            $prc = 90;
        }
        $servername = $ligne["servername"];
        build_progress("{reconfigure} {$servername}", $prc);
        system("{$php} /usr/share/artica-postfix/exec.nginx.single.php {$servername} --no-reload --output --no-buildmain");
    }
    build_progress("{cleaning_old_configs}...", 91);
    system("{$php} /usr/share/artica-postfix/exec.nginx.wizard.php --check-http");
    build_progress("{building_main_settings}", 95);
    system("{$php} /usr/share/artica-postfix/exec.nginx.php --main");
    build_progress("{$ligne["servername"]}: {reloading_reverse_proxy} ", 96);
    system("/etc/init.d/nginx reload --force");
    build_progress("{$ligne["servername"]}: {reloading_reverse_proxy}  {done}", 100);
}
function start()
{
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        return;
    }
    @file_put_contents($pidFile, getmypid());
    $time = $unix->file_time_min($pidtime);
    if ($time < 5) {
        return;
    }
    @file_put_contents($pidtime, time());
    $free = $unix->find_program("free");
    $echo = $unix->find_program("echo");
    $sync = $unix->find_program("sync");
    $swapoff = $unix->find_program("swapoff");
    $swapon = $unix->find_program("swapon");
    exec("{$free} 2>&1", $results);
    $used = 0;
    $total = 0;
    while (list($num, $ligne) = each($results)) {
        if (preg_match("#Swap:\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)#", $ligne, $re)) {
            $total = $re[1];
            $used = $re[2];
        }
    }
    if (!is_numeric($total)) {
        return;
    }
    if ($total == 0) {
        return;
    }
    if ($used == 0) {
        return;
    }
    if ($total == $used) {
        return;
    }
    $tot1 = $used / $total;
    $tot1 = $tot1 * 100;
    if ($GLOBALS["VERBOSE"]) {
        echo "Swap:{$used}/{$total} - {$tot1}\n";
    }
    $perc = round($tot1);
    if ($GLOBALS["VERBOSE"]) {
        echo "Swap:{$used}/{$total} {$perc}%\n";
    }
    $t = time();
    $GLOBALS["ALL_SCORES"]++;
    shell_exec("{$swapoff} -a && {$swapon} -a");
    $usedTXT = FormatBytes($used);
    $report = $unix->ps_mem_report();
    $distance = $unix->distanceOfTimeInWords($t, time(), true);
    squid_admin_mysql(0, "System swap exceed rule: {$perc}%", "Used {$usedTXT}\nSystem cache was flushed took {$distance}\nThis means you did have enough memory for this computer.\n{$report}", __FILE__, __LINE__);
}
Exemple #27
0
function sealion_pid()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/usr/local/sealion-agent/var/run/sealion.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    return 0;
}
function install_key($keyfile)
{
    $path = "/usr/share/artica-postfix/ressources/conf/upload/{$keyfile}";
    $license_bin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager";
    $time = time();
    $unix = new unix();
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) {
            progress("{failed} Already running", 110);
            echo "Already runinng PID {$pid}\n";
            return;
        }
    }
    echo "License....: {$path}\n";
    echo "Binary File: {$license_bin}\n";
    if (!is_file($path)) {
        echo "{$path} No such file..\n";
        progress("{failed} {$keyfile} No such file", 110);
        die;
    }
    if (!is_file($license_bin)) {
        echo "{$path} No such file..\n";
        progress("{failed} " . basename($license_bin) . " No such binary", 110);
        @unlink($path);
        die;
    }
    $sock = new sockets();
    $nohup = $unix->find_program("nohup");
    $sock->SET_INFO("kavicapserverEnabled", 1);
    @unlink("/etc/artica-postfix/kav4proxy-licensemanager");
    @unlink("/etc/artica-postfix/kav4proxy-licensemanager-i");
    progress("{removing_old_licenses}", 20);
    system("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -d a");
    progress("{installing} {$keyfile}", 30);
    $cmd = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -c /etc/opt/kaspersky/kav4proxy.conf -a {$path}";
    system($cmd);
    @unlink($path);
    progress("{analyze_license} {$keyfile}", 50);
    shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i 2>&1");
    progress("{stopping_service}", 60);
    echo "/etc/init.d/kav4proxy stop\n";
    system("/etc/init.d/kav4proxy stop");
    progress("{starting_service}", 60);
    echo "/etc/init.d/kav4proxy start\n";
    system("{$nohup} /etc/init.d/kav4proxy start >/dev/null 2>&1 &");
    system("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    progress("{launch_updates}", 70);
    $nohup = $unix->find_program("nohup");
    $php = $unix - LOCATE_PHP5_BIN();
    sleep(2);
    progress("{launch_updates}", 80);
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.keepup2date.php --update --force >/dev/null 2>&1 &");
    sleep(3);
    progress("{success}", 100);
}
function InMemQUestion()
{
    $unix = new unix();
    $pid = $unix->PIDOF_PATTERN("philesight --db");
    if ($unix->process_exists($pid)) {
        return true;
    }
    return false;
}
function squid_transparent_exe()
{
    $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__))) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $sock = new sockets();
    $squid = new squidbee();
    $WizardProxyTransparent = unserialize($sock->GET_INFO("WizardProxyTransparent"));
    $WizardProxyTransparent = unserialize($sock->GET_INFO("WizardProxyTransparent"));
    $connected_port = intval($WizardProxyTransparent["connected_port"]);
    $transparent_port = intval($WizardProxyTransparent["transparent_port"]);
    $transparent_ssl_port = intval($WizardProxyTransparent["transparent_ssl_port"]);
    $EnableSSLBump = intval($WizardProxyTransparent["EnableSSLBump"]);
    if ($connected_port == 0) {
        build_progress("Fatal connected port unconfigured", 110);
        return;
    }
    if ($transparent_port == 0) {
        build_progress("Fatal Transparent port unconfigured", 110);
        return;
    }
    echo "Connected port........: {$connected_port}\n";
    echo "Transparent port......: {$transparent_port}\n";
    echo "Transparent SSL.......: {$EnableSSLBump}/{$transparent_ssl_port}\n";
    sleep(3);
    build_progress("{reconfigure}", 20);
    $squid = new squidbee();
    $squid->listen_port = $transparent_port;
    $squid->second_listen_port = $connected_port;
    $squid->hasProxyTransparent = 1;
    if ($EnableSSLBump == 1) {
        echo "EnableSquidSSLCRTD ----> 1\n";
        $sock->SET_INFO("EnableSquidSSLCRTD", 1);
        $squid->SSL_BUMP = 1;
        $squid->ssl_port = $transparent_ssl_port;
    }
    build_progress("{saving_parameters}", 20);
    sleep(3);
    $squid->SaveToLdap(true);
    echo "hasProxyTransparent -------> 1\n";
    $sock->SET_INFO("hasProxyTransparent", 1);
    echo "SquidTransparentMixed -----> 1\n";
    $sock->SET_INFO("SquidTransparentMixed", 1);
    build_progress("{building_settings}", 30);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    build_progress("{restarting_service}", 50);
    system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force");
    build_progress("{apply_firewall_rules}", 90);
    system("{$php} /usr/share/artica-postfix/exec.squid.transparent.php --force");
    build_progress("{done}", 100);
}