function start()
{
    $unix = new unix();
    $unix->ToSyslog("[START_STOP]: Server is started...");
    squid_admin_mysql(0, "Server is is started!", "This a notification that notice a system start procedure on the server", __FILE__, __LINE__);
    $sock = new sockets();
    system_admin_mysql(0, "Server is started!", "This a notification that notice a system start procedure on the server", __FILE__, __LINE__);
}
示例#2
0
function reload_hosts()
{
    $unix = new unix();
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $unix->ToSyslog("Artica Framework: Order framework to reload service");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.dnsmasq.php --restart");
}
示例#3
0
function reload_hosts()
{
    $unix = new unix();
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $unix->ToSyslog("Artica Framework: Order framework to reload service");
    shell_exec("{$nohup} /etc/init.d/dnsmasq restart >/dev/null 2>&1 &");
}
示例#4
0
function xtart()
{
    if (!isset($GLOBALS["ARTICALOGDIR"])) {
        $GLOBALS["ARTICALOGDIR"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaLogDir");
        if ($GLOBALS["ARTICALOGDIR"] == null) {
            $GLOBALS["ARTICALOGDIR"] = "/var/log/artica-postfix";
        }
    }
    $unix = new unix();
    $binfile = "/usr/share/artica-postfix/bin/seeker";
    if (!is_file($binfile)) {
        build_progress("{failed}", 110);
        events("Unable to stat {$binfile}");
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/exec.seeker.php.xtart.time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        events("Already process executed pid {$pid}");
        return;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        events("Overloaded system, schedule it later", __LINE__);
        $unix->THREAD_COMMAND_SET("{$php} " . __FILE__);
        build_progress("{failed} Overloaded", 110);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $timefile = $unix->file_time_min($pidTime);
    $DisksBenchs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisksBenchs"));
    $DisksBenchs = $DisksBenchs * 60;
    if (!$GLOBALS["FORCE"]) {
        if ($timefile < $DisksBenchs) {
            events("{$timefile}mn, require at least {$DisksBenchs}mn", __LINE__);
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    build_progress("{scanning} {disks}", 10);
    $fdisk = $unix->find_program("fdisk");
    exec("{$fdisk} -l 2>&1", $results);
    $DISKS = array();
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#^(Disque|Disk)\\s+\\/([a-zA-Z0-9\\-\\_\\/\\.]+).*?:\\s+[0-9]+.*?(bytes|octets)#", $line, $re)) {
            $DISKS["/" . $re[2]] = true;
        }
    }
    if (count($DISKS) == 0) {
        build_progress("{scanning} {disks} {failed}", 110);
        events("Unable to detect disks");
        $unix->ToSyslog("Unable to detect disks");
        system_admin_events("Unable to detect disks\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "system");
        return;
    }
    $RUN = false;
    while (list($disk, $line) = each($DISKS)) {
        $results = array();
        @chmod("{$binfile}", 0755);
        $cmd = "{$binfile} \"" . trim($disk) . "\" 2>&1";
        build_progress("{scanning} {$disk}", 60);
        events("{$cmd}");
        exec($cmd, $results);
        while (list($index, $line) = each($results)) {
            $line = trim($line);
            echo "***: {$line}\n";
            $md5 = md5("{$disk}" . time());
            if ($line == null) {
                continue;
            }
            if (!preg_match("#^Results:\\s+([0-9]+)\\s+seeks.*?,\\s+([0-9\\.]+)\\s+ms#", $line, $re)) {
                continue;
            }
            $seeks = $re[1];
            $ms = $re[2];
            events("{$disk} {$seeks} seeks, {$ms} ms", __LINE__);
            $array = array();
            @mkdir("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue", 0755, true);
            $array["SEEKS"] = $seeks;
            $array["DISK"] = $disk;
            $array["MS"] = $ms;
            $array["time"] = time();
            $unix->ToSyslog("Bench disk {$disk} {$ms} ms for {$seeks} seeks");
            events("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", __LINE__);
            @file_put_contents("{$GLOBALS["ARTICALOGDIR"]}/seeker-queue/{$md5}.ay", serialize($array));
            $RUN = true;
            break;
        }
    }
    if ($RUN) {
        $php = $unix->LOCATE_PHP5_BIN();
        $nohup = $unix->find_program("nohup");
        build_progress("{analyze}", 90);
        $cmd = "{$php} " . dirname(__FILE__) . "/exec.syslog-engine.php --seeker";
        events($cmd);
        system($cmd);
    }
    build_progress("{done}", 100);
}
示例#5
0
function SERVICE_STOP($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $socket = "/var/run/mysqld/mysqld.sock";
    $mysqlbin = $unix->LOCATE_mysqld_bin();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $mysqladmin = $unix->find_program("mysqladmin");
    $kill = $unix->find_program("kill");
    $pgrep = $unix->find_program("pgrep");
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    $kill = $unix->find_program("kill");
    if (!$aspid) {
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Stopping MySQL...............: This script is already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 5) {
                if (!$GLOBALS["FORCE"]) {
                    return;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($GLOBALS["VERBOSE"]) {
        echo "DEBUG:: PID RETURNED {$pid}\n";
    }
    $unix->ToSyslog("MySQL: Stopping MySQL server");
    if (!$unix->process_exists($pid, $mysqlbin)) {
        echo "Stopping MySQL...............: Already stopped\n";
        return;
    }
    $q = new mysql();
    $q2 = new mysql_squid_builder();
    $q2->MEMORY_TABLES_DUMP();
    if (is_file($mysqladmin)) {
        if (is_file($socket)) {
            $cmds[] = "nohup";
            $cmds[] = $mysqladmin;
            $cmds[] = "--user={$q->mysql_admin}";
            if ($q->mysql_password != null) {
                $password = $q->mysql_password;
                $password = $unix->shellEscapeChars($password);
                $cmds[] = "--password={$password}";
            }
            $cmds[] = "--socket={$socket}";
            $cmds[] = "shutdown";
            $cmd = @implode(" ", $cmds);
            $cmd = $cmd . " >/dev/null 2>&1 &";
            echo "Stopping MySQL...............: Stopping smoothly mysqld pid:{$pid}\n";
            if ($GLOBALS["VERBOSE"]) {
                echo "[VERBOSE]: {$cmd}\n";
            }
            for ($i = 0; $i < 10; $i++) {
                sleep(1);
                $pid = PID_NUM();
                if (!$unix->process_exists($pid, $mysqlbin)) {
                    break;
                }
                echo "Stopping MySQL...............: Stopping, please wait {$i}/10\n";
            }
        }
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid, $mysqlbin)) {
        echo "Stopping MySQL...............: Stopped\n";
        system_admin_events("Success to STOP MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        return;
    }
    mysql_admin_mysql(0, "Stopping MySQL service PID {$pid}", null, __FILE__, __LINE__);
    echo "Stopping MySQL...............: killing smoothly PID {$pid}\n";
    unix_system_kill($pid);
    for ($i = 0; $i < 5; $i++) {
        sleep(1);
        $pid = PID_NUM();
        if (!$unix->process_exists($pid, $mysqlbin)) {
            break;
        }
    }
    if (!$unix->process_exists($pid, $mysqlbin)) {
        echo "Stopping MySQL...............: Stopped\n";
        system_admin_events("Success to STOP MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        return;
    }
    echo "Stopping MySQL...............: Force killing PID {$pid}\n";
    unix_system_kill_force($pid);
    for ($i = 0; $i < 5; $i++) {
        sleep(1);
        $pid = PID_NUM();
        if (!$unix->process_exists($pid, $mysqlbin)) {
            break;
        }
    }
    if (!$unix->process_exists($pid, $mysqlbin)) {
        echo "Stopping MySQL...............: Stopped\n";
        system_admin_events("Success to STOP MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        return;
    }
    echo "Stopping MySQL...............: failed\n";
}
示例#6
0
function sync_time($aspid = false)
{
    if (isset($GLOBALS[__FUNCTION__])) {
        return;
    }
    $unix = new unix();
    $sock = new sockets();
    $NtpdateAD = intval($sock->GET_INFO("NtpdateAD"));
    if ($NtpdateAD == 0) {
        return;
    }
    $function = __FUNCTION__;
    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__))) {
            $timeExec = intval($unix->PROCCESS_TIME_MIN($pid));
            writelogs("Process {$pid} already exists since {$timeExec}Mn", __FUNCTION__, __FILE__, __LINE__);
            if ($timeExec > 5) {
                $kill = $unix->find_program("kill");
                system_admin_events("killing old pid {$pid} (already exists since {$timeExec}Mn)", __FUNCTION__, __FILE__, __LINE__);
                unix_system_kill_force($pid);
            } else {
                return;
            }
        }
        @file_put_contents($pidfile, getmypid());
    }
    $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos")));
    $hostname = strtolower(trim($array["WINDOWS_SERVER_NETBIOSNAME"])) . "." . strtolower(trim($array["WINDOWS_DNS_SUFFIX"]));
    $ipaddr = trim($array["ADNETIPADDR"]);
    $ntpdate = $unix->find_program("ntpdate");
    $hwclock = $unix->find_program("hwclock");
    if (!is_file($ntpdate)) {
        progress_logs(20, "{sync_time_ad}", "{$function}, ntpdate no such binary Line:" . __LINE__ . "");
        return;
    }
    progress_logs(20, "{sync_time_ad}", "{$function}, sync the time with the Active Directory {$hostname} [{$ipaddr}]...");
    if ($ipaddr != null) {
        $cmd = "{$ntpdate} -u {$ipaddr}";
    } else {
        $cmd = "{$ntpdate} -u {$hostname}";
    }
    if ($GLOBALS["VERBOSE"]) {
        progress_logs(20, "{sync_time_ad}", "{$cmd} line:" . __LINE__ . "");
    }
    exec($cmd . " 2>&1", $results);
    while (list($num, $a) = each($results)) {
        $unix->ToSyslog($a, false, "ntpd");
        progress_logs(20, "{sync_time_ad}", "{$function}, {$a} Line:" . __LINE__ . "");
    }
    if (is_file($hwclock)) {
        progress_logs(20, "{sync_time_ad}", "{$function}, sync the Hardware time with {$hwclock}");
        shell_exec("{$hwclock} --systohc");
    }
    $GLOBALS[__FUNCTION__] = true;
}
示例#7
0
<?php

$GLOBALS["SCHEDULE_ID"] = 0;
if (preg_match("#schedule-id=([0-9]+)#", implode(" ", $argv), $re)) {
    $GLOBALS["SCHEDULE_ID"] = $re[1];
}
include_once dirname(__FILE__) . '/ressources/class.templates.inc';
include_once dirname(__FILE__) . '/ressources/class.ini.inc';
include_once dirname(__FILE__) . '/ressources/class.users.menus.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql-server.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/ressources/class.mysql-multi.inc';
include_once dirname(__FILE__) . "/framework/class.unix.inc";
include_once dirname(__FILE__) . "/framework/frame.class.inc";
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
$pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid";
$pid = @file_get_contents($pidfile);
$unix = new unix();
if ($unix->process_exists($pid, basename(__FILE__))) {
    system_admin_events("Starting......: " . date("H:i:s") . "Already executed PID {$pid}...", __FUNCTION__, __FILE__, __LINE__, "mysql");
    die;
}
@file_put_contents($pidfile, getmypid());
$t = time();
$unix = new unix();
$unix->ToSyslog("Restarting MySQL service");
mysql_admin_mysql(1, "Restarting MySQL service...", null, __FILE__, __LINE__);
exec("/etc/init.d/mysql restart --framework=" . __FILE__ . " 2>&1", $results);
$took = $unix->distanceOfTimeInWords($t, time());
system_admin_events("Restarting MySQL service done took {$took}:\n" . @implode("\n", $results), __FUNCTION__, __FILE__, __LINE__, "mysql");
function import_quarantine($directory)
{
    if (!is_file("{$directory}/ENTIRE_MESSAGE")) {
        if ($GLOBALS["VERBOSE"]) {
            echo "{$directory}/ENTIRE_MESSAGE no such file\n";
        }
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Scanning directory {$directory}\n";
    }
    $unix = new unix();
    $rm = $unix->find_program("rm");
    $msgmd5 = md5_file("{$directory}/ENTIRE_MESSAGE");
    $last_modified = filemtime("{$directory}/ENTIRE_MESSAGE");
    $filesize = @filesize("{$directory}/ENTIRE_MESSAGE");
    $zdate = date("Y-m-d H:i:s", $last_modified);
    if ($GLOBALS["VERBOSE"]) {
        echo "Message MD5....: {$msgmd5}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Message Date...: {$last_modified} ({$zdate})\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Size...........: {$filesize}\n";
    }
    $MimeDefangMaxQuartime = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/MimeDefangMaxQuartime"));
    if ($MimeDefangMaxQuartime == 0) {
        $MimeDefangMaxQuartime = 129600;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Retention time.: {$MimeDefangMaxQuartime}Mn\n";
    }
    $f = explode("\n", @file_get_contents("{$directory}/HEADERS"));
    while (list($index, $line) = each($f)) {
        if (preg_match("#Subject:\\s+(.*)#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Subject........: {$re[1]}\n";
            }
            $Subject = $re[1];
        }
        if (preg_match("#From:\\s+(.*)#i", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "From...........: {$re[1]}\n";
            }
            $FromHeader = $re[1];
            $FromHeader = str_replace("<", "", $FromHeader);
            $FromHeader = str_replace(">", "", $FromHeader);
            $FromHeader = trim($FromHeader);
            if (preg_match("#(.*?)\\s+#", $FromHeader, $re)) {
                $FromHeader = $re[1];
            }
        }
    }
    $mailsTo_array = array();
    $f = explode("\n", @file_get_contents("{$directory}/RECIPIENTS"));
    while (list($index, $line) = each($f)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $line = str_replace("<", "", $line);
        $line = str_replace(">", "", $line);
        if (strpos($line, "@") == 0) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "Recipient......: {$line}\n";
        }
        $mailsTo_array[$line] = $line;
    }
    $mailfrom = trim(@file_get_contents("{$directory}/SENDER"));
    if ($GLOBALS["VERBOSE"]) {
        echo "Sender.........: {$mailfrom}\n";
    }
    if ($mailfrom == null) {
        $mailfrom = $FromHeader;
    }
    $mailfrom = str_replace("<", "", $mailfrom);
    $mailfrom = str_replace(">", "", $mailfrom);
    $q = new postgres_sql();
    $Subject = str_replace("'", "`", $Subject);
    $mailfromz = explode("@", $mailfrom);
    $domainfrom = $mailfromz[1];
    $final = strtotime("+{$MimeDefangMaxQuartime} minutes", $last_modified);
    $prefix = "INSERT INTO quarmsg (zdate,final,msgmd5,size,subject,mailfrom,mailto,domainfrom,domainto ) VALUES ";
    $f = array();
    while (list($a, $mailto) = each($mailsTo_array)) {
        $mailto = trim(strtolower($mailto));
        if ($mailto == null) {
            continue;
        }
        $mailtoz = explode("@", $mailto);
        $domainto = $mailtoz[1];
        $f[] = "('{$zdate}','{$final}','{$msgmd5}','{$filesize}','{$Subject}','{$mailfrom}','{$mailto}','{$domainfrom}','{$domainto}')";
    }
    if (count($f) == 0) {
        echo "No... count(f)=0\n";
        shell_exec("{$rm} -rf \"{$directory}\"");
        return false;
    }
    $final_sql = $prefix . " " . @implode(",", $f);
    $q->QUERY_SQL($final_sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n{$final_sql}\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    $filecontent_gz = $unix->FILE_TEMP() . ".gz";
    $unix = new unix();
    if (!$unix->compress("{$directory}/ENTIRE_MESSAGE", $filecontent_gz)) {
        @unlink($filecontent_gz);
        echo "No... Compress error\n";
        return;
    }
    @chmod($filecontent_gz, 0777);
    $q->QUERY_SQL("INSERT INTO quardata (zdate,msgmd5,final,contentid) VALUES ('{$zdate}','{$msgmd5}','{$final}',lo_import('{$filecontent_gz}') ) ON CONFLICT DO NOTHING");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    @unlink($filecontent_gz);
    $unix->ToSyslog("from=<{$mailfrom}> [{$Subject}] {$directory}/ENTIRE_MESSAGE success to Quarantine");
    echo "{$directory}/ENTIRE_MESSAGE (success)\n";
    shell_exec("{$rm} -rf \"{$directory}\"");
    return true;
}
function CACHE_DIR_SIZE_CACHES()
{
    $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $unix = new unix();
    if ($unix->file_time_min($pidtime) < 45) {
        return;
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    $q = new mysql();
    $sql = "SELECT * FROM squid_caches_center WHERE `enabled`=1 AND `remove`=0 ORDER BY zOrder";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = mysql_fetch_assoc($results)) {
        $ID = $ligne["ID"];
        $cachename = $ligne["cachename"];
        $cache_dir = $ligne["cache_dir"];
        $cache_type = $ligne["cache_type"];
        $cache_size = $ligne["cache_size"];
        $cache_dir_level1 = $ligne["cache_dir_level1"];
        $cache_dir_level2 = $ligne["cache_dir_level2"];
        if ($cache_type == "tmpfs") {
            continue;
        }
        if ($cache_type == "Cachenull") {
            continue;
        }
        if ($cache_type == "rock") {
            continue;
        }
        if (@is_link($cache_dir)) {
            $cache_dir = @readlink($cache_dir);
        }
        $size = $unix->DIRSIZE_MB($cache_dir);
        $unix->ToSyslog("squid-cache: {$cache_dir} = {$size}MB");
    }
}
示例#10
0
function xtstart()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtimeNTP = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.ntp.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 "ReStarting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $sock = new sockets();
    $NtpdateAD = intval($sock->GET_INFO("NtpdateAD"));
    $NTPDClientEnabled = intval($sock->GET_INFO("NTPDClientEnabled"));
    if ($NtpdateAD == 1) {
        $NTPDClientEnabled = 1;
    }
    if ($NTPDClientEnabled == 0) {
        return;
    }
    $NTPDClientPool = intval($sock->GET_INFO("NTPDClientPool"));
    if ($NTPDClientPool == 0) {
        $NTPDClientPool = 120;
    }
    $pidtimeNTPT = $unix->file_time_min($pidtimeNTP);
    if (!$GLOBALS["FORCE"]) {
        if ($pidtimeNTPT < $NTPDClientPool) {
            return;
        }
    }
    @unlink($pidtimeNTP);
    @file_put_contents($pidtimeNTP, time());
    if ($NtpdateAD == 1) {
        $nohup = $unix->find_program("nohup");
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.kerbauth.php --ntpdate >/dev/null 2>&1 &");
        return;
    }
    $ntpdate = $unix->find_program("ntpdate");
    $q = new mysql();
    $sql = "SELECT * FROM ntpd_servers ORDER BY `ntpd_servers`.`order` ASC";
    $results = $q->QUERY_SQL($sql, "artica_backup");
    if (mysql_num_rows($results) == 0) {
        $ntp = new ntpd();
        $ntp->builddefaults_servers();
        $results = $q->QUERY_SQL($sql, "artica_backup");
    }
    if (!$q->ok) {
        echo "{$q->mysql_error}<br>";
    }
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $serv = trim($ligne["ntp_servers"]);
        if ($serv == null) {
            continue;
        }
        $serv2 = explode(" ", $serv);
        if (count($serv2) > 1) {
            $f[] = $serv2[0];
        } else {
            $f[] = $ligne["ntp_servers"];
        }
    }
    if (count($f) == 0) {
        return;
    }
    $SERVERS = @implode(" ", $f);
    exec("{$ntpdate} -v {$SERVERS} 2>&1", $results);
    while (list($num, $text) = each($results)) {
        $unix->ToSyslog($text, false, "ntpd");
    }
    $hwclock = $unix->find_program("hwclock");
    if (is_file($hwclock)) {
        $unix->ToSyslog("sync the Hardware time with {$hwclock}", false, "ntpd");
        shell_exec("{$hwclock} --systohc");
    }
}
示例#11
0
function stop_ldap($aspid = false)
{
    if ($GLOBALS["MONIT"]) {
        xsyslog("Not accept a stop order from MONIT process");
        return;
    }
    $sock = new sockets();
    $users = new usersMenus();
    $ldaps = array();
    $unix = new unix();
    $kill = $unix->find_program("kill");
    $slapd = $unix->find_program("slapd");
    $pgrep = $unix->find_program("pgrep");
    $SLAPD_PID_FILE = $unix->SLAPD_PID_PATH();
    $MYPID_FILE = "/etc/artica-postfix/pids/stop_ldap.pid";
    if ($users->ZARAFA_INSTALLED) {
        stop_zarafa();
    }
    if (!$aspid) {
        $pid = $unix->get_pid_from_file($MYPID_FILE);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            echo "slapd: [INFO] Artica task already running pid {$pid} since {$pidtime}mn\n";
            if ($pidtime > 10) {
                echo "slapd: [INFO] Killing this Artica task...\n";
                unix_system_kill_force($pid);
            } else {
                die;
            }
        }
        @unlink($MYPID_FILE);
        @file_put_contents($MYPID_FILE, getmypid());
    }
    $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
    $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
    if ($unix->process_exists($pid)) {
        $timeDaemon = $unix->PROCESS_TTL($pid);
        $unix->ToSyslog("Stopping the OpenLDAP daemon running since {$timeDaemon}Mn", false, basename(__FILE__));
        echo "slapd: [INFO] slapd shutdown ldap server PID:{$pid}...\n";
        unix_system_kill($pid);
    } else {
        $pid = $unix->PIDOF($slapd);
        if ($unix->process_exists($pid)) {
            echo "slapd: [INFO] slapd shutdown ldap server PID:{$pid}...\n";
            unix_system_kill($pid);
        }
    }
    for ($i = 0; $i < 10; $i++) {
        $pid = intval($unix->get_pid_from_file($SLAPD_PID_FILE));
        if ($pid == 0) {
            break;
        }
        restart_ldap_progress("{stopping_service} stop PID:{$pid}", 20);
        if ($unix->process_exists($pid)) {
            echo "slapd: [INFO] slapd waiting the server to stop PID:{$pid}...\n";
            sleep(1);
            continue;
        }
        $pid = $unix->PIDOF($slapd);
        if ($unix->process_exists($pid)) {
            echo "slapd: [INFO] slapd waiting the server to stop PID:{$pid}...\n";
            sleep(1);
            continue;
        }
    }
    $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
    if ($unix->process_exists($pid)) {
        echo "slapd: [INFO] slapd PID:{$pid} still exists, kill it...\n";
        unix_system_kill_force($pid);
    }
    $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
    if ($unix->process_exists($pid)) {
        echo "slapd: [INFO] slapd PID:{$pid} still exists, start the force kill procedure...\n";
    }
    restart_ldap_progress("{stopping_service} Checking {$slapd}", 25);
    $pid = $unix->PIDOF($slapd);
    if ($unix->process_exists($pid)) {
        echo "slapd: [INFO] slapd PID:{$pid} still exists, kill it...\n";
        unix_system_kill_force($pid);
        return;
    }
    restart_ldap_progress("{stopping_service} Checking {$slapd}", 28);
    exec("{$pgrep} -l -f {$slapd} 2>&1", $results);
    while (list($num, $line) = each($results)) {
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (preg_match("^([0-9]+)\\s+", $line, $re)) {
            echo "slapd: [INFO] slapd PID:{$re[1]} still exists, kill it\n";
            unix_system_kill_force($re[1]);
        }
    }
    restart_ldap_progress("{stopping_service} {success}", 30);
    echo "slapd: [INFO] slapd stopped, success...\n";
}
示例#12
0
function Events($text)
{
    $unix = new unix();
    $unix->ToSyslog($text);
}
示例#13
0
function verif_organization()
{
    $unix = new unix();
    $EnableOpenLDAP = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP"));
    if ($EnableOpenLDAP == 0) {
        return;
    }
    if (!isset($GLOBALS["SQUID_INSTALLED"])) {
        $squidbin = $unix->LOCATE_SQUID_BIN();
        if (is_file($squidbin)) {
            $GLOBALS["SQUID_INSTALLED"] = true;
        } else {
            $GLOBALS["SQUID_INSTALLED"] = false;
        }
    }
    $timeStamp = "/etc/artica-postfix/pids/exec.verifldap.php.verif_organization.time";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$timeStamp}\n";
    }
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        return;
    }
    @unlink($pidFile);
    @file_put_contents($pidFile, getmypid());
    if (!$GLOBALS["FORCE"]) {
        $TimeEx = $unix->file_time_min($timeStamp);
        if ($TimeEx < 240) {
            return;
        }
    }
    @unlink($timeStamp);
    @file_put_contents($timeStamp, time());
    $sock = new sockets();
    if ($sock->EnableIntelCeleron == 1) {
        die;
        exit;
    }
    $WizardSavedSettings = unserialize(base64_decode(@file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings")));
    if (!isset($WizardSavedSettings["organization"])) {
        return;
    }
    $organization = $WizardSavedSettings["organization"];
    if ($organization == null) {
        return;
    }
    $ldap = new clladp();
    if ($GLOBALS["VERBOSE"]) {
        echo "Loading LDAP\n";
    }
    if ($ldap->ldapFailed) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Unable to connect to the LDAP server {$ldap->ldap_host}!\n";
        }
        if ($ldap->ldap_host == "127.0.0.1") {
            $unix->ToSyslog("LDAP error {$ldap->ldap_last_error}", false, basename(__FILE__));
            if ($GLOBALS["SQUID_INSTALLED"]) {
                squid_admin_mysql(1, "Connecting to local LDAP server failed [action=restart LDAP]", "Error: {$ldap->ldap_last_error}\nLdap host:{$ldap->ldap_host}", __FILE__, __LINE__);
            }
            system_admin_events("Error, Connecting to local LDAP server failed [action=restart LDAP]", __FUNCTION__, __FILE__, __LINE__);
            shell_exec("/etc/init.d/slapd restart --framework=" . basename(__FILE__));
            $ldap = new clladp();
            if ($GLOBALS["VERBOSE"]) {
                echo "Loading LDAP\n";
            }
            if ($ldap->ldapFailed) {
                echo $unix->ToSyslog("Unable to connect to the LDAP server {$ldap->ldap_host}! -> Abort..", false, __FILE__);
                return;
            }
        } else {
            return;
        }
    }
    $hash = $ldap->hash_get_ou(false);
    $CountDeOU = count($hash);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$CountDeOU} Organization(s)\n";
    }
    if (count($hash) > 0) {
        return;
    }
    system_admin_events("Error, no organization found, create the first one {$organization}", __FUNCTION__, __FILE__, __LINE__);
    if (!$ldap->AddOrganization($organization)) {
        system_admin_events("Error, unable to create first organization {$organization}\n{$ldap->ldap_last_error}", __FUNCTION__, __FILE__, __LINE__);
        if ($GLOBALS["SQUID_INSTALLED"]) {
            squid_admin_mysql(0, "Error, unable to create first organization {$organization}", $ldap->ldap_last_error, __FILE__, __LINE__);
        }
    }
}
示例#14
0
function start($aspid = false)
{
    if (!is_file("/etc/artica-postfix/settings/Daemons/SquidPerformance")) {
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 1);
    }
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        if (!is_file("/etc/artica-postfix/artica-iso-setup-launched")) {
            return;
        }
    }
    $unix = new unix();
    $sock = new sockets();
    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["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["STARTED_BY_CRON"]) {
            $unix->ToSyslog("Artica Status is already started {$pid} since {$timepid}Mn ( asked by cron daemon )");
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableArticaStatus = $sock->GET_INFO("EnableArticaStatus");
    if (!is_numeric($EnableArticaStatus)) {
        $EnableArticaStatus = 1;
    }
    if ($EnableArticaStatus == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableArticaStatus)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["STARTED_BY_CRON"]) {
        $unix->ToSyslog("Starting Artica Status ( asked by cron daemon )");
    }
    $cmd = "{$nohup} {$php5} " . dirname(__FILE__) . "/exec.status.php >/dev/null 2>&1 &";
    @unlink("/etc/artica-postfix/pids/class.status.squid.inc.squid_master_status.time");
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
function import_backup_file($filepath)
{
    if ($GLOBALS["VERBOSE"]) {
        echo "Import {$filepath}\n";
    }
    $dirname = dirname($filepath);
    $filename = basename($filepath);
    $filecontent = $dirname . "/" . str_replace(".email", ".msg", $filename);
    if (!is_file($filecontent)) {
        echo "{$filecontent} no such file\n";
        @unlink($filepath);
        return true;
    }
    $last_modified = filemtime($filepath);
    //$FinalLog="$Subject|||$Sender|||$recipt|||$body_hash|||$body_length||$rententiontime";
    $F = explode("|||", @file_get_contents($filepath));
    print_r($F);
    if (count($F) < 5) {
        echo "Truncated file index : {$filepath} !\n";
        return false;
    }
    $q = new postgres_sql();
    $zdate = date("Y-m-d H:i:s", $last_modified);
    $subject = str_replace("'", "`", $F[0]);
    $mailfrom = $F[1];
    $mailfrom = str_replace("<", "", $mailfrom);
    $mailfrom = str_replace(">", "", $mailfrom);
    $mailfromz = explode("@", $mailfrom);
    $domainfrom = $mailfromz[1];
    $mailto_line = $F[2];
    $hash = $F[3];
    $retentiontime = $F[5];
    $filesize = @filesize($filecontent);
    $msgmd5 = md5_file($filecontent);
    $final = strtotime("+{$retentiontime} minutes", $last_modified);
    $prefix = "INSERT INTO backupmsg (zdate,final,msgmd5,size,subject,mailfrom,mailto,domainfrom,domainto ) VALUES ";
    $mailsTo_array = explode(";", $mailto_line);
    $f = array();
    while (list($a, $mailto) = each($mailsTo_array)) {
        $mailto = trim(strtolower($mailto));
        $mailto = str_replace("<", "", $mailto);
        $mailto = str_replace(">", "", $mailto);
        if ($mailto == null) {
            continue;
        }
        $mailtoz = explode("@", $mailto);
        $domainto = $mailtoz[1];
        $f[] = "('{$zdate}','{$final}','{$msgmd5}','{$filesize}','{$subject}','{$mailfrom}','{$mailto}','{$domainfrom}','{$domainto}')";
    }
    if (count($f) == 0) {
        echo "No... count(f)=0\n";
        @unlink($filepath);
        @unlink($filecontent);
        return false;
    }
    $final_sql = $prefix . " " . @implode(",", $f);
    $q->QUERY_SQL($final_sql);
    if (!$q->ok) {
        echo $q->mysql_error . "\n{$final_sql}\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    $filecontent_gz = "{$filecontent}.gz";
    $unix = new unix();
    if (!$unix->compress($filecontent, $filecontent_gz)) {
        @unlink($filecontent_gz);
        echo "No... Compress error\n";
        return;
    }
    @chmod($filecontent_gz, 0777);
    $q->QUERY_SQL("INSERT INTO backupdata (zdate,msgmd5,final,contentid) VALUES ('{$zdate}','{$msgmd5}','{$final}',lo_import('{$filecontent_gz}') ) ON CONFLICT DO NOTHING");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        echo "No... PostgreSQL error\n";
        return false;
    }
    $unix->ToSyslog("from=<{$mailfrom}> [{$subject}] {$filepath} success to backup");
    echo "{$filepath} (success)\n{$filecontent} (success)\n";
    @unlink($filepath);
    @unlink($filecontent);
    @unlink($filecontent_gz);
    return true;
}