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"]);
}
Esempio n. 2
0
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 ScanFoldders()
{
    $sock = new sockets();
    $unix = new unix();
    $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["VERBOSE"]) {
        echo "{$timefile}\n";
    }
    if (system_is_overloaded(basename(__FILE__))) {
        die;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timeMin = $unix->PROCCESS_TIME_MIN($pid);
        if ($timeMin > 240) {
            system_admin_events("Too many TTL, {$pid} will be killed", __FUNCTION__, __FILE__, __LINE__, "logrotate");
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        } else {
            die;
        }
    }
    if (!$GLOBALS["FORCE"]) {
        $TimeExec = $unix->file_time_min($timefile);
        if ($TimeExec < 240) {
            return;
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    $SystemLogsPath = $sock->GET_INFO("SystemLogsPath");
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    $maillogStoragePath = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/maillogStoragePath"));
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting Main\n";
    }
    $q = new mysql();
    $q->QUERY_SQL("DROP TABLE `sysstorestatus`", "artica_events");
    $sql = "CREATE TABLE IF NOT EXISTS `sysstorestatus` (\n\t\t\t  `filepath` VARCHAR(255) NOT NULL,\n\t\t\t  `filesize`  BIGINT UNSIGNED NOT NULL,\n\t\t\t  `zDate` DATETIME,\n\t\t\t  PRIMARY KEY (`filepath`),\n\t\t\t  KEY `zDate` (`zDate`),\n\t\t\t  KEY `filesize` (`filesize`)\n\t\t\n\t\t\t)";
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error;
        return;
    }
    ScanThis("/home/postfix/maillog");
    ScanThis("/home/logrotate");
    ScanThis("/home/logrotate_backup");
    ScanThis("/home/logs-backup");
    ScanThis("/home/backup/postfix");
    ScanThis($LogRotatePath);
    ScanThis($SystemLogsPath);
    ScanThis($maillogStoragePath);
}
function ParseMainDir()
{
    $unix = new unix();
    $mypid = getmypid();
    $kill = $unix->find_program("kill");
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    @mkdir("/etc/artica-postfix/pids", 0755, true);
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pidtime_hour = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".hours.time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time > 60) {
            unix_system_kill_force($pid);
        } else {
            events("Already executed pid {$pid} since {$time}mn-> DIE");
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid} since {$time}mn\n";
            }
            die;
        }
    }
    $timeP = $unix->file_time_min($pidtime);
    if ($timeP < 3) {
        events("Main::Line: " . __LINE__ . " 3Mn minimal current: {$timeP}mn-> DIE");
        die;
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    @file_put_contents($pidfile, $mypid);
    $dirs = $unix->dirdir("/var/log/artica-postfix/squid/queues");
    while (list($directory, $array) = each($dirs)) {
        $dirs2 = $unix->dirdir($directory);
        if (count($dirs2) == 0) {
            events("{$dirs2} 0 elements, remove...", __LINE__);
            @rmdir($directory);
            continue;
        }
        if (is_dir("{$directory}/SearchWords")) {
            events("Scanning {$directory}/SearchWords", __LINE__);
            ParseSubDir("{$directory}/SearchWords");
        }
    }
    $timeP = $unix->file_time_min($pidtime_hour);
    if ($timeP > 30) {
        @unlink($pidtime_hour);
        @file_put_contents($pidtime_hour, time());
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid-searchwords.php --hour >/dev/null 2>&1");
    }
}
function parse()
{
    $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time";
    $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.pid";
    $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());
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    $time = $unix->file_time_min($TimeFile);
    if (!$GLOBALS["FORCE"]) {
        if ($time < 1440) {
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $f = $unix->DirFiles("/var/log/squid", "[0-9]+_QUOTASIZE\\.db");
    $export_path = "/home/artica/squid/dbExport";
    @mkdir($export_path, 0755, true);
    while (list($filename, $none) = each($f)) {
        preg_match("#([0-9]+)_#", $filename, $re);
        $xdate = $re[1];
        echo "{$filename} ( {$xdate} )\n";
        if ($SquidPerformance > 1) {
            if (!@copy("/var/log/squid/{$filename}", "{$export_path}/{$filename}")) {
                continue;
            }
            @unlink("/var/log/squid/{$filename}");
            continue;
        }
        if (!parse_file("/var/log/squid/{$filename}", $xdate)) {
            continue;
        }
        if (!@copy("/var/log/squid/{$filename}", "{$export_path}/{$filename}")) {
            continue;
        }
        @unlink("/var/log/squid/{$filename}");
    }
}
function watchdog($maxProcesses = 50)
{
    $unix = new unix();
    $pdns_server = $unix->find_program("pdns_server");
    $pdns_recursor = $unix->find_program("pdns_recursor");
    $pidof = $unix->find_program("pidof");
    $kill = $unix->find_program("kill");
    echo "pdns_server = {$pdns_server}\n";
    echo "pdns_recursor = {$pdns_recursor}\n";
    exec("{$pidof} {$pdns_server} 2>&1", $results);
    $string = @implode("", $results);
    $exploded = @explode(" ", $string);
    while (list($num, $val) = each($exploded)) {
        if (!is_numeric($val)) {
            echo "skip {$val}\n";
            continue;
        }
        $PIDS[$val] = $val;
    }
    echo count($PIDS) . " processes <> {$maxProcesses} for {$pdns_server}\n";
    if (count($PIDS) > $maxProcesses) {
        echo "Watchdog GO -> kill {$pdns_server} !\n";
        while (list($num, $int) = each($PIDS)) {
            echo "Killing {$pdns_server} pid {$num}\n";
            unix_system_kill_force($num);
        }
        $PIDS = array();
        exec("{$pidof} {$pdns_recursor} 2>&1", $results);
        $string = @implode("", $results);
        $exploded = @explode(" ", $string);
        while (list($num, $val) = each($exploded)) {
            if (!is_numeric($val)) {
                continue;
            }
            $PIDS[$val] = $val;
        }
        echo count($PIDS) . " processes <> {$maxProcesses} for {$pdns_recursor}\n";
        while (list($num, $int) = each($PIDS)) {
            echo "Killing {$pdns_recursor} pid {$num} \n";
            unix_system_kill_force($num);
        }
    }
    echo "Finish\n";
}
Esempio n. 7
0
function start()
{
    // /etc/artica-postfix/pids/exec.loadavg.php.start.time
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidfileTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pidfileTime}\n";
    }
    if (!$GLOBALS["VERBOSE"]) {
        if ($unix->file_time_min($pidfileTime) < 59) {
            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 ($timepid < 15) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded()) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Overloaded\n";
        }
        die;
    }
    @unlink($pidfileTime);
    @file_put_contents($pidfileTime, time());
    if ($GLOBALS["VERBOSE"]) {
        echo "cpustats\n";
    }
    cpustats();
}
Esempio n. 8
0
function stop($id)
{
    $unix = new unix();
    $sql = "SELECT * FROM imapsync WHERE ID='{$id}'";
    $q = new mysql();
    $ligne = @mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if (!$q->ok) {
        write_syslog("Mysql error {$q->mysql_error}", __FILE__);
        die;
    }
    $pid_org = $ligne["pid"];
    $ligne["imap_server"] = str_replace(".", "\\.", $ligne["imap_server"]);
    $ligne["username"] = str_replace(".", "\\.", $ligne["username"]);
    exec($unix->find_program("pgrep") . " -f \"imapsync.+?--host1 {$ligne["imap_server"]}.+?--user1 {$ligne["username"]}\"", $pids);
    while (list($index, $pid) = each($pids)) {
        if ($pid > 5) {
            unix_system_kill_force($pid);
        }
    }
    unix_system_kill_force($pid_org);
}
Esempio n. 9
0
function run()
{
    $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $unix = new unix();
    $tmpfile = $unix->FILE_TEMP();
    $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 (!$GLOBALS["FORCE"]) {
            if ($timepid < 14) {
                return;
            }
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
        }
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        if (!$GLOBALS["VERBOSE"]) {
            $time = $unix->file_time_min($TimeFile);
            if ($time < 14) {
                echo "Current {$time}Mn, require at least 14mn\n";
                return;
            }
        }
    }
    $binary = "/usr/share/artica-postfix/bin/pflogsumm.pl";
    @chmod("{$binary}", 0755);
    system("{$binary} -d today /var/log/mail.log >{$tmpfile}");
    ParseReport($tmpfile);
    @unlink($tmpfile);
    stats_total();
}
Esempio n. 10
0
function stop($aspid = false)
{
    $unix = new unix();
    $kill = $unix->find_program("kill");
    if (!$aspid) {
        $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 "Stopping......: " . date("H:i:s") . " [INIT]: nginx-tail, Already task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = GETPID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: nginx-tail, already stopped\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: nginx-tail, stopping pid: {$pid}\n";
    }
    unix_system_kill_force($pid);
    for ($i = 0; $i < 6; $i++) {
        $pid = GETPID();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: nginx-tail, waiting pid: {$pid} {$i}/5\n";
        }
        unix_system_kill_force($pid);
        sleep(1);
    }
    $tail = $unix->find_program("tail");
    $pid = $unix->PIDOF("/bin/nginx-tail");
    if ($unix->process_exists($pid)) {
        for ($i = 0; $i < 20; $i++) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: killing old process pid {$pid}\n";
            }
            unix_system_kill_force($pid);
            usleep(800);
            $pid = $unix->PIDOF("/bin/access-tail");
            if (!$unix->process_exists($pid)) {
                break;
            }
            unix_system_kill_force($pid);
        }
    }
    $pid = GETPID();
    if (!$unix->process_exists($pid)) {
        events("exec.init-tail-nginx.phpp success to stop daemon...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: nginx-tail, success\n";
        }
    } else {
        events("exec.init-tail-nginx.php failed to stop daemon...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: nginx-tail, failed\n";
        }
    }
}
Esempio n. 11
0
function MultiplesInstances_stop($hostname)
{
    $unix = new unix();
    $pid = MultiplesInstancesPID($hostname);
    if (!$unix->process_exists($pid)) {
        echo "{$GLOBALS["deflog_sstop"]} {$hostname} already stopped\n";
        return;
    }
    echo "{$GLOBALS["deflog_sstop"]} {$hostname} stopping pid {$pid}\n";
    unix_system_kill($pid);
    for ($i = 0; $i < 20; $i++) {
        $pid = MultiplesInstancesPID($hostname);
        if (!$unix->process_exists($pid)) {
            echo "{$GLOBALS["deflog_sstop"]} {$hostname} stopped\n";
            break;
        }
        echo "{$GLOBALS["deflog_sstop"]} {$hostname} waiting pid {$pid}\n";
        if ($unix->process_exists($pid)) {
            unix_system_kill_force($pid);
            sleep(1);
            continue;
        }
        break;
    }
}
Esempio n. 12
0
function GetInstances()
{
    $unix = new unix();
    $pidsARR = array();
    $kill = $unix->find_program("kill");
    $pgrep = $unix->find_program("pgrep");
    exec("{$pgrep} -l -f \"python.*?tespeed\\.py\" 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (!preg_match("#([0-9]+)\\s+(.*?)#", $line, $re)) {
            continue;
        }
        $pid = $re[1];
        $cmdline = trim($re[2]);
        if (preg_match("#^sh\\s+#", $cmdline)) {
            continue;
        }
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time > 15) {
            unix_system_kill_force($pid);
            continue;
        }
        $pidsARR[$pid] = true;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "-> " . count($pidsARR) . " instances..\n";
    }
    return count($pidsARR);
}
Esempio n. 13
0
function stop($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__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    $pid = ZARAFA_SEARCH_PID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already stopped...\n";
        }
        return;
    }
    if (is_file("/tmp/zarafa-upgrade-lock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} database upgrade is taking place.\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: Do not stop this process bacause it may render your database unusable..\n";
        }
        return;
    }
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Daemon with a ttl of {$time}mn\n";
    }
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} killing smoothly PID {$pid}...\n";
    }
    unix_system_kill($pid);
    sleep(1);
    for ($i = 1; $i < 5; $i++) {
        $pid = ZARAFA_SEARCH_PID();
        if (!$unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} pid {$pid} successfully stopped ...\n";
            }
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} wait pid {$pid} {$i}/5\n";
        }
        sleep(1);
    }
    $pid = ZARAFA_SEARCH_PID();
    if ($unix->process_exists($pid)) {
        unix_system_kill_force($pid);
        sleep(1);
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} force killing {$pid}...\n";
        }
        for ($i = 1; $i < 5; $i++) {
            $pid = ZARAFA_SEARCH_PID();
            if (!$unix->process_exists($pid)) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} pid {$pid} successfully stopped ...\n";
                }
                break;
            }
            unix_system_kill_force($pid);
            sleep(1);
        }
    }
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} daemon success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} daemon failed...\n";
    }
}
Esempio n. 14
0
function xstart()
{
    $unix = new unix();
    $TimeFile = "/etc/artica-postfix/pids/exec.squidcache.php.time";
    $PidFile = "/etc/artica-postfix/pids/exec.squidcache.php.pid";
    $Pid = $unix->get_pid_from_file($PidFile);
    if ($unix->process_exists($Pid)) {
        $pidtime = $unix->PROCCESS_TIME_MIN($Pid);
        if ($pidtime > 29) {
            events("Max execution time reached 30Mn for PID {$Pid} Kill it...", 0, 2, __LINE__);
            unix_system_kill_force($Pid);
            die;
        }
        events("Already running PID {$Pid} since {$pidtime}Mn", 0, 2, __LINE__);
        return;
    }
    @file_put_contents($PidFile, getmypid());
    $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__));
    if (count($pids) > 3) {
        events("Too many instances " . count($pids) . " dying", 0, 1, __LINE__);
        $mypid = getmypid();
        while (list($pid, $ligne) = each($pids)) {
            if ($pid == $mypid) {
                continue;
            }
            events("Killing {$pid}");
            unix_system_kill_force($pid);
        }
    }
    $pids = $unix->PIDOF_PATTERN_ALL(basename(__FILE__));
    if (count($pids) > 3) {
        events("Too many instances " . count($pids) . " dying", 0, 2, __LINE__);
        die;
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $sock = new sockets();
    $GLOBALS["HyperCacheStoragePath"] = $sock->GET_INFO("HyperCacheStoragePath");
    if ($GLOBALS["HyperCacheStoragePath"] == null) {
        $GLOBALS["HyperCacheStoragePath"] = "/home/artica/proxy-cache";
    }
    @chown("/usr/share/squid3", "squid");
    @chgrp("/usr/share/squid3", "squid");
    HyperCacheMirror();
    if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
        events("Storage path: {$GLOBALS["HyperCacheStoragePath"]}", 0, 2, __LINE__);
        events("Scanning /usr/share/squid3", 0, 2, __LINE__);
    }
    $f = $unix->DirFiles("/usr/share/squid3", "HyperCacheQueue-.+?-([0-9]+)\\.db\$");
    $GLOBALS["SIZE_DOWNLOADED"] = 0;
    $GLOBALS["HITS"] = 0;
    while (list($num, $file) = each($f)) {
        if ($GLOBALS["HYPER_CACHE_VERBOSE"]) {
            events("Found database: {$file}", 0, 2, __LINE__);
        }
        if (!preg_match("#^HyperCacheQueue-.+?-([0-9]+)\\.db\$#", $file, $re)) {
            continue;
        }
        if (preg_match("#HyperCacheQueue-dropbox\\.com#", $file)) {
            continue;
        }
        $ID = $re[1];
        HyperCacheScanDBFile("/usr/share/squid3/{$file}", $ID);
    }
    if ($GLOBALS["SIZE_DOWNLOADED"] > 0) {
        $size = FormatBytes($GLOBALS["SIZE_DOWNLOADED"] / 1024);
        $hits = $GLOBALS["HITS"];
        events("{$size} downloaded -  {$hits} requests", $ID, 2, __LINE__);
        squid_admin_enforce(2, "{$size} downloaded and store {$hits} requests", null, __FILE__, __LINE__);
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "xstart ---> DeleteRules\n";
    }
    DeleteRules();
    if ($GLOBALS["VERBOSE"]) {
        echo "xstart ---> GetRulesSizes\n";
    }
    GetRulesSizes();
}
Esempio n. 15
0
function stop()
{
    $SERV_NAME = $GLOBALS["SERV_NAME"];
    $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 "Stopping......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} Already task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $pid = RSYNC_PID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} already stopped...\n";
        }
        return;
    }
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} with a ttl of {$time}mn\n";
    }
    $MirrorDebianDir = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("MirrorDebianDir");
    if ($MirrorDebianDir == null) {
        $MirrorDebianDir = "/home/mirrors/Debian";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} with a mirror located in \"{$MirrorDebianDir}\"\n";
    }
    $kill = $unix->find_program("kill");
    for ($i = 0; $i < 10; $i++) {
        $pid = RSYNC_PID();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} kill pid {$pid}..\n";
            }
            unix_system_kill_force($pid);
        } else {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} wait {$i}/10\n";
        }
        sleep(1);
    }
    $pid = RSYNC_PID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Failed...\n";
    }
}
Esempio n. 16
0
function ScanPurgeexc()
{
    $unix = new unix();
    $purge = $unix->find_program("purge");
    $pidof = $unix->find_program("pidof");
    $kill = $unix->find_program("kill");
    exec("{$pidof} {$purge} 2>&1", $results);
    $pp = array();
    $pids = explode(" ", @implode("", $results));
    while (list($index, $pid) = each($pids)) {
        if (!is_numeric(trim($pid))) {
            continue;
        }
        $pp[] = $pid;
    }
    $count = count($pp);
    if ($count > 1) {
        unset($pp[0]);
        while (list($index, $pid) = each($pp)) {
            unix_system_kill_force($pid);
        }
    }
    $count = count($pp);
    return $count;
}
Esempio n. 17
0
if ($argv[1] == "--initd") {
    buildinit();
    die;
}
$unix = new unix();
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
$pid = @file_get_contents($pidfile);
if ($unix->process_exists($pid, basename(__FILE__))) {
    $time = $unix->PROCCESS_TIME_MIN($pid);
    echo "Starting......: " . date("H:i:s") . " hamachi already executed PID: {$pid} since {$time}Mn\n";
    writelogs("hamachi already executed PID: {$pid}", "MAIN", __FUNCTION__, __FILE__, __LINE__);
    if (!$GLOBALS["FORCE"]) {
        die;
    }
    $kill = $unix->find_program("kill");
    unix_system_kill_force($pid);
}
@file_put_contents($pidfile, getmypid());
main();
function main()
{
    $sock = new sockets();
    $unix = new unix();
    $users = new usersMenus();
    if (!$users->HAMACHI_INSTALLED) {
        echo "Starting......: " . date("H:i:s") . " hamachi not installed\n";
        die;
    }
    if (!isset($GLOBALS["hamachi_bin"])) {
        $GLOBALS["hamachi_bin"] = $unix->find_program("hamachi");
    }
Esempio n. 18
0
function killbyports()
{
    $sock = new sockets();
    $unix = new unix();
    $kill = $unix->find_program("kill");
    $ufdbguardConfig = unserialize(base64_decode($sock->GET_INFO("ufdbguardConfig")));
    if (!isset($datas["listen_addr"])) {
        $datas["listen_addr"] = "127.0.0.1";
    }
    if (!isset($datas["listen_port"])) {
        $datas["listen_port"] = "3977";
    }
    if (!isset($datas["tcpsockets"])) {
        $datas["tcpsockets"] = 0;
    }
    if ($datas["listen_addr"] == null) {
        $datas["listen_addr"] = "127.0.0.1";
    }
    if (!is_numeric($datas["listen_port"])) {
        $datas["listen_port"] = "3977";
    }
    if ($datas["tcpsockets"] == 0) {
        return 1;
    }
    $PIDS = $unix->PIDOF_BY_PORT($datas["listen_port"]);
    if (count($PIDS) == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} 0 PID listens {$datas["listen_port"]}...\n";
        }
        return;
    }
    while (list($pid, $b) = each($PIDS)) {
        if ($unix->process_exists($pid)) {
            $cmdline = @file_get_contents("/proc/{$pid}/cmdline");
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} killing PID {$pid} that listens {$datas["listen_port"]} TCP port\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmdline}\n";
            }
            unix_system_kill_force($pid);
        }
    }
}
Esempio n. 19
0
function SERVICE_START($nochecks = false, $nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    if (!$nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " MySQL this script is already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 5) {
                if (!$GLOBALS["FORCE"]) {
                    return;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    if (is_file("/etc/artica-postfix/mysql.stop")) {
        echo "Starting......: " . date("H:i:s") . " MySQL locked, exiting\n";
        return;
    }
    $PID_NUM = PID_NUM();
    if ($unix->process_exists($PID_NUM)) {
        $timemin = $unix->PROCCESS_TIME_MIN($PID_NUM);
        echo "Starting......: " . date("H:i:s") . " MySQL already running PID \"{$PID_NUM}\" since {$timemin}Mn\n";
        return;
    }
    $mysql_install_db = $unix->find_program('mysql_install_db');
    $mysqlbin = $unix->LOCATE_mysqld_bin();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if (!is_file($mysqlbin)) {
        echo "Starting......: " . date("H:i:s") . " MySQL is not installed, abort\n";
        return;
    }
    $EnableMysqlFeatures = $sock->GET_INFO('EnableMysqlFeatures');
    $MysqlBinAllAdresses = $sock->GET_INFO('MysqlBinAllAdresses');
    $MySQLTMPMEMSIZE = $sock->GET_INFO('MySQLTMPMEMSIZE');
    $MysqlTooManyConnections = $sock->GET_INFO("MysqlTooManyConnections");
    $MysqlRemoveidbLogs = $sock->GET_INFO("MysqlRemoveidbLogs");
    $innodb_force_recovery = $sock->GET_INFO("innodb_force_recovery");
    if (!is_numeric($innodb_force_recovery)) {
        $innodb_force_recovery = 0;
    }
    if (!is_numeric($MysqlRemoveidbLogs)) {
        $MysqlRemoveidbLogs = 0;
    }
    if (!is_numeric($MysqlBinAllAdresses)) {
        $MysqlBinAllAdresses = 0;
    }
    if (!is_numeric($MySQLTMPMEMSIZE)) {
        $MySQLTMPMEMSIZE = 0;
    }
    if (!is_numeric($MysqlTooManyConnections)) {
        $MysqlTooManyConnections = 0;
    }
    if (!is_numeric($EnableMysqlFeatures)) {
        $EnableMysqlFeatures = 1;
    }
    $MySqlTmpDir = $sock->GET_INFO('MySQLTMPDIR');
    $MySQLLOgErrorPath = $sock->GET_INFO('MySQLLOgErrorPath');
    $datadir = $unix->MYSQL_DATA_DIR();
    $EnableMysqlLog = $sock->GET_INFO("EnableMysqlLog");
    if (!is_numeric($EnableMysqlLog)) {
        $EnableMysqlLog = 0;
    }
    if ($datadir == null) {
        $datadir = '/var/lib/mysql';
    }
    if ($MySqlTmpDir == '/tmp') {
        $MySqlTmpDir = null;
    }
    if ($MySQLLOgErrorPath == null) {
        $MySQLLOgErrorPath = $datadir . '/mysqld.err';
    }
    if ($MysqlTooManyConnections == 1) {
        echo "Starting......: " . date("H:i:s") . " MySQL MysqlTooManyConnections=1, abort\n";
        return;
    }
    if (isset($GLOBALS["RECOVERY"])) {
        $innodb_force_recovery = $GLOBALS["RECOVERY"];
    }
    if (strlen($MySqlTmpDir) > 3) {
        echo "Starting......: " . date("H:i:s") . " MySQL tempdir : {$MySqlTmpDir}\n";
        shell_exec("{$php5} /usr/share/artica-postfix/exec.mysql.build.php --tmpfs");
        $MySqlTmpDir = str_replace("//", "/", $MySqlTmpDir);
        if (!is_dir($MySqlTmpDir)) {
            @mkdir($MySqlTmpDir, 0755, true);
            $unix->chown_func("mysql", "mysql", $MySqlTmpDir);
        }
        $MySqlTmpDirCMD = " --tmpdir={$MySqlTmpDir}";
    }
    if ($EnableMysqlFeatures == 0) {
        echo "Starting......: " . date("H:i:s") . " MySQL is disabled by \"EnableMysqlFeatures\"...\n";
        return;
    }
    $pid_file = "/var/run/mysqld/mysqld.pid";
    $socket = "/var/run/mysqld/mysqld.sock";
    $mysql_user = "******";
    @mkdir("/var/run/mysqld", 0755, true);
    @mkdir("/var/log/mysql", 0755, true);
    @mkdir($datadir, 0755, true);
    $dirs = $unix->dirdir("/var/lib/mysql");
    while (list($num, $directory) = each($dirs)) {
        echo "Starting......: " . date("H:i:s") . " MySQL, apply permissions on " . basename($directory) . "\n";
        $unix->chown_func("mysql", "mysql", "{$directory}/*");
    }
    $bind_address = ' --bind-address=127.0.0.1';
    $bind_address2 = "127.0.0.1";
    if ($MysqlBinAllAdresses == 1) {
        $bind_address2 = 'All (0.0.0.0)';
        $bind_address = ' --bind-address=0.0.0.0';
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Pid path.......:{$pid_file}\n";
    echo "Starting......: " . date("H:i:s") . " datadir..............:{$datadir}\n";
    echo "Starting......: " . date("H:i:s") . " Log error............:{$MySQLLOgErrorPath}\n";
    echo "Starting......: " . date("H:i:s") . " socket...............:{$socket}\n";
    echo "Starting......: " . date("H:i:s") . " user.................:{$mysql_user}\n";
    echo "Starting......: " . date("H:i:s") . " LOGS ENABLED.........:{$EnableMysqlLog}\n";
    echo "Starting......: " . date("H:i:s") . " Daemon...............:{$mysqlbin}\n";
    echo "Starting......: " . date("H:i:s") . " Bind address.........:{$bind_address2}\n";
    echo "Starting......: " . date("H:i:s") . " Temp Dir.............:{$MySqlTmpDir}\n";
    echo "Starting......: " . date("H:i:s") . " innodb_force_recovery:{$innodb_force_recovery}\n";
    mysql_admin_mysql(1, "Starting MySQL service...", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " Settings permissions..\n";
    @mkdir("/var/run/mysqld", 0755, true);
    $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld");
    $unix->chown_func($mysql_user, $mysql_user, "/var/log/mysql");
    $unix->chown_func($mysql_user, $mysql_user, $datadir);
    $unix->chown_func($mysql_user, $mysql_user, "{$datadir}/*");
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        @unlink("/var/run/mysqld/mysqld.sock");
    }
    if (is_file('/var/run/mysqld/mysqld.err')) {
        @unlink('/var/run/mysqld/mysqld.err');
    }
    if (is_file("/var/run/mysqld/mysqld.pid")) {
        $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld/mysqld.pid");
    }
    if ($MysqlRemoveidbLogs == 1) {
        shell_exec('/bin/mv /var/lib/mysql/ib_logfile* /tmp/');
        $sock->SET_INFO('MysqlRemoveidbLogs', '0');
    }
    $logpathstring = " --log-error={$MySQLLOgErrorPath}";
    if ($EnableMysqlLog == 1) {
        $logpathstring = " --log=/var/log/mysql.log --log-slow-queries=/var/log/mysql-slow-queries.log --log-error={$MySQLLOgErrorPath} --log-warnings";
    }
    $toTouch[] = "/var/log/mysql-slow-queries.log";
    $toTouch[] = "/var/log/mysql.error";
    $toTouch[] = "/var/log/mysql.log";
    $toTouch[] = "/var/log/mysql.warn";
    while (list($num, $filename) = each($toTouch)) {
        if (!is_file($filename)) {
            @file_put_contents($filename, "#\n");
        }
        $unix->chown_func($mysql_user, $mysql_user, $filename);
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm\n";
    if (!is_file("{$datadir}/mysql/host.frm")) {
        if (is_file($mysql_install_db)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Installing default databases\n";
            shell_exec("{$mysql_install_db} --datadir=\"{$datadir}\"");
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm OK\n";
    }
    $cmd2 = array();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    if ($AsCategoriesAppliance == 1) {
        $MEMORY = 620288;
    }
    if ($MEMORY < 624288) {
        $GetStartedValues = GetStartedValues();
        echo "Starting......: " . date("H:i:s") . " MySQL Warning memory did not respond to pre-requesites, tuning to lower memory\n";
        if ($GetStartedValues["--key-buffer-size"]) {
            $cmd2[] = "--key-buffer-size=8M";
        }
        if ($GetStartedValues["--max-allowed-packet"]) {
            $cmd2[] = "--max-allowed-packet=4M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=4";
        }
        if ($GetStartedValues["--sort-buffer-size"]) {
            $cmd2[] = "--sort-buffer-size=64k";
        }
        if ($GetStartedValues["--read-buffer-size"]) {
            $cmd2[] = "--read-buffer-size=256k";
        }
        if ($GetStartedValues["--read-rnd-buffer-size"]) {
            $cmd2[] = "--read-rnd-buffer-size=128k";
        }
        if ($GetStartedValues["--net-buffer-length"]) {
            $cmd2[] = "--net-buffer-length=2k";
        }
        if ($GetStartedValues["--thread-stack"]) {
            $cmd2[] = "--thread-stack=192k";
        }
        if ($GetStartedValues["--thread-cache-size"]) {
            $cmd2[] = "--thread-cache-size=128";
        }
        if ($GetStartedValues["--thread-concurrency"]) {
            $cmd2[] = "--thread-concurrency=10";
        }
        if ($GetStartedValues["--default-storage-engine"]) {
            $cmd2[] = "--default-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--default-tmp-storage-engine"]) {
            $cmd2[] = "--default-tmp-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--tmp-table-size"]) {
            $cmd2[] = "--tmp-table-size=16M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=64";
        }
        if ($GetStartedValues["--query-cache-limit"]) {
            $cmd2[] = "--query-cache-limit=4M";
        }
        if ($GetStartedValues["--query-cache-size"]) {
            $cmd2[] = "--query-cache-size=32M";
        }
        if ($GetStartedValues["--max-connections"]) {
            $cmd2[] = "--max-connections=50";
        }
        if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
            $cmd2[] = "--innodb=OFF";
        }
        echo "Starting......: " . date("H:i:s") . " MySQL " . count($cmd2) . " forced option(s)\n";
    }
    if (is_file($MySQLLOgErrorPath)) {
        @unlink($MySQLLOgErrorPath);
    }
    $cmds[] = $mysqlbin;
    if ($MEMORY < 624288) {
        $cmds[] = "--no-defaults --user=mysql";
    }
    $cmds[] = "--pid-file=/var/run/mysqld/mysqld.pid";
    $cmds[] = trim($logpathstring);
    $cmds[] = trim($MySqlTmpDirCMD);
    $cmds[] = "--socket={$socket}";
    $cmds[] = "--datadir=\"{$datadir}\"";
    if (count($cmd2) == 0) {
        if ($innodb_force_recovery > 0) {
            $cmds[] = "--innodb-force-recovery={$innodb_force_recovery}";
        }
    }
    if (count($cmd2) > 0) {
        $cmds[] = @implode(" ", $cmd2);
    }
    $cmds[] = ">/dev/null 2>&1 &";
    if (is_file('/usr/sbin/aa-complain')) {
        echo "Starting......: " . date("H:i:s") . " Mysql Adding mysql in apparamor complain mode...\n";
        shell_exec("/usr/sbin/aa-complain {$mysqlbin} >/dev/null 2>&1");
    }
    $cmd = @implode(" ", $cmds);
    while (list($num, $ligne) = each($cmds)) {
        echo "Starting......: " . date("H:i:s") . " MySQL Option: {$ligne}\n";
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Starting daemon, please wait\n";
    writelogs("Starting MySQL {$cmd}", __FUNCTION__, __FILE__, __LINE__);
    shell_exec($cmd);
    $count = 0;
    sleep(2);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid, $mysqlbin)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon running...\n";
            break;
        }
        echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon, please wait ({$i}/6)\n";
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " MySQL failed\n";
        echo "Starting......: " . date("H:i:s") . " {$cmd}\n";
        system_admin_events("Failed to start MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.mysql.build.php >/dev/null 2>&1 &");
    } else {
        for ($i = 0; $i < 4; $i++) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock waiting {$i}/3\n";
            if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
                break;
            }
            sleep(1);
        }
        if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            mysql_admin_mysql(0, "Failed to start MySQL Server /var/run/mysqld/mysqld.sock no such socket after 4 seconds", null, __FILE__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock failed...\n";
        }
        mysql_admin_mysql(1, "Success to start MySQL Server with new pid {$pid}", null, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " MySQL Success pid {$pid}\n";
        $q = new mysql_squid_builder();
        $q->MEMORY_TABLES_RESTORE();
    }
}
function Execute()
{
    build_progress("Executing", 5);
    if (!ifMustBeExecuted()) {
        if ($GLOBALS["VERBOSE"]) {
            echo "No make sense to execute this script...\n";
        }
        while (list($filename, $line) = each($GLOBALS["ifMustBeExecuted"])) {
            ufdbevents("ifMustBeExecuted:: {$line}");
        }
        build_progress("No make sense to execute this script", 110);
        die;
    }
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $StandardTime = 240;
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, __FILE__)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time > 240) {
            unix_system_kill_force($pid);
        }
    }
    if ($unix->process_exists($pid, __FILE__)) {
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $CategoriesDatabasesByCron = $sock->GET_INFO("CategoriesDatabaseByCron");
    if (!is_numeric($CategoriesDatabasesByCron)) {
        $CategoriesDatabasesByCron = 1;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($CategoriesDatabasesByCron == 1) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Execute():: Only bycron, aborting...\n";
            }
            if (!$GLOBALS["BYCRON"]) {
                build_progress("Not executed by CRON.. Aborting", 110);
                return;
            }
        }
    }
    if (!$GLOBALS["FORCE"]) {
        if (!$GLOBALS["BYCRON"]) {
            $timeFile = $unix->file_time_min($timeFile);
            if ($timeFile < $StandardTime) {
                build_progress("{$timeFile}mn < {$StandardTime}Mn, aborting...use --force ", 110);
                if ($GLOBALS["VERBOSE"]) {
                    echo "Execute():: {$timeFile}mn < {$StandardTime}Mn, aborting...use --force to bypass\n";
                }
                return;
            }
        }
    }
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    $sock = new sockets();
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    if ($EnableArticaMetaClient == 1) {
        build_progress("Using Artica Meta server", 10);
        return artica_meta_client();
    }
    $BASE_URI = "ftp://ftp.univ-tlse1.fr/pub/reseau/cache/squidguard_contrib";
    $myFile = basename(__FILE__);
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$GLOBALS["SCHEDULE_ID"]}.time";
    $unix = new unix();
    $ufdbGenTable = $unix->find_program("ufdbGenTable");
    $kill = $unix->find_program("kill");
    $pid = @file_get_contents($pidfile);
    $getmypid = $GLOBALS["MYPID"];
    if (!$GLOBALS["FORCE"]) {
        if ($unix->process_exists($pid, $myFile)) {
            $timePid = $unix->PROCCESS_TIME_MIN($pid);
            if ($timePid < 60) {
                build_progress("Already running PID {$pid}", 110);
                die;
            } else {
                unix_system_kill_force($pid);
            }
        }
    }
    @file_put_contents($pidfile, $getmypid);
    if ($GLOBALS["VERBOSE"]) {
        echo "Executed pid {$getmypid}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "ufdbGenTable:{$ufdbGenTable}\n";
    }
    $sock = new sockets();
    $SquidDatabasesUtlseEnable = $sock->GET_INFO("SquidDatabasesUtlseEnable");
    if (!is_numeric($SquidDatabasesUtlseEnable)) {
        $SquidDatabasesUtlseEnable = 1;
    }
    if ($SquidDatabasesUtlseEnable == 0) {
        build_progress("{database_disabled}", 110);
        update_progress(100, "{database_disabled}");
        echo "Toulouse university is disabled\n";
        artica_update_event(2, "Toulouse university is disabled, aborting", null, __FILE__, __LINE__);
    }
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($cachetime);
        if ($time < 120) {
            $q = new mysql_squid_builder();
            if ($q->COUNT_ROWS("univtlse1fr") == 0) {
                BuildDatabaseStatus();
            }
            ufdbevents("{$cachetime}: {$time}Mn need 120Mn");
            echo "{$cachetime}: {$time}Mn need 120Mn\n";
            die;
        }
    }
    @unlink($cachetime);
    @file_put_contents($cachetime, time());
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL("SELECT * FROM ftpunivtlse1fr");
    if (!$q->ok) {
        if (strpos($q->mysql_error, "doesn't exist") > 0) {
            $q->CheckTables();
            $results = $q->QUERY_SQL("SELECT * FROM ftpunivtlse1fr");
        }
    }
    if (!$q->ok) {
        ufdbevents("Fatal: {$q->mysql_error}");
        ufdbguard_admin_events("Fatal: {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "Toulouse DB");
    }
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $ARRAYSUM_LOCALE[$ligne["filename"]] = $ligne["zmd5"];
    }
    $STATUS = unserialize(@file_get_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD"));
    $STATUS["LAST_CHECK"] = time();
    @file_put_contents("/etc/artica-postfix/TLSE_LAST_DOWNLOAD", serialize($STATUS));
    if (!isset($GLOBALS["UFDB_COUNT_OF_DOWNLOADED"])) {
        $GLOBALS["UFDB_COUNT_OF_DOWNLOADED"] = 0;
    }
    build_progress("Check MD5", 10);
    $ARRAYSUM_REMOTE = GET_MD5S_REMOTE();
    $TOT = count($ARRAYSUM_REMOTE);
    $c = 0;
    $start = 15;
    while (list($filename, $md5) = each($ARRAYSUM_REMOTE)) {
        $c++;
        $prc = round($c / $TOT * 100);
        update_progress($c, $filename);
        if (!isset($ARRAYSUM_LOCALE[$filename])) {
            $ARRAYSUM_LOCALE[$filename] = null;
        }
        if ($ARRAYSUM_LOCALE[$filename] != $md5) {
            $size = FormatBytes($GLOBALS["UFDB_SIZE"] / 1024);
            if ($prc < 15) {
                build_progress("Downloading {$filename} ({$size})", 15);
                $prclog = 15;
            }
            if ($prc > 15) {
                if ($prc < 80) {
                    build_progress("Downloading {$filename} ({$size})", $prc);
                    $prclog = $prc;
                }
                if ($prc > 79) {
                    build_progress("Downloading {$filename} ({$size})", 79);
                    $prclog = 79;
                }
            }
            update_remote_file($BASE_URI, $filename, $md5, $prclog);
        }
    }
    if (count($GLOBALS["squid_admin_mysql"])) {
        $UFDB_SIZE = FormatBytes($GLOBALS["UFDB_SIZE"] / 1024);
        build_progress(count($GLOBALS["squid_admin_mysql"]) . " downloaded items - {$UFDB_SIZE}", 80);
        artica_update_event(2, count($GLOBALS["squid_admin_mysql"]) . " downloaded items - {$UFDB_SIZE} - Webfiltering Toulouse Databases updated", @implode("\n", $GLOBALS["squid_admin_mysql"]), __FILE__, __LINE__);
        unset($GLOBALS["squid_admin_mysql"]);
    }
    build_progress("{done}", 85);
    update_progress(100, "{done}");
    build_progress("CoherenceOffiels()", 85);
    CoherenceOffiels();
    build_progress("CoherenceRepertoiresUfdb()", 90);
    CoherenceRepertoiresUfdb();
    build_progress("BuildDatabaseStatus()", 95);
    BuildDatabaseStatus();
    build_progress("remove_bad_files()", 98);
    remove_bad_files();
    build_progress("{finish}", 100);
    if ($GLOBALS["UFDB_COUNT_OF_DOWNLOADED"] > 0) {
        artica_meta_server(true);
    } else {
        artica_meta_server();
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $ufdbConvertDB = $unix->find_program("ufdbConvertDB");
    if (is_file($ufdbConvertDB)) {
        shell_exec("{$ufdbConvertDB} /var/lib/ftpunivtlse1fr");
    }
    if (is_dir("/var/lib/ftpunivtlse1fr")) {
        $chown = $unix->find_program("chown");
        shell_exec("{$chown} squid:squid /var/lib/ftpunivtlse1fr");
        shell_exec("{$chown} -R squid:squid /var/lib/ftpunivtlse1fr/");
    }
    $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.squidguard.php --disks");
}
Esempio n. 21
0
function RestartDedicatedServices($aspid = false)
{
    $unix = new unix();
    if ($aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " RestartDedicatedServices already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 120) {
                if (!$GLOBALS["FORCE"]) {
                    die;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.web-community-filter.php --register");
    events("Starting artica");
    echo "Starting......: " . date("H:i:s") . " nightly builds starting artica...\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 45);
    system("/etc/init.d/artica-postfix start");
    echo "Starting......: " . date("H:i:s") . " nightly builds building init scripts\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 50);
    system("{$php} /usr/share/artica-postfix/exec.initslapd.php --force >/dev/null 2>&1");
    echo "Starting......: " . date("H:i:s") . " nightly builds updating network\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 55);
    system("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php >/dev/null 2>&1");
    system("{$php} /usr/share/artica-postfix/exec.monit.php --build >/dev/null 2>&1");
    echo "Starting......: " . date("H:i:s") . " nightly builds purge and clean....\n";
    @file_put_contents("/usr/share/artica-postfix/download_progress", 60);
    shell_exec("{$nohup} /etc/init.d/slapd start >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/artica-webconsole start >/dev/null 2>&1 &");
    if (is_file("/etc/init.d/nginx")) {
        shell_exec("{$nohup} /etc/init.d/nginx reload >/dev/null 2>&1 &");
    }
    shell_exec("{$nohup} /etc/init.d/auth-tail restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/artica-framework restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/process1 -perm >/dev/null 2>&1 &");
    shell_exec("{$nohup} /usr/share/artica-postfix/bin/artica-make --empty-cache >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.squid.php --build-schedules >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.schedules.php --defaults >/dev/null 2>&1 &");
    if (is_file($squidbin)) {
        squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__);
        $cmd = "/etc/init.d/squid reload --script=" . basename(__FILE__) . " >/dev/null 2>&1 &";
        shell_exec($cmd);
    }
    events("done");
    @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
    echo "Starting......: " . date("H:i:s") . " Done you can close the screen....\n";
    _artica_update_event(2, "RestartDedicatedServices(): finish", null, __FILE__, __LINE__);
}
Esempio n. 22
0
function updatev2()
{
    $sock = new sockets();
    $unix = new unix();
    $GLOBALS["TEMP_PATH"] = $unix->TEMP_DIR();
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    $timeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $ArticaDbReplicate = $sock->GET_INFO("ArticaDbReplicate");
    $CategoriesDatabasesByCron = $sock->GET_INFO("CategoriesDatabaseByCron");
    if (!is_numeric($CategoriesDatabasesByCron)) {
        $CategoriesDatabasesByCron = 1;
    }
    $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics");
    $ArticaDBPath = $sock->GET_INFO("ArticaDBPath");
    if ($ArticaDBPath == null) {
        $ArticaDBPath = "/opt/articatech";
    }
    $ManualArticaDBPath = $sock->GET_INFO("ManualArticaDBPath");
    if ($ManualArticaDBPath == null) {
        $ManualArticaDBPath = "/home/manualupdate/articadb.tar.gz";
    }
    $ManualArticaDBPathNAS = $sock->GET_INFO("ManualArticaDBPathNAS");
    $datas = unserialize(base64_decode($sock->GET_INFO("ufdbguardConfig")));
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    if (!is_numeric($ManualArticaDBPathNAS)) {
        $ManualArticaDBPathNAS = 0;
    }
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    if (!is_numeric($ArticaDbReplicate)) {
        $ArticaDbReplicate = 0;
    }
    $WizardStatsAppliance = unserialize(base64_decode($sock->GET_INFO("WizardStatsAppliance")));
    if (!isset($WizardStatsAppliance["SERVER"])) {
        $WizardStatsAppliance["SERVER"] = null;
    }
    if ($DisableArticaProxyStatistics == 1) {
        updatev2_progress(110, "Error: Artica statistics are disabled");
    }
    if ($datas["UseRemoteUfdbguardService"] == 1) {
        updatev2_progress(110, "Error: - UseRemoteUfdbguardService -  Only used by {$WizardStatsAppliance["SERVER"]}");
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($CategoriesDatabasesByCron == 1) {
            if (!$GLOBALS["BYCRON"]) {
                updatev2_progress(110, "Error: Only executed by schedule...");
                return;
            }
        }
    }
    if ($GLOBALS["FORCE"]) {
        ufdbevents("***** Force enabled ***** ");
        ufdbevents("*****");
        ufdbevents("*****");
        ufdbevents("Executed as {$GLOBALS["CMDLINE"]}");
        ufdbevents("*****");
        ufdbevents("*****");
    }
    if (!$GLOBALS["CHECKTIME"]) {
        ufdbevents("***** CHECKTIME disabled ***** ");
    }
    $CHECKTIME = $unix->file_time_min($timeFile);
    ufdbevents(" **");
    ufdbevents(" **");
    ufdbevents("{$timeFile} = {$CHECKTIME}Mn");
    ufdbevents(" **");
    ufdbevents(" **");
    if (!$GLOBALS["FORCE"]) {
        if ($CHECKTIME < 240) {
            updatev2_progress(110, "STOP: current {$CHECKTIME}Mn, require 240mn");
            return;
        }
    }
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, __FILE__)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time < 10200) {
            updatev2_progress(110, "Error: already running pid {$pid} since {$time}Mn");
            return;
        } else {
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
            if ($GLOBALS["SCHEDULE_ID"] > 0) {
                artica_update_event(1, "Warning: Old task pid {$pid} since {$time}Mn has been killed, (reach 7200mn)", null, __FILE__, __LINE__);
            }
        }
    }
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    ufdbevents("Stamp {$timeFile}");
    @unlink($timeFile);
    $tlse_force_token = null;
    @file_put_contents($timeFile, time());
    @file_put_contents($pidfile, getmypid());
    $tlse_token = null;
    if ($GLOBALS["BYCRON"]) {
        $tlse_token == " --bycron --force";
    }
    if ($GLOBALS["FORCE"]) {
        $tlse_force_token = " --force";
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    ufdbevents("Running  exec.update.squid.tlse.php");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.update.squid.tlse.php --schedule-id={$GLOBALS["SCHEDULE_ID"]}{$tlse_force_token}{$tlse_token} >/dev/null 2>&1 &");
    updatev2_progress(10, "{checking} [" . __LINE__ . "]");
    updatev2_checkversion();
    updatev2_progress(12, "{runing} [" . __LINE__ . "]");
    ufdbtables(true);
    C_ICAP_TABLES(true);
    schedulemaintenance();
    EXECUTE_BLACK_INSTANCE();
}
Esempio n. 23
0
function SendStatus()
{
    emergency(true);
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $sock = new sockets();
    $EnableSargGenerator = $sock->GET_INFO("EnableSargGenerator");
    if (TestsCron($pidfile)) {
        $ArticaMetaPingEnable = $sock->GET_INFO("ArticaMetaPingEnable");
        events("SendPing={$ArticaMetaPingEnable}", __FUNCTION__, __FILE__, __LINE__);
        if ($ArticaMetaPingEnable == 1) {
            SendPing();
        }
        return true;
    }
    $ArticaMetaEnabled = $sock->GET_INFO("ArticaMetaEnabled");
    if ($ArticaMetaEnabled != 1) {
        return;
    }
    $t1 = time();
    if (!is_file("/usr/share/artica-postfix/ressources/logs/global.status.ini")) {
        events("Unable to stat /usr/share/artica-postfix/ressources/logs/global.status.ini", __FUNCTION__, __FILE__, __LINE__);
        return null;
    }
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $ptime = $unix->PROCESS_TTL($pid);
        if ($ptime > $GLOBALS["MAXTTL"]) {
            events("killing process {$pid} ttl:{$ptime} minutes", __FUNCTION__, __FILE__, __LINE__);
            unix_system_kill_force($pid);
        } else {
            events("Already executed, process {$pid}", __FUNCTION__, __FILE__, __LINE__);
            die;
        }
    }
    events("Running pid " . getmypid(), __FUNCTION__, __FILE__, __LINE__);
    @file_put_contents($pidfile, getmypid());
    CheckNetwork();
    $http = new httpget();
    $meta = new artica_meta();
    $filecache = "/etc/artica-postfix/artica-meta-files.cache";
    events("My uuid=\"{$meta->uuid}\"", __FUNCTION__, __FILE__, __LINE__);
    $memCache = "/usr/share/artica-postfix/ressources/logs/status.memory.hash";
    $cpu_graphs = "/opt/artica/share/www/system/rrd/01cpu-1day.png";
    $server_status = "/usr/share/artica-postfix/ressources/logs/status.right.1.html";
    $squid_realtime = "/etc/artica-postfix/squid-realtime.cache";
    $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY));
    $ini = new Bs_IniHandler();
    $ini->loadFile("/usr/share/artica-postfix/ressources/logs/global.status.ini");
    $ArrayFileCache = unserialize(@file_get_contents($filecache));
    if (is_file($memCache)) {
        $MEM_CACHE = base64_encode(@file_get_contents($memCache));
    } else {
        include_once "ressources/class.os.system.tools.inc";
        $os = new os_system();
        $os->html_Memory_usage();
        $MEM_CACHE = base64_encode(serialize($os->meta_array));
    }
    if (is_file($cpu_graphs)) {
        if ($ArrayFileCache["STATS_DAY"] != filemtime($cpu_graphs)) {
            $http->uploads["STATS_DAY"] = $cpu_graphs;
            $ArrayFileCache["STATS_DAY"] = filemtime($cpu_graphs);
            @file_put_contents($filecache, serialize($ArrayFileCache));
        }
    }
    if (is_file($server_status)) {
        if ($ArrayFileCache["SERVER_STATUS"] != filemtime($server_status)) {
            $http->uploads["SERVER_STATUS"] = $server_status;
            $ArrayFileCache["SERVER_STATUS"] = filemtime($server_status);
            @file_put_contents($filecache, serialize($ArrayFileCache));
        }
    }
    if (is_file($squid_realtime)) {
        if ($ArrayFileCache["SQUID_REALTIME"] != filemtime($squid_realtime)) {
            $http->uploads["SQUID_REALTIME"] = $squid_realtime;
            $ArrayFileCache["SQUID_REALTIME"] = filemtime($squid_realtime);
            @file_put_contents($filecache, serialize($ArrayFileCache));
        }
    }
    if ($EnableSargGenerator == 1) {
        $push_sarg = false;
        $sock = new sockets();
        $SargOutputDir = $sock->GET_INFO("SargOutputDir");
        if ($SargOutputDir == null) {
            $SargOutputDir = "/var/www/html/squid-reports";
        }
        if (is_file("{$SargOutputDir}/index.html")) {
            if (!is_file("/etc/artica-postfix/sarg.tgz")) {
                shell_exec("cd {$SargOutputDir} && tar -cjf /etc/artica-postfix/sarg.tgz ./*");
                $push_sarg = true;
            } else {
                if ($ArrayFileCache["SQUID_SARG"] != filemtime("{$SargOutputDir}/index.html")) {
                    @unlink("/etc/artica-postfix/sarg.tgz");
                    shell_exec("cd {$SargOutputDir} && tar -cjf /etc/artica-postfix/sarg.tgz ./*");
                    $push_sarg = true;
                }
            }
            if ($push_sarg) {
                $http->uploads["SQUID_SARG"] = "/etc/artica-postfix/sarg.tgz";
            }
        }
    }
    $users = new usersMenus();
    $status = base64_encode(serialize($ini->_params));
    $pasmoinsaux = pasmoinsaux();
    if ($users->VMWARE_HOST) {
        $VMWARE_HOST = 1;
    } else {
        $VMWARE_HOST = 0;
    }
    shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.dmidecode.php");
    $dmidecode = base64_encode(@file_get_contents("/etc/artica-postfix/dmidecode.cache"));
    //SQUID
    if ($users->SQUID_INSTALLED) {
        $sock = new sockets();
        $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
        if (!is_numeric($SQUIDEnable)) {
            $SQUIDEnable = 1;
        }
        if ($SQUIDEnable == 1) {
            $SQUID_CACHES = base64_encode(serialize($unix->squid_get_cache_infos()));
        }
        if (is_array($SQUID_CACHES)) {
            $squid = new squidbee();
            $cacheconf = $squid->cache_list;
            $cacheconf[$squid->CACHE_PATH]["cache_type"] = $squid->CACHE_TYPE;
            $cacheconf[$squid->CACHE_PATH]["cache_size"] = $squid->CACHE_SIZE;
            $cacheconf[$squid->CACHE_PATH]["cache_dir_level1"] = 16;
            $cacheconf[$squid->CACHE_PATH]["cache_dir_level2"] = 256;
            events("Caches: " . count($cacheconf), __FILE__, __LINE__);
            $SQUID_CACHES_CONFIG = base64_encode(serialize($cacheconf));
        }
    }
    if ($users->SAMBA_INSTALLED) {
        _CheckSambaConfig();
    }
    if ($users->ZARAFA_INSTALLED) {
        if (is_file("/etc/artica-postfix/settings/Daemons/ZarafaLicenseInfos")) {
            $ZARAFA_LICENSE = @file_get_contents("/etc/artica-postfix/settings/Daemons/ZarafaLicenseInfos");
        } else {
            $ZARAFA_LICENSE = "Free edition";
        }
    }
    if (is_file("/etc/artica-postfix/zarafa-export.db")) {
        $ZARAFA_DB = @file_get_contents("/etc/artica-postfix/zarafa-export.db");
    }
    $body = $http->send("{$meta->ArticaMetaHostname}/lic.status.server.php", "post", array("DATAS" => $datasToSend, "STATUS" => $status, "MEMORIES" => $MEM_CACHE, "VERSION" => $users->ARTICA_VERSION, "DISTRI" => $users->LinuxDistriCode, "UPTIME" => getUptime(), "DISTRINAME" => $users->LinuxDistriFullName, "MAIN_PRODUCTS" => base64_encode(serialize(array("ZARAFA" => $users->ZARAFA_INSTALLED, "POSTFIX" => $users->POSTFIX_INSTALLED, "SQUID" => $users->SQUID_INSTALLED, "SAMBA" => $users->SAMBA_INSTALLED, "CYRUS" => $users->cyrus_imapd_installed, "OPENVPN" => $users->OPENVPN_INSTALLED))), "PROCESSES" => base64_encode($pasmoinsaux), "TOP_PROCESSES" => top10cpumem(), "NETS" => Networks(), "VMWARE_HOST" => $VMWARE_HOST, "SETTINGS_INC" => base64_encode(serialize(settings_inc())), "LOCAL_VERSIONS" => LocalVersions(), "VBOXGUESTS" => VirtualBoxList(), "APTCHECK" => APTCHECK(), "DMIDECODE" => $dmidecode, "SQUID_CACHES" => $SQUID_CACHES, "SQUID_CACHES_CONFIG" => $SQUID_CACHES_CONFIG, "OPENPORTS" => OpenPorts($meta->serial, $meta->uuid), "OPENVPN_CLIENTS_STATUS" => @file_get_contents("/usr/share/artica-postfix/ressources/logs/openvpn-clients.status"), "ZARAFA_DB" => $ZARAFA_DB, "ZARAFA_LICENSE" => $ZARAFA_LICENSE));
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    if (preg_match("#NOTIFY_DISCONNECT#is", $body)) {
        events("NOTIFY_DISCONNECT detected -> unregister_server()", __FUNCTION__, __FILE__, __LINE__);
        unregister_server();
        return;
    }
    if (preg_match("#NOTIFY_EXPORT_USERS#is", $body)) {
        events("NOTIFY_EXPORT_USERS -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_DOMAINS#is", $body)) {
        events("NOTIFY_EXPORT_DOMAINS -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all-domains", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-domains >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_OU#is", $body)) {
        events("NOTIFY_EXPORT_OU -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all-ou", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-ou >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_GROUPS#is", $body)) {
        events("NOTIFY_EXPORT_GROUPS -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all-groups", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-groups >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_SETTINGS#is", $body)) {
        $cmd = $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-settings >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_SETTINGS -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_COMPUTERS#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-computers >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_SETTINGS -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_DNS_ENTRIES#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-dns >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_DNS_ENTRIES -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_GROUPWARES#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-groupwares >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_GROUPWARES -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_FETCHMAIL_RULES#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-fetchmail-rules >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_FETCHMAIL_RULES -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#<TASKS>(.+?)</TASKS>#is", $body, $re)) {
        events("Save tasks to /etc/artica-postfix/artica-meta.tasks", __FUNCTION__, __FILE__, __LINE__);
        @file_put_contents("/etc/artica-postfix/artica-meta.tasks", $re[1]);
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.tasks.php >/dev/null 2>&1 &";
        events("TASKS ->{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    } else {
        events("No tasks ordered for me...", __FUNCTION__, __FILE__, __LINE__);
        @unlink("/etc/artica-postfix/artica-meta.tasks");
    }
    if (preg_match("#<HOST_CONF>(.+?)</HOST_CONF>#is", $body, $re)) {
        ParseMyConf($re[1]);
    } else {
        events("No configuration for me...", __FUNCTION__, __FILE__, __LINE__);
    }
    shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --socks >/dev/null 2>&1 &");
    if (users_queue()) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --user-queue >/dev/null 2>&1 &";
        events("users settings queue is not empty -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (computer_queue()) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --computer-queue >/dev/null 2>&1 &";
        events("computer settings queue is not empty -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if ($users->OPENVPN_INSTALLED) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-openvpn-logs >/dev/null 2>&1 &";
        events("OpenVpn is installed -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    $time_iptables = file_time_min("/etc/artica-postfix/artica.meta.iptables.time");
    if ($time_iptables > 180) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --iptables >/dev/null 2>&1 &";
        events("iptables -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
        $cmd = $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-settings >/dev/null 2>&1 &";
        events("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        @unlink("/etc/artica-postfix/artica.meta.iptables.time");
        @file_put_contents("/etc/artica-postfix/artica.meta.iptables.time", "#");
    }
    $t2 = time();
    $time_duration = distanceOfTimeInWords($t1, $t2);
    events("Send status to {$meta->ArticaMetaHostname} DONE ({$time_duration})", __FUNCTION__, __FILE__, __LINE__);
}
Esempio n. 24
0
function stop()
{
    $SERV_NAME = $GLOBALS["SERV_NAME"];
    $MYSQL_SOCKET = $GLOBALS["MYSQL_SOCKET"];
    $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 "Stopping......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} Already task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $sock = new sockets();
    $ArticaDBPath = $sock->GET_INFO("ArticaDBPath");
    if ($ArticaDBPath == null) {
        $ArticaDBPath = "/opt/articatech";
    }
    $GLOBALS["WORKDIR"] = $ArticaDBPath;
    $GLOBALS["MYSQL_BIN_PATH"] = "{$GLOBALS["WORKDIR"]}/bin/articadb";
    $pid = DBPID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) already stopped...\n";
        }
        return;
    }
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Stopping MySQL Daemon ({$SERV_NAME}) with a ttl of {$time}mn\n";
    }
    $mysqladmin = $unix->find_program("mysqladmin");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Stopping MySQL Daemon ({$SERV_NAME}) smoothly...\n";
    }
    $cmd = "{$mysqladmin} --socket={$MYSQL_SOCKET}  --protocol=socket --user=root shutdown >/dev/null";
    shell_exec($cmd);
    $pid = DBPID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) success...\n";
        }
        return;
    }
    $kill = $unix->find_program("kill");
    for ($i = 0; $i < 10; $i++) {
        $pid = DBPID();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) kill pid {$pid}..\n";
            }
            unix_system_kill_force($pid);
        } else {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) wait {$i}/10\n";
        }
        sleep(1);
    }
    $pid = DBPID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) success...\n";
        }
        @unlink($MYSQL_SOCKET);
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) Failed...\n";
    }
}
Esempio n. 25
0
function stop($aspid = false)
{
    $unix = new unix();
    if (!$aspid) {
        $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 "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n";
        }
        build_progress("{stopping_service}", 45);
        return;
    }
    $pid = PID_NUM();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n";
    }
    unix_system_kill($pid);
    build_progress("{stopping_service}", 15);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    build_progress("{stopping_service}", 20);
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n";
        }
        build_progress("{stopping_service}", 45);
        return;
    }
    build_progress("{stopping_service}", 25);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n";
    }
    unix_system_kill_force($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n";
        }
        build_progress("{stopping_service}", 45);
        return;
    }
    build_progress("{stopping_service}", 45);
}
Esempio n. 26
0
function export_dns()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        $ptime = $unix->PROCESS_TTL($pid);
        if ($ptime > $GLOBALS["MAXTTL"]) {
            events("export_dns():: killing process {$pid} ttl:{$ptime} minutes");
            unix_system_kill_force($pid);
        } else {
            events("export_dns():: already executed, process {$pid}");
            die;
        }
    }
    $time = file_time_min($pidfile);
    events("{$pidfile}={$time}Mn", __FUNCTION__, __FILE__, __LINE__);
    if ($time == 0) {
        events("Cannot replicate DNS before one minute...", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $ldap = new clladp();
    $http = new httpget();
    $sock = new sockets();
    $meta = new artica_meta();
    $pattern = "(&(objectclass=*)(arecord=*))";
    $sr = ldap_search($ldap->ldap_connection, "ou=dns,{$ldap->suffix}", $pattern, array());
    $cachefile = "/etc/artica-postfix/dns.cache";
    if ($sr) {
        $hash = ldap_get_entries($ldap->ldap_connection, $sr);
        for ($i = 0; $i < $hash["count"]; $i++) {
            $macrecord = $hash[$i]["macrecord"][0];
            $arecord = $hash[$i]["arecord"][0];
            if ($arecord == "127.0.0.1") {
                continue;
            }
            if ($arecord == null) {
                continue;
            }
            echo "{$macrecord} {$arecord}\n";
            $array[$arecord] = array("MAC" => $macrecord, "NAMES" => $hash[$i]["associateddomain"]);
            $arecord = null;
            $macrecord = null;
        }
    } else {
        events("LDAP link failed", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (!is_array($array)) {
        return;
    }
    @file_put_contents($cachefile, base64_encode(serialize($array)));
    $http->uploads["DNS_COMPUTERS"] = $cachefile;
    $body = $http->send("{$meta->ArticaMetaHostname}/lic.users.import.php", "post", array("DATAS" => base64_encode(serialize($meta->GLOBAL_ARRAY))));
    if (!preg_match("#<RESULTS>OK</RESULTS>#is", $body)) {
        events(count($array) . " DNS failed to be exported to global Management console", __FUNCTION__, __FILE__, __LINE__);
        return;
    } else {
        events(count($array) . " DNS exported to global Management console", __FUNCTION__, __FILE__, __LINE__);
        send_email_events(count($array) . " DNS exported to global Management console", null, "CLOUD");
        @unlink($cachefile);
    }
}
Esempio n. 27
0
function kill_pid()
{
    $unix = new unix();
    $kill = $unix->find_program("kill");
    $pid = $_GET["kill-pid"];
    if (!is_numeric($pid)) {
        return;
    }
    if ($pid < 10) {
        return;
    }
    unix_system_kill_force($pid);
}
Esempio n. 28
0
function nginx($aspid = false)
{
    $unix = new unix();
    if (is_file("/etc/lsb-release")) {
        if ($GLOBALS["VERBOSE"]) {
            "CheckSourcesList: Ubuntu system, aborting\n";
        }
    }
    if (!is_file("/etc/debian_version")) {
        return;
    }
    $nginx = $unix->find_program("nginx");
    if (is_file($nginx)) {
        return;
    }
    if ($aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
        $kill = $unix->find_program("kill");
        $timexec = $unix->file_time_min($pidTime);
        if ($timexec < 240) {
            return;
        }
        @unlink($pidTime);
        @file_put_contents($pidTime, time());
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($time < 30) {
                return;
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $ver = trim(@file_get_contents("/etc/debian_version"));
    preg_match("#^([0-9]+)\\.#", $ver, $re);
    if (preg_match("#squeeze\\/sid#", $ver)) {
        $Major = 6;
    }
    $Major = $re[1];
    if ($Major != 6) {
        echo "CheckSourcesList: Debian version <> {$Major} aborting...\n";
        return;
    }
    check_nginx();
    $unix = new unix();
    $aptget = $unix->find_program("apt-get");
    echo "CheckSourcesList: Installing nginx\n";
    $cmd = "DEBIAN_FRONTEND=noninteractive {$aptget} -o Dpkg::Options::=\"--force-confnew\" --force-yes -y install nginx 2>&1";
    echo "CheckSourcesList: {$cmd}\n";
    shell_exec($cmd);
    $nginx = $unix->find_program("nginx");
    if (is_file($nginx)) {
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.initslapd.php --nginx");
        shell_exec("/etc/init.d/nginx restart");
    }
}
Esempio n. 29
0
function stop($aspid = false)
{
    $unix = new unix();
    if (!$aspid) {
        $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]: Nginx service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: Nginx service already stopped...\n";
        }
        GHOSTS_PID();
        return;
    }
    $pid = PID_NUM();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $lighttpd_bin = $unix->find_program("lighttpd");
    $kill = $unix->find_program("kill");
    $nginx = $unix->find_program("nginx");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Nginx service Shutdown pid {$pid}...\n";
    }
    shell_exec("{$nginx} -c /etc/nginx/nginx.conf -s stop >/dev/null 2>&1");
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: Nginx service success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Nginx service shutdown - force - pid {$pid}...\n";
    }
    unix_system_kill_force($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: Nginx service success...\n";
        }
        GHOSTS_PID();
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Nginx service failed...\n";
    }
    GHOSTS_PID();
}
Esempio n. 30
0
function stop($ID)
{
    $SERV_NAME = $GLOBALS["SERV_NAME"];
    $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 "Stopping......: " . date("H:i:s") . " [INIT]: Already task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $pid = GET_PID($ID);
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} already stopped...\n";
        }
        return;
    }
    $kill = $unix->find_program("kill");
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Stopping {$SERV_NAME} with a ttl of {$time}mn\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Stopping {$SERV_NAME} smoothly...\n";
    }
    $cmd = "{$kill} {$pid} >/dev/null";
    shell_exec($cmd);
    $pid = GET_PID($ID);
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} success...\n";
        }
        return;
    }
    for ($i = 0; $i < 10; $i++) {
        $pid = GET_PID($ID);
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} kill pid {$pid}..\n";
            }
            unix_system_kill_force($pid);
        } else {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} wait {$i}/10\n";
        }
        sleep(1);
    }
    $pid = GET_PID($ID);
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Failed...\n";
    }
}