annotate keygen.php @ 1097:ebf52bf47fb7

Temporary fix of #1580. Updated schema in preparation of #1661, #1469 & #1649
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Thu, 10 Mar 2016 16:42:16 +0000
parents c07b9e2312ba
children ba6b9e1aaef5
rev   line source
n@1090 1 <?php
n@1090 2 // This checks the key sent by the JavaScript against the current bunch of saves
n@1090 3 // XML Saves location - assumes it will be saves/
n@1090 4 $saves = glob("saves/*.xml");
n@1090 5
n@1090 6 $key_requested = $_GET['key'];
n@1090 7
n@1090 8 $xml_good = "<response><state>OK</state><key>".$key_requested."</key></response>";
n@1090 9 $xml_bad = "<response><state>NO</state><key>".$key_requested."</key></response>";
n@1090 10 $xml_error = "<response><state>ERROR</state><key>".$key_requested."</key></response>";
n@1090 11 if (is_array($saves))
n@1090 12 {
n@1090 13 foreach($saves as $filename) {
n@1090 14 $xml_string = file_get_contents($filename, FILE_TEXT);
n@1090 15 $xml_object = simplexml_load_string($xml_string);
n@1090 16 if ($xml_object != false) {
n@1090 17 if (isset($value['key']))
n@1090 18 {
n@1090 19 if ($value['key'] == $key_requested) {
n@1090 20 echo $xml_bad;
n@1090 21 return;
n@1090 22 }
n@1090 23 }
n@1090 24 }
n@1090 25 }
n@1090 26 echo $xml_good;
n@1090 27 // TODO:
n@1090 28 // Generate the XML Base file and save it
n@1090 29 $doc_struct = new SimpleXMLElement('<waetresult/>');
n@1090 30 $doc_struct->addAttribute("key",$key_requested);
n@1090 31 // Add start time
n@1090 32 // Add IP Address information
n@1090 33 // Save the file
n@1090 34 $doc_struct->asXML("saves/save-".$key_requested.".xml");
n@1090 35 return;
n@1090 36 } else {
n@1090 37 echo $xml_error;
n@1090 38 return;
n@1090 39 }
n@1090 40 ?>