cakefoot/www/report_arcade_update.php
Cocktail Frank 93aee14547 Add cURL to Linux, Windows, and macOS builds
Replace cpp-httplib with sb:☁️:HTTP, and use it to send the arcade
auto-update remote log request.

Use -Oz instead of -O3 to reduce executable size on Linux, Windows, and
macOS builds.

Make the arcade auto-update script path configurable, and add support
for username and password credentials.

Add exit codes to the auto-update script to indicate specific results.

Update the remoter logger PHP script to read JSON data and prepend a
timestamp to the log entry.

Start an empty test case for HTTP functionality.
2025-04-10 20:08:58 -04:00

46 lines
1.6 KiB
PHP

<?php
$report_path = $_SERVER['REMOTE_ADDR'] . "-Arcade_Report.json";
/* Read JSON data from the report path. If the file doesn't exist, is not in JSON format, or any other exception occurs,
* just set the history to an empty array. */
$report = array("reports" => array());
try
{
/* Check for file existence, especially because doing so will avoid a warning being written to the log when the path
* doesn't exist but file_get_contents is used on the path */
if (file_exists($report_path))
{
$report = json_decode(file_get_contents($report_path), true, 512, JSON_THROW_ON_ERROR);
}
}
catch (Exception $e)
{
error_log("Error while reading report path \"$report_path\": $e");
}
/*!
* Try reading the new format which is passed as JSON. Fallback to the deprecated format which is a string.
*
* Read JSON data containing the report passed as a POST request. Limit to 2048 characters to protect against
* injections.
*/
$incoming_report = json_decode(file_get_contents("php://input", false, null, 0, 2048), true)["report"];
if ($incoming_report == null)
{
/* A string containing the update results is passed as a POST request. Sanitize by stripping all special
* characters. */
$incoming_report = filter_input(INPUT_POST, "report", FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW);
}
/* Prepend a timestamp to the log entry */
$incoming_report = date(DATE_RFC2822) . " " . $incoming_report;
/* Add new report to existing array of reports. */
array_push($report["reports"], $incoming_report);
/* Write all reports as JSON */
file_put_contents($report_path, json_encode($report, JSON_PRETTY_PRINT) . "\n");
?>