2017-11-01 16:50:09 +00:00
|
|
|
<?php
|
|
|
|
|
2017-11-12 15:35:28 +00:00
|
|
|
require_once 'lib/autoloader.php';
|
|
|
|
|
|
|
|
use \TclUpdates\XmlParser;
|
|
|
|
|
2017-11-03 22:08:06 +00:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2017-11-12 15:35:28 +00:00
|
|
|
$input_xml = file_get_contents('php://input', false, null, -1, 8192); // read max 8 KiB
|
2017-11-05 00:36:18 +00:00
|
|
|
if (strlen($input_xml) >= 8192) {
|
2017-11-12 15:35:28 +00:00
|
|
|
// Max length, probably even longer, definitely no data we want
|
2017-11-05 00:36:18 +00:00
|
|
|
http_response_code(413); // "Payload too large"
|
|
|
|
exit;
|
|
|
|
}
|
2017-11-12 15:35:28 +00:00
|
|
|
$xp = new XmlParser();
|
|
|
|
$load_ok = $xp->loadXmlFromString($input_xml);
|
|
|
|
if (!$load_ok) {
|
2017-11-05 00:36:18 +00:00
|
|
|
// XML could not be parsed - invalid or no XML
|
|
|
|
http_response_code(406); // "Not acceptable"
|
|
|
|
exit;
|
|
|
|
}
|
2017-11-12 15:35:28 +00:00
|
|
|
if (!$xp->validateGOTU()) {
|
|
|
|
// No root node or root node isn't <GOTU>, so no update XML
|
2017-11-05 00:36:18 +00:00
|
|
|
http_response_code(412); // "Precondition failed"
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
// ### At this point we can be relatively sure to have the XML we want
|
2017-11-03 22:08:06 +00:00
|
|
|
echo "Input length is " . strlen($input_xml) . " Bytes." . PHP_EOL;
|
2017-11-12 15:35:28 +00:00
|
|
|
#echo $input_xml . PHP_EOL;
|
|
|
|
|
|
|
|
|
2017-11-03 22:08:06 +00:00
|
|
|
// TODO: Check if it's XML
|
|
|
|
// If so: Store a copy for re-parsing (or to print out and hang up on a wall)
|
|
|
|
// Then parse XML into database
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-11-05 00:36:18 +00:00
|
|
|
echo "Here is the normal page. " . $_SERVER['REQUEST_METHOD'];
|
2017-11-03 22:08:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
// TODO: Show statistics from database
|