Last active
October 8, 2015 01:58
-
-
Save honzajavorek/3259848 to your computer and use it in GitHub Desktop.
Apache root index file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!empty($_GET['phpinfo'])) { | |
phpinfo(); | |
exit; | |
} | |
function run($cmd) { | |
$output = array(); | |
exec($cmd, $output); | |
return implode("\n", $output); | |
} | |
function match($pattern, $string) { | |
$matches = array(); | |
preg_match($pattern, $string, $matches); | |
if (empty($matches)) { | |
return NULL; | |
} | |
return $matches; | |
} | |
function isPresent($program) { | |
return (bool)run("which $program"); | |
} | |
function version($string) { | |
$match = match('#\d+(\.\d+)+#', $string); | |
if ($match) { | |
return $match[0]; | |
} | |
return NULL; | |
} | |
$os = php_uname('s'); | |
$hostname = php_uname('n'); | |
$host = $_SERVER['HTTP_HOST']; | |
$ip = file_get_contents('http://automation.whatismyip.com/n09230945.asp'); | |
$server = $_SERVER["SERVER_SOFTWARE"]; | |
?> | |
<!DOCTYPE html> | |
<html dir="ltr" lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title><?php echo $hostname; ?></title> | |
</head> | |
<body> | |
<style> | |
body { font-size: 100%; text-align: center; font-family: ubuntu, sans-serif; } | |
h1 { font-size: 300%; } | |
th, td { text-align: left; width: 50%; padding: 0.5em 1em; } | |
th { text-align: right; } | |
table { width: 100%; max-width: 700px; margin: 5em auto; } | |
a { color: #BBB; } | |
small { margin-left: 3em; } | |
</style> | |
<h1><?php echo $hostname; ?></h1> | |
<table> | |
<tr> | |
<th> | |
OS | |
</th> | |
<td> | |
<?php echo $os; ?> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
IP | |
</th> | |
<td> | |
<?php echo $ip; ?> (<?php echo $host; ?>) | |
</td> | |
</tr> | |
<tr> | |
<th> | |
Server | |
</th> | |
<td> | |
<?php echo $server; ?> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
PHP | |
</th> | |
<td> | |
<?php echo version(phpversion()); ?> (<a href="?phpinfo=✔">info</a>) | |
</td> | |
</tr> | |
<tr> | |
<th> | |
Python | |
</th> | |
<td> | |
<?php if (isPresent('python')) { echo version(run('python --version 2>&1')); } else { ?>✖<?php }; ?> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
MySQL | |
</th> | |
<td> | |
<?php if (isPresent('mysql')) { echo version(run('echo "SELECT VERSION();" | mysql')); } else { ?>✖<?php }; ?> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
PostgreSQL | |
</th> | |
<td> | |
<?php if (isPresent('psql')) { echo version(run('psql --version')); } else { ?>✖<?php }; ?> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
MongoDB | |
</th> | |
<td> | |
<?php if (isPresent('psql')) { echo version(run('mongod --version')); } else { ?>✖<?php }; ?> | |
</td> | |
</tr> | |
<tr> | |
<th> | |
Redis | |
</th> | |
<td> | |
<?php if (isPresent('redis-server')) { echo version(run('redis-server --version')); } else { ?>✖<?php }; ?> | |
</td> | |
</tr> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment