コード例 #1
0
function start()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $PID = GET_PID();
    if ($unix->process_exists($PID)) {
        squid_admin_mysql(1, "Watchdog says that rsyslog is off, but exists [action=stamp-pid]", null, __FILE__, __LINE__);
        $SrcPid = intval(@file_get_contents("/var/run/rsyslogd.pid"));
        if ($SrcPid != $PID) {
            squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists (PID:{$PID}) [action=stamp-pid]", null, __FILE__, __LINE__);
            @file_put_contents("/var/run/rsyslogd.pid", $PID);
        } else {
            squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists [action=nothing]", null, __FILE__, __LINE__);
        }
        @unlink($pidfile);
        die(1);
    }
    squid_admin_mysql(0, "Syslog daemon is down [action=start]", null, __FILE__, __LINE__);
    system("/etc/init.d/rsyslog start");
    $squid = $unix->LOCATE_SQUID_BIN();
    if (is_file($squid)) {
        sleep(3);
        squid_admin_mysql(1, "Reloading proxy service after starting syslog daemon", null, __FILE__, __LINE__);
        system("{$squid} -f /etc/squid3/squid.conf -k reconfigure");
    }
}
コード例 #2
0
function purge()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtime = "/etc/artica-postfix/pids/exec.suricata.hourly.purge.time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded()) {
        return;
    }
    $timeExec = $unix->file_time_min($pidtime);
    if ($timeExec < 1440) {
        return;
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $q = new postgres_sql();
    $sock = new sockets();
    $SuricataPurge = intval($sock->GET_INFO("SuricataPurge"));
    if ($SuricataPurge == 0) {
        $SuricataPurge = 15;
    }
    $q->QUERY_SQL("DELETE FROM suricata_events WHERE zdate < NOW() - INTERVAL '{$SuricataPurge} days'");
}
コード例 #3
0
ファイル: exec.watchdog.php プロジェクト: rsd/artica-1.5
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"); 
	}

}
コード例 #4
0
ファイル: exec.TextToLdap.php プロジェクト: BillTheBest/1.6.x
function scan_connections()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Artica Task Already running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded()) {
        system_admin_events("Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__);
        return false;
    }
    $q = new mysql();
    $sql = "SELECT * FROM texttoldap";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (mysql_num_rows($results) == 0) {
        return;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        if (!connect($ligne)) {
            continue;
        }
        import($ligne);
        $ID = $ligne["ID"];
    }
}
コード例 #5
0
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"]);
}
コード例 #6
0
function xstart()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = @file_get_contents($pidfile);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$pidtime}\n";
    }
    $unix = new unix();
    $squid = $unix->LOCATE_SQUID_BIN();
    if (!$GLOBALS["FORCE"]) {
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["VERBOSE"]) {
                echo "Already executed pid {$pid} since {$time}mn\n";
            }
            die;
        }
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $timefile = $unix->file_time_min($pidtime);
    if ($GLOBALS["VERBOSE"]) {
        echo "Timelock:{$pidtime} {$timefile} Mn\n";
    }
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < 5) {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$timefile}mn require 5mn\n";
            }
            return;
        }
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    if (!is_file("/home/ufdb/smtp-events/ACCESS_LOG")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "/home/ufdb/smtp-events/ACCESS_LOG no such file\n";
        }
    }
    $array = explode("\n", @file_get_contents("/home/ufdb/smtp-events/ACCESS_LOG"));
    @unlink("/home/ufdb/smtp-events/ACCESS_LOG");
    $body = array();
    $mmstp = new ufdb_msmtp();
    $Subject = count($array) . " Web filtering blocked event(s)";
    $body[] = "Return-Path: <{$mmstp->smtp_sender}>";
    $body[] = "Date: " . date("D, d M Y H:i:s") . " +0100 (CET)";
    $body[] = "From: {$mmstp->smtp_sender}";
    $body[] = "Subject: {$Subject}";
    $body[] = "To: {$mmstp->recipient}";
    $body[] = "";
    $body[] = "";
    $body[] = @implode("\r\n", $array);
    $body[] = "";
    $body[] = "";
    $finalbody = @implode("\r\n", $body);
    if (!$mmstp->Send($finalbody)) {
        squid_admin_mysql(0, "Unable to send notification {$Subject} to {$mmstp->recipient}", "{$Subject} to {$mmstp->recipient}\n------------------\n" . @implode("\n", $array) . "\n\t\tThe following error encountered\n" . $mmstp->logs . "\n", __FILE__, __LINE__);
    }
}
コード例 #7
0
function xstart()
{
    $unix = new unix();
    $sock = new sockets();
    $GLOBALS["CLASS_SOCKETS"] = $sock;
    $FORCED_TEXT = null;
    $NOTIFY = false;
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS_FULL.db";
    $pid = $unix->get_pid_from_file($pidfile);
    $GLOBALS["CLASS_UNIX"] = $unix;
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Already executed\n";
        return;
    }
    if (!$GLOBALS["FORCE"]) {
        if ($unix->file_time_min($pidTime) < 30) {
            return;
        }
    }
    $GLOBALS["MAIN_ARRAY"] = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS.db"));
    ArticaWebFilter();
    ArticaUfdb();
    @mkdir("/usr/share/artica-postfix/ressources/logs", 0755, true);
    @unlink($pidTime);
    @file_put_contents($pidTime, serialize($GLOBALS["MAIN_ARRAY"]));
    if ($GLOBALS["VERBOSE"]) {
        echo "Saving {$pidTime}\n";
    }
    @chmod($pidTime, 0755);
}
コード例 #8
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();
}
コード例 #9
0
function compile_destination($cacheid)
{
    $unix = new unix();
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".compile_destination." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (!is_numeric($cacheid)) {
        build_progress("Error Destination ID is not set", 110);
        return;
    }
    if ($cacheid == 0) {
        build_progress("Error Destination ID is Zero", 110);
        return;
    }
    $q = new mysql_squid_builder();
    $sql = "SELECT servername FROM reverse_www WHERE cache_peer_id={$cacheid}";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        build_progress("Error MySQL error", 110);
        echo $q->mysql_error;
        return;
    }
    $count = mysql_num_rows($results);
    if ($count == 0) {
        echo "{$sql}\n";
        build_progress("Error no destination for ID {$cacheid}", 110);
        return;
    }
    build_progress("{$count} Destination(s)", 5);
    $c = 0;
    $php = $unix->LOCATE_PHP5_BIN();
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $c++;
        $prc = $c / $count;
        $prc = $prc * 100;
        if ($prc > 90) {
            $prc = 90;
        }
        $servername = $ligne["servername"];
        build_progress("{reconfigure} {$servername}", $prc);
        system("{$php} /usr/share/artica-postfix/exec.nginx.single.php {$servername} --no-reload --output --no-buildmain");
    }
    build_progress("{cleaning_old_configs}...", 91);
    system("{$php} /usr/share/artica-postfix/exec.nginx.wizard.php --check-http");
    build_progress("{building_main_settings}", 95);
    system("{$php} /usr/share/artica-postfix/exec.nginx.php --main");
    build_progress("{$ligne["servername"]}: {reloading_reverse_proxy} ", 96);
    system("/etc/init.d/nginx reload --force");
    build_progress("{$ligne["servername"]}: {reloading_reverse_proxy}  {done}", 100);
}
コード例 #10
0
function install_key($keyfile)
{
    $path = "/usr/share/artica-postfix/ressources/conf/upload/{$keyfile}";
    $license_bin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager";
    $time = time();
    $unix = new unix();
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) {
            progress("{failed} Already running", 110);
            echo "Already runinng PID {$pid}\n";
            return;
        }
    }
    echo "License....: {$path}\n";
    echo "Binary File: {$license_bin}\n";
    if (!is_file($path)) {
        echo "{$path} No such file..\n";
        progress("{failed} {$keyfile} No such file", 110);
        die;
    }
    if (!is_file($license_bin)) {
        echo "{$path} No such file..\n";
        progress("{failed} " . basename($license_bin) . " No such binary", 110);
        @unlink($path);
        die;
    }
    $sock = new sockets();
    $nohup = $unix->find_program("nohup");
    $sock->SET_INFO("kavicapserverEnabled", 1);
    @unlink("/etc/artica-postfix/kav4proxy-licensemanager");
    @unlink("/etc/artica-postfix/kav4proxy-licensemanager-i");
    progress("{removing_old_licenses}", 20);
    system("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -d a");
    progress("{installing} {$keyfile}", 30);
    $cmd = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -c /etc/opt/kaspersky/kav4proxy.conf -a {$path}";
    system($cmd);
    @unlink($path);
    progress("{analyze_license} {$keyfile}", 50);
    shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i 2>&1");
    progress("{stopping_service}", 60);
    echo "/etc/init.d/kav4proxy stop\n";
    system("/etc/init.d/kav4proxy stop");
    progress("{starting_service}", 60);
    echo "/etc/init.d/kav4proxy start\n";
    system("{$nohup} /etc/init.d/kav4proxy start >/dev/null 2>&1 &");
    system("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &");
    progress("{launch_updates}", 70);
    $nohup = $unix->find_program("nohup");
    $php = $unix - LOCATE_PHP5_BIN();
    sleep(2);
    progress("{launch_updates}", 80);
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.keepup2date.php --update --force >/dev/null 2>&1 &");
    sleep(3);
    progress("{success}", 100);
}
コード例 #11
0
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);
}
コード例 #12
0
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");
    }
}
コード例 #13
0
ファイル: exec.myisamchk.php プロジェクト: BillTheBest/1.6.x
function start($database, $table)
{
    $unix = new unix();
    if ($database == null) {
        WriteIsamLogs("Requested myismamchk database:{$database}, table: {$table} -> database is null");
        return;
    }
    if ($table == null) {
        WriteIsamLogs("Requested myismamchk database:{$database}, table: {$table} -> table is null");
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . md5("{$database}{$table}") . ".pid";
    $pid = @file_get_contents("{$database}{$table}");
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        WriteIsamLogs("Already PID {$pid} running since {$timepid}mn, aborting");
        return;
    }
    @file_put_contents($pidfile, getmypid());
    WriteIsamLogs("Requested myismamchk database:{$database}, table: {$table}");
    $pgrep = $unix->find_program("pgrep");
    $myisamchk = $unix->find_program("myisamchk");
    $touch = $unix->find_program("touch");
    $myisamchk = $unix->find_program("myisamchk");
    $pgrep = $unix->find_program("pgrep");
    exec("{$pgrep} -l -f \"{$myisamchk}.*?{$table}\"", $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (preg_match("#^[0-9]+\\s+#", $line)) {
            writelogs("{$line} already executed", @implode("\r\n", $results), __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    $MYSQL_DATADIR = $unix->MYSQL_DATADIR();
    if (!is_file("{$MYSQL_DATADIR}/{$database}/{$table}.MYD")) {
        WriteIsamLogs("unable to stat {$MYSQL_DATADIR}/{$database}/{$table}.MYD");
        return;
    }
    if (!is_file("{$MYSQL_DATADIR}/{$database}/{$table}.MYI")) {
        WriteIsamLogs("{$MYSQL_DATADIR}/{$database}/{$table}.MYI no such file");
        return;
    }
    $results = array();
    WriteIsamLogs("{$myisamchk} --safe-recover --backup {$MYSQL_DATADIR}/{$database}/{$table}.MYI");
    exec("{$myisamchk} --safe-recover --backup {$MYSQL_DATADIR}/{$database}/{$table}.MYI 2>&1", $results);
    while (list($index, $line) = each($results)) {
        WriteIsamLogs("{$line}");
    }
}
コード例 #14
0
function Get_owncloud()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time";
    $pid = @file_get_contents($pidfile);
    $unix = new unix();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid} since {$time}mn\n";
        }
        die;
    }
    $uri = download();
    if ($uri == null) {
        return;
    }
    $curl = new ccurl($uri);
    $curl->NoHTTP_POST = true;
    $cp = $unix->find_program("cp");
    $rm = $unix->find_program("rm");
    progress("Downloading Owncloud package...", 25);
    if (!$curl->GetFile("/root/owncloud.tar.gz")) {
        progress("Failed download owncloud package", 110);
        return;
    }
    if (is_dir("/usr/share/owncloud")) {
        shell_exec("{$rm} -rf /usr/share/owncloud");
    }
    @mkdir("/usr/share/owncloud", 0755, true);
    if (!is_dir("/usr/share/owncloud")) {
        progress("/usr/share/owncloud permission denied", 110);
        @unlink("/root/owncloud.tar.gz");
        return;
    }
    $tar = $unix->find_program("tar");
    progress("Extracting package...", 35);
    shell_exec("{$tar} xf /root/owncloud.tar.gz -C /usr/share/owncloud/");
    @unlink("/root/owncloud.tar.gz");
    if (is_dir("/usr/share/owncloud/owncloud")) {
        shell_exec("{$cp} -rf /usr/share/owncloud/owncloud/* /usr/share/owncloud/");
        shell_exec("{$rm} -rf /usr/share/owncloud/owncloud");
    }
    if (is_file("/usr/share/owncloud/settings/settings.php")) {
        progress("Success...", 100);
        $unix->Process1(true);
        return;
    }
    progress("Failed...", 110);
}
コード例 #15
0
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}");
    }
}
コード例 #16
0
function postfix_hours()
{
    $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 ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        system_admin_events("Already PID {$pid} running since {$timepid}mn", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    if (!$GLOBALS["VERBOSE"]) {
        $timeexec = $unix->file_time_min($timefile);
        if ($timeexec < 60) {
            return;
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $GLOBALS["Q"] = new mysql_postfix_builder();
    $LIST_HOUR_TABLES = $GLOBALS["Q"]->LIST_HOUR_TABLES();
    if (count($LIST_HOUR_TABLES) == 0) {
        return;
    }
    $currentHourTable = date("YmdH") . "_hour";
    $MyTime = time();
    while (list($tablesource, $time) = each($LIST_HOUR_TABLES)) {
        if ($currentHourTable == $tablesource) {
            continue;
        }
        $xtime = strtotime($time);
        if ($xtime > $MyTime) {
            $GLOBALS["Q"]->QUERY_SQL("DROP TABLE `{$tablesource}`");
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "{$tablesource}\t{$time}\n";
        }
        if (_parse_hour_table($tablesource, $xtime)) {
            $GLOBALS["Q"]->DUMP_TABLE($tablesource);
            $GLOBALS["Q"]->QUERY_SQL("DROP TABLE `{$tablesource}`");
        } else {
            if ($GLOBALS["VERBOSE"]) {
                echo "{$tablesource}\t{$time} FAILED\n";
            }
        }
    }
}
コード例 #17
0
function parseQueue()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    $sock = new sockets();
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $pidTime = $unix->PROCCESS_TIME_MIN($pid);
        events("Already process PID: {$pid} running since {$pidTime} minutes", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    @file_put_contents($pidfile, getmypid());
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
        return;
    }
    $EnableArticaSMTPStatistics = $sock->GET_INFO("EnableArticaSMTPStatistics");
    if (!is_numeric($EnableArticaSMTPStatistics)) {
        $EnableArticaSMTPStatistics = 0;
    }
    $directory = "/var/log/artica-mail";
    if (!is_dir($directory)) {
        return;
    }
    if (!($handle = @opendir($directory))) {
        return;
    }
    $q = new mysql_postfix_builder();
    $q->CheckTables();
    events("open {$directory}");
    while (false !== ($filename = readdir($handle))) {
        if ($EnableArticaSMTPStatistics == 0) {
            @unlink("{$directory}/{$filename}");
            continue;
        }
        if (!preg_match("#(.+?)\\.[0-9]+\\.aws#", $filename, $re)) {
            continue;
        }
        $instancename = $re[1];
        ParseFile("{$directory}/{$filename}");
        if (system_is_overloaded(basename(__FILE__))) {
            system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats");
            return;
        }
    }
}
コード例 #18
0
ファイル: exec.sysctl.php プロジェクト: BillTheBest/1.6.x
function restart()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    stop(true);
    build();
    sleep(1);
    start(true);
}
コード例 #19
0
ファイル: offlineimap.php プロジェクト: BillTheBest/1.6.x
function run_backup_exec()
{
    $unix = new unix();
    $md5 = $_GET["md5"];
    $pidfile = "/var/run/offlineimap-{$md5}.pid";
    if (!is_file($pidfile)) {
        writelogs_framework("{$pidfile} -> no such file", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    $pid = @file_get_contents($pidfile);
    writelogs_framework("{$pidfile} -> {$pid}", __FUNCTION__, __FILE__, __LINE__);
    if ($unix->process_exists($pid)) {
        $timemin = $unix->PROCCESS_TIME_MIN($pid);
        echo "<articadatascgi>{$timemin}</articadatascgi>";
        return;
    }
    writelogs_framework("{$pidfile} -> FALSE", __FUNCTION__, __FILE__, __LINE__);
}
コード例 #20
0
function parse_days()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if (!$GLOBALS["VERBOSE"]) {
        if ($unix->file_time_min($pidTime) < 1440) {
            return;
        }
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $sock = new sockets();
    $EnableNginxStats = $sock->GET_INFO("EnableNginxStats");
    if (!is_numeric($EnableNginxStats)) {
        $EnableNginxStats = 0;
    }
    if ($EnableNginxStats == 0) {
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]} aborting", __FUNCTION__, __LINE__);
        return;
    }
    $FALSES["information_schema"] = true;
    $FALSES["mysql"] = true;
    $q = new nginx_stats();
    $DATABASE_LIST_SIMPLE = $q->DATABASE_LIST_SIMPLE();
    while (list($db, $b) = each($DATABASE_LIST_SIMPLE)) {
        if (isset($FALSES[$db])) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Parsing database {$db}\n";
        }
        parse_database($db);
    }
}
コード例 #21
0
function purge_bysquid()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if ($pid < 100) {
        $pid = null;
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        ufdbguard_admin_events("Already executed pid {$pid} since {$timepid}", __FUNCTION__, __FILE__, __LINE__, "purge");
        if ($GLOBALS["VERBOSE"]) {
            echo "Already executed pid {$pid}\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $sock = new sockets();
    $users = new usersMenus();
    $rm = $unix->find_program("rm");
    $df = $unix->find_program("df");
    $DF_RESULTS[] = "Scanning Artica directories in /var/log\ncurrent status:";
    exec("{$df} -i /var/log 2>&1", $DF_RESULTS);
    $DF_RESULTS[] = "";
    exec("{$df} -h /var/log 2>&1", $DF_RESULTS);
    $dirs = $unix->DirFiles("/var/log/artica-postfix");
    while (list($directory, $b) = each($dirs)) {
        $DF_RESULTS[] = "";
        $DF_RESULTS[] = "";
        $DF_RESULTS[] = date("Y-m-d H:i:s") . " Removing content of {$directory}";
        $DF_RESULTS[] = date("Y-m-d H:i:s") . " {$directory} Before:";
        $DF_RESULTS[] = "";
        exec("{$df} -i {$directory} 2>&1", $DF_RESULTS);
        $DF_RESULTS[] = "";
        exec("{$df} -h {$directory} 2>&1", $DF_RESULTS);
        shell_exec("{$rm} -rf {$directory}/* 2>&1");
        $DF_RESULTS[] = date("Y-m-d H:i:s") . " {$directory} After removing content:";
        exec("{$df} -i {$directory} 2>&1", $DF_RESULTS);
        $DF_RESULTS[] = "";
        exec("{$df} -h {$directory} 2>&1", $DF_RESULTS);
        $DF_RESULTS[] = "";
    }
    squid_admin_mysql(0, "Log partition cleaning report", @implode("\n", $DF_RESULTS) . __FILE__, __LINE__);
}
コード例 #22
0
ファイル: exec.loadavg.php プロジェクト: BillTheBest/1.6.x
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();
}
コード例 #23
0
ファイル: exec.pflogsumm.php プロジェクト: BillTheBest/1.6.x
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();
}
コード例 #24
0
ファイル: exec.nginx.php プロジェクト: BillTheBest/1.6.x
function parse_memory()
{
    $unix = new unix();
    $nginx = $unix->find_program("nginx");
    $sock = new sockets();
    $nginx = $unix->find_program("nginx");
    if (!is_file($nginx)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, not installed\n";
        }
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pidStampReload = $GLOBALS["pidStampReload"];
    if (!$GLOBALS["VERBOSE"]) {
        echo "{$pidtime}\n";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        $TimExec = $unix->file_time_min($pidtime);
        if ($TimExec < 5) {
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $python = $unix->find_program("python");
    $nice = $unix->EXEC_NICE();
    exec("{$nice}{$python} /usr/share/artica-postfix/bin/ps_mem.py 2>&1", $results);
    $FOUND = false;
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (!preg_match("#^[0-9\\.]+.*?=\\s+([0-9\\.]+)\\s+(.+?)\\s+nginx#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Not found \"{$line}\"\n";
            }
            continue;
        }
        $memoryValue = $re[1];
        $unit = trim(strtolower($re[2]));
        echo "Found {$memoryValue} {$unit}\n";
        if ($unit == "kib") {
            $memoryValue = $memoryValue / 1048.576;
        }
        if ($unit == "mib") {
            $memoryValue = $memoryValue * 1.048576;
        }
        if ($unit == "gib") {
            $memoryValue = $memoryValue * 1048.576;
        }
        $FOUND = true;
        break;
    }
    if (!$FOUND) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Not found...\n";
        }
        return;
    }
    $memoryValue = round($memoryValue, 2);
    $MaxMemory = max_memory();
    $MaxMemoryReload = $MaxMemory / 2;
    $memoryValueInt = intval($memoryValue);
    echo "Nginx = {$memoryValue} MB  INT({$memoryValueInt}) Reload on:{$MaxMemoryReload}MB; Restart on:{$MaxMemory}MB\n";
    $ACTION_DONE = false;
    if ($MaxMemory > 0) {
        if ($memoryValueInt > 0) {
            if ($memoryValueInt > $MaxMemoryReload) {
                $StampTime = $unix->file_time_min($pidStampReload);
                if ($StampTime > 20) {
                    squid_admin_mysql(1, "Reverse proxy reach medium memory {$memoryValueInt}MB Reload:{$MaxMemoryReload}MB [action=reload]", "The service will be restarted");
                    reload(true);
                    @unlink($pidStampReload);
                    @file_put_contents($pidStampReload, time());
                    $ACTION_DONE = true;
                }
            }
            if (!$ACTION_DONE) {
                if ($memoryValueInt > $MaxMemory) {
                    squid_admin_mysql(0, "Reverse proxy reach max memory allowed {$memoryValueInt}MB MAX:{$MaxMemory}MB [action=restart]", "The service will be restarted");
                    stop(true);
                    start(true);
                    @unlink($pidStampReload);
                }
            }
        }
    }
    add_memory_value($memoryValue);
}
コード例 #25
0
function dhcpd_leases_script()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "<articadatascgi>" . base64_encode(serialize(array($pid, $time))) . "</articadatascgi>";
    }
}
コード例 #26
0
ファイル: exec.arpscan.php プロジェクト: brucewu16899/1.6.x
function scanarp()
{
    $GLOBALS["CLASS_USERS"] = new usersMenus();
    $GLOBALS["CLASS_SOCKETS"] = new sockets();
    if (!$GLOBALS["CLASS_USERS"]->ARPD_INSTALLED) {
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . " ARPD_INSTALLED = FALSE\n";
        }
        return;
    }
    $EnableArpDaemon = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableArpDaemon");
    if (!is_numeric($EnableArpDaemon)) {
        $EnableArpDaemon = 1;
    }
    if ($EnableArpDaemon == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . " EnableArpDaemon = {$EnableArpDaemon}\n";
        }
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " {$pid} --> Already executed.. aborting the process\n";
        }
        $time = $unix->PROCCESS_TIME_MIN($pid);
        system_admin_events("Already executed pid {$pid} since {$time}Mn.. aborting the process", __FUNCTION__, __FILE__, __LINE__, "system");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    if (!is_file("/var/lib/arpd/arpd.db")) {
        die;
    }
    $GLOBALS["CLASS_UNIX"] = $unix;
    $GLOBALS["nmblookup"] = $unix->find_program("nmblookup");
    $GLOBALS["arpd"] = $unix->find_program("arpd");
    $GLOBALS["arp"] = $unix->find_program("arp");
    $GLOBALS["ARP_DB"] = "/var/lib/arpd/arpd.db";
    $GLOBALS["CACHE_DB"] = "/etc/artica-postfix/arpd.cache";
    $GLOBALS["EnableMacAddressFilter"] = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableMacAddressFilter"));
    if (!is_numeric($GLOBALS["EnableMacAddressFilter"])) {
        $GLOBALS["EnableMacAddressFilter"] = 1;
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (is_file($squidbin)) {
        if ($GLOBALS["EnableMacAddressFilter"] == 0) {
            return;
        }
    }
    $ArpdArray = unserialize(base64_decode(@file_get_contents($GLOBALS["CACHE_DB"])));
    if ($GLOBALS["FLUSH"]) {
        $ArpdArray = array();
    }
    if (!is_array($ArpdArray)) {
        $ArpdArray = array();
    }
    if (!isset($ArpdArray["LAST"])) {
        $ArpdArray["LAST"] = 0;
    }
    $last_modified = filemtime($GLOBALS["ARP_DB"]);
    $TimeArpd = $ArpdArray["LAST"];
    if ($TimeArpd == $last_modified) {
        events("{$TimeArpd} -> {$last_modified} No modification time", __FUNCTION__, __LINE__);
        return;
    }
    events("Scanning ARP table....", __FUNCTION__, __LINE__);
    $ArpdArray["LAST"] = $last_modified;
    exec("{$GLOBALS["arpd"]} -l 2>&1", $results);
    events("{$GLOBALS["arpd"]} -l return " . count($results) . " element(s)", __FUNCTION__, __LINE__);
    while (list($num, $ligne) = each($results)) {
        if (preg_match("#unexpected file type or format#", $ligne)) {
            @unlink($GLOBALS["ARP_DB"]);
            @unlink($GLOBALS["CACHE_DB"]);
            shell_exec("/etc/init.d/arpd restart");
            die;
        }
        if (!preg_match("#^[0-9]+\\s+\\s+(.+?)\\s+(.+)#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "line: {$num}, unexpected line..\n";
            }
            continue;
        }
        if (preg_match("#FAILED:#", $re[2])) {
            continue;
        }
        $mac = $re[2];
        $ipaddr = $re[1];
        if ($GLOBALS["VERBOSE"]) {
            echo "line: {$num}, MAC:{$mac} -> {$ipaddr}\n";
        }
        if (isset($ArpdArray["MACS"][$mac])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "MAC:{$mac} Already cached, aborting....\n";
            }
            continue;
        }
        $ArpdArray["MACS"][$mac] = true;
        $cmp = new computers();
        $uid = $cmp->ComputerIDFromMAC($mac);
        if ($GLOBALS["VERBOSE"]) {
            echo "line: {$num}, MAC:{$mac} -> {$uid}\n";
        }
        if ($uid == null) {
            $res2 = array();
            $computer_name = null;
            events("It is time to add {$mac}/{$ipaddr} in database", __FUNCTION__, __LINE__);
            exec("{$GLOBALS["arp"]} -a {$ipaddr} 2>&1", $res2);
            if (preg_match("#^(.+?)\\s+\\(#", trim(@implode("", $res2)), $rz)) {
                $computer_name = $rz[1];
            }
            if (strlen($computer_name) < 3) {
                $computer_name = $ipaddr;
            }
            $cmp->uid = "{$computer_name}\$";
            $cmp->ComputerIP = $ipaddr;
            $cmp->ComputerMacAddress = $mac;
            system_admin_events("adding/editing {$computer_name} with MAC:{$mac}", __FUNCTION__, __FILE__, __LINE__, "network");
            $cmp->Add();
        } else {
            if ($GLOBALS["FLUSH"]) {
                $res2 = array();
                $cmp = new computers($uid);
                $computer_name = null;
                events("It is time to edit {$uid}/{$mac}/{$ipaddr} in database", __FUNCTION__, __LINE__);
                exec("{$GLOBALS["arp"]} -a {$ipaddr} 2>&1", $res2);
                if ($GLOBALS["VERBOSE"]) {
                    echo "{$GLOBALS["arp"]} -a {$ipaddr} 2>&1 = >" . trim(@implode("", $res2));
                }
                if (preg_match("#^(.+?)\\s+\\(#", trim(@implode("", $res2)), $rz)) {
                    $computer_name = $rz[1];
                } else {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Unable to find computer name\n";
                    }
                }
                if (strlen($computer_name) < 3) {
                    $computer_name = $ipaddr;
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "line: {$num}, UID:{$mac} -> {$uid}\n";
                }
                if ($GLOBALS["VERBOSE"]) {
                    echo "line: {$num}, NAME:{$computer_name} -> {$uid}\n";
                }
                system_admin_events("adding/editing {$computer_name} with MAC:{$mac}", __FUNCTION__, __FILE__, __LINE__, "network");
                $cmp->ComputerIP = $ipaddr;
                $cmp->ComputerMacAddress = $mac;
                $cmp->Add();
            }
        }
        if (system_is_overloaded(basename(__FILE__))) {
            @file_put_contents($GLOBALS["CACHE_DB"], base64_encode(serialize($ArpdArray)));
            system_admin_events("Overloaded system, aborting the task...", __FUNCTION__, __FILE__, __LINE__, "network");
            return;
        }
        @file_put_contents($GLOBALS["CACHE_DB"], base64_encode(serialize($ArpdArray)));
        $nice = EXEC_NICE();
        $unix = new unix();
        $nohup = $unix->find_program("nohup");
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$nice} {$php5} " . __FILE__ . " --tomysql schedule-id={$GLOBALS["SCHEDULE_ID"]} >/dev/null 2>&1 &");
    }
}
コード例 #27
0
function logrotatelogs($nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    if ($nopid) {
        $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidpath);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            system_admin_events(basename(__FILE__) . ":: " . __FUNCTION__ . " Already process {$pid} running since {$pidtime} Mn.. Aborting", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        @file_put_contents($pidpath, getmypid());
    }
    $echo = $unix->find_program("echo");
    $LogsRotateDeleteSize = $sock->GET_INFO("LogsRotateDeleteSize");
    if (!is_numeric($LogsRotateDeleteSize)) {
        $LogsRotateDeleteSize = 5000;
    }
    include_once dirname(__FILE__) . "/ressources/class.mysql.syslog.inc";
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . " line:" . __LINE__ . "\n";
    }
    $q = new mysql_syslog();
    if ($q->COUNT_ROWS("logrotate") == 0) {
        $q->CheckDefaults();
    }
    $sql = "SELECT RotateFiles FROM logrotate WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        echo $q->mysql_error;
    }
    while ($ligne = mysql_fetch_assoc($results)) {
        $filepath = $ligne["RotateFiles"];
        if (strpos($filepath, "*") > 0) {
            if ($GLOBALS["VERBOSE"]) {
                echo __FUNCTION__ . ":: Scanning {$filepath} line:" . __LINE__ . "\n";
            }
            foreach (glob($filepath) as $filename) {
                $size = $unix->file_size($filename);
                $size = $size / 1024;
                $size = round($size / 1000, 2);
                $ARRAY[$filename] = $size;
            }
        } else {
            if (is_file($filepath)) {
                $size = $unix->file_size($filepath);
                $size = $size / 1024;
                $size = round($size / 1000, 2);
                $ARRAY[$filepath] = $size;
            }
            if (is_dir($filepath)) {
                while (list($num, $filename) = each($f)) {
                    $filepath = "/var/log/{$filename}";
                    $f = $unix->DirFiles("{$filepath}");
                    $size = $unix->file_size($filepath);
                    $size = $size / 1024;
                    $size = round($size / 1000, 2);
                    $ARRAY[$filepath] = $size;
                }
            }
        }
    }
    $f = $unix->DirFiles("/var/log");
    while (list($num, $filename) = each($f)) {
        $filepath = "/var/log/{$filename}";
        $size = $unix->file_size($filepath);
        $size = $size / 1024;
        $size = round($size / 1000, 2);
        $ARRAY[$filepath] = $size;
    }
    $f = $unix->DirFiles("/var/log/artica-postfix");
    while (list($num, $filename) = each($f)) {
        $filepath = "/var/log/artica-postfix/{$filename}";
        $size = $unix->file_size($filepath);
        $size = $size / 1024;
        $size = round($size / 1000, 2);
        $ARRAY[$filepath] = $size;
    }
    $restart = false;
    while (list($filepath, $sizeM) = each($ARRAY)) {
        if ($sizeM > $LogsRotateDeleteSize) {
            shell_exec("{$echo} \"\" >{$filepath}");
            $restart = true;
            $unix->send_email_events("{$filepath} was cleaned ({$sizeM}M)", "It exceed maximal size {$LogsRotateDeleteSize}M", "system");
        }
    }
    if ($restart) {
        shell_exec("/etc/init.d/syslog restart");
        shell_exec("/etc/init.d/artica-syslog restart");
        shell_exec("/etc/init.d/auth-tail restart");
        shell_exec("/etc/init.d/postfix-logger restart");
    }
}
コード例 #28
0
ファイル: exec.freshclam.php プロジェクト: articatech/artica
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";
        }
        return;
    }
    $pid = PID_NUM();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $kill = $unix->find_program("kill");
    $chmod = $unix->find_program("chmod");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n";
    }
    unix_system_kill($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);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n";
        }
        return;
    }
    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";
        }
        return;
    }
}
コード例 #29
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";
        }
    }
}
コード例 #30
0
ファイル: services.php プロジェクト: brucewu16899/1.6.x
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>";
}