function user_status_table()
{
    if (isset($GLOBALS["user_status_table_executed"])) {
        if ($GLOBALS["VERBOSE"]) {
            $trace = debug_backtrace();
            if (isset($trace[1])) {
                $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
                echo "user_status_table Already executed {$called}\n";
            }
        }
        return;
    }
    $GLOBALS["user_status_table_executed"] = true;
    $unix = new unix();
    $sock = new sockets();
    $timefile = "/usr/share/artica-postfix/ressources/databases/ZARAFA_DB_STATUS.db";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $mns = $unix->file_time_min($timefile);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$timefile} = {$mns}Mn\n";
    }
    if (!$GLOBALS["FORCE"]) {
        if (system_is_overloaded(basename(__FILE__))) {
            system_admin_events("Overload system, aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa");
            return;
        }
        if ($mns < 180) {
            return;
        }
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $timeProcess = $unix->PROCCESS_TIME_MIN($pid);
            system_admin_events("{$pid}, task is already executed (since {$timeProcess}Mn}), aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa");
            if ($timeProcess < 15) {
                return;
            }
            $kill = $unix->find_program("kill");
            unix_system_kill_force($pid);
            system_admin_events("{$pid}, killed (since {$timeProcess}Mn}), aborting", __FUNCTION__, __FILE__, __LINE__, "zarafa");
        }
    }
    @file_put_contents($pidfile, getmypid());
    @unlink($timefile);
    @file_put_contents($timefile, time());
    $ZarafaIndexPath = $sock->GET_INFO("ZarafaIndexPath");
    $ZarafaStoreOutsidePath = $sock->GET_INFO("ZarafaStoreOutsidePath");
    $ZarafaMySQLServiceType = $sock->GET_INFO("ZarafaMySQLServiceType");
    if (!is_numeric($ZarafaMySQLServiceType)) {
        $ZarafaMySQLServiceType = 1;
    }
    // $ZarafaMySQLServiceType =1 ou 2 /var/lib/mysql
    // $ZarafaMySQLServiceType =3 --> dedicated instance
    if ($ZarafaIndexPath == null) {
        $ZarafaIndexPath = "/var/lib/zarafa/index";
    }
    if ($ZarafaStoreOutsidePath == null) {
        $ZarafaStoreOutsidePath = "/var/lib/zarafa";
    }
    $ARRAY["ZARAFA_INDEX"] = $unix->DIRSIZE_BYTES($ZarafaIndexPath);
    if ($ZarafaMySQLServiceType == 1 or $ZarafaMySQLServiceType == 2) {
        $ARRAY["ZARAFA_DB"] = $unix->DIRSIZE_BYTES("/var/lib/mysql");
    }
    if ($ZarafaMySQLServiceType == 3) {
        $WORKDIR = $sock->GET_INFO("ZarafaDedicateMySQLWorkDir");
        if ($WORKDIR == null) {
            $WORKDIR = "/home/zarafa-db";
        }
        $ARRAY["ZARAFA_DB"] = $unix->DIRSIZE_BYTES($WORKDIR);
    }
    $ARRAY["ATTACHS"] = $unix->DIRSIZE_BYTES($ZarafaStoreOutsidePath);
    @file_put_contents($timefile, serialize($ARRAY));
    @chmod($timefile, 0750);
    unset($ARRAY);
    $zarafaadmin = $unix->find_program("zarafa-admin");
    $kill = $unix->find_program("kill");
    $pids = $unix->PIDOF_PATTERN_ALL("zarafa-admin -l");
    if (count($pids) > 0) {
        while (list($pid, $line) = each($pids)) {
            $time = $unix->PROCESS_TTL($pid);
            if ($time > 15) {
                $unix->_syslog("killing zarafa-admin -l pid {$pid} ({$time}mn)", basename(__FILE__));
                unix_system_kill_force($pid);
            }
        }
    }
    $pid = $unix->PIDOF_PATTERN("zarafa-admin -l");
    if ($unix->process_exists($pid)) {
        $unix->_syslog("zarafa-admin -l pid {$pid} still running", basename(__FILE__));
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$zarafaadmin} -l 2>&1\n--------------------------------------------------------------------\n";
    }
    exec("{$zarafaadmin} -l 2>&1", $results);
    while (list($num, $line) = each($results)) {
        $line = trim($line);
        if ($GLOBALS["VERBOSE"]) {
            echo "\"{$line}\"\n";
        }
        if (preg_match("#User list for\\s+(.+?)\\(#i", $line, $re)) {
            $ou = $re[1];
            continue;
        }
        if (preg_match("#Username#", $line)) {
            continue;
        }
        if (preg_match("#SYSTEM#", $line)) {
            continue;
        }
        if (preg_match("#^(.+?)\\s+.+?#", $line, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "\"{$ou}\" -> \"{$re[1]}\" -> \"_user_status_table_info({$re[1]},{$zarafaadmin})\"\n";
            }
            $array[$ou][$re[1]] = _user_status_table_info($re[1], $zarafaadmin);
        }
    }
    $q = new mysql();
    if (!$q->TABLE_EXISTS('zarafauserss', 'artica_events')) {
        $sql = "CREATE TABLE IF NOT EXISTS `zarafauserss` (\n\t\t\t  `zmd5` varchar(90) NOT NULL PRIMARY KEY,\n\t\t\t  `uid` varchar(128) NOT NULL,\n\t\t\t  `ou` varchar(128) NOT NULL,\n\t\t\t  `mail` varchar(255) NOT NULL,\n\t\t\t  `license` smallint(1) NOT NULL,\n\t\t\t  `NONACTIVETYPE` varchar(60) NOT NULL,\n\t\t\t  `storesize` BINT(100) UNSIGNED NOT NULL,\n\t\t\t  KEY `uid` (`uid`),\n\t\t\t  KEY `ou` (`ou`),\n\t\t\t  KEY `mail` (`mail`),\n\t\t\t  KEY `license` (`license`),\n\t\t\t  KEY `NONACTIVETYPE` (`NONACTIVETYPE`),\n\t\t\t  KEY `storesize` (`storesize`)\n\t\t\t) ";
        $q->QUERY_SQL($sql, 'artica_events');
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
            return;
        }
    }
    $prefix = "INSERT IGNORE INTO zarafauserss (zmd5,uid,ou,mail,license,NONACTIVETYPE,storesize) VALUES ";
    while (list($ou, $members) = each($array)) {
        while (list($uid, $main) = each($members)) {
            $md5 = md5("{$uid}{$ou}");
            if (!isset($main["NONACTIVETYPE"])) {
                $main["NONACTIVETYPE"] = '';
            }
            if ($GLOBALS["VERBOSE"]) {
                echo "\"('{$md5}','{$uid}','{$ou}','{$main["MAIL"]}','{$main["ACTIVE"]}','{$main["NONACTIVETYPE"]}','{$main["STORE_SIZE"]}')\n";
            }
            $f[] = "('{$md5}','{$uid}','{$ou}','{$main["MAIL"]}','{$main["ACTIVE"]}','{$main["NONACTIVETYPE"]}','{$main["STORE_SIZE"]}')";
        }
    }
    if (count($f) == 0) {
        return;
    }
    $q->QUERY_SQL("TRUNCATE TABLE zarafauserss", "artica_events");
    $q->QUERY_SQL($prefix . @implode(",", $f), "artica_events");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "FINISH\n--------------------------------------------------------------------\n";
    }
}
Beispiel #2
0
function export_dns()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $oldpid = @file_get_contents($pidfile);
    if ($unix->process_exists($oldpid)) {
        $ptime = $unix->PROCESS_TTL($oldpid);
        if ($ptime > $GLOBALS["MAXTTL"]) {
            events("export_dns():: killing process {$oldpid} ttl:{$ptime} minutes");
            shell_exec("/bin/kill -9 {$oldpid}");
        } else {
            events("export_dns():: already executed, process {$oldpid}");
            die;
        }
    }
    $time = file_time_min($pidfile);
    events("{$pidfile}={$time}Mn", __FUNCTION__, __FILE__, __LINE__);
    if ($time == 0) {
        events("Cannot replicate DNS before one minute...", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $ldap = new clladp();
    $http = new httpget();
    $sock = new sockets();
    $meta = new artica_meta();
    $pattern = "(&(objectclass=*)(arecord=*))";
    $sr = ldap_search($ldap->ldap_connection, "ou=dns,{$ldap->suffix}", $pattern, array());
    $cachefile = "/etc/artica-postfix/dns.cache";
    if ($sr) {
        $hash = ldap_get_entries($ldap->ldap_connection, $sr);
        for ($i = 0; $i < $hash["count"]; $i++) {
            $macrecord = $hash[$i]["macrecord"][0];
            $arecord = $hash[$i]["arecord"][0];
            if ($arecord == "127.0.0.1") {
                continue;
            }
            if ($arecord == null) {
                continue;
            }
            echo "{$macrecord} {$arecord}\n";
            $array[$arecord] = array("MAC" => $macrecord, "NAMES" => $hash[$i]["associateddomain"]);
            $arecord = null;
            $macrecord = null;
        }
    } else {
        events("LDAP link failed", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    if (!is_array($array)) {
        return;
    }
    @file_put_contents($cachefile, base64_encode(serialize($array)));
    $http->uploads["DNS_COMPUTERS"] = $cachefile;
    $body = $http->send("{$meta->ArticaMetaHostname}/lic.users.import.php", "post", array("DATAS" => base64_encode(serialize($meta->GLOBAL_ARRAY))));
    if (!preg_match("#<RESULTS>OK</RESULTS>#is", $body)) {
        events(count($array) . " DNS failed to be exported to global Management console", __FUNCTION__, __FILE__, __LINE__);
        return;
    } else {
        events(count($array) . " DNS exported to global Management console", __FUNCTION__, __FILE__, __LINE__);
        send_email_events(count($array) . " DNS exported to global Management console", null, "CLOUD");
        @unlink($cachefile);
    }
}
Beispiel #3
0
function process_timeexec()
{
    $unix = new unix();
    echo "<articadatascgi>" . $unix->PROCESS_TTL($_GET["pid"]) . "</articadatascgi>";
}
function restore()
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["VERBOSE"]) {
        echo "PID: {$pidfile}\n";
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        $TTL = $unix->PROCESS_TTL($pid);
        if ($TTL < 240) {
            return;
        }
        $kill = $unix->find_program("kill");
        unix_system_kill_force($pid);
    }
    @file_put_contents($pidfile, getmypid());
    $hostname = $unix->hostname_g();
    progress(10, "{mounting}");
    if (!restore_TestNas()) {
        system_admin_events("Mounting NAS filesystem report false", __FUNCTION__, __FILE__, __LINE__);
        progress(100, "{failed}");
        return;
    }
    $BackupArticaRestoreNASIpaddr = $sock->GET_INFO("BackupArticaRestoreNASIpaddr");
    $BackupArticaRestoreNASFolder = $sock->GET_INFO("BackupArticaRestoreNASFolder");
    $BackupArticaRestoreNASUser = $sock->GET_INFO("BackupArticaRestoreNASUser");
    $BackupArticaRestoreNASPassword = $sock->GET_INFO("BackupArticaRestoreNASPassword");
    $BackupArticaRestoreNASFolderSource = $sock->GET_INFO("BackupArticaRestoreNASFolderSource");
    $BackupArticaRestoreNetwork = $sock->GET_INFO("BackupArticaRestoreNetwork");
    $mountPoint = "/mnt/BackupArticaRestoreNAS";
    $BackupArticaRestoreNASFolderSource = str_replace("\\", "/", $BackupArticaRestoreNASFolderSource);
    $sourceDir = "{$mountPoint}/{$BackupArticaRestoreNASFolderSource}";
    $sourceDir = str_replace("//", "/", $sourceDir);
    if (!is_file("{$sourceDir}/BKVERSION.txt")) {
        progress(100, "{failed} BKVERSION.txt no such file");
        $mount = new mount("/var/log/artica-postfix/backup.debug");
        if ($mount->ismounted($mountPoint)) {
            $mount->umount($mountPoint);
        }
        return;
    }
    $time = trim(@file_get_contents("{$sourceDir}/BKVERSION.txt"));
    progress(15, "{backup} " . date("Y-m-d H:i:s"));
    progress(20, "{restoring_ldap_database}, {please_wait}...");
    Restore_ldap($sourceDir);
    progress(40, "{restoring_artica_settings}, {please_wait}...");
    restore_artica_settings($sourceDir);
    progress(50, "{restoring_artica_databases}, {please_wait}...");
    restore_artica_backup($sourceDir);
    progress(60, "{restoring_artica_databases}, {please_wait}...");
    restore_ocsweb($sourceDir);
    progress(80, "{restoring_artica_databases}, {please_wait}...");
    restore_squidlogs($sourceDir);
    progress(82, "{restoring} PowerDNS, {please_wait}...");
    restore_powerdns($sourceDir);
    progress(90, "{reconfigure_server}, {please_wait}...");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $php = $unix->LOCATE_PHP5_BIN();
    if (is_file($squidbin)) {
        shell_exec("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
    }
    progress(100, "{success}");
    $mount = new mount("/var/log/artica-postfix/backup.debug");
    if ($mount->ismounted($mountPoint)) {
        $mount->umount($mountPoint);
    }
    if ($BackupArticaRestoreNetwork == 1) {
        $unix->THREAD_COMMAND_SET("{$php} /usr/share/artica-postfix/exec.virtuals-ip.php --build");
    }
    return;
}
Beispiel #5
0
function restart()
{
    if (!is_run()) {
        echo "Starting......: " . date("H:i:s") . " WINBIND (restart) not running, start it...\n";
        Winbindd_events("Winbindd (restart) not running, start it", __FUNCTION__, __LINE__);
        start(true);
        return;
    }
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $filetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $time = $unix->file_time_min($filetime);
    Winbindd_events("Winbindd ask to restart since {$time}Mn", __FUNCTION__, __LINE__);
    if (!$GLOBALS["FORCE"]) {
        if ($time < 59) {
            $pid = WINBIND_PID();
            if ($unix->process_exists($pid)) {
                $timepid = $unix->PROCESS_TTL($pid);
                echo "Starting......: " . date("H:i:s") . " WINBIND ask to restart need to wait 60Mn pid:{$pid} {$timepid}\n";
                Winbindd_events("Winbindd ask to restart need to wait 60Mn pid:{$pid} {$timepid}", __FUNCTION__, __LINE__);
                return;
            } else {
                echo "Starting......: " . date("H:i:s") . " WINBIND (restart) not running, start it...\n";
                shell_exec("{$php5} /usr/share/artica-postfix/exec.winbindd.php --start");
            }
        }
    }
    @unlink($filetime);
    @file_put_contents($filetime, time());
    $smbcontrol = $unix->find_program("smbcontrol");
    $chmod = $unix->find_program("chmod");
    $settings = new settings_inc();
    DirsPrivileges();
    if (!$GLOBALS["FORCE"]) {
        if (is_file($smbcontrol)) {
            Winbindd_events("Winbindd reloading", __FUNCTION__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " WINBIND reloading...\n";
            shell_exec("{$smbcontrol} winbindd reload-config");
            shell_exec("{$smbcontrol} winbindd offline");
            shell_exec("{$smbcontrol} winbindd online");
            setfacl_squid();
            return;
        }
    }
    Winbindd_events("Winbindd stop", __FUNCTION__, __LINE__);
    stop();
    Winbindd_events("Winbindd ask to start", __FUNCTION__, __LINE__);
    start(true);
}
<?php

include dirname(__FILE__) . '/ressources/class.qos.inc';
include_once dirname(__FILE__) . '/framework/frame.class.inc';
include_once dirname(__FILE__) . '/framework/class.unix.inc';
include_once dirname(__FILE__) . '/ressources/class.artica-meta.inc';
include_once dirname(__FILE__) . '/ressources/class.ldap.inc';
include_once dirname(__FILE__) . '/ressources/class.computers.inc';
include_once dirname(__FILE__) . '/ressources/class.sockets.inc';
include_once dirname(__FILE__) . '/ressources/class.groups.inc';
include_once dirname(__FILE__) . '/ressources/class.http.pear.inc';
$unix = new unix();
$pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
$pid = @file_get_contents($pidfile);
if ($unix->process_exists($pid)) {
    $ptime = $unix->PROCESS_TTL($pid);
    die;
}
if ($argv[1] == '--org') {
    export($argv[2], $argv[3]);
}
if ($argv[1] == '--upload') {
    export_ou_http($argv[2], $argv[3]);
}
function export_ou_http($ou, $session)
{
    $sock = new sockets();
    $ldap = new clladp();
    $path = "/root";
    echo "Exporting meta informations session {$session} for ou=`{$ou}`\n";
    export($ou, $path);
function start()
{
    $unix = new unix();
    $pid = getmypid();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if ($GLOBALS["VERBOSE"]) {
        echo "pidTime: {$pidTime}\n";
    }
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        if ($pid != $pid) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($time > 120) {
                ToSyslog("killing {$pid}  (line:  Line: " . __LINE__ . ")");
                unix_system_kill_force($pid);
            } else {
                die;
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    $pidTimeEx = $unix->file_time_min($pidTime);
    if (!$GLOBALS["FORCE"]) {
        if ($pidTimeEx < 240) {
            ToSyslog("Waiting 240mn minimal - current ({$pidTimeEx}Mn)");
            return;
        }
    }
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $ARRAY = array();
    $curlftps = $unix->find_program("curlftpfs");
    $pgrep = $unix->find_program("pgrep");
    exec("{$pgrep} -l -f \"{$curlftps}\" 2>&1", $results);
    while (list($index, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        $MOUNTED = null;
        $pidtime = 0;
        $pid = 0;
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) {
            $pid = $re[1];
            $pidtime = $unix->PROCESS_TTL($pid);
            $cmdline = trim($re[2]);
            $cmdline = str_replace($curlftps, "", $cmdline);
            $cmdline = trim($re[2]);
            if ($GLOBALS["VERBOSE"]) {
                echo "Found {$pid} {$pidtime}Mn [{$cmdline}]\n";
            }
            $ARRAY[$pid]["TIME"] = $pidtime;
            if ($GLOBALS["VERBOSE"]) {
                echo "Explode {$cmdline}\n";
            }
            $TR = explode(" ", $cmdline);
            while (list($index2, $bg) = each($TR)) {
                if ($GLOBALS["VERBOSE"]) {
                    echo "Checks {$bg}\n";
                }
                if (substr($bg, 0, 1) == "/") {
                    $MOUNTED = $bg;
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Found {$pid} {$pidtime}Mn mounted on {$bg}\n";
                    }
                    $ARRAY[$pid]["MOUNTED"] = $MOUNTED;
                    break;
                }
            }
        }
    }
    if (count($ARRAY) == 0) {
        return;
    }
    $umount = $unix->find_program("umount");
    while (list($pid, $ar) = each($ARRAY)) {
        $TIME = $ar["TIME"];
        $MOUNTED = $ar["MOUNTED"];
        if ($TIME < 960) {
            continue;
        }
        ToSyslog("Umounting curlftps process id {$pid} mounted on {$MOUNTED} and running since {$TIME}mn, and exceed 960mn");
        shell_exec("{$umount} -l {$MOUNTED}");
        if ($unix->process_exists($pid)) {
            ToSyslog("Killing curlftps process id {$pid}");
            $unix->KILL_PROCESS($pid, 9);
        }
    }
}
Beispiel #8
0
function reload($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 "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $amavisbin = $unix->LOCATE_AMAVISD_BIN_PATH();
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Not running\n";
        }
        start(true);
        return;
    }
    $TTL = $unix->PROCESS_TTL($pid);
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["OUTPUT"]) {
        echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} reloading PID {$pid} running since {$TTL}mn\n";
    }
    buildconfig();
    $cmd = "{$nohup} {$amavisbin} -c /usr/local/etc/amavisd.conf reload >/dev/null 2>&1 &";
    shell_exec($cmd);
}
Beispiel #9
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("ufdbgclient");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ufdbgclient not installed\n";
        }
        return false;
    }
    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 true;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $EnableUfdbGuard = intval($sock->EnableUfdbGuard());
    $SquidUFDBUrgency = intval($sock->GET_INFO("SquidUFDBUrgency"));
    if ($SquidUFDBUrgency == 1) {
        $EnableUfdbGuard = 0;
    }
    if ($EnableUfdbGuard == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not Enabled\n";
        }
        return false;
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, already running PID {$pid} since {$ttl}Mn\n";
            }
        }
        return true;
    }
    if (IsInSquid()) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Hooked chock proxy\n";
        }
        squid_admin_mysql(1, "Reload proxy service to run Web filtering clients.", null, __FILE__, __LINE__);
        $squidbin = $unix->LOCATE_SQUID_BIN();
        system("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not Hooked! Hook proxy\n";
        }
        EnableClient();
    }
    for ($i = 1; $i < 8; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Waiting {$i}/5\n";
        }
        sleep(1);
        $pids = GetAllPids();
        if (count($pids) > 0) {
            break;
        }
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            $fty[] = "Success PID {$pid} since {$ttl}Mn";
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid} since {$ttl}Mn\n";
            }
        }
        squid_admin_mysql(2, "Succes {starting_web_filtering} Client service from the proxy{$GLOBALS["ADPLUS"]}", @implode("\n", $fty), __FILE__, __LINE__);
        return true;
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Failed\n";
        }
    }
}
function Checks_mgrinfos($MonitConfig, $aspid = false)
{
    $sock = new sockets();
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $SystemInfoCache = "/etc/squid3/squid_get_system_info.db";
    $StoreDirCache = "/etc/squid3/squid_storedir_info.db";
    if (!is_array($MonitConfig)) {
        $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
        $MonitConfig = watchdog_config_default($MonitConfig);
    }
    $FailOverArticaParams = FailOverParams();
    $MgrInfosMaxTimeOut = $MonitConfig["MgrInfosMaxTimeOut"];
    $MgrInfosRestartFailed = $MonitConfig["MgrInfosRestartFailed"];
    $MgrInfosFaileOverFailed = $MonitConfig["MgrInfosFaileOverFailed"];
    $MgrInfosMaxFailed = $MonitConfig["MgrInfosFaileOverFailed"];
    $MgrInfosMaxFailedCount = @file_get_contents("/etc/squid3/MgrInfosMaxFailedCount");
    if (!is_numeric($MgrInfosMaxFailedCount)) {
        $MgrInfosMaxFailedCount = 0;
    }
    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 ($time > 5) {
                $kill = $unix->find_program("kill");
                Events("kill old {$pid} process {$time}mn");
                unix_system_kill_force($pid);
            } else {
                system_admin_events("Start_squid:: Already task running PID {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__, "proxy");
                return;
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    $squidpid = SQUID_PID();
    if (!$unix->process_exists($squidpid)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Squid not running aborting\n";
        }
        $GLOBALS["ALL_SCORES"]++;
        $GLOBALS["ALL_SCORES_WHY"][] = "function " . __FUNCTION__ . " return Squid not running";
        return;
    }
    $rpcesstime = $unix->PROCESS_TTL($squidpid);
    if ($rpcesstime < 5) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Squid running since {$rpcesstime}mn, need 5mn\n";
        }
        return;
    }
    if (is31()) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Only squid 3.1x... aborting\n";
        }
        Checks_mgrinfos_31();
        return;
    }
    $SquidMgrListenPort = trim($sock->GET_INFO("SquidMgrListenPort"));
    if (!is_numeric($SquidMgrListenPort) or $SquidMgrListenPort == 0) {
        $SquidBinIpaddr = $sock->GET_INFO("SquidBinIpaddr");
        if ($SquidBinIpaddr == null) {
            $SquidBinIpaddr = "127.0.0.1";
        }
        $http_port = squid_get_alternate_port();
        if (preg_match("#(.+?):([0-9]+)#", $http_port, $re)) {
            $SquidBinIpaddr = $re[1];
            if ($SquidBinIpaddr == "0.0.0.0") {
                $SquidBinIpaddr = "127.0.0.1";
            }
            $http_port = $re[2];
        }
    } else {
        $SquidBinIpaddr = "127.0.0.1";
        $http_port = $SquidMgrListenPort;
    }
    $t0 = time();
    $curl = new ccurl("http://{$SquidBinIpaddr}:{$http_port}/squid-internal-mgr/info", true);
    $curl->CURLOPT_NOPROXY = $SquidBinIpaddr;
    $curl->ArticaProxyServerEnabled == "no";
    $curl->interface = "127.0.0.1";
    $curl->Timeout = $MgrInfosMaxTimeOut;
    $curl->UseDirect = true;
    if (!$curl->get()) {
        $MgrInfosMaxFailedCount++;
        if ($MgrInfosRestartFailed == 1) {
            squid_admin_mysql(0, "Unable to retreive informations [{$MgrInfosMaxFailedCount}/{$MgrInfosMaxFailed}] from {$SquidBinIpaddr}:{$http_port}", $curl->errors, __FILE__, __LINE__);
        }
        if ($MgrInfosRestartFailed == 0) {
            squid_admin_mysql(1, "Unable to retreive informations [{$MgrInfosMaxFailedCount}/{$MgrInfosMaxFailed}] from {$SquidBinIpaddr}:{$http_port}", $curl->errors, __FILE__, __LINE__);
        }
        if ($MgrInfosMaxFailedCount <= $MgrInfosMaxFailed) {
            @file_put_contents("/etc/squid3/MgrInfosMaxFailedCount", $MgrInfosMaxFailedCount);
            return true;
        }
        @file_put_contents("/etc/squid3/MgrInfosMaxFailedCount", 0);
        if ($MonitConfig["watchdog"] == 1) {
            if ($MgrInfosFaileOverFailed == 1) {
                FailOverDown("Unable to retreive informations [{$MgrInfosMaxFailedCount}/{$MgrInfosMaxFailed}] from {$SquidBinIpaddr}:{$http_port}, {$curl->error}");
            }
        }
        if ($MgrInfosRestartFailed == 1) {
            RESTARTING_SQUID_WHY($MonitConfig, "{$curl->error}: Unable to retreive informations [{$MgrInfosMaxFailedCount}/{$MgrInfosMaxFailed}] from {$SquidBinIpaddr}:{$http_port}");
            $GLOBALS["ALL_SCORES_WHY"][] = "function " . __FUNCTION__ . " return failed";
            $GLOBALS["ALL_SCORES"]++;
        }
    } else {
        STAMP_MAX_RESTART_RESET();
        @file_put_contents("/etc/squid3/MgrInfosMaxFailedCount", 0);
        if ($MonitConfig["EnableFailover"] == 1) {
            FailOverUp();
        }
        $StoreDirCache = "/etc/squid3/squid_storedir_info.db";
        $curl = new ccurl("http://{$SquidBinIpaddr}:{$http_port}/squid-internal-mgr/storedir");
        $curl->ArticaProxyServerEnabled == "no";
        $curl->interface = "127.0.0.1";
        $curl->Timeout = $MgrInfosMaxTimeOut;
        $curl->UseDirect = true;
        if ($curl->get()) {
            $array = MgrStoreDirToArray($curl->data);
            if (is_array($array)) {
                @unlink($StoreDirCache);
                @file_put_contents($StoreDirCache, serialize($array));
                $time = $unix->file_time_min("/etc/artica-postfix/pids/exec.squid.php.caches_infos.time");
                if ($time > 15) {
                    shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --cache-infos");
                }
            }
        }
    }
    $array = MgrInfoToArray($curl->data);
    if (count($array) > 5) {
        @unlink($SystemInfoCache);
        @file_put_contents("{$SystemInfoCache}", serialize($array));
    }
    if ($MonitConfig["watchdog"] == 1) {
        if ($GLOBALS["VERBOSE"]) {
            echo " *** *** *** Checks_external_webpage() *** *** *** \n";
        }
        Checks_external_webpage($MonitConfig);
    }
}
Beispiel #11
0
function phpcgi()
{
    $unix = new unix();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $pids = $unix->PIDOF_PATTERN_ALL($phpcgi);
    if (count($pids) == 0) {
        return;
    }
    $c = 0;
    while (list($pid, $ligne) = each($pids)) {
        $time = $unix->PROCESS_TTL($pid);
        if ($time > 1640) {
            $c++;
            $unix->KILL_PROCESS($pid, 9);
        }
    }
}
Beispiel #12
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";
}
function start_import($aspid = false)
{
    $sock = new sockets();
    $syslog = new mysql_storelogs();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    if (!$aspid) {
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCESS_TTL($pid);
            stats_admin_events(2, "A already Importation Task is executed pid:{$pid} since {$time}Mn", null, __FILE__, __LINE__);
            writelogs("Already executed pid:{$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        $pid = @file_get_contents("/var/run/squid-stats-central.pid");
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCESS_TTL($pid);
            stats_admin_events(2, "An anlready Importation Task is executed pid:{$pid} since {$time}Mn", null, __FILE__, __LINE__);
            writelogs("Already executed pid:{$pid}", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    $import_processes = import_processes();
    if ($import_processes > 6) {
        Import_logs("Too many processes ({$import_processes})...aborting task...");
        return;
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $ArticaProxyStatisticsBackupFolder = $sock->GET_INFO("ArticaProxyStatisticsBackupFolder");
    if ($ArticaProxyStatisticsBackupFolder == null) {
        $ArticaProxyStatisticsBackupFolder = "/home/artica/squid/backup-statistics";
    }
    $ArticaProxyStatisticsBackupFolder = $ArticaProxyStatisticsBackupFolder . "/import";
    $files = $unix->DirFiles($ArticaProxyStatisticsBackupFolder);
    if ($GLOBALS["VERBOSE"]) {
        echo "PUSH Scanning {$ArticaProxyStatisticsBackupFolder}\n";
    }
    $mysql = $unix->find_program("mysql");
    $bzip2 = $unix->find_program("bzip2");
    $total = count($files);
    $c = 0;
    if ($total == 0) {
        return;
    }
    stats_admin_events(2, "Importing {$total} files to MySQL", null, __FILE__, __LINE__);
    while (list($filename, $none) = each($files)) {
        $c++;
        if (if_process_import_exists($filename)) {
            Import_logs("SKIP {$ArticaProxyStatisticsBackupFolder}/{$filename} Already running...");
            continue;
        }
        percentage("Extracting {$filename} {$c}/{$total}", 2);
        $size = @filesize("{$ArticaProxyStatisticsBackupFolder}/{$filename}");
        Import_logs("IMPORT {$ArticaProxyStatisticsBackupFolder}/{$filename}");
        $f = array();
        $results = array();
        $f[] = "{$bzip2} -d -c {$ArticaProxyStatisticsBackupFolder}/{$filename} |";
        $f[] = "{$mysql} --show-warnings";
        $f[] = "--socket=/var/run/mysqld/squid-db.sock";
        $f[] = "--protocol=socket --user=root --batch --force";
        $f[] = "--debug-info --database=squidlogs 2>&1";
        $cmd = @implode(" ", $f);
        $results[] = $cmd;
        percentage("Importing {$filename} to MySQL {$c}/{$total}", 2);
        exec($cmd, $results);
        Import_logs(@implode("\n", $results));
        stats_admin_events(2, "Success importing {$filename} to MySQL", @implode("\n", $results), __FILE__, __LINE__);
        Import_logs("Backup {$ArticaProxyStatisticsBackupFolder}/{$filename}");
        $syslog->ROTATE_TOMYSQL("{$ArticaProxyStatisticsBackupFolder}/{$filename}");
    }
}
Beispiel #14
0
function SERVICE_RESTART()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    $kill = $unix->find_program("kill");
    $LastExec = $unix->file_time_min($pidTime);
    if (!$GLOBALS["BY_WIZARD"]) {
        if ($LastExec < 1) {
            $unix->ToSyslog("Restarting MySQL service Aborted Need at least 1mn", true, basename(__FILE__));
            return;
        }
    }
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($time < 5) {
            $unix->ToSyslog("Restarting MySQL service Aborted an artica task {$pid} is running", true, basename(__FILE__));
            return;
        }
        $unix->ToSyslog("Killing `Restart task` Running too long {$time}Mn");
        unix_system_kill_force($pid);
    }
    $unix->ToSyslog("Restarting MySQL service `{$GLOBALS["CMDLINE"]}`", true, basename(__FILE__));
    if ($GLOBALS["FORCE"]) {
        mysql_admin_mysql(0, "Restarting MySQL using Force mode !", __FILE__, __LINE__);
    }
    if ($GLOBALS["BY_FRAMEWORK"] == null) {
        $unix->ToSyslog("Restarting MySQL server without specify --framework!", true, basename(__FILE__));
        if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            echo "Restarting....: " . date("H:i:s") . " MySQL socket seems ok\n";
            $unix->ToSyslog("MySQL, socket seems ok", true, basename(__FILE__));
        }
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            mysql_admin_mysql(0, "Starting MySQL server by=[{$GLOBALS["BY_FRAMEWORK"]}] Service is not running,  start it", __FILE__, __LINE__);
            SERVICE_START(false, true);
            return;
        }
        $time = $unix->PROCESS_TTL($pid);
        echo "Restarting....: " . date("H:i:s") . " MySQL running since {$time}Mn\n";
        $unix->ToSyslog("MySQL, PID {$pid} running since {$time}Mn, nothing to do, not make sense...", true, basename(__FILE__));
        echo "Restarting MySQL service can only done by using \"--force --framework\" token\n";
        echo "Use /etc/init.d/mysql restart --force --framework=byhand\n";
        return;
    }
    if ($GLOBALS["BY_SOCKET_FAILED"]) {
        echo "Restarting....: " . date("H:i:s") . " MySQL Seems socket is failed\n";
        $unix->ToSyslog("MySQL, Seems socket is failed...", true, basename(__FILE__));
    }
    if ($GLOBALS["BY_SOCKET_FAILED"]) {
        if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            mysql_admin_mysql(0, "Watchdog say that the socket is failed but find it..aborting", __FILE__, __LINE__);
            return;
        } else {
            mysql_admin_mysql(2, "Watchdog say that the socket is failed and did not find it...", __FILE__, __LINE__);
        }
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        mysql_admin_mysql(0, "Restarting MySQL server by=[{$GLOBALS["BY_FRAMEWORK"]}] Service is not running,  start it", __FILE__, __LINE__);
        SERVICE_START(false, true);
        return;
    }
    $time = $unix->PROCESS_TTL($pid);
    mysql_admin_mysql(0, "Restarting MySQL server running since {$time}Mn by=[{$GLOBALS["BY_FRAMEWORK"]}]...", __FILE__, __LINE__);
    SERVICE_STOP(true);
    SERVICE_START(false, true);
}
Beispiel #15
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("ufdbgclient");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ufdbgclient not installed\n";
        }
        return false;
    }
    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 true;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $EnableUfdbGuard = $sock->EnableUfdbGuard();
    if ($EnableUfdbGuard == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not Enabled\n";
        }
        return false;
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, already running PID {$pid} since {$ttl}Mn\n";
            }
        }
        return true;
    }
    if (IsInSquid()) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Hooked chock proxy\n";
        }
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
    } else {
        EnableClient();
    }
    for ($i = 1; $i < 8; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Waiting {$i}/5\n";
        }
        sleep(1);
        $pids = GetAllPids();
        if (count($pids) > 0) {
            break;
        }
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            $fty[] = "Success PID {$pid} since {$ttl}Mn";
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid} since {$ttl}Mn\n";
            }
        }
        squid_admin_mysql(2, "Succes starting Web Filtering Client service from the proxy{$GLOBALS["ADPLUS"]}", @implode("\n", $fty), __FILE__, __LINE__);
        return true;
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Failed\n";
        }
    }
}
Beispiel #16
0
function SendStatus()
{
    emergency(true);
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $sock = new sockets();
    $EnableSargGenerator = $sock->GET_INFO("EnableSargGenerator");
    if (TestsCron($pidfile)) {
        $ArticaMetaPingEnable = $sock->GET_INFO("ArticaMetaPingEnable");
        events("SendPing={$ArticaMetaPingEnable}", __FUNCTION__, __FILE__, __LINE__);
        if ($ArticaMetaPingEnable == 1) {
            SendPing();
        }
        return true;
    }
    $ArticaMetaEnabled = $sock->GET_INFO("ArticaMetaEnabled");
    if ($ArticaMetaEnabled != 1) {
        return;
    }
    $t1 = time();
    if (!is_file("/usr/share/artica-postfix/ressources/logs/global.status.ini")) {
        events("Unable to stat /usr/share/artica-postfix/ressources/logs/global.status.ini", __FUNCTION__, __FILE__, __LINE__);
        return null;
    }
    $unix = new unix();
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $ptime = $unix->PROCESS_TTL($pid);
        if ($ptime > $GLOBALS["MAXTTL"]) {
            events("killing process {$pid} ttl:{$ptime} minutes", __FUNCTION__, __FILE__, __LINE__);
            unix_system_kill_force($pid);
        } else {
            events("Already executed, process {$pid}", __FUNCTION__, __FILE__, __LINE__);
            die;
        }
    }
    events("Running pid " . getmypid(), __FUNCTION__, __FILE__, __LINE__);
    @file_put_contents($pidfile, getmypid());
    CheckNetwork();
    $http = new httpget();
    $meta = new artica_meta();
    $filecache = "/etc/artica-postfix/artica-meta-files.cache";
    events("My uuid=\"{$meta->uuid}\"", __FUNCTION__, __FILE__, __LINE__);
    $memCache = "/usr/share/artica-postfix/ressources/logs/status.memory.hash";
    $cpu_graphs = "/opt/artica/share/www/system/rrd/01cpu-1day.png";
    $server_status = "/usr/share/artica-postfix/ressources/logs/status.right.1.html";
    $squid_realtime = "/etc/artica-postfix/squid-realtime.cache";
    $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY));
    $ini = new Bs_IniHandler();
    $ini->loadFile("/usr/share/artica-postfix/ressources/logs/global.status.ini");
    $ArrayFileCache = unserialize(@file_get_contents($filecache));
    if (is_file($memCache)) {
        $MEM_CACHE = base64_encode(@file_get_contents($memCache));
    } else {
        include_once "ressources/class.os.system.tools.inc";
        $os = new os_system();
        $os->html_Memory_usage();
        $MEM_CACHE = base64_encode(serialize($os->meta_array));
    }
    if (is_file($cpu_graphs)) {
        if ($ArrayFileCache["STATS_DAY"] != filemtime($cpu_graphs)) {
            $http->uploads["STATS_DAY"] = $cpu_graphs;
            $ArrayFileCache["STATS_DAY"] = filemtime($cpu_graphs);
            @file_put_contents($filecache, serialize($ArrayFileCache));
        }
    }
    if (is_file($server_status)) {
        if ($ArrayFileCache["SERVER_STATUS"] != filemtime($server_status)) {
            $http->uploads["SERVER_STATUS"] = $server_status;
            $ArrayFileCache["SERVER_STATUS"] = filemtime($server_status);
            @file_put_contents($filecache, serialize($ArrayFileCache));
        }
    }
    if (is_file($squid_realtime)) {
        if ($ArrayFileCache["SQUID_REALTIME"] != filemtime($squid_realtime)) {
            $http->uploads["SQUID_REALTIME"] = $squid_realtime;
            $ArrayFileCache["SQUID_REALTIME"] = filemtime($squid_realtime);
            @file_put_contents($filecache, serialize($ArrayFileCache));
        }
    }
    if ($EnableSargGenerator == 1) {
        $push_sarg = false;
        $sock = new sockets();
        $SargOutputDir = $sock->GET_INFO("SargOutputDir");
        if ($SargOutputDir == null) {
            $SargOutputDir = "/var/www/html/squid-reports";
        }
        if (is_file("{$SargOutputDir}/index.html")) {
            if (!is_file("/etc/artica-postfix/sarg.tgz")) {
                shell_exec("cd {$SargOutputDir} && tar -cjf /etc/artica-postfix/sarg.tgz ./*");
                $push_sarg = true;
            } else {
                if ($ArrayFileCache["SQUID_SARG"] != filemtime("{$SargOutputDir}/index.html")) {
                    @unlink("/etc/artica-postfix/sarg.tgz");
                    shell_exec("cd {$SargOutputDir} && tar -cjf /etc/artica-postfix/sarg.tgz ./*");
                    $push_sarg = true;
                }
            }
            if ($push_sarg) {
                $http->uploads["SQUID_SARG"] = "/etc/artica-postfix/sarg.tgz";
            }
        }
    }
    $users = new usersMenus();
    $status = base64_encode(serialize($ini->_params));
    $pasmoinsaux = pasmoinsaux();
    if ($users->VMWARE_HOST) {
        $VMWARE_HOST = 1;
    } else {
        $VMWARE_HOST = 0;
    }
    shell_exec(LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.dmidecode.php");
    $dmidecode = base64_encode(@file_get_contents("/etc/artica-postfix/dmidecode.cache"));
    //SQUID
    if ($users->SQUID_INSTALLED) {
        $sock = new sockets();
        $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
        if (!is_numeric($SQUIDEnable)) {
            $SQUIDEnable = 1;
        }
        if ($SQUIDEnable == 1) {
            $SQUID_CACHES = base64_encode(serialize($unix->squid_get_cache_infos()));
        }
        if (is_array($SQUID_CACHES)) {
            $squid = new squidbee();
            $cacheconf = $squid->cache_list;
            $cacheconf[$squid->CACHE_PATH]["cache_type"] = $squid->CACHE_TYPE;
            $cacheconf[$squid->CACHE_PATH]["cache_size"] = $squid->CACHE_SIZE;
            $cacheconf[$squid->CACHE_PATH]["cache_dir_level1"] = 16;
            $cacheconf[$squid->CACHE_PATH]["cache_dir_level2"] = 256;
            events("Caches: " . count($cacheconf), __FILE__, __LINE__);
            $SQUID_CACHES_CONFIG = base64_encode(serialize($cacheconf));
        }
    }
    if ($users->SAMBA_INSTALLED) {
        _CheckSambaConfig();
    }
    if ($users->ZARAFA_INSTALLED) {
        if (is_file("/etc/artica-postfix/settings/Daemons/ZarafaLicenseInfos")) {
            $ZARAFA_LICENSE = @file_get_contents("/etc/artica-postfix/settings/Daemons/ZarafaLicenseInfos");
        } else {
            $ZARAFA_LICENSE = "Free edition";
        }
    }
    if (is_file("/etc/artica-postfix/zarafa-export.db")) {
        $ZARAFA_DB = @file_get_contents("/etc/artica-postfix/zarafa-export.db");
    }
    $body = $http->send("{$meta->ArticaMetaHostname}/lic.status.server.php", "post", array("DATAS" => $datasToSend, "STATUS" => $status, "MEMORIES" => $MEM_CACHE, "VERSION" => $users->ARTICA_VERSION, "DISTRI" => $users->LinuxDistriCode, "UPTIME" => getUptime(), "DISTRINAME" => $users->LinuxDistriFullName, "MAIN_PRODUCTS" => base64_encode(serialize(array("ZARAFA" => $users->ZARAFA_INSTALLED, "POSTFIX" => $users->POSTFIX_INSTALLED, "SQUID" => $users->SQUID_INSTALLED, "SAMBA" => $users->SAMBA_INSTALLED, "CYRUS" => $users->cyrus_imapd_installed, "OPENVPN" => $users->OPENVPN_INSTALLED))), "PROCESSES" => base64_encode($pasmoinsaux), "TOP_PROCESSES" => top10cpumem(), "NETS" => Networks(), "VMWARE_HOST" => $VMWARE_HOST, "SETTINGS_INC" => base64_encode(serialize(settings_inc())), "LOCAL_VERSIONS" => LocalVersions(), "VBOXGUESTS" => VirtualBoxList(), "APTCHECK" => APTCHECK(), "DMIDECODE" => $dmidecode, "SQUID_CACHES" => $SQUID_CACHES, "SQUID_CACHES_CONFIG" => $SQUID_CACHES_CONFIG, "OPENPORTS" => OpenPorts($meta->serial, $meta->uuid), "OPENVPN_CLIENTS_STATUS" => @file_get_contents("/usr/share/artica-postfix/ressources/logs/openvpn-clients.status"), "ZARAFA_DB" => $ZARAFA_DB, "ZARAFA_LICENSE" => $ZARAFA_LICENSE));
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    if (preg_match("#NOTIFY_DISCONNECT#is", $body)) {
        events("NOTIFY_DISCONNECT detected -> unregister_server()", __FUNCTION__, __FILE__, __LINE__);
        unregister_server();
        return;
    }
    if (preg_match("#NOTIFY_EXPORT_USERS#is", $body)) {
        events("NOTIFY_EXPORT_USERS -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_DOMAINS#is", $body)) {
        events("NOTIFY_EXPORT_DOMAINS -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all-domains", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-domains >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_OU#is", $body)) {
        events("NOTIFY_EXPORT_OU -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all-ou", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-ou >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_GROUPS#is", $body)) {
        events("NOTIFY_EXPORT_GROUPS -> {$nohup}{$EXEC_NICE}exec.artica.meta.users.php --export-all-groups", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-groups >/dev/null 2>&1 &");
    }
    if (preg_match("#NOTIFY_EXPORT_SETTINGS#is", $body)) {
        $cmd = $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-settings >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_SETTINGS -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_COMPUTERS#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-computers >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_SETTINGS -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_DNS_ENTRIES#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-dns >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_DNS_ENTRIES -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_GROUPWARES#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-groupwares >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_GROUPWARES -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#NOTIFY_EXPORT_FETCHMAIL_RULES#is", $body)) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-fetchmail-rules >/dev/null 2>&1 &";
        events("NOTIFY_EXPORT_FETCHMAIL_RULES -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (preg_match("#<TASKS>(.+?)</TASKS>#is", $body, $re)) {
        events("Save tasks to /etc/artica-postfix/artica-meta.tasks", __FUNCTION__, __FILE__, __LINE__);
        @file_put_contents("/etc/artica-postfix/artica-meta.tasks", $re[1]);
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.tasks.php >/dev/null 2>&1 &";
        events("TASKS ->{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    } else {
        events("No tasks ordered for me...", __FUNCTION__, __FILE__, __LINE__);
        @unlink("/etc/artica-postfix/artica-meta.tasks");
    }
    if (preg_match("#<HOST_CONF>(.+?)</HOST_CONF>#is", $body, $re)) {
        ParseMyConf($re[1]);
    } else {
        events("No configuration for me...", __FUNCTION__, __FILE__, __LINE__);
    }
    shell_exec($nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --socks >/dev/null 2>&1 &");
    if (users_queue()) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --user-queue >/dev/null 2>&1 &";
        events("users settings queue is not empty -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if (computer_queue()) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --computer-queue >/dev/null 2>&1 &";
        events("computer settings queue is not empty -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    if ($users->OPENVPN_INSTALLED) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-openvpn-logs >/dev/null 2>&1 &";
        events("OpenVpn is installed -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    $time_iptables = file_time_min("/etc/artica-postfix/artica.meta.iptables.time");
    if ($time_iptables > 180) {
        $cmd = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --iptables >/dev/null 2>&1 &";
        events("iptables -> {$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
        $cmd = $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-all-settings >/dev/null 2>&1 &";
        events("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        @unlink("/etc/artica-postfix/artica.meta.iptables.time");
        @file_put_contents("/etc/artica-postfix/artica.meta.iptables.time", "#");
    }
    $t2 = time();
    $time_duration = distanceOfTimeInWords($t1, $t2);
    events("Send status to {$meta->ArticaMetaHostname} DONE ({$time_duration})", __FUNCTION__, __FILE__, __LINE__);
}
Beispiel #17
0
function reload($aspid = false)
{
    $unix = new unix();
    $ln = $unix->find_program("ln");
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = @file_get_contents($pidfile);
    if (!$aspid) {
        if ($unix->process_exists($pid)) {
            echo "Reloading.....: " . date("H:i:s") . " [INIT]: c-icap service " . __FUNCTION__ . "() already running PID:{$pid}\n";
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $echo = $unix->find_program("echo");
    if (!is_running()) {
        echo "Reloading.....: " . date("H:i:s") . " [INIT]: c-icap service not running...\n";
        echo "Reloading.....: " . date("H:i:s") . " [INIT]: c-icap Starting C-ICAP service...\n";
        start(true);
        return;
    }
    $PID = PID_NUM();
    $PROCESS_TTL = $unix->PROCESS_TTL($PID);
    checkFilesAndSecurity();
    echo "Reloading.....: " . date("H:i:s") . " [INIT]: c-icap service running since {$PROCESS_TTL}Mn\n";
    shell_exec("{$echo} -n \"reconfigure\" > /var/run/c-icap/c-icap.ctl");
}