changeset 3120:53d701288da5

Create new php config to allow saves to be stored outside of web scope
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Wed, 18 Jul 2018 16:47:07 +0100
parents aa4503f8c630
children edd536f01e4b
files php/comment_parser.php php/config.php php/get_filtered_count.php php/get_tests.php php/pool.php php/pseudo.php php/requestKey.php php/save.php php/score_parser.php php/test_write.php
diffstat 10 files changed, 40 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/php/comment_parser.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/comment_parser.php	Wed Jul 18 16:47:07 2018 +0100
@@ -1,4 +1,5 @@
 <?php
+incluce_once("config.php");
 // Comment Parser for PHP
 header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
 header("Cache-Control: post-check=0, pre-check=0", false);
@@ -20,7 +21,8 @@
     }
 }
 // XML Saves location - assumes it will be saves/
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 $comment_struct = array();
 if (is_array($saves))
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/php/config.php	Wed Jul 18 16:47:07 2018 +0100
@@ -0,0 +1,16 @@
+<?php
+function getSaveLocation() {
+    if (isset($_ENV["WAET_SAVES_LOCATION"])) {
+        return $_ENV["WAET_SAVES_LOCATION"];
+    } else {
+        return "../saves/";
+    }
+}
+function getTestLocation() {
+    if (isset($_ENV["WAET_TEST_LOCATION"])) {
+        return $_ENV["WAET_TEST_LOCATION"];
+    } else {
+        return "../tests/";
+    }
+}
+?>
\ No newline at end of file
--- a/php/get_filtered_count.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/get_filtered_count.php	Wed Jul 18 16:47:07 2018 +0100
@@ -33,7 +33,8 @@
 }
 
 $files = array();
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/get_tests.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/get_tests.php	Wed Jul 18 16:47:07 2018 +0100
@@ -12,7 +12,8 @@
 
 // XML Saves location - assumes it will be saves/
 $data = array();
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/pool.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/pool.php	Wed Jul 18 16:47:07 2018 +0100
@@ -37,7 +37,8 @@
 
 $waet_url = rel2abs("pool.php","http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
 
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/pseudo.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/pseudo.php	Wed Jul 18 16:47:07 2018 +0100
@@ -16,15 +16,16 @@
 } else {
     $dir = $_GET["dir"];
 }
-
-$files = glob('../saves/' . $prefix . '*.xml');
+$saveLocation = getSaveLocation();
+$files = glob($saveLocation . $prefix . '*.xml');
 $numsaves = 0;
 if ( $files !== false )
 {
     $numsaves = count( $files );
 }
 
-$files = glob('../tests/' . $dir . '*.xml');
+$testLocation = getTestLocation();
+$files = glob($testLocation . $dir . '*.xml');
 $numtests = 0;
 
 if ( $numtests !== false )
--- a/php/requestKey.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/requestKey.php	Wed Jul 18 16:47:07 2018 +0100
@@ -57,8 +57,8 @@
         $key = $tempKey;
     }
 }
-
-$filename = "../saves/".$saveFilenamePrefix.$key.".xml";
+$saveLocation = getSaveLocation();
+$filename = $saveLocation.$saveFilenamePrefix.$key.".xml";
 $fileHandle = fopen($filename, 'w');
 if ($fileHandle == FALSE) {
     die("<response><state>ERROR</state><key>".$key."</key><message>Could not open file for writing</message></response>");
--- a/php/save.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/save.php	Wed Jul 18 16:47:07 2018 +0100
@@ -39,10 +39,12 @@
     $update = $_GET["update"] == "update";
 }
 
+$saveLocation = getSaveLocation();
+
 if ($update) {
-    $filename = '../saves/update-'.$saveFilenamePrefix.$file_key.".xml";
+    $filename = $saveLocation.'update-'.$saveFilenamePrefix.$file_key.".xml";
 } else {
-    $filename = '../saves/'.$saveFilenamePrefix.$file_key.".xml";
+    $filename = $saveLocation.$saveFilenamePrefix.$file_key.".xml";
 }
 
 if (!file_exists($filename)) {
@@ -144,6 +146,6 @@
 echo $xml;
 
 if (!$update) {
-    unlink('../saves/update-'.$saveFilenamePrefix.$file_key.".xml");
+    unlink($saveLocation.'update-'.$saveFilenamePrefix.$file_key.".xml");
 }
 ?>
--- a/php/score_parser.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/score_parser.php	Wed Jul 18 16:47:07 2018 +0100
@@ -51,7 +51,8 @@
 $root = new nestedObject("root");
 
 // XML Saves location - assumes it will be saves/
-$saves = glob("../saves/*.xml");
+$saveLocation = getSaveLocation();
+$saves = glob($saveLocation."*.xml");
 if (is_array($saves))
 {
     foreach($saves as $filename) {
--- a/php/test_write.php	Wed Jul 18 16:32:44 2018 +0100
+++ b/php/test_write.php	Wed Jul 18 16:47:07 2018 +0100
@@ -1,5 +1,6 @@
 <?php
-$file = "../saves/test-save.xml";
+$saveLocation = getSaveLocation();
+$file = $saveLocation."test-save.xml";
 $state = file_put_contents($file, "<xml></xml>");
 if ($state == FALSE) {
     echo "<response state=\"error\"><message>Could not open file</message></response>";