cakefoot/www/report_arcade_update.php
Cocktail Frank 9b1dd3ac0d Send a report over HTTP after update script runs
The report is a string sent using the cpp-httplib library, which
requires libssl and libcrypto. It only runs on the Linux arcade build,
which is the only build with auto-updates. The cpp-httplib library has
a single header httplib.h which is added to the project source tree.

On the server side, there is a PHP script added in this commit that
receives the report and writes it to a file in the www/ folder.

Add libssl and libcrypto object files to the Linux distributable.
2025-03-18 13:35:41 -04:00

34 lines
1.5 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");
}
/* JSON data containing the user's play history is passed as a POST request from JavaScript in pre_js_collect.js. Remove
* HTML and PHP special characters and limit length of input to 2048 characters to protect against injections. */
$incoming_report = filter_input(INPUT_POST, "report", FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_STRIP_LOW);
/* Add new report to existing array of reports. */
array_push($report["reports"], $incoming_report);
/* Merge the passed play history into the history array, overwriting any existing data at the current session ID, or adding a new
* section to the array if the session ID doesn't exist as a key in the array yet. Write the array to the history path. */
file_put_contents($report_path, json_encode($report, JSON_PRETTY_PRINT) . "\n");
?>