示例#1
0
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);
    $sock = new sockets();
    $ini = new Bs_IniHandler();
    echo "Reading session {$session} for ou=`{$ou}`\n";
    if ($ou == null) {
        echo "Failed, no such ou set....\n";
        die;
    }
    $ini->loadString($sock->GET_INFO($session));
    $filepath = "{$path}/{$ou}.gz";
    if (!is_file($filepath)) {
        echo "{$filepath} no such file";
    }
    echo "Uploading to https://{$ini->_params["CONF"]["servername"]}:{$ini->_params["CONF"]["port"]}\n";
    $uri = "https://{$ini->_params["CONF"]["servername"]}:{$ini->_params["CONF"]["port"]}/cyrus.murder.listener.php";
    $command = "?export-ou=yes&admin={$ini->_params["CONF"]["username"]}&pass={$ini->_params["CONF"]["password"]}&original-suffix={$ldap->suffix}";
    //lic.users.import.php
    $http = new httpget();
    $http->uploads["EXPORT-OU"] = "{$filepath}";
    $body = $http->send("https://{$ini->_params["CONF"]["servername"]}:{$ini->_params["CONF"]["port"]}/cyrus.murder.listener.php", "post", array("AUTH" => base64_encode(serialize($ini->_params["CONF"])), "ORG" => $ou));
    @unlink($filepath);
    echo $body;
}
示例#2
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__);
}
示例#3
0
function export_virtualbox_logs()
{
    $users = new usersMenus();
    $sock = new sockets();
    if (!$users->VIRTUALBOX_INSTALLED) {
        return;
    }
    $unix = new unix();
    $VBoxManage = $unix->find_program("VBoxManage");
    if ($VBoxManage == null) {
        if ($GLOBALS["VERBOSE"]) {
            echo "VBoxManage no such tool\n";
        }
        return;
    }
    $CacheDatas = unserialize(@file_get_contents("/etc/artica-postfix/vboxLogs.cache"));
    exec("{$VBoxManage} list -l vms 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#UUID:\\s+(.+)#", $line, $re)) {
            $uuid = $re[1];
        }
        if (preg_match("#Config file:\\s+(.+)#", $line, $re)) {
            $file = dirname(trim($re[1])) . "/Logs/VBox.log";
            if (is_file($file)) {
                $array[$uuid] = $file;
            }
            continue;
        }
    }
    if (!is_array($array)) {
        return;
    }
    $gzip = $unix->find_program("gzip");
    @mkdir("/tmp/gzip_vbox", 666, true);
    while (list($uuid, $filepath) = each($array)) {
        $filetime = filemtime($filepath);
        if ($filetime == $CacheDatas["{$filepath}"]) {
            continue;
        }
        $CacheDatas["{$filepath}"] = $filetime;
        $filepath_gzipped = "/tmp/gzip_vbox/{$uuid}.gz";
        if ($GLOBALS["VERBOSE"]) {
            echo "Compress {$filepath} to {$filepath_gzipped}\n";
        }
        shell_exec("{$gzip} -f -c \"{$filepath}\"  > \"{$filepath_gzipped}\"");
        if (is_file($filepath_gzipped)) {
            $gzipeds[] = "\"{$filepath_gzipped}\"";
        }
    }
    if (!is_array($gzipeds)) {
        return;
    }
    $cmd = "cd /tmp/gzip_vbox && tar -cjf VboxLogs.tar.gz * ";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    $http = new httpget();
    $meta = new artica_meta();
    $filesize = filesize("/tmp/gzip_vbox/VboxLogs.tar.gz") / 1024;
    if ($GLOBALS["VERBOSE"]) {
        echo "Send to Artica Meta (" . FormatBytes($filesize) . ")\n";
    }
    $http->uploads["VBOXGUEST_LOGS"] = "/tmp/gzip_vbox/VboxLogs.tar.gz";
    $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)) {
        return;
    } else {
        @file_put_contents("/etc/artica-postfix/vboxLogs.cache", serialize($CacheDatas));
    }
}
function OPENVPN_CONCENTRATEUR($value)
{
    $unix = new unix();
    $unzip = $unix->find_program("unzip");
    events("Decoding parameters", __FUNCTION__, __FILE__, __LINE__);
    $array = unserialize(base64_decode($value));
    $EXEC_NICE = EXEC_NICE();
    if (is_file("/usr/bin/nohup")) {
        $nohup = "/usr/bin/nohup ";
    }
    $reload_datas = $nohup . $EXEC_NICE . LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.users.php --export-openvpn-sites >/dev/null 2>&1 &";
    if (strlen($unzip) == 0) {
        events("Unable to stat unzip, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (unzip no such file)", null, "VPN");
        return true;
    }
    if (!is_array($array)) {
        events("Corrupted data, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (corrupted datas)", null, "VPN");
        return true;
    }
    $master = $array["MASTER"];
    $sitename = $array["SITENAME"];
    events("download configuration file for master:{$master} and site name: {$sitename}", __FUNCTION__, __FILE__, __LINE__);
    $meta = new artica_meta(true);
    $http = new httpget();
    $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY));
    $body = $http->send("{$meta->ArticaMetaHostname}/lic.query.server.php", "post", array("DATAS" => $datasToSend, "GET_OVPN_REMOTE_SITE" => "yes", "master_uuid" => "{$master}", "sitename" => "{$sitename}"));
    if (strlen($body) < 10) {
        events("Corrupted data after downloading, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (corrupted datas after download)", null, "VPN");
        return true;
    }
    @mkdir("/tmp/{$sitename}", 666, true);
    @file_put_contents("/tmp/{$sitename}/conf.zip", $body);
    shell_exec("{$unzip} -j -o /tmp/{$sitename}/conf.zip -d /tmp/{$sitename}/ >/tmp/{$sitename}/unzip.txt 2>&1");
    include_once "ressources/class.openvpn.inc";
    $openvpn = new openvpn();
    $handle = opendir("/tmp/{$sitename}");
    $f = false;
    while (false !== ($file = readdir($handle))) {
        if (preg_match("#(.+?).ovpn\$#", $file)) {
            if (!$openvpn->ImportConcentrateur("/tmp/{$sitename}/{$file}", $master)) {
                events("ImportConcentrateur() failed" . @implode("\n", $openvpn->events), __FUNCTION__, __FILE__, __LINE__);
                send_email_events("Failed to import concentrator parameters ()", @implode("\n", $openvpn->events), "VPN");
                return true;
            }
            $f = true;
        }
    }
    if (!$f) {
        events("Corrupted data after downloading, aborting", __FUNCTION__, __FILE__, __LINE__);
        send_email_events("Failed to import concentrator parameters (unable to find ovpn file after uncompress)", null, "VPN");
    }
    shell_exec($reload_datas);
    events("Restarting OpenVPN", __FUNCTION__, __FILE__, __LINE__);
    shell_exec("/etc/init.d/artica-postfix restart openvpn &");
    return true;
}
示例#5
0
function ParseEvents()
{
    ParseReboot();
    $unix = new unix();
    $path = "/var/log/artica-postfix/events";
    $f = new filesClasses();
    $hash = $f->DirListTable($path);
    if (!is_array($hash)) {
        return null;
    }
    $users = new usersMenus();
    $sock = new sockets();
    $ArticaMetaEnabled = $sock->GET_INFO("ArticaMetaEnabled");
    echo date('Y-m-d h:i:s') . " " . count($hash) . " file(s) notifications...\n";
    events(count($hash) . " file(s) notifications...");
    if (count($hash) == 0) {
        return;
    }
    if ($ArticaMetaEnabled == 1) {
        $meta = new artica_meta();
        $datasToSend = base64_encode(serialize($meta->GLOBAL_ARRAY));
        $ArticaMetaHostname = $meta->ArticaMetaHostname;
        events("ArticaMetaEnabled: \"{$ArticaMetaEnabled}\" -> ({$ArticaMetaHostname})");
    }
    $mysql = new mysql();
    while (list($num, $file) = each($hash)) {
        $text = null;
        $processname = null;
        $date = null;
        $context = null;
        $subject = null;
        $recipient = null;
        $FULL_PATH = "{$path}/{$file}";
        if ($unix->file_time_min($FULL_PATH) > 480) {
            @unlink($FULL_PATH);
            continue;
        }
        $bigtext = @file_get_contents($FULL_PATH);
        echo date('Y-m-d h:i:s') . " Parsing {$file} " . strlen($bigtext) . " bytes text\n";
        $ini = new Bs_IniHandler();
        if (preg_match("#<text>(.+?)</text>#is", $bigtext, $re)) {
            $text = $re[1];
            $bigtext = str_replace($re[0], '', $bigtext);
            $bigtext = str_replace("'", "`", $bigtext);
        }
        if (preg_match("#<attachedfiles>(.+?)</attachedfiles>#is", $bigtext, $re)) {
            $bigtext = str_replace($re[0], '', $bigtext);
            $files_text = addslashes($re[1]);
        }
        $ini->loadString($bigtext);
        $processname = $ini->_params["LOG"]["processname"];
        $date = $ini->_params["LOG"]["date"];
        $context = $ini->_params["LOG"]["context"];
        if ($context == "YTowOnt9") {
            $context = "system";
        }
        $subject = $ini->_params["LOG"]["subject"];
        $recipient = $ini->_params["LOG"]["recipient"];
        if (strlen($text) < 2) {
            $text = $ini->_params["LOG"]["text"];
        }
        $arrayToSend["context"] = $context;
        $arrayToSend["subject"] = $subject;
        $arrayToSend["text"] = $text;
        $arrayToSend["date"] = $date;
        echo date('Y-m-d h:i:s') . " Parsing subject {$subject} " . strlen($text) . " bytes text\n";
        writelogs("New notification: {$subject} (" . strlen($text) . " bytes) {$date}", __FUNCTION__, __FILE__, __LINE__);
        $event_id = time();
        //$text=addslashes($text);
        $text = str_replace("'", "`", $text);
        $subject = str_replace("'", "`", $subject);
        $text = addslashes($text);
        $subject = addslashes($subject);
        if ($subject == null) {
            if (strlen($text) > 5) {
                if (strpos($text, "\n") == 0) {
                    $subject = $text;
                } else {
                    $subject = substr($text, 0, 75) . "...";
                }
            }
        }
        if (strlen($subject) < 5) {
            writelogs("Warning New notification: Subject seems to be empty ! \"{$text}\" removing {$path}/{$file}", __FUNCTION__, __FILE__, __LINE__);
            @unlink("{$path}/{$file}");
            continue;
        }
        if (strpos($users->hostname, ".") > 0) {
            $ty = explode($users->hostname, ".");
            $users->hostname = $ty[0];
        }
        if (strlen($text) < 5) {
            $text = "No content body as been added for this notification";
        }
        $sql = "INSERT IGNORE INTO events (zDate,hostname,process,text,context,content,attached_files,recipient,event_id) VALUES(\n        \t'{$date}',\n        \t'{$users->hostname}',\n        \t'{$processname}',\n        \t'{$subject}',\n        \t'{$context}','{$text}','{$files_text}','{$recipient}','{$event_id}')";
        if (!$mysql->UseMysql) {
            $sql = "INSERT IGNORE INTO events (id,zDate,hostname,\n        \tprocess,text,context,content,attached_files,recipient,event_id) VALUES(\n        \t'{$event_id}','{$date}',\n        \t'{$users->hostname}',\n        \t'{$processname}',\n        \t'{$subject}',\n        \t'{$context}','{$text}','{$files_text}','{$recipient}','{$event_id}')";
        }
        events(date('Y-m-d h:i:s') . " run mysql query -> {$subject}");
        if (!$mysql->QUERY_SQL($sql, 'artica_events')) {
            events("Mysql error keep {$path}/{$file};");
            events("Fatal: {$mysql->mysql_error}", __FUNCTION__, __FILE__, __LINE__);
            if (preg_match("#Access denied for user.+?using password:#", $mysql->mysql_error)) {
                events("Access denied for user password: {$mysql->mysql_server}@{$mysql->mysql_admin}:{$mysql->mysql_password} detected");
                if ($mysql->mysql_server == "127.0.0.1" or $mysql->mysql_server == "localhost") {
                    $ldap = new clladp();
                    $unix = new unix();
                    $ldap->ldap_password = $unix->shellEscapeChars($ldap->ldap_password);
                    writelogs("Try to change the mysql password: /usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline root \"secret\"", __FUNCTION__, __FILE__, __LINE__);
                    exec("/usr/share/artica-postfix/bin/artica-install --change-mysqlroot --inline root \"secret\" 2>&1", $chroot);
                    writelogs("Chaning password="******"\n", $chroot), __FUNCTION__, __FILE__, __LINE__);
                    die;
                }
            }
            if (preg_match("#Unknown column#", $mysql->mysql_error)) {
                events("->BuildTables()");
                $mysql->BuildTables();
            }
            if (preg_match("#Unknown database#", $mysql->mysql_error)) {
                events("->BuildTables()");
                $mysql->BuildTables();
            }
            if (preg_match("#connect to local MySQL server through socket#", $mysql->mysql_error)) {
                shell_exec("/etc/init.d/artica-postfix start mysql &");
            }
            writelogs("{$sql}", __FUNCTION__, __FILE__, __LINE__);
            break;
        }
        unlink($path . '/' . $file);
        if ($ArticaMetaEnabled == 1) {
            $pidfile = "/etc/artica-postfix/pids/exec.artica.meta.php.SendStatus.pid";
            $sock = new sockets();
            $ArticaMetaPoolTimeMin = $sock->GET_INFO("ArticaMetaPoolTimeMin");
            if (!is_numeric($ArticaMetaPoolTimeMin)) {
                $ArticaMetaPoolTimeMin = 15;
            }
            if ($ArticaMetaPoolTimeMin < 2) {
                $ArticaMetaPoolTimeMin = 15;
            }
            $minutes = file_time_min($pidfile);
            if ($minutes < round($ArticaMetaPoolTimeMin / 2.5)) {
                $meta->events(basename($pidfile) . ":{$minutes}<" . round($ArticaMetaPoolTimeMin / 2.5) . "Mn, aborting", __FUNCTION__, __FILE__, __LINE__);
                return;
            }
            $http = new httpget();
            $meta->events("Send notification \"{$arrayToSend["subject"]}\" to Meta Server", __FUNCTION__, __FILE__, __LINE__);
            $metaconsole = $http->send("{$ArticaMetaHostname}/lic.status.notifs.php", "post", array("DATAS" => $datasToSend, "NOTIF" => base64_encode(serialize($arrayToSend))));
            events("META CONSOLE: {$metaconsole} aborting notifications");
            if ($metaconsole == "FAILED_CONNECT") {
                $meta->events("Result:\"{$metaconsole}\"", __FUNCTION__, __FILE__, __LINE__);
                return;
            }
            if (!is_file("/etc/artica-postfix/artica-meta.tasks")) {
                if (preg_match("#<TASKS>(.+?)</TASKS>#is", $metaconsole, $re)) {
                    $meta->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 = LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.artica.meta.tasks.php >/dev/null 2>&1 &";
                    $meta->events("TASKS ->{$cmd}", __FUNCTION__, __FILE__, __LINE__);
                    shell_exec($cmd);
                }
            }
        }
        $text = addslashes($text);
        $context = addslashes($context);
        $subject = addslashes($subject);
    }
    if (count($hash) > 0) {
        events(count($hash) . " events queue parsed...");
    }
    if ($ArticaMetaEnabled == 1) {
        if (is_file("/etc/artica-postfix/artica-meta.tasks")) {
            $NICE = EXEC_NICE();
            shell_exec($NICE . LOCATE_PHP5_BIN2() . " " . dirname(__FILE__) . "/exec.artica.meta.tasks.php &");
        }
    }
}