Esempio n. 1
0
}
$hostStats['external_ip'] = getExternalIP();
if ($hostStats['virtual'] == 'xen0') {
    $domUs = parseXenDomUs();
    $hostStats['domUs'] = $domUs;
}
$vhosts = parseVhosts();
if (!empty($vhosts[0])) {
    $hostStats['vhosts'] = $vhosts;
}
$hostStats['disk']['partitions'] = partitionInfo();
if ($hostStats['virtual'] == 'xen0') {
    $hostStats['disk']['physical'] = physicalDiskInfo();
}
$hostStats['software_updates'] = softwareUpdates($hostStats['lsbdistid']);
$hostStats['uptime'] = getUptime();
function softwareUpdates($operatingsystem)
{
    $updates = array();
    if ($operatingsystem == 'Debian') {
        shell_exec("apt-get -qq update");
        $aptget = trim(shell_exec("/usr/bin/apt-get -q -y --allow-unauthenticated -s upgrade | /bin/grep ^Inst | /usr/bin/cut -d\\  -f2 | /usr/bin/sort"));
        $updates = !empty($aptget) ? explode("\n", $aptget) : array();
    }
    return $updates;
}
/**
 * Returns uptime in seconds
 *
 * @return int
 * @author Henrik Farre <*****@*****.**>
Esempio n. 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__);
}
Esempio n. 3
0
                $time = ", " . $time;
            }
            if ($days > 0) {
                $time = $days[0] . " D" . $time;
            }
        } else {
            $time = false;
        }
    } else {
        $time = false;
    }
    return $time;
}
function getUserCount()
{
    return exec("cat /etc/passwd | wc -l");
}
$finalResponse = json_encode(array("CPU_Usage" => getCPUUsage(), "RAM_Usage" => getRAMUsage(), "Uptime" => getUptime(), "Free_Disk_Space" => getFreeDiskSpace(), "ConnectionCount" => getConnectionCount(), "UserCount" => getUserCount()));
switch ($clientRequest) {
    case "status":
        echo $finalResponse;
        break;
    default:
        echo "No Request Given!";
        break;
}
?>