annotate php/keygen.php @ 2514:fb8f43204ae0

Fix for #158
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Mon, 24 Oct 2016 11:01:55 +0100
parents 4cbd314e5d9f
children
rev   line source
nicholas@2224 1 <?php
nicholas@2457 2 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
nicholas@2457 3 header("Cache-Control: post-check=0, pre-check=0", false);
nicholas@2457 4 header("Pragma: no-cache");
nicholas@2224 5 // This checks the key sent by the JavaScript against the current bunch of saves
nicholas@2224 6 // XML Saves location - assumes it will be saves/
nicholas@2224 7 $saves = glob("../saves/*.xml");
nicholas@2224 8
nicholas@2224 9 $key_requested = $_GET['key'];
nicholas@2224 10
nicholas@2224 11 $xml_good = "<response><state>OK</state><key>".$key_requested."</key></response>";
nicholas@2224 12 $xml_bad = "<response><state>NO</state><key>".$key_requested."</key></response>";
nicholas@2514 13 $xml_error = "<response><state>ERROR</state><key>".$key_requested."</key><message>Could not open file for writing</message></response>";
nicholas@2224 14 if (is_array($saves))
nicholas@2224 15 {
nicholas@2224 16 foreach($saves as $filename) {
nicholas@2224 17 $xml_string = file_get_contents($filename, FILE_TEXT);
nicholas@2224 18 $xml_object = simplexml_load_string($xml_string);
nicholas@2224 19 if ($xml_object != false) {
nicholas@2224 20 if (isset($value['key']))
nicholas@2224 21 {
nicholas@2224 22 if ($value['key'] == $key_requested) {
nicholas@2224 23 echo $xml_bad;
nicholas@2224 24 return;
nicholas@2224 25 }
nicholas@2224 26 }
nicholas@2224 27 }
nicholas@2224 28 }
nicholas@2513 29 $filename = "../saves/save-".$key_requested.".xml";
nicholas@2513 30 $fileHandle = fopen($filename, 'c');
nicholas@2510 31 if ($fileHandle == FALSE) {
nicholas@2510 32 echo $xml_error;
nicholas@2511 33 return;
nicholas@2510 34 }
nicholas@2510 35 fclose($fileHandle);
nicholas@2224 36 // TODO:
nicholas@2224 37 // Generate the XML Base file and save it
nicholas@2224 38 $doc_struct = new SimpleXMLElement('<waetresult/>');
nicholas@2224 39 $doc_struct->addAttribute("key",$key_requested);
nicholas@2224 40 // Add start time
nicholas@2224 41 // Add IP Address information
nicholas@2224 42 // Save the file
nicholas@2510 43 $doc_struct->asXML($filename);
nicholas@2510 44 echo $xml_good;
nicholas@2224 45 return;
nicholas@2224 46 } else {
nicholas@2224 47 echo $xml_error;
nicholas@2224 48 return;
nicholas@2224 49 }
nicholas@2510 50 ?>