106 lines
3 KiB
PHP
106 lines
3 KiB
PHP
<?php
|
|
|
|
require("settings.php");
|
|
require("utilities/comment_key.php");
|
|
require("utilities/transform.php");
|
|
require("utilities/simplexmlwriter.php");
|
|
|
|
header("content-type: text/plain");
|
|
|
|
if(empty($_GET["place_id"]))
|
|
exit("Error: No place id provided.\n");
|
|
if(empty($_GET["summary"]))
|
|
exit("Error: No summary provided.\n");
|
|
if(empty($_GET["version"]))
|
|
exit("No version provided.\n");
|
|
|
|
/*if(empty($_GET["key"]))
|
|
exit("Error: No key provided.\n");
|
|
|
|
if(!key_verify(
|
|
$_GET["key"],
|
|
$settings->comment_key_pass,
|
|
$settings->comment_key_min_age, $settings->comment_key_max_age
|
|
))
|
|
exit("Error: Invalid key.\n");
|
|
*/
|
|
/******************************************************/
|
|
|
|
$places = json_decode(file_get_contents("$settings->data_dir/places.json"));
|
|
|
|
$place = null;
|
|
foreach($places as $current_place) {
|
|
if($place->key == $_GET["place_id"]) {
|
|
$place = $current_place;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if($place == null)
|
|
exit("Error: Place id doesn't match.\n");
|
|
|
|
$new_report = new stdClass();
|
|
$new_report->version = escape4xml($_GET["version"]);
|
|
$new_report->summary = escape4xml($_GET["summary"]);
|
|
$new_report->stack_trace = escape4xml(file_get_contents('php://input'));
|
|
|
|
$report_dir = "$settings->data_dir/places/$place->name";
|
|
$report_filename = "$report_dir/" . slugify($new_report->summary) . ".xml";
|
|
|
|
// Save the individual report
|
|
|
|
if(!file_exists($report_filename)) {
|
|
$writer = new SimpleXmlWriter();
|
|
$writer->start();
|
|
$writer->add_xslt("../../theme/stack_traces.xslt");
|
|
$writer->open("error_info");
|
|
$writer->addtag("summary", [], $new_report->summary);
|
|
$writer->open("reports");
|
|
$writer->close();
|
|
$writer->close();
|
|
file_put_contents($report_filename, $writer->render());
|
|
}
|
|
|
|
$report_xml = simplexml_load_file($report_filename);
|
|
|
|
if($report_xml === false)
|
|
exit("Error: invalid XML generated when creating a new report file.\n");
|
|
|
|
$report_node = $report_xml->reports->addChild("report");
|
|
$report_node->addChild("timestamp", date(DATE_ATOM));
|
|
$report_node->addChild("version", $new_report->version);
|
|
$report_node->addChild("summary", $new_report->summary);
|
|
$report_node->addChild("stack_trace", $new_report->stack_trace);
|
|
|
|
file_put_contents($report_filename, $report_xml->asXML());
|
|
|
|
// Update the place index
|
|
$place_index_filename = "$report_dir/index.xml";
|
|
if(!file_exists($place_index_filename)) {
|
|
$writer = new SimpleXmlWriter();
|
|
$writer->start();
|
|
$writer->add_xslt("../../theme/place_index.xslt");
|
|
$writer->open("errors");
|
|
$writer->close();
|
|
file_put_contents($place_index_filename, $writer->render());
|
|
}
|
|
$index_xml = simplexml_load_file($place_index_filename);
|
|
|
|
$index_entry = null;
|
|
foreach($index_xml as $entry) {
|
|
if($entry->summary->__toString() != $new_report->summary)
|
|
continue;
|
|
$index_entry = $entry;
|
|
break;
|
|
}
|
|
|
|
if($index_entry == null) {
|
|
$index_entry = $index_xml->addChild("error");
|
|
$index_entry->summary = $new_report->summary;
|
|
$index_entry->last_report = date(DATE_ATOM);
|
|
$index_entry->report_count = 0;
|
|
}
|
|
|
|
$index_entry->report_count = intval($index_entry->report_count) + 1;
|
|
|
|
file_put_contents($place_index_filename, $index_xml->asXML());
|