2014-06-18 04:11:11 -04:00
|
|
|
<?php
|
2015-07-07 09:57:41 -04:00
|
|
|
require '../autoload.php';
|
2016-01-08 08:46:38 -05:00
|
|
|
date_default_timezone_set(@date_default_timezone_get());
|
2014-06-18 04:11:11 -04:00
|
|
|
|
|
|
|
// Hostname
|
|
|
|
$hostname = php_uname('n');
|
|
|
|
|
|
|
|
// OS
|
2017-03-20 11:20:07 -04:00
|
|
|
if (!file_exists('/usr/bin/lsb_release') || !($os = shell_exec('/usr/bin/lsb_release -ds | cut -d= -f2 | tr -d \'"\'')))
|
2014-06-18 04:11:11 -04:00
|
|
|
{
|
2017-03-20 11:20:07 -04:00
|
|
|
if (!file_exists('/etc/system-release') || !($os = shell_exec('cat /etc/system-release | cut -d= -f2 | tr -d \'"\'')))
|
2014-06-18 04:15:18 -04:00
|
|
|
{
|
2017-03-20 11:20:07 -04:00
|
|
|
if (!file_exists('/etc/os-release') || !($os = shell_exec('cat /etc/os-release | grep PRETTY_NAME | tail -n 1 | cut -d= -f2 | tr -d \'"\'')))
|
2014-11-10 10:37:10 -05:00
|
|
|
{
|
2016-04-19 12:01:40 -04:00
|
|
|
if (!($os = shell_exec('find /etc/*-release -type f -exec cat {} \; | grep PRETTY_NAME | tail -n 1 | cut -d= -f2 | tr -d \'"\'')))
|
|
|
|
{
|
|
|
|
$os = 'N.A';
|
|
|
|
}
|
2014-11-10 10:37:10 -05:00
|
|
|
}
|
2014-06-18 04:15:18 -04:00
|
|
|
}
|
2014-06-18 04:11:11 -04:00
|
|
|
}
|
2015-01-16 12:14:07 -05:00
|
|
|
$os = trim($os, '"');
|
2015-02-11 15:20:02 -05:00
|
|
|
$os = str_replace("\n", '', $os);
|
2014-06-18 04:11:11 -04:00
|
|
|
|
|
|
|
// Kernel
|
|
|
|
if (!($kernel = shell_exec('/bin/uname -r')))
|
|
|
|
{
|
|
|
|
$kernel = 'N.A';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uptime
|
|
|
|
if (!($totalSeconds = shell_exec('/usr/bin/cut -d. -f1 /proc/uptime')))
|
|
|
|
{
|
|
|
|
$uptime = 'N.A';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-02 15:54:43 -04:00
|
|
|
$uptime = Misc::getHumanTime((int)$totalSeconds);
|
2014-06-18 04:11:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Last boot
|
|
|
|
if (!($upt_tmp = shell_exec('cat /proc/uptime')))
|
|
|
|
{
|
|
|
|
$last_boot = 'N.A';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$upt = explode(' ', $upt_tmp);
|
|
|
|
$last_boot = date('Y-m-d H:i:s', time() - intval($upt[0]));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Current users
|
2014-11-11 11:05:49 -05:00
|
|
|
if (!($current_users = shell_exec('who -u | awk \'{ print $1 }\' | wc -l')))
|
2014-06-18 04:11:11 -04:00
|
|
|
{
|
|
|
|
$current_users = 'N.A';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Server datetime
|
|
|
|
if (!($server_date = shell_exec('/bin/date')))
|
|
|
|
{
|
|
|
|
$server_date = date('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$datas = array(
|
|
|
|
'hostname' => $hostname,
|
|
|
|
'os' => $os,
|
|
|
|
'kernel' => $kernel,
|
|
|
|
'uptime' => $uptime,
|
|
|
|
'last_boot' => $last_boot,
|
|
|
|
'current_users' => $current_users,
|
|
|
|
'server_date' => $server_date,
|
|
|
|
);
|
|
|
|
|
2017-03-20 11:20:07 -04:00
|
|
|
echo json_encode($datas);
|