Last active
February 15, 2023 19:36
-
-
Save GitKageHub/c58ceae2edffc2f992d20dab4cb96018 to your computer and use it in GitHub Desktop.
This PHP script displays system information and provides buttons to create a file and restart the web server with appropriate checks. This is for educational purposes.
This file contains 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>System Information and Control Panel</title> | |
<meta charset="UTF-8"> | |
</head> | |
<body> | |
<h1>System Information</h1> | |
<table> | |
<tr> | |
<th>Hostname</th> | |
<th>Processor Type</th> | |
<th>Total RAM</th> | |
<th>Total Storage</th> | |
</tr> | |
<tr> | |
<td><?php echo gethostname(); ?></td> | |
<td><?php echo php_uname('m'); ?></td> | |
<td><?php echo round(memory_get_usage(true) / 1048576, 2); ?> MB</td> | |
<td><?php echo round(disk_total_space('/') / 1073741824, 2); ?> GB</td> | |
</tr> | |
</table> | |
<br> | |
<form method="post"> | |
<button type="submit" name="test" value="test">Test</button> | |
<button type="submit" name="restart" value="restart">Restart Web Server</button> | |
</form> | |
<?php | |
if (isset($_POST['test'])) { | |
$file = __DIR__ . '/zreceived'; | |
file_put_contents($file, 'This file was created by the test button.'); | |
echo '<p>The file ' . $file . ' was created.</p>'; | |
} | |
if (isset($_POST['restart'])) { | |
$cmd = ''; | |
if (strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false) { | |
$cmd .= 'sudo apachectl restart && '; | |
} | |
if (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) { | |
$cmd .= 'sudo systemctl restart nginx && '; | |
} | |
if (!empty($cmd)) { | |
$cmd = rtrim($cmd, ' && '); | |
exec($cmd); | |
echo '<p>The web server was restarted.</p>'; | |
} | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script was updated to remove the hardcoded output location for the test button and use the directory the script is running in. This should avoid any permissions issues in a majority of cases.