示例#1
0
function amavis_logger($fullpath)
{
    $q = new mysql();
    $ini = new iniFrameWork($fullpath);
    $message_id = $ini->_params["TIME"]["message-id"];
    $time_amavis = $ini->_params["TIME"]["time_amavis"];
    $smtp_sender = $ini->_params["TIME"]["server_from"];
    $mailfrom = $ini->_params["TIME"]["mailfrom"];
    $mailto = $ini->_params["TIME"]["mailto"];
    $Country = $ini->_params["TIME"]["Country"];
    $Region = $ini->_params["TIME"]["Region"];
    $City = $ini->_params["TIME"]["City"];
    $kas = $ini->_params["TIME"]["kas"];
    $banned = $ini->_params["TIME"]["banned"];
    $infected = $ini->_params["TIME"]["infected"];
    $spammy = $ini->_params["TIME"]["spammy"];
    $spam = $ini->_params["TIME"]["spam"];
    $blacklisted = $ini->_params["TIME"]["blacklisted"];
    $whitelisted = $ini->_params["TIME"]["whitelisted"];
    $size = $ini->_params["TIME"]["size"];
    $subject = trim($ini->_params["TIME"]["subject"]);
    events("amavis_logger():: " . basename($fullpath) . " ({$message_id}) from=<{$mailfrom}> to=<{$mailto}>");
    $Region = trim(str_replace("'", '`', $Region));
    $Country = trim(str_replace("'", '`', $Country));
    $City = trim(str_replace("'", '`', $City));
    if ($Country == null) {
        $array_geo = GeoIP($smtp_sender);
        $Country = $array_geo[0];
        $City = $array_geo[1];
        $City = addslashes($City);
        $Country = addslashes($Country);
    }
    if (preg_match('#(.+?)@(.+)#', $mailfrom, $re)) {
        $domain_from = $re[2];
    }
    if (!is_numeric($whitelisted)) {
        $whitelisted = 0;
    }
    if (!is_numeric($blacklisted)) {
        $blacklisted = 0;
    }
    if (!is_numeric($kas)) {
        $kas = 0;
    }
    if (!is_numeric($banned)) {
        $banned = 0;
    }
    if (!is_numeric($infected)) {
        $infected = 0;
    }
    if (!is_numeric($spammy)) {
        $spammy = 0;
    }
    if (!is_numeric($spam)) {
        $spam = 0;
    }
    if (!is_numeric($size)) {
        $size = 0;
    }
    $mailto = str_replace("'", "", $mailto);
    $mailfrom = str_replace("'", '', $mailfrom);
    $mailto = $mailto . ",";
    $mailto_array = explode(",", $mailto);
    if (!is_array($mailto_array)) {
        return null;
    }
    //mb_internal_encoding("UTF-8");
    //$subject = mb_decode_mimeheader($subject);
    events("amavis_logger():: Delete id <{$message_id}> in mysql");
    if ($message_id != null) {
        deleteid_from_messageid($message_id, $q);
    }
    if ($message_id == null) {
        $message_id = md5($ini->toString());
    }
    events("amavis_logger():: Start loop for Recipients number=" . count($mailto_array) . " id=<{$message_id}>");
    $bounce_error = null;
    if ($bounce_error == null) {
        if ($infected == 1) {
            $bounce_error = "INFECTED";
        }
    }
    if ($bounce_error == null) {
        if ($banned == 1) {
            $bounce_error = "BANNED";
        }
    }
    if ($bounce_error == null) {
        if ($spammy == 1) {
            $bounce_error = "SPAM";
        }
    }
    if ($bounce_error == null) {
        if ($spam == 1) {
            $bounce_error = "SPAM";
        }
    }
    if ($bounce_error == null) {
        if ($blacklisted == 1) {
            $bounce_error = "BLACKLISTED";
        }
    }
    if ($bounce_error == null) {
        if ($whitelisted == 1) {
            $bounce_error = "WHITELISTED";
        }
    }
    if ($bounce_error == null) {
        if ($kas > 90) {
            $bounce_error = "KAS3";
        }
    }
    if ($bounce_error == null) {
        $bounce_error = "PASS";
    }
    $prefix = "INSERT INTO amavis_event (`from`,`from_domain`,`to`,`to_domain`,`subject`,`size`,`bounce_error`,`country`,`city`,`zDate`,`ipaddr`) VALUES";
    $subject = addslashes($subject);
    $inserted_number = 0;
    while (list($num, $destataire) = each($mailto_array)) {
        $destataire = trim($destataire);
        if ($message_id == null) {
            continue;
        }
        if ($destataire == null) {
            continue;
        }
        if (preg_match('#(.+?)@(.+)#', $destataire, $re)) {
            $domain_to = $re[2];
        }
        $inserted_number++;
        events("amavis_logger():: {$time_amavis} {$message_id} rcpt=<{$destataire}> From=<{$mailfrom}> {$bounce_error} Geo:{$Country}/{$City}");
        $f[] = "('{$mailfrom}','{$domain_from}','{$destataire}','{$domain_to}','{$subject}','{$size}','{$bounce_error}','{$Country}','{$City}','{$time_amavis}','{$smtp_sender}')";
    }
    $sql = $prefix . " " . @implode(",", $f);
    $q->QUERY_SQL($sql, "artica_events");
    if (!$q->ok) {
        events("amavis_logger():: FAILED {$sql}");
        return null;
    }
    events("amavis_logger():: DELETE {$fullpath}");
    if (!@unlink("{$fullpath}")) {
        events("amavis_logger():: WARNING UNABLE TO DELETE " . basename($fullpath));
    }
}
示例#2
0
function mysql_events()
{
    $instance_id = $_GET["instance-id"];
    if (!is_numeric($instance_id)) {
        $instance_id = 0;
    }
    $file = "/var/run/mysqld/mysqld.err";
    if ($instance_id > 0) {
        $ini = new iniFrameWork();
        $ini->loadFile("/etc/mysql-multi.cnf");
        $file = $ini->get("mysqld{$instance_id}", "log_error");
    }
    $unix = new unix();
    $tail = $unix->find_program("tail");
    $results = array();
    if ($instance_id == 0) {
        if (is_file("/var/lib/mysql/mysqld.err")) {
            $cmd = "{$tail} -n 300 /var/lib/mysql/mysqld.err 2>&1";
            writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
            exec($cmd, $results);
        }
        if (is_file("/var/run/mysqld/mysqld.err")) {
            $cmd = "{$tail} -n 300 /var/run/mysqld/mysqld.err 2>&1";
            writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
            exec($cmd, $results);
        }
    } else {
        if (is_file($file)) {
            $cmd = "{$tail} -n 300 /var/run/mysqld/mysqld.err 2>&1";
            writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
            exec($cmd, $results);
        }
    }
    if (count($results) == 0) {
        $datas = base64_encode(serialize(array("{error_no_datas}")));
        echo "<articadatascgi>{$datas}</articadatascgi>";
        return;
    }
    $datas = base64_encode(serialize($results));
    echo "<articadatascgi>{$datas}</articadatascgi>";
}
示例#3
0
function hamachi_status()
{
    exec("/usr/share/artica-postfix/bin/artica-install --hamachi-status", $rr);
    $ini = new iniFrameWork();
    $ini->loadString(implode("\n", $rr));
    echo "<articadatascgi>" . base64_encode(serialize($ini->_params)) . "</articadatascgi>";
}
示例#4
0
function nightly()
{
    @mkdir("/var/log/artica-postfix", 0755, true);
    $GLOBALS["MasterIndexFile"] = "/usr/share/artica-postfix/ressources/index.ini";
    $unix = new unix();
    $sock = new sockets();
    $autoinstall = true;
    $timefile = "/etc/artica-postfix/croned.1/nightly";
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
    $pid = @file_get_contents($pidfile);
    $kill = $unix->find_program("kill");
    $tmpdir = $unix->TEMP_DIR();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        echo "Starting......: " . date("H:i:s") . " nightly build already executed PID: {$pid} since {$time}Mn\n";
        system_admin_events("nightly build already executed PID: {$pid} since {$time}Mn", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        if ($time < 120) {
            if (!$GLOBALS["FORCE"]) {
                die;
            }
        }
        unix_system_kill_force($pid);
    }
    $mypid = getmypid();
    @file_put_contents($pidfile, $mypid);
    $EnableScheduleUpdates = $sock->GET_INFO("EnableScheduleUpdates");
    if (!is_numeric($EnableScheduleUpdates)) {
        $EnableScheduleUpdates = 0;
    }
    if ($GLOBALS["FORCE"]) {
        _artica_update_event(1, "Update task pid {$mypid} is forced by an human.", null, __FILE__, __LINE__);
    }
    if ($EnableScheduleUpdates == 1) {
        if (!$GLOBALS["FORCE"]) {
            if (!$GLOBALS["BYCRON"]) {
                _artica_update_event(2, "Operation must be only executed by scheduler ( use --force to by pass)", null, __FILE__, __LINE__);
                @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
                return;
            }
        }
    }
    $ini = new iniFrameWork();
    $ini->loadFile('/etc/artica-postfix/artica-update.conf');
    if (!isset($ini->_params["AUTOUPDATE"]["enabled"])) {
        $ini->_params["AUTOUPDATE"]["enabled"] = "yes";
    }
    if (trim($ini->_params["AUTOUPDATE"]["enabled"]) == null) {
        $ini->_params["AUTOUPDATE"]["enabled"] = "yes";
    }
    if ($ini->_params["AUTOUPDATE"]["enabled"] == null) {
        $ini->_params["AUTOUPDATE"]["enabled"] = "yes";
    }
    if (trim($ini->_params["AUTOUPDATE"]["uri"]) == null) {
        $ini->_params["AUTOUPDATE"]["uri"] = "http://www.articatech.net/auto.update.php";
    }
    if ($ini->_params["AUTOUPDATE"]["enabled"] == 1) {
        $ini->_params["AUTOUPDATE"]["enabled"] = 'yes';
    }
    if (!is_numeric(trim($ini->_params["AUTOUPDATE"]["CheckEveryMinutes"]))) {
        $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"] = 60;
    }
    if ($ini->_params["AUTOUPDATE"]["enabled"] != 'yes') {
        echo "Starting......: " . date("H:i:s") . " Artica Update feature is disabled (enabled = {$ini->_params["AUTOUPDATE"]["enabled"]} )\n";
        return;
    }
    $CheckEveryMinutes = $ini->_params["AUTOUPDATE"]["CheckEveryMinutes"];
    $uri = $ini->_params["AUTOUPDATE"]["uri"];
    $arrayURI = parse_url($uri);
    $MAIN_URI = "{$arrayURI["scheme"]}://{$arrayURI["host"]}";
    $MAIN_URI = str_replace("www.artica.fr", "www.articatech.net", $MAIN_URI);
    if (!$GLOBALS["FORCE"]) {
        if ($EnableScheduleUpdates == 0) {
            if ($unix->file_time_min($timefile) < $CheckEveryMinutes) {
                echo "Starting......: " . date("H:i:s") . " update feature (too short time, require {$CheckEveryMinutes}mn)\n";
                @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
                return;
            }
        }
    }
    @unlink($timefile);
    @file_put_contents($timefile, time());
    if ($GLOBALS["FORCE"]) {
        if (is_file("/root/artica-latest.tgz")) {
            echo "Starting......: " . date("H:i:s") . " Installing old downloaded package\n";
            if (install_package("/root/artica-latest.tgz")) {
                return;
            }
        }
    }
    // ----------------------- LANCEMENT ------------------------------------------------------------------------------
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    if ($EnableArticaMetaClient == 1) {
        echo "Starting......: " . date("H:i:s") . " Nightly builds using Artica Meta console\n";
        system("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --artica-updates >/dev/null 2>&1 &");
        die;
    }
    echo "Starting......: " . date("H:i:s") . " Nightly builds checking an official release first\n";
    if (update_release()) {
        return;
    }
    $nightly = trim(strtolower($ini->_params["AUTOUPDATE"]["nightlybuild"]));
    if ($nightly == 1) {
        $nightly = "yes";
    }
    if ($GLOBALS["FORCE"]) {
        $nightly = "yes";
    }
    if ($GLOBALS["FORCE_NIGHTLY"]) {
        $nightly = "yes";
    }
    if ($nightly != 'yes') {
        echo "Starting......: " . date("H:i:s") . " Nightly builds feature is disabled [{$nightly}]\n";
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/download_progress", 100);
        return;
    }
    if ($ini->_params["AUTOUPDATE"]["autoinstall"] == 1) {
        $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes";
    }
    if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == null) {
        $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes";
    }
    if ($ini->_params["AUTOUPDATE"]["autoinstall"] != "yes") {
        $autoinstall = false;
    }
    @file_put_contents("/usr/share/artica-postfix/download_progress", 0);
    $MyCurrentVersion = GetCurrentVersion();
    echo "Starting......: " . date("H:i:s") . " Current version: {$MyCurrentVersion}\n";
    $Lastest = trim(strtolower($GLOBALS["lastest-nightly"]));
    echo "Starting......: " . date("H:i:s") . " Nightly builds version \"{$Lastest}\" on repository\n";
    $MyNextVersion = intval(str_replace(".", "", $Lastest));
    echo "Starting......: " . date("H:i:s") . " nightly builds Cur:{$MyCurrentVersion}, Next:{$MyNextVersion}\n";
    if ($MyNextVersion == $MyCurrentVersion) {
        echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Same version\"\n";
        @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
        return;
    }
    if ($MyCurrentVersion > $MyNextVersion) {
        echo "Starting......: " . date("H:i:s") . " nightly builds {$MyCurrentVersion}/{$MyNextVersion} \"Up to date - Most updated\"\n";
        @file_put_contents("/usr/share/artica-postfix/download_progress", 100);
        return;
    }
    $t1 = time();
    _artica_update_event(2, "nightly builds Downloading new version {$Lastest}", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " nightly builds Downloading new version {$Lastest}, please wait\n";
    events("Downloading new version {$Lastest}");
    $uri = "{$MAIN_URI}/nightbuilds/artica-{$Lastest}.tgz";
    $ArticaFileTemp = "{$tmpdir}/{$Lastest}/artica-{$Lastest}.tgz";
    @mkdir("{$tmpdir}/{$Lastest}", 0755, true);
    $curl = new ccurl($uri);
    $curl->Timeout = 2400;
    $curl->WriteProgress = true;
    $curl->ProgressFunction = "nightly_progress";
    $t = time();
    if (!$curl->GetFile($ArticaFileTemp)) {
        _artica_update_event(0, "nightly builds Unable to download latest nightly build with error {$curl->error}", null, __FILE__, __LINE__);
        events("Unable to download latest nightly build with error {$curl->error}");
        system_admin_events("Unable to download latest nightly build with error {$curl->error}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
        @unlink($ArticaFileTemp);
        return;
    }
    $took = $unix->distanceOfTimeInWords($t, time(), true);
    _artica_update_event(2, "artica-{$Lastest}.tgz download, took {$took}", null, __FILE__, __LINE__);
    system_admin_events("artica-{$Lastest}.tgz download, took {$took}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
    events("artica-{$Lastest}.tgz download, took {$took}");
    $size = @filesize($ArticaFileTemp);
    $size = FormatBytes($size / 1024, true);
    ArticaMeta_nightly($ArticaFileTemp);
    echo "Starting......: " . date("H:i:s") . " nightly builds took {$took}\n";
    if (!$GLOBALS["FORCE"]) {
        if ($autoinstall == false) {
            _artica_update_event(2, "artica-latest.tgz will be stored in /root", null, __FILE__, __LINE__);
            @copy("{$ArticaFileTemp}", "/root/artica-latest.tgz");
            @unlink($ArticaFileTemp);
            _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size}) waiting order", null, __FILE__, __LINE__);
            system_admin_events("New Artica update v.{$Lastest} waiting your order", __FUNCTION__, __FILE__, __LINE__, "artica-update");
            return;
        } else {
        }
    }
    events("Now, installing the newest version in {$ArticaFileTemp} package...");
    $size = @filesize($ArticaFileTemp);
    $size = FormatBytes($size / 1024, true);
    if (!install_package($ArticaFileTemp, $Lastest)) {
        events("Install package Failed...");
        return false;
    }
    events("New Artica update v.{$Lastest}");
    _artica_update_event(1, "Nightly builds New Artica update v.{$Lastest} ({$size})", null, __FILE__, __LINE__);
    system_admin_events("New Artica update v.{$Lastest}", __FUNCTION__, __FILE__, __LINE__, "artica-update");
}
示例#5
0
function instance_delete()
{
    $instance_id = $_GET["instance_id"];
    $pidfile = "/var/run/mysqld/mysqld{$instance_id}.pid";
    $ini = new iniFrameWork("/etc/mysql-multi.cnf");
    $database_path = $ini->get("mysqld{$instance_id}", "datadir");
    $unix = new unix();
    if (is_file("/usr/sbin/mysqlmulti-start{$instance_id}")) {
        @unlink("/usr/sbin/mysqlmulti-start{$instance_id}");
    }
    if (is_file("/usr/sbin/mysqlmulti-stop{$instance_id}")) {
        @unlink("/usr/sbin/mysqlmulti-stop{$instance_id}");
    }
    if (is_file("/etc/monit/conf.d/mysqlmulti{$instance_id}.monitrc")) {
        @unlink("/etc/monit/conf.d/mysqlmulti{$instance_id}.monitrc");
    }
    $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --monit-check");
    $rm = $unix->find_program("rm");
    $kill = $unix->find_program("kill");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $pid = $unix->get_pid_from_file($pidfile);
    writelogs_framework("{$pidfile} -> {$pid}", __FUNCTION__, __FILE__, __LINE__);
    if ($unix->process_exists($pid)) {
        $cmd = "{$kill} -9 {$pid}";
        writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    writelogs_framework("database path -> '{$database_path}'", __FUNCTION__, __FILE__, __LINE__);
    if (is_dir($database_path)) {
        $cmd = "{$rm} -rf \"{$database_path}\" 2>&1";
        writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
        shell_exec($cmd);
    }
    $cmd = "{$php5} /usr/share/artica-postfix/exec.mysql.build.php --multi";
    writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__);
    shell_exec($cmd);
}
示例#6
0
function amavis_watchdog_load_conf(){
if(is_file("/etc/artica-postfix/settings/Daemons/AmavisGlobalConfiguration")){
			$ini=new iniFrameWork();
			$ini->loadFile("/etc/artica-postfix/settings/Daemons/AmavisGlobalConfiguration");
			$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]=$ini->_params["BEHAVIORS"]["max_servers"];
			$GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"]=$ini->_params["BEHAVIORS"]["child_timeout"];
			
		}	
		$GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]=filemtime("/usr/local/etc/amavisd.conf");
		
		events("/usr/local/etc/amavisd.conf: time:{$GLOBALS["AMAVIS_WATCHDOG_CONF_TIME"]}",__FUNCTION__,__LINE__);
		events("max_servers: {$GLOBALS["AMAVIS_WATCHDOG_MAX_SERVERS"]}",__FUNCTION__,__LINE__);
		events("child_timeout: {$GLOBALS["AMAVIS_WATCHDOG_CHILD_TIMEOUT"]}",__FUNCTION__,__LINE__);
}
示例#7
0
function master_index()
{
    @unlink($GLOBALS["MasterIndexFile"]);
    $ini = new iniFrameWork();
    $ini->loadFile('/etc/artica-postfix/artica-update.conf');
    if (trim($ini->_params["AUTOUPDATE"]["autoinstall"]) == null) {
        $ini->_params["AUTOUPDATE"]["autoinstall"] = "yes";
    }
    if ($ini->_params["AUTOUPDATE"]["autoinstall"] != "yes") {
        $autoinstall = false;
    }
    $uri = $ini->_params["AUTOUPDATE"]["uri"];
    $arrayURI = parse_url($uri);
    $MAIN_URI = "{$arrayURI["scheme"]}://{$arrayURI["host"]}";
    echo "Starting......: " . date("H:i:s") . " Refreshing index file...\n";
    $curl = new ccurl("{$uri}?time=" . time());
    if (!$curl->GetFile($GLOBALS["MasterIndexFile"])) {
        _artica_update_event(0, "Error {$curl->error}", null, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " Error {$curl->error_num};{$curl->error}, Try direct\n";
        if (!$GLOBALS["NOT_FORCE_PROXY"]) {
            echo "Starting......: " . date("H:i:s") . " FATAL: Unable to download index file, try in direct mode\n";
            $GLOBALS["NOT_FORCE_PROXY"] = true;
            return master_index();
        }
        if ($curl->error == "{CURLE_COULDNT_RESOLVE_HOST}") {
            if ($arrayURI["host"] == "www.artica.fr") {
                if (!$GLOBALS["CHANGED"]) {
                    echo "Starting......: " . date("H:i:s") . " trying www.articatech.net\n";
                    $ini->_params["AUTOUPDATE"]["uri"] = "http://www.articatech.net/auto.update.php";
                    $ini->saveFile("/etc/artica-postfix/artica-update.conf");
                    $GLOBALS["CHANGED"] = true;
                    return master_index();
                }
            }
        }
        return;
    }
    if (!is_file($GLOBALS["MasterIndexFile"])) {
        echo "Starting......: " . date("H:i:s") . " {$GLOBALS["MasterIndexFile"]} no such file...\n";
        return;
    }
    return true;
}
示例#8
0
function multi_start($ID)
{
    $q = new mysqlserver();
    $GLOBALS["MULTI"] = true;
    $GLOBALS["SHOWLOGONLYFOR"] = $ID;
    multi_monit($ID);
    multi_create_cache();
    $q->mysql_multi();
    echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID}..\n";
    $pidfile = "/var/run/mysqld/mysqld{$ID}.pid";
    echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} PID:{$pidfile}..\n";
    $unix = new unix();
    if ($unix->process_exists($unix->get_pid_from_file($pidfile))) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} already running...\n";
        return;
    }
    $chmod = $unix->find_program("chmod");
    $ini = new iniFrameWork("/etc/mysql-multi.cnf");
    $database_path = $ini->get("mysqld{$ID}", "datadir");
    if (is_file("{$database_path}/error.log")) {
        @unlink("{$database_path}/error.log");
    }
    echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} database={$database_path}\n";
    $cmd = "{$chmod} 755 {$database_path}";
    exec($cmd, $results);
    $mysqld_multi = $unix->find_program("mysqld_multi");
    $cmd = "{$mysqld_multi} --defaults-file=/etc/mysql-multi.cnf start {$ID} --verbose --no-log 2>&1";
    if (is_file("{$database_path}/maria_log_control")) {
        @unlink("{$database_path}/maria_log_control");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    exec($cmd, $results);
    while (list($index, $ligne) = each($results)) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} {$ligne}\n";
    }
    for ($i = 0; $i < 4; $i++) {
        sleep(1);
        if ($unix->process_exists(multi_get_pid($ID))) {
            sleep(1);
            break;
        }
    }
    if (!$unix->process_exists(multi_get_pid($ID))) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} failed..\n";
    } else {
        $q = new mysql_multi($ID);
        $q->QUERY_SQL_NO_BASE("create user 'mysqld_multi'@'127.0.0.1' identified by 'mysqld_multi'");
        $q->QUERY_SQL_NO_BASE("create user 'mysqld_multi'@'localhost' identified by 'mysqld_multi'");
        $q->QUERY_SQL_NO_BASE("create user 'grant shutdown on *.* to mysqld_multi'");
        $q = new mysqlserver_multi($ID);
        $q->setssl();
    }
    if (is_file("{$database_path}/error.log")) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} {$database_path}/error.log\n";
        $f = explode("\n", @file_get_contents("{$database_path}/error.log"));
        while (list($index, $ligne) = each($f)) {
            if (trim($ligne) == null) {
                continue;
            }
            if (preg_match("#^[0-9]+\\s+[0-9\\:]+\\s+(.+)#", $ligne, $re)) {
                $ligne = $re[1];
            }
            echo "Starting......: " . date("H:i:s") . " {$ligne}\n";
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} {$database_path}/error.log no such file\n";
    }
}
function artica_updates_scheduled($aspid = false)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    if (!$aspid) {
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " artica_updates_scheduled already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 120) {
                if (!$GLOBALS["FORCE"]) {
                    die;
                }
            }
            unix_system_kill_force($pid);
        }
    } else {
        $pidTimeEx = $unix->file_time_min($pidTime);
        if ($pidTimeEx < 61) {
            events("Skip Artica updates, current {$pidTimeEx}Mn, require 60mn ", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
    }
    @chdir("/root");
    @file_put_contents($pidfile, getmypid());
    @unlink($pidTime);
    @file_put_contents($pidTime, time());
    $tmpdir = $unix->TEMP_DIR();
    $meta = new artica_meta();
    $ARRAY = array();
    $sock = new sockets();
    $MetaClientAutoUpdate = intval($sock->GET_INFO("MetaClientAutoUpdate"));
    $ini = new iniFrameWork();
    $ini->loadFile('/etc/artica-postfix/artica-update.conf');
    $nightly = trim(strtolower($ini->_params["AUTOUPDATE"]["nightlybuild"]));
    if ($nightly == 1) {
        $nightly = "yes";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Update nightly ? `{$nightly}`\n";
    }
    $curl = $meta->buildCurl("/meta-updates/releases/");
    if (!$curl->GetFile("{$tmpdir}/releases.txt")) {
        events("Fatal: /meta-updates/releases/releases.txt {$curl->errors}", __FUNCTION__, __FILE__, __LINE__);
        artica_update_event(0, "Failed Downloading /meta-updates/releases/", @implode("\n", $curl->errors), __FILE__, __LINE__);
        meta_admin_mysql(0, "Failed Downloading /meta-updates/releases/", @implode("\n", $curl->errors), __FILE__, __LINE__);
        return false;
    }
    $data = @file_get_contents("{$tmpdir}/releases.txt");
    $f = explode("\n", $data);
    @unlink("{$tmpdir}/releases.txt");
    while (list($index, $ligne) = each($f)) {
        if (!preg_match("#href.*?artica-([0-9\\.]+)\\.tgz#", $ligne, $re)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Not Found {$ligne}\n";
            }
            continue;
        }
        $verbin = intval(str_replace(".", "", $re[1]));
        events("Found : v{$verbin} /meta-updates/releases/artica-{$re[1]}.tgz", __FUNCTION__, __FILE__, __LINE__);
        $ARRAY[$verbin] = "/meta-updates/releases/artica-{$re[1]}.tgz";
    }
    if ($MetaClientAutoUpdate == 1) {
        $nightly = "yes";
    }
    if ($nightly == "yes") {
        $curl = $meta->buildCurl("/meta-updates/nightlys/");
        if (!$curl->GetFile("{$tmpdir}/nightlys.txt")) {
            artica_update_event(0, "Failed Downloading /meta-updates/nightlys/", @implode("\n", $curl->errors), __FILE__, __LINE__);
            meta_admin_mysql(0, "Failed Downloading /meta-updates/nightlys/", @implode("\n", $curl->errors), __FILE__, __LINE__);
        } else {
            $data = @file_get_contents("{$tmpdir}/nightlys.txt");
            $f = explode("\n", $data);
            @unlink("{$tmpdir}/nightlys.txt");
            while (list($index, $ligne) = each($f)) {
                if (!preg_match("#href.*?artica-([0-9\\.]+)\\.tgz#", $ligne, $re)) {
                    if ($GLOBALS["VERBOSE"]) {
                        echo "Not Found {$ligne}\n";
                    }
                    continue;
                }
                $verbin = intval(str_replace(".", "", $re[1]));
                events("Found : v{$verbin} /meta-updates/nightlys/artica-{$re[1]}.tgz", __FUNCTION__, __FILE__, __LINE__);
                $ARRAY[$verbin] = "/meta-updates/nightlys/artica-{$re[1]}.tgz";
            }
        }
    }
    krsort($ARRAY);
    while (list($index, $ligne) = each($ARRAY)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Found v.{$index} / {$ligne}\n";
        }
        $TA[] = $index;
        $TZ[] = $ligne;
    }
    $LASTVER = $TA[0];
    $LASTFILE = $TZ[0];
    $MYVERSION_TEXT = trim(@file_get_contents("/usr/share/artica-postfix/VERSION"));
    $MYVERSION = intval(str_replace(".", "", $MYVERSION_TEXT));
    events("Last version: {$LASTVER} -> {$LASTFILE} against {$MYVERSION}", __FUNCTION__, __FILE__, __LINE__);
    if ($MYVERSION > $LASTVER) {
        events("Most updated, aborting", __FUNCTION__, __FILE__, __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "Most updated, aborting\n";
        }
        return;
    }
    if ($MYVERSION == $LASTVER) {
        events("Most updated, aborting", __FUNCTION__, __FILE__, __LINE__);
        if ($GLOBALS["VERBOSE"]) {
            echo "Most updated, aborting\n";
        }
        return;
    }
    $curl = $meta->buildCurl($LASTFILE);
    $tmpfile = "{$tmpdir}/" . basename($LASTFILE);
    if (!$curl->GetFile($tmpfile)) {
        events("Failed Downloading {$LASTFILE} {$curl->errors}", __FUNCTION__, __FILE__, __LINE__);
        artica_update_event(0, "Failed Downloading {$LASTFILE}", @implode("\n", $curl->errors), __FILE__, __LINE__);
        meta_admin_mysql(0, "Failed Downloading {$LASTFILE}", @implode("\n", $curl->errors), __FILE__, __LINE__);
        @unlink($tmpfile);
        return;
    }
    if (!$unix->TARGZ_TEST_CONTAINER($tmpfile)) {
        artica_update_event(0, "Failed {$tmpfile} corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__);
        meta_admin_mysql(0, "Failed {$tmpfile} corrupted package", @implode("\n", $curl->errors), __FILE__, __LINE__);
        @unlink($tmpfile);
        return false;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Extracting {$tmpfile}\n";
    }
    $tar = $unix->find_program("tar");
    shell_exec("{$tar} xf {$tmpfile} -C /usr/share/");
    @unlink($tmpfile);
    $MYVERSION_TEXT = trim(@file_get_contents("/usr/share/artica-postfix/VERSION"));
    $php = $unix->LOCATE_PHP5_BIN();
    shell_exec("{$php} /usr/share/artica-postfix/exec.nightly.php --restart-services >/dev/null 2>&1");
    artica_update_event(2, "Success update Artica to {$MYVERSION_TEXT}", null, __FILE__, __LINE__);
    meta_admin_mysql(2, "Success update Artica to {$MYVERSION_TEXT}", null, __FILE__, __LINE__);
}