Created
June 8, 2023 08:26
-
-
Save pmeszaros/76ad46a7be360a528e8389f710437e11 to your computer and use it in GitHub Desktop.
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
<?php | |
/* A modified version of the monitoring script described in the article at | |
https://medium.com/winkhosting/server-monitoring-with-php-and-bash-scripts-c078616a6e2f | |
For demonstration purposes only | |
Since the monitor script does not send files, the script is written | |
to handle the POST request via routes | |
*/ | |
// Received files storage path. | |
$_SAVEPATH = __DIR__ . "/files"; | |
// Preparation of valid routes | |
$valid_route = array("storage", "memoryusage", "top10cpu", "uptime"); | |
// Remove trailing slash from request URI | |
$route = ltrim($_SERVER["REQUEST_URI"], '/'); | |
// Check valid routes and save POST content to the file to the $_SAVEPATH | |
if (in_array($route, $valid_route)) { | |
$_SAVEPATH = $_SAVEPATH . "/" . date("Ymdhis") . "_" . $route . ".log"; | |
file_put_contents($_SAVEPATH, file_get_contents('php://input')); | |
echo "File saved at {$_SAVEPATH}\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment