diff --git a/public/version.php b/public/version.php new file mode 100644 index 0000000..d76a06f --- /dev/null +++ b/public/version.php @@ -0,0 +1,8 @@ +load(); + +include "../src/status/version.php"; diff --git a/src/status/main.php b/src/status/main.php index 4888f46..e88b137 100644 --- a/src/status/main.php +++ b/src/status/main.php @@ -21,10 +21,11 @@ function stripFirstLine($text) } } # uptime -preg_match("/^\s*(.+) up (.+), .+ user, load average: (.+)\s*$/", shell_exec("uptime"), $matches); +preg_match("/\s*(.+?) up (.+?), .+? user, load average: (.+?)\s*/", shell_exec("uptime"), $matches); $uptime = [ 'time' => $matches[1] ?? '', 'up' => $matches[2] ?? '', + 'core' => intval(rtrim(shell_exec('nproc'))), 'load' => array_map(function ($x) { return floatval(trim($x)); }, explode(',', $matches[3] ?? '0,0,0')), @@ -54,8 +55,7 @@ function stripFirstLine($text) foreach ($df as $dfk => $dfv) { preg_match_all("/(.+?)\s+(\d+?)\s+(\d+?)\s+(\d+?)\s+(\d+?%)\s+(.+)/", $dfv, $matches, PREG_SET_ORDER); - $df[$dfk] = array_map(function ($x) - { + $df[$dfk] = array_map(function ($x) { return [ 'name' => $x[1], 'total' => $x[2], diff --git a/src/status/version.php b/src/status/version.php new file mode 100644 index 0000000..cac0854 --- /dev/null +++ b/src/status/version.php @@ -0,0 +1,53 @@ + 'cat /etc/centos-release', + 'bash' => 'bash --version', + 'curl' => 'curl -V', + 'wget' => 'wget -V', + 'nano' => 'nano --version', + 'vim' => 'vim --version', + 'tar' => 'tar --version', + 'zip' => 'zip --version', + 'git' => 'git --version', + 'openssl' => 'openssl version', + // services + 'named' => 'named -v', + 'iptables' => 'iptables --version', + 'proftpd' => 'proftpd -v', + 'nginx' => 'nginx -v', + 'mysql' => 'mysql -V', + 'psql' => 'psql -V', + 'passenger' => 'passenger -v', + // language services + 'php' => 'php -v', + 'php56' => 'php56 -v', + 'php80' => 'php80 -v', + 'composer' => 'composer -V', + 'python' => 'python -V', + 'python3.6' => 'python3.6 -V', + 'python3.8' => 'python3.8 -V', + 'pip' => 'pip -V', + 'pip3.6' => 'pip3.6 -V', + 'pip3.8' => 'pip3.8 -V', + 'node' => 'node -v', + 'npm' => 'npm -v', + 'yarn' => 'yarn -v', + 'ruby' => 'ruby -v', + 'gem' => 'gem -v', + 'go' => 'go version', + 'rustc' => 'rustc -V', + 'cargo' => 'cargo -V', + 'gcc' => 'gcc --version', + 'g++' => 'g++ --version', +]; +foreach ($programs as $key => $value) { + preg_match('/[\d.]+\w*/', shell_exec($value), $match); + $programs[$key] = $match[0]; +} +header('content-type: application/json'); +echo json_encode($programs);