annotate keygen.php @ 2212:279733b3b67e

Move pythonServer-legacy.py to scripts
author Brecht De Man <b.deman@qmul.ac.uk>
date Wed, 13 Apr 2016 15:46:12 +0100
parents 686f1fb84d7c
children
rev   line source
nickjillings@2147 1 <?php
nickjillings@2147 2 // This checks the key sent by the JavaScript against the current bunch of saves
nickjillings@2147 3 // XML Saves location - assumes it will be saves/
nickjillings@2149 4 $saves = glob("saves/*.xml");
nickjillings@2147 5
nickjillings@2147 6 $key_requested = $_GET['key'];
nickjillings@2147 7
nickjillings@2147 8 $xml_good = "<response><state>OK</state><key>".$key_requested."</key></response>";
nickjillings@2147 9 $xml_bad = "<response><state>NO</state><key>".$key_requested."</key></response>";
nickjillings@2151 10 $xml_error = "<response><state>ERROR</state><key>".$key_requested."</key></response>";
nickjillings@2147 11 if (is_array($saves))
nickjillings@2147 12 {
nickjillings@2147 13 foreach($saves as $filename) {
nickjillings@2147 14 $xml_string = file_get_contents($filename, FILE_TEXT);
nickjillings@2147 15 $xml_object = simplexml_load_string($xml_string);
nickjillings@2147 16 if ($xml_object != false) {
nickjillings@2147 17 if (isset($value['key']))
nickjillings@2147 18 {
nickjillings@2147 19 if ($value['key'] == $key_requested) {
nickjillings@2147 20 echo $xml_bad;
nickjillings@2147 21 return;
nickjillings@2147 22 }
nickjillings@2147 23 }
nickjillings@2147 24 }
nickjillings@2147 25 }
nickjillings@2147 26 echo $xml_good;
nickjillings@2147 27 // TODO:
nickjillings@2147 28 // Generate the XML Base file and save it
nickjillings@2149 29 $doc_struct = new SimpleXMLElement('<waetresult/>');
nickjillings@2149 30 $doc_struct->addAttribute("key",$key_requested);
nickjillings@2147 31 // Add start time
nickjillings@2147 32 // Add IP Address information
nickjillings@2149 33 // Save the file
nickjillings@2149 34 $doc_struct->asXML("saves/save-".$key_requested.".xml");
nickjillings@2147 35 return;
nickjillings@2147 36 } else {
nickjillings@2147 37 echo $xml_error;
nickjillings@2147 38 return;
nickjillings@2147 39 }
nickjillings@2147 40 ?>