Update robots file to allow crawling arcade cabinet HTML file Update upstream library which includes gzip play session files
55 lines
1.9 KiB
PHP
55 lines
1.9 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_json = json_decode(file_get_contents("php://input", false, null, 0, 2048), true);
|
|
if ($incoming_json != null)
|
|
{
|
|
if (array_key_exists("report", $incoming_json)) {
|
|
$incoming_report = $incoming_json["report"];
|
|
}
|
|
else {
|
|
/* Dump the array as a string because it is in a broken format */
|
|
$incoming_report = print_r($incoming_json, true);
|
|
}
|
|
}
|
|
else {
|
|
/* Deprecated message format is a string containing the update results 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");
|
|
|
|
?>
|