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");
}
Esempio n. 2
0
function checkProcess1(){
	
	$unix=new unix();
	$pid=$unix->PIDOF_PATTERN("bin/process1");
	if($pid<5){return null;}
	$process1=$unix->PROCCESS_TIME_MIN($pid);
	$mem=$unix->PROCESS_MEMORY($pid);
	Myevents("process1: $pid ($process1 mn) memory:$mem Mb",__FUNCTION__);
	
	if($mem>30){
		@copy("/var/log/artica-postfix/process1.debug","/var/log/artica-postfix/process1.killed".time().".debug");
		system("/bin/kill -9 $pid");
		$unix->send_email_events(
		"artica process1 (process1) Killed",
		"Process1 use too much memory $mem MB","watchdog"); 		
	}
	
	if($process1>2){
		@copy("/var/log/artica-postfix/process1.debug","/var/log/artica-postfix/process1.killed".time().".debug");
		system("/bin/kill -9 $pid");
		$unix->send_email_events(
		"artica process1 (process1) Killed",
		"Process1 run since $process1 Pid: $pid and exceed 2 minutes live","watchdog"); 
	}

}
Esempio n. 3
0
function InMemQUestion()
{
    $unix = new unix();
    $pid = $unix->PIDOF_PATTERN("philesight --db");
    if ($unix->process_exists($pid)) {
        return true;
    }
    return false;
}
Esempio n. 4
0
function XZARAFA_SERVER_PID()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/zarafa-server.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    return $unix->PIDOF_PATTERN("zarafa-server -c /etc/zarafa/server.cfg");
}
Esempio n. 5
0
function PID_NUM()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/openvpn/openvpn-server.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $Masterbin = $unix->find_program("openvpn");
    return $unix->PIDOF_PATTERN("{$Masterbin} --port.+?--dev");
}
Esempio n. 6
0
function PID_NUM()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/zarafa-web/httpd.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $apachebin = $unix->LOCATE_APACHE_BIN_PATH();
    return $unix->PIDOF_PATTERN("{$apachebin}.*?/etc/zarafa/httpd.conf");
}
Esempio n. 7
0
function ZARAFADB_PID()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/zarafa-db.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $mysqld = $unix->find_program("mysqld");
    $pid = $unix->PIDOF_PATTERN("{$mysqld}.*?--pid-file=/var/run/zarafa-db.pid");
    return $pid;
}
function GETPID()
{
    $unix = new unix();
    if (is_file("/var/run/suricata-tail.pid")) {
        $pid = @file_get_contents("/var/run/suricata-tail.pid");
    }
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $pid = $unix->PIDOF_PATTERN("/usr/share/artica-postfix/bin/suricata-tail.py");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
}
function GETPID()
{
    $unix = new unix();
    if (is_file('/etc/artica-postfix/exec.hotspot-tail.php.pid')) {
        $pid = @file_get_contents("'/etc/artica-postfix/exec.hotspot-tail.php.pid'");
    }
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $pid = $unix->PIDOF("/bin/hotspot-tail");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    return $unix->PIDOF_PATTERN("exec.hotspot-tail.php");
}
Esempio n. 10
0
function PID_NUM()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/urlfilterdb/ufdbguardd.pid");
    if ($unix->process_exists($pid)) {
        $cmdline = trim(@file_get_contents("/proc/{$pid}/cmdline"));
        if (!preg_match("#ufdbcatdd#", $cmdline)) {
            return $pid;
        }
    }
    $Masterbin = $unix->find_program("ufdbguardd");
    $pid = $unix->PIDOF_PATTERN("ufdbguardd.*?-c.*?conf");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
}
Esempio n. 11
0
function PID_NUM()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/ufdbcat/ufdbguardd.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $pid = $unix->PIDOF_PATTERN("ufdbcatdd.*?-c.*?conf");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
}
function Scan($filepath, $md5file = null)
{
    $unix = new unix();
    if ($filepath == null) {
        echo "No path defined\n";
        return;
    }
    $pid = $unix->PIDOF_PATTERN(basename(__FILE__));
    $MyPid = getmypid();
    if ($MyPid != $pid) {
        if ($unix->process_exists($pid)) {
            $timeFile = $unix->PROCESS_TIME_INT($pid);
            $pidCmdline = @file_get_contents("/proc/{$pid}/cmdline");
            if ($timeFile < 30) {
                echo "Already PID {$pid} is running since {$timeFile}Mn\n";
                die;
            }
        }
    }
    $nextFile = null;
    if (!is_file($filepath)) {
        if ($md5file != null) {
            mysql_progress($md5file, 100, 3, "{$filepath} no such file");
        }
        echo "{$filepath} no such file";
    }
    @mkdir("/home/artica/import-temp", 0755, true);
    $basename = basename($filepath);
    if (preg_match("#\\.gz\$#", $basename)) {
        if ($md5file != null) {
            mysql_progress($md5file, 5, 0, "Uncompress {$filepath}");
        }
        echo "Uncompress {$basename}";
        $nextFile = dirname($filepath) . "/" . str_replace(".gz", "", $basename);
        echo "Uncompress {$basename} to {$nextFile}\n";
        if (is_file($nextFile)) {
            @unlink($nextFile);
        }
        if (!$unix->uncompress($filepath, $nextFile)) {
            if ($md5file != null) {
                mysql_progress($md5file, 100, 3, "Uncompress {$basename} failed");
            }
            echo "Uncompress {$basename} failed\n";
            return false;
        }
        $filepath = $nextFile;
    }
    if (!ExplodeFile($filepath, $md5file)) {
        return false;
    }
    if ($nextFile != null) {
        @unlink($nextFile);
    }
    return true;
}
Esempio n. 13
0
function VboxPid()
{
    $unix = new unix();
    $pid = $unix->PIDOF_PATTERN($_GET["VboxPid"]);
    if ($pid > 0) {
        $array["PID"] = $pid;
        $array["INFOS"] = "[APP_VIRTUALBOX]\n" . $unix->GetSingleMemoryOf($pid);
    }
    echo "<articadatascgi>" . base64_encode(serialize($array)) . "</articadatascgi>";
}
function start($aspid = false)
{
    $GLOBALS["LOGS"] = array();
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $sock = new sockets();
    $reconfigure = false;
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    $NtpdateAD = $sock->GET_INFO("NtpdateAD");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $SquidPerformance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance"));
    $HyperCacheStoreID = intval($sock->GET_INFO("HyperCacheStoreID"));
    $kill = $unix->find_program("kill");
    if ($SQUIDEnable == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Proxy service is disabled...\n";
        }
        return;
    }
    if ($HyperCacheStoreID == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: HyperCache is disabled...\n";
        }
        return;
    }
    if ($SquidPerformance > 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Statistics are disabled...\n";
        }
        return;
    }
    if (is_file("/etc/artica-postfix/squid.lock")) {
        $time = $unix->file_time_min("/etc/artica-postfix/squid.lock");
        if ($time < 60) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Proxy service is locked (since {$time}Mn...\n";
            }
            return;
        }
        @unlink("/etc/artica-postfix/squid.lock");
    }
    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]: {$GLOBALS["DAEMON_NAME"]}, Already task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = GETPID();
    if (!is_file($GLOBALS["log_path"])) {
        @file_put_contents($GLOBALS["log_path"], "");
    }
    @chmod($GLOBALS["log_path"], 0755);
    @chown($GLOBALS["log_path"], "squid");
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["DAEMON_NAME"]}, already running since {$time}Mn\n";
        }
        return;
    }
    $tail = $unix->find_program("tail");
    if (!is_file("/bin/hypercache-tail")) {
        @copy($tail, "/bin/hypercache-tail");
    }
    @chmod("/bin/hypercache-tail", 0755);
    $pid = $unix->PIDOF_PATTERN("/bin/hypercache-tail -F -n 0 {$GLOBALS["log_path"]}");
    if ($unix->process_exists($pid)) {
        for ($i = 0; $i < 20; $i++) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: killing old process pid {$pid}\n";
            }
            unix_system_kill_force($pid);
            usleep(800);
            $pid = $unix->PIDOF_PATTERN("/bin/hypercache-tail -F -n 0 {$GLOBALS["log_path"]}");
            if (!$unix->process_exists($pid)) {
                break;
            }
            unix_system_kill_force($pid);
        }
    }
    $cmd = "/bin/hypercache-tail --follow=name --retry --max-unchanged-stats=50 -n 0 {$GLOBALS["log_path"]}|{$GLOBALS["TAIL_STARTUP"]} >>/var/log/artica-postfix/squid-logger-start.log 2>&1 &";
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = GETPID();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["DAEMON_NAME"]}, waiting {$i}/5\n";
        }
        sleep(1);
    }
    $pid = GETPID();
    if ($unix->process_exists($pid)) {
        events("hypercache-tail success to start daemon PID:{$pid}...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["DAEMON_NAME"]}, success PID:{$pid}\n";
        }
    } else {
        events("hypercache-tail failed to start daemon...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["DAEMON_NAME"]}, failed\n";
        }
    }
}
Esempio n. 15
0
function build()
{
    $timefile = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    // /etc/artica-postfix/pids/exec.squid.rotate.php.build.time
    $sock = new sockets();
    $unix = new unix();
    $ls = $unix->find_program("ls");
    $pid = $unix->PIDOF_PATTERN(basename(__FILE__));
    $MyPid = getmypid();
    if ($MyPid != $pid) {
        if ($unix->process_exists($pid)) {
            $timeFile = $unix->PROCESS_TIME_INT($pid);
            $pidCmdline = @file_get_contents("/proc/{$pid}/cmdline");
            if ($timeFile < 30) {
                echo "Already PID {$pid} is running since {$timeFile}Mn\n";
                squid_admin_mysql(1, "[LOG ROTATION]: Skip task, already running {$pid} since {$timeFile}Mn", "Running: {$pidCmdline}", __FILE__, __LINE__);
                die;
            } else {
                squid_admin_mysql(1, "[LOG ROTATION]: Killing old task {$pid} running more than 30mn ({$timeFile}Mn)", "Running: {$pidCmdline}", __FILE__, __LINE__);
                $unix->KILL_PROCESS($pid);
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $time = $unix->file_time_min($timefile);
        if ($time < 60) {
            echo "Only each 60mn\n";
            die;
        }
        @unlink($timefile);
        @file_put_contents($timefile, time());
    }
    $syslog = new mysql_storelogs();
    $SquidLogRotateFreq = intval($sock->GET_INFO("SquidLogRotateFreq"));
    if ($SquidLogRotateFreq < 10) {
        $SquidLogRotateFreq = 1440;
    }
    $LastRotate = $unix->file_time_min("/etc/artica-postfix/pids/squid-rotate-cache.time");
    $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation");
    $SquidRotateOnlySchedule = intval($sock->GET_INFO("SquidRotateOnlySchedule"));
    if (!is_numeric($LogsRotateDefaultSizeRotation)) {
        $LogsRotateDefaultSizeRotation = 100;
    }
    $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir == null) {
        $BackupMaxDaysDir = "/home/logrotate_backup";
    }
    $BackupSquidLogsUseNas = intval($sock->GET_INFO("BackupSquidLogsUseNas"));
    $SquidRotateAutomount = intval($sock->GET_INFO("SquidRotateAutomount"));
    $SquidRotateClean = intval($sock->GET_INFO("SquidRotateClean"));
    $SquidRotateAutomountRes = $sock->GET_INFO("SquidRotateAutomountRes");
    $SquidRotateAutomountFolder = $sock->GET_INFO("SquidRotateAutomountFolder");
    if ($SquidRotateAutomount == 1) {
        shell_exec("{$ls} /automounts/{$SquidRotateAutomountRes} >/dev/null 2>&1");
        if (ifdirMounted("/automounts/{$SquidRotateAutomountRes}")) {
            $BackupSquidLogsUseNas = 0;
            $BackupMaxDaysDir = "/automounts/{$SquidRotateAutomountRes}/{$SquidRotateAutomountFolder}";
        } else {
            $syslog->events("/automounts/{$SquidRotateAutomountRes} not mounted", __FUNCTION__, __LINE__);
            squid_admin_mysql(1, "[ROTATE],Auto-mount {$SquidRotateAutomountRes} not mounted", null, __FILE__, __LINE__);
        }
    }
    $BackupMaxDaysDir = str_replace("//", "/", $BackupMaxDaysDir);
    $BackupMaxDaysDir = str_replace("\\", "/", $BackupMaxDaysDir);
    if (!is_dir($BackupMaxDaysDir)) {
        @mkdir($BackupMaxDaysDir, 0755, true);
    }
    if (!is_dir($BackupMaxDaysDir)) {
        $syslog->events("{$BackupMaxDaysDir} not such directory or permission denied", __FUNCTION__, __LINE__);
        squid_admin_mysql(1, "[ROTATE],{$BackupMaxDaysDir} not such directory or permission denied", null, __FILE__, __LINE__);
        if ($SquidRotateAutomount == 1) {
            $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir");
            if ($BackupMaxDaysDir == null) {
                $BackupMaxDaysDir = "/home/logrotate_backup";
            }
            if (!is_dir($BackupMaxDaysDir)) {
                @mkdir($BackupMaxDaysDir, 0755, true);
            }
            $syslog->events("Return back to {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
        } else {
            return;
        }
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $hostname = $unix->hostname_g();
    $InFluxBackupDatabaseDir = $sock->GET_INFO("InFluxBackupDatabaseDir");
    if ($InFluxBackupDatabaseDir == null) {
        $InFluxBackupDatabaseDir = "/home/artica/influx/backup";
    }
    $LogRotatePath = $sock->GET_INFO("LogRotatePath");
    if ($LogRotatePath == null) {
        $LogRotatePath = "/home/logrotate";
    }
    $LogRotateAccess = "{$LogRotatePath}/access";
    $LogRotateTail = "{$LogRotatePath}/tail";
    $LogRotateCache = "{$LogRotatePath}/cache";
    $syslog->events("Launch rotation only by schedule.: {$SquidRotateOnlySchedule}", __FUNCTION__, __LINE__);
    $syslog->events("SquidLogRotateFreq...............: {$SquidLogRotateFreq}Mn", __FUNCTION__, __LINE__);
    $syslog->events("LastRotate.......................: {$LastRotate}Mn", __FUNCTION__, __LINE__);
    $syslog->events("Working directory................: {$LogRotatePath}", __FUNCTION__, __LINE__);
    $syslog->events("Launch rotation when exceed......: {$LogsRotateDefaultSizeRotation}M", __FUNCTION__, __LINE__);
    $syslog->events("Final storage directory..........: {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
    $syslog->events("Backup files to a NAS............: {$BackupSquidLogsUseNas}", __FUNCTION__, __LINE__);
    ss5_log($BackupMaxDaysDir);
    if ($handle = opendir("/var/run/squid")) {
        while (false !== ($file = readdir($handle))) {
            if ($file == ".") {
                continue;
            }
            if ($file == "..") {
                continue;
            }
            $path = "/var/run/squid/{$file}";
            if (preg_match("#\\.[0-9]+\\.status\$#", $file)) {
                $time = $unix->file_time_min($path);
                if ($time > 1440) {
                    $syslog->events("Removing {$path}", __FUNCTION__, __LINE__);
                    @unlink($path);
                }
                continue;
            }
            if (preg_match("#\\.[0-9]+\\.state\$#", $file)) {
                $time = $unix->file_time_min($path);
                if ($time > 1440) {
                    $syslog->events("Removing {$path}", __FUNCTION__, __LINE__);
                    @unlink($path);
                }
                continue;
            }
        }
    }
    $size = @filesize("/var/log/squid/access.log");
    $size = $size / 1024;
    $size = $size / 1024;
    $syslog->events("/var/log/squid/access.log........: {$size}M", __FUNCTION__, __LINE__);
    $syslog->events("Analyze /var/log/squid directory for cache.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir("/var/log/squid"))) {
        build_progress_rotation("Unable to open /var/log/squid", 110);
        $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__);
        return;
    }
    build_progress_rotation("Scanning /var/log/squid", 40);
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "/var/log/squid/{$file}";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^cache\\.log\\.[0-9]+\$#", $file)) {
                continue;
            }
            @mkdir("{$LogRotateCache}", 0755, true);
            $size = @filesize($path);
            $size = $size / 1024;
            $size = $size / 1024;
            $destfile = "{$LogRotateCache}/{$file}." . time() . ".log";
            if (!@copy($path, $destfile)) {
                $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                @unlink($destfile);
                continue;
            }
            $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
            @unlink($path);
        }
    }
    $syslog->events("Analyze /var/log/squid directory for access.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir("/var/log/squid"))) {
        $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__);
        return;
    }
    @mkdir($LogRotateAccess, 0755, true);
    @mkdir($LogRotateTail, 0755, true);
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "/var/log/squid/{$file}";
            if (is_dir($path)) {
                continue;
            }
            if (preg_match("#^childs-access\\.log\\.[0-9]+\$#", $file)) {
                $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log";
                if (!@copy($path, $destfile)) {
                    $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                    @unlink($destfile);
                    continue;
                }
                $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
                @unlink($path);
                continue;
            }
            $syslog->events("Analyze {$file} ^squidtail\\.log\\.[0-9]+\$", __FUNCTION__, __LINE__);
            if (preg_match("#^squidtail\\.log\\.[0-9]+\$#", $file)) {
                $destfile = "{$LogRotateTail}/{$file}";
                if (!@copy($path, $destfile)) {
                    $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                    @unlink($destfile);
                    continue;
                }
                $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
                @unlink($path);
                continue;
            }
            $syslog->events("Analyze {$file} ^access\\.log\\.[0-9]+\$", __FUNCTION__, __LINE__);
            if (!preg_match("#^access\\.log\\.[0-9]+\$#", $file)) {
                continue;
            }
            @mkdir("{$LogRotatePath}", 0755, true);
            $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log";
            if (!@copy($path, $destfile)) {
                $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__);
                @unlink($destfile);
                continue;
            }
            $syslog->events("Removed {$path}", __FUNCTION__, __LINE__);
            @unlink($path);
        }
    }
    $syslog->events("Analyze {$LogRotateAccess} for access.log", __FUNCTION__, __LINE__);
    if (!($handle = opendir($LogRotateAccess))) {
        $syslog->events("Unable to open {$LogRotateAccess} directory.", __FUNCTION__, __LINE__);
        return;
    }
    $ROTATED = false;
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $path = "{$LogRotateAccess}/{$file}";
            echo "OPEN {$path}\n";
            if (is_dir($path)) {
                continue;
            }
            if (!preg_match("#^access\\.log#", $file)) {
                continue;
            }
            range_fichier_source($path, $BackupMaxDaysDir);
            $ROTATED = true;
        }
    }
    if ($handle = opendir($LogRotateTail)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                $path = "{$LogRotateTail}/{$file}";
                echo "OPEN {$path}\n";
                if (is_dir($path)) {
                    continue;
                }
                if (!preg_match("#^squidtail\\.log#", $file)) {
                    continue;
                }
                range_fichier_tail($path, $BackupMaxDaysDir);
                $ROTATED = true;
            }
        }
    }
    if (!$ROTATED) {
        return;
    }
    $q = new mysql();
    $sql = "CREATE TABLE IF NOT EXISTS `backuped_logs` (\n\t\t\t  `path` CHAR(255)  NOT NULL,\n\t\t\t  `zDate`  DATETIME,\n\t\t\t  `size` INT UNSIGNED NOT NULL,\n\t\t\t  PRIMARY KEY (`path`),\n\t\t\t  KEY `zDate` (`zDate`)\n\t\t\t)  ENGINE = MYISAM;";
    $q->QUERY_SQL($sql, "artica_events");
    $syslog->events("Analyze /home/logrotate/work for access.log", __FUNCTION__, __LINE__);
    build_progress_rotation("Scanning /home/logrotate/work", 45);
    analyze_directory("/home/logrotate/work", $BackupMaxDaysDir);
    $BackupMaxDaysDir2 = $sock->GET_INFO("BackupMaxDaysDir");
    if ($BackupMaxDaysDir2 == null) {
        $BackupMaxDaysDir2 = "/home/logrotate_backup";
    }
    if ($BackupMaxDaysDir2 != $BackupMaxDaysDir) {
        build_progress_rotation("Scanning {$BackupMaxDaysDir2}", 46);
        $syslog->events("{$BackupMaxDaysDir2} is different of {$BackupMaxDaysDir}", __FUNCTION__, __LINE__);
        analyze_directory($BackupMaxDaysDir2, $BackupMaxDaysDir);
    }
    build_progress_rotation("Scanning /home/logrotate/merged", 47);
    analyze_garbage_directory("/home/logrotate/merged", $BackupMaxDaysDir, 1440);
    build_progress_rotation("Scanning {$LogRotateCache}", 48);
    analyze_cache_directory($LogRotateCache, $BackupMaxDaysDir);
    build_progress_rotation("Scanning /home/logrotate/work", 49);
    analyze_cache_directory("/home/logrotate/work", $BackupMaxDaysDir);
    build_progress_rotation("Scanning /home/squid/cache-logs", 49);
    analyze_cache_directory("/home/squid/cache-logs", $BackupMaxDaysDir);
    if ($GLOBALS["VERBOSE"]) {
        echo "TRUNCATE TABLE backuped_logs !!!\n";
    }
    $q->QUERY_SQL("TRUNCATE TABLE backuped_logs", "artica_events");
    if ($BackupSquidLogsUseNas == 1) {
        build_progress_rotation("Backup to N.A.S", 50);
        BackupToNas($BackupMaxDaysDir);
        build_progress_rotation("Backup to N.A.S BigData backups", 50);
        BackupToNas($InFluxBackupDatabaseDir, false);
    } else {
        build_progress_rotation("Scanning {$BackupMaxDaysDir}", 50);
        analyze_destination_directory($BackupMaxDaysDir);
    }
    @file_put_contents("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", $unix->DIRSIZE_KO($BackupMaxDaysDir));
    @chmod("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", 0777);
    return;
}
Esempio n. 16
0
function redis_pid()
{
    $unix = new unix();
    $masterbin = $unix->find_program("redis-server");
    $pid = $unix->get_pid_from_file('/var/run/redis/redis-server.pid');
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    return $unix->PIDOF_PATTERN($masterbin . " -f /etc/redis/redis.conf");
}
Esempio n. 17
0
function SERVICEDB_PID()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file($GLOBALS["PID_PATH"]);
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $mysqld = $unix->find_program("mysqld");
    $pid = $unix->PIDOF_PATTERN("{$mysqld}.*?--pid-file={$GLOBALS["PID_PATH"]}");
    return $pid;
}
Esempio n. 18
0
function PID_NUM()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file($GLOBALS["APACHE_PID_PATH"]);
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $apache2ctl = $unix->LOCATE_APACHE_BIN_PATH();
    return $unix->PIDOF_PATTERN($apache2ctl . " -f {$GLOBALS["APACHE_CONFIG_PATH"]}");
}
Esempio n. 19
0
function PID_NUM()
{
    $filename = PID_PATH();
    $pid = trim(@file_get_contents($filename));
    $unix = new unix();
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $lighttpd_bin = $unix->find_program("lighttpd");
    return $unix->PIDOF_PATTERN("{$lighttpd_bin} -f /etc/artica-postfix/squidguard-lighttpd.conf");
}
Esempio n. 20
0
function restore_process_array()
{
    $unix = new unix();
    $pid = $unix->PIDOF_PATTERN("exec.zarafa-db.php --restorefrom");
    if ($unix->process_exists($pid)) {
        $WORKDIR = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/ZarafaDedicateMySQLWorkDir"));
        if ($WORKDIR == null) {
            $WORKDIR = "/home/zarafa-db";
        }
        $time = $unix->PROCCESS_TIME_MIN($pid);
        $ARRAY["PID"] = $pid;
        $ARRAY["TIME"] = $time;
        $ARRAY["SIZE"] = $unix->DIRSIZE_KO("{$WORKDIR}/data/zarafa");
        echo "<articadatascgi>" . base64_encode(serialize($ARRAY)) . "</articadatascgi>";
    }
}
Esempio n. 21
0
function GET_PID($ID = null)
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/dante/{$ID}.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $daemonbin = $unix->find_program("sockd");
    $daemonbin = basename($daemonbin);
    $conffile = str_replace(".", "\\.", $conffile);
    return $unix->PIDOF_PATTERN("{$daemonbin}.*?config\\.{$ID}");
}
Esempio n. 22
0
function PID_NUM()
{
    $filename = PID_PATH();
    $pid = trim(@file_get_contents($filename));
    $unix = new unix();
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $cntlm = $unix->find_program("cntlm");
    return $unix->PIDOF_PATTERN("{$cntlm}.*?cntlm\\.pid");
}
Esempio n. 23
0
function PID_NUM()
{
    $pid = trim(@file_get_contents("/etc/artica-postfix/exec.ufdbguard-tail.php.pid"));
    $unix = new unix();
    if ($GLOBALS["VERBOSE"]) {
        echo "/etc/artica-postfix/exec.ufdbguard-tail.php.pid = {$pid}\n";
    }
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    return $unix->PIDOF_PATTERN("exec.ufdbguard-tail.php");
}
Esempio n. 24
0
function start($aspid = false)
{
    $GLOBALS["LOGS"] = array();
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $sock = new sockets();
    $reconfigure = false;
    $Enabled = $sock->GET_INFO("EnableNginx");
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    $InfluxSyslogRemote = intval($sock->GET_INFO("InfluxSyslogRemote"));
    if ($InfluxUseRemote == 0) {
        $InfluxSyslogRemote = 0;
    }
    if (!is_file("/etc/artica-postfix/settings/Daemons/EnableInfluxDB")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableInfluxDB", 1);
    }
    $EnableInfluxDB = intval($sock->GET_INFO("EnableInfluxDB"));
    $kill = $unix->find_program("kill");
    if ($Enabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Proxy service is disabled...\n";
        }
        return;
    }
    if ($EnableInfluxDB == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: InfluxDB database engine is disabled\n";
        }
        return;
    }
    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-tail, Already task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = GETPID();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: nginx-tail, already running since {$time}Mn\n";
        }
        return;
    }
    $tail = $unix->find_program("tail");
    if (!is_file("/bin/nginx-tail")) {
        @copy($tail, "/bin/nginx-tail");
    }
    @chmod("/bin/nginx-tail", 0755);
    $pid = $unix->PIDOF_PATTERN("/bin/nginx-tail -F -n 0 {$GLOBALS["log_path"]}");
    if ($unix->process_exists($pid)) {
        for ($i = 0; $i < 20; $i++) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: killing old process pid {$pid}\n";
            }
            unix_system_kill_force($pid);
            usleep(800);
            $pid = $unix->PIDOF_PATTERN("/bin/access-tail -F -n 0 {$GLOBALS["log_path"]}");
            if (!$unix->process_exists($pid)) {
                break;
            }
            unix_system_kill_force($pid);
        }
    }
    $cmd = "/bin/nginx-tail --follow=name --retry --max-unchanged-stats=50 -n 0 {$GLOBALS["log_path"]}|{$GLOBALS["TAIL_STARTUP"]} >>/var/log/artica-postfix/squid-logger-start.log 2>&1 &";
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = GETPID();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: nginx-tail, waiting {$i}/5\n";
        }
        sleep(1);
    }
    $pid = GETPID();
    if ($unix->process_exists($pid)) {
        events("nginx-tail success to start daemon PID:{$pid}...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: nginx-tail, success PID:{$pid}\n";
        }
    } else {
        events("nginx-tail failed to start daemon...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: nginx-tail, failed\n";
        }
    }
}
Esempio n. 25
0
function PID_NUM()
{
    $unix = new unix();
    $Masterbin = $unix->find_program("syncthing");
    $pid = $unix->PIDOF_PATTERN("syncthing.*?no-browser");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
}
Esempio n. 26
0
function xtsart()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "TimeFile:{$pidTime}\n";
    }
    $unix = new unix();
    if (!$GLOBALS["VERBOSE"]) {
        if ($unix->file_time_min($pidTime) < 10) {
            die;
        }
        if ($unix->process_exists(@file_get_contents($pidfile, basename(__FILE__)))) {
            if ($GLOBALS["VERBOSE"]) {
                echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n";
            }
            writelogs(basename(__FILE__) . ":Already executed.. aborting the process", basename(__FILE__), __FILE__, __LINE__);
            die;
        }
        @file_put_contents($pidfile, getmypid());
        @unlink($pidTime);
        @file_put_contents($pidTime, time());
    }
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    $time = time();
    $BASEDIR = "/usr/share/artica-postfix";
    $hash_mem = array();
    @chmod("/usr/share/artica-postfix/ressources/mem.pl", 0755);
    $datas = shell_exec(dirname(__FILE__) . "/ressources/mem.pl");
    if (preg_match('#T=([0-9]+) U=([0-9]+)#', $datas, $re)) {
        $ram_used = $re[2];
    }
    $cpuUsage = null;
    $ps = $unix->find_program("ps");
    exec("{$ps} -aux 2>&1", $processes);
    foreach ($processes as $process) {
        $cols = explode(' ', preg_replace('# +#', ' ', $process));
        if (strpos($cols[2], '.') > -1) {
            $cpuUsage += floatval($cols[2]);
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "CPU: {$cpuUsage}, LOAD: {$internal_load}, MEM: {$ram_used}\n";
    }
    $q = new postgres_sql();
    $q->CREATE_TABLES();
    $proxyname = $unix->hostname_g();
    $time = date("Y-m-d H:i:s");
    $sql = "INSERT INTO system (zdate,proxyname,load_avg,mem_stats,cpu_stats)\n\tVALUES('{$time}','{$proxyname}','{$internal_load}','" . intval($ram_used) . "','{$cpuUsage}')";
    if ($GLOBALS["VERBOSE"]) {
        echo $sql . "\n";
    }
    $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
    }
    RXTX();
    if (system_is_overloaded(basename(__FILE__))) {
        $date = time();
        @mkdir("/var/log/artica-postfix/sys_alerts", 0755, true);
        if (!is_file("/var/log/artica-postfix/sys_alerts/{$date}")) {
            $ps = $unix->find_program("ps");
            $nohup = $unix->find_program($nohup);
            $nice = $unix->EXEC_NICE();
            $load = $GLOBALS["SYSTEM_INTERNAL_LOAD"];
            if (!$unix->process_exists($unix->PIDOF_PATTERN("{$ps}"))) {
                $cmd = trim("{$nohup} {$nice} {$ps} auxww >/var/log/artica-postfix/sys_alerts/{$date}-{$load} 2>&1");
                shell_exec($cmd);
            }
        }
    }
}
Esempio n. 27
0
function locales_gen_running()
{
    $unix = new unix();
    $nohup = $unix->find_program("locale-gen");
    $pid = $unix->PIDOF_PATTERN($nohup);
    writelogs_framework("{$nohup} - > {$pid}", __FUNCTION__, __FILE__, __LINE__);
    if (!$unix->process_exists($pid)) {
        return;
    }
    $ARRAY["PID"] = $pid;
    $ARRAY["SINCE"] = $unix->PROCCESS_TIME_MIN($pid);
    echo "<articadatascgi>" . base64_encode(serialize($ARRAY)) . "</articadatascgi>";
}
Esempio n. 28
0
function RestoreFromBackup($backuppath)
{
    $unix = new unix();
    $PidRestore = "/etc/artica-postfix/pids/zarafaRestore.pid";
    $rm = $unix->find_program("rm");
    $pid = $unix->get_pid_from_file($PidRestore);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $pid = $unix->PIDOF_PATTERN("exec.zarafa-db.php --restorefrom");
    if ($pid != getmypid()) {
        if ($unix->process_exists($pid)) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    $mysql = $unix->find_program("mysql");
    $pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa");
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restore Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($PidRestore, getmypid());
    $sock = new sockets();
    $SourceDir = dirname($backuppath);
    $WORKDIR = $sock->GET_INFO("ZarafaDedicateMySQLWorkDir");
    if ($WORKDIR == null) {
        $WORKDIR = "/home/zarafa-db";
    }
    if (is_file("{$SourceDir}/ldap.ldif")) {
        RestoreFromBackup_progress("{restore_ldap_database}", 10);
        RestoreFromBackup_ldap("{$SourceDir}/ldap.ldif");
    }
    $unix = new unix();
    if (!is_file($backuppath)) {
        echo "Action: `{$backuppath}` no such file: ABORT!\n";
        RestoreFromBackup_progress("{failed}", 100);
        return;
    }
    echo "Action: Removing Zarafa Database MySQL client `{$mysql}`....\n";
    RestoreFromBackup_progress("Removing Zarafa Database", 30);
    $cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa --execute=\"DROP DATABASE zarafa\" 2>&1";
    $results = array();
    exec("{$cmd}", $results);
    while (list($num, $ligne) = each($results)) {
        echo "MySQL: (Delete Database) {$ligne}\n";
    }
    RestoreFromBackup_progress("Removing all content", 32);
    if (is_dir("{$WORKDIR}/data/zarafa")) {
        recursive_remove_directory("{$WORKDIR}");
    }
    RestoreFromBackup_progress("Restarting MySQL service (recovery)", 40);
    echo "Action: Restarting MySQL service...\n";
    echo "Action: Stopping MySQL service...\n";
    stop(true);
    echo "Action: Starting MySQL service (InnoDB recovery mode)...\n";
    start(true, true);
    while (list($num, $ligne) = each($results)) {
        echo "Service: {$ligne}\n";
    }
    sleep(5);
    $ZARAFADB_PID = ZARAFADB_PID();
    if (!$unix->process_exists($ZARAFADB_PID)) {
        RestoreFromBackup_progress("Failed to restart dedicated MySQL", 100);
        return;
    }
    RestoreFromBackup_progress("Stopping Zarafa server", 43);
    @unlink("/tmp/zarafa-upgrade-lock");
    shell_exec("/etc/init.d/zarafa-server stop --force");
    $pid = XZARAFA_SERVER_PID();
    if ($unix->process_exists($pid)) {
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    RestoreFromBackup_progress("Restarting MySQL service (normal)", 45);
    echo "Action: Restarting MySQL service...\n";
    echo "Action: Stopping MySQL service...\n";
    stop(true);
    echo "Action: Starting MySQL service (InnoDB normal mode)...\n";
    start(true, false);
    while (list($num, $ligne) = each($results)) {
        echo "Service: {$ligne}\n";
    }
    sleep(2);
    $ZARAFADB_PID = ZARAFADB_PID();
    if (!$unix->process_exists($ZARAFADB_PID)) {
        RestoreFromBackup_progress("Failed to restart dedicated MySQL", 100);
        return;
    }
    if (!$unix->is_socket("/var/run/mysqld/zarafa-db.sock")) {
        echo "Action: /var/run/mysqld/zarafa-db.sock waiting socket\n";
        for ($i = 0; $i < 5; $i++) {
            if ($unix->is_socket("/var/run/mysqld/zarafa-db.sock")) {
                break;
            }
            echo "Action: Waiting zarafa-db.sock {$i}/4\n";
            sleep(1);
        }
    }
    if (!$unix->is_socket("/var/run/mysqld/zarafa-db.sock")) {
        echo "Action: /var/run/mysqld/zarafa-db.sock no such socket\n";
        RestoreFromBackup_progress("zarafa-db.sock no such socket", 100);
        return;
    }
    echo "Action: /var/run/mysqld/zarafa-db.sock OK\n";
    echo "Action: create a freshed Zarafa database\n";
    $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath");
    if ($ZarafaIndexPath == null) {
        $ZarafaIndexPath = "/var/lib/zarafa/index";
    }
    RestoreFromBackup_progress("Cleaning/Stopping Zarafa search DBs", 50);
    if (is_dir($ZarafaIndexPath)) {
        recursive_remove_directory("{$ZarafaIndexPath}");
        shell_exec("/etc/init.d/zarafa-search stop");
    }
    RestoreFromBackup_progress("Create a freshed Zarafa database", 50);
    $results = array();
    $cmd = "{$mysql} --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --execute=\"CREATE DATABASE zarafa\" 2>&1";
    $results = array();
    exec("{$cmd}", $results);
    while (list($num, $ligne) = each($results)) {
        echo "MySQL: (Create Database) {$ligne}\n";
    }
    RestoreFromBackup_progress("Testing Database...", 51);
    if (!is_dir("{$WORKDIR}/data/zarafa")) {
        echo "Action: FAILED TO create a freshed Zarafa database: ABORT!!\n";
        echo "Action: {$WORKDIR}/data/zarafa no such directory\n";
        RestoreFromBackup_progress("FAILED to create a freshed Zarafa database", 100);
        return;
    }
    RestoreFromBackup_progress("Checks Database size", 53);
    databasesize(true);
    $gunzip = $unix->find_program("gunzip");
    $SourceFileBase = basename($backuppath);
    $file_ext = $unix->file_ext($SourceFileBase);
    $tStart = time();
    $nohup = $unix->find_program("nohup");
    $backuppath1 = $unix->shellEscapeChars($backuppath);
    $cmd = "{$nohup} {$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa < {$backuppath1} >/root/mysqllog.txt 2>&1 &";
    echo "Action: {$SourceFileBase} extension {$file_ext}\n";
    echo "Action: Restoring From {$backuppath1}\n";
    if ($file_ext == "gz") {
        echo "Action: Restoring From {$backuppath1} with uncompress..\n";
        $cmd = "{$nohup} {$gunzip} -c {$backuppath1} |{$mysql} --show-warnings --socket=/var/run/mysqld/zarafa-db.sock --protocol=socket --user=root --batch --debug-info --database=zarafa >/root/mysqllog.txt 2>&1 &";
    }
    $size = @filesize($backuppath);
    $size = FormatBytes($size / 1024);
    echo "Action: Please wait, it should take time...\nAction: Do not shutdown the computer or restart the MySQL service!\n";
    $results = array();
    RestoreFromBackup_progress("{restoring_data} {$size} {please_wait} !", 70);
    $lastmd5 = null;
    $continue = true;
    shell_exec($cmd);
    $ALRDLO = array();
    while ($continue) {
        $fileMD5 = @md5_file("/root/mysqllog.txt");
        if ($fileMD5 != $lastmd5) {
            $LOGS = explode("\n", @file_get_contents("/root/mysqllog.txt"));
            while (list($num, $ligne) = each($LOGS)) {
                if (trim($ligne) == null) {
                    continue;
                }
                if (isset($ALRDLO[md5($ligne)])) {
                    continue;
                }
                $ALRDLO[md5($ligne)] = true;
                if (preg_match("#ERROR\\s+([0-9]+)\\s+\\(#", $ligne, $re)) {
                    echo date("Y-m-d H:i:s") . " MySQL: FAILED !!! {$ligne}\n";
                    RestoreFromBackup_progress("{failed} {error} {$re[1]} ", 100);
                    return;
                }
                echo date("Y-m-d H:i:s") . " MySQL: {$ligne}\n";
            }
            $lastmd5 = $fileMD5;
        }
        $pid = $unix->PIDOF_PATTERN("{$mysql}\\s+.*?--socket=/var/run/mysqld/zarafa-db.sock.*?database=zarafa");
        echo "Action: PID: {$pid}\n";
        if (!$unix->process_exists($pid)) {
            echo "Action: injection stopped running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n";
            $continue = false;
            break;
        }
        echo "Action: PID {$pid} running since " . $unix->distanceOfTimeInWords($tStart, time(), true) . ", please wait...\n";
        RestoreFromBackup_progress($unix->distanceOfTimeInWords($tStart, time(), true) . " {please_wait} !", 71);
        $continue = true;
        sleep(30);
        continue;
    }
    echo "Action: Done, took: " . $unix->distanceOfTimeInWords($tStart, time(), true) . "\n";
    echo "Action: Please wait, Checks Database size\n";
    RestoreFromBackup_progress("Checks Database size", 75);
    databasesize(true);
    RestoreFromBackup_progress("{restoring_data} {success}", 80);
    echo "Action: restart_services\n";
    RestoreFromBackup_progress("{restart_services}", 90);
    $unix->THREAD_COMMAND_SET("/etc/init.d/zarafa-server restart");
    echo "Action: Restore task done...\n";
    echo "Action: You can close the windows now...\n";
    RestoreFromBackup_progress("{done}", 100);
    die;
}
Esempio n. 29
0
function PID_NUM()
{
    $unix = new unix();
    $pid = $unix->get_pid_from_file("/var/run/clamav/freshclam.pid");
    if ($unix->process_exists($pid)) {
        return $pid;
    }
    $Masterbin = $unix->find_program("freshclam");
    return $unix->PIDOF_PATTERN("{$Masterbin}.*?--on-update-execute=");
}
Esempio n. 30
0
function start($aspid = false)
{
    $GLOBALS["LOGS"] = array();
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $sock = new sockets();
    $reconfigure = false;
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    $NtpdateAD = $sock->GET_INFO("NtpdateAD");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $SquidPerformance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance"));
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    $InfluxSyslogRemote = intval($sock->GET_INFO("InfluxSyslogRemote"));
    $EnableIntelCeleron = intval($sock->GET_INFO("EnableIntelCeleron"));
    if ($InfluxUseRemote == 0) {
        $InfluxSyslogRemote = 0;
    }
    if (!is_file("/etc/artica-postfix/settings/Daemons/EnableInfluxDB")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableInfluxDB", 1);
    }
    $EnableInfluxDB = intval($sock->GET_INFO("EnableInfluxDB"));
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $SQUIDEnable = 1;
        $InfluxSyslogRemote = 0;
        $SquidPerformance = 0;
        $EnableInfluxDB = 1;
        $GLOBALS["log_path"] = "/var/log/squid/squidtail.log";
    }
    @mkdir(dirname($GLOBALS["log_path"]), 0755, true);
    if (!is_file($GLOBALS["log_path"])) {
        @touch($GLOBALS["log_path"]);
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        @chmod($GLOBALS["log_path"], 0755);
        @chown($GLOBALS["log_path"], "squid");
        @chgrp($GLOBALS["log_path"], "squid");
    }
    $kill = $unix->find_program("kill");
    $enabled = $unix->SQUID_TAIL_ENABLED();
    if ($enabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: service disabled...\n";
        }
        return;
    }
    if (is_file("/etc/artica-postfix/squid.lock")) {
        $time = $unix->file_time_min("/etc/artica-postfix/squid.lock");
        if ($time < 60) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Proxy service is locked (since {$time}Mn...\n";
            }
            return;
        }
        @unlink("/etc/artica-postfix/squid.lock");
    }
    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]: access-tail, Already task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = GETPID();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: access-tail, already running since {$time}Mn\n";
        }
        return;
    }
    $tail = $unix->find_program("tail");
    if (!is_file("/bin/access-tail")) {
        @copy($tail, "/bin/access-tail");
    }
    @chmod("/bin/access-tail", 0755);
    $pid = $unix->PIDOF_PATTERN("/bin/access-tail.*?{$GLOBALS["log_path"]}");
    if ($unix->process_exists($pid)) {
        for ($i = 0; $i < 20; $i++) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: killing old process pid {$pid}\n";
            }
            unix_system_kill_force($pid);
            usleep(800);
            $pid = $unix->PIDOF_PATTERN("/bin/access-tail -F -n 0 {$GLOBALS["log_path"]}");
            if (!$unix->process_exists($pid)) {
                break;
            }
            unix_system_kill_force($pid);
        }
    }
    $cmd = "/bin/access-tail --follow=name --retry --max-unchanged-stats=50 -n 0 {$GLOBALS["log_path"]}|{$GLOBALS["TAIL_STARTUP"]} >>/var/log/artica-postfix/squid-logger-start.log 2>&1 &";
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = GETPID();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: access-tail, waiting {$i}/5\n";
        }
        sleep(1);
    }
    $pid = GETPID();
    if ($unix->process_exists($pid)) {
        events("access-tail success to start daemon PID:{$pid}...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: access-tail, success PID:{$pid}\n";
        }
    } else {
        events("access-tail failed to start daemon...");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: access-tail, failed\n";
        }
    }
}