config file setup instructions
authorChristian Weiske <cweiske@cweiske.de>
Fri, 4 Jul 2014 16:25:01 +0000 (18:25 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Fri, 4 Jul 2014 16:25:01 +0000 (18:25 +0200)
src/phorkie/SetupCheck.php
src/phorkie/Tools.php
tests/phorkie/ToolsTest.php
www/setup.php

index 69cffd8f073e7b200dfb861eeb1a92183f2858ce..f8edd869b2999e80b84395be62e67e807e8e4c6c 100644 (file)
@@ -48,9 +48,12 @@ class SetupCheck
     {
         foreach ($GLOBALS['phorkie']['cfgfiles'] as $file => $loaded) {
             if ($loaded) {
-                $this->ok('Loaded config file: ' . $file);
+                $this->ok('Loaded config file: ' . Tools::foldPath($file));
             } else {
-                $this->info('Possible config file: ' . $file . ' (not loaded)');
+                $this->info(
+                    'Possible config file: ' . Tools::foldPath($file)
+                    . ' (not loaded)'
+                );
             }
         }
     }
index 7c9c46eb84a540709c52cc6932b5329095c68204..7819cda77efb956bf6cf35ae58a20c9398c12a23 100644 (file)
@@ -96,5 +96,17 @@ class Tools
 
         return '/';
     }
+
+    /**
+     * Resolves "/../" and "/./" in file paths without validating them.
+     */
+    public static function foldPath($path)
+    {
+        $path = str_replace('/./', '/', $path);
+        $path = str_replace('/./', '/', $path);
+        $path = preg_replace('#/[^/]+/\.\./#', '/', $path);
+        $path = preg_replace('#/[^/]+/\.\./#', '/', $path);
+        return $path;
+    }
 }
 ?>
index 7a5be16f71367fd95f445626610e027664fc441d..021797d2ef53d1b6815023baec075c01455cfe7c 100644 (file)
@@ -33,5 +33,37 @@ class ToolsTest extends \PHPUnit_Framework_TestCase
         $_SERVER['SCRIPT_NAME'] = '/new.php';
         $this->assertEquals('/foo/', Tools::detectBaseUrl());
     }
+
+    public function testFoldPathParentSingle()
+    {
+        $this->assertEquals(
+            '/path/to/foo',
+            Tools::foldPath('/path/to/bar/../foo')
+        );
+    }
+
+    public function testFoldPathParentDouble()
+    {
+        $this->assertEquals(
+            '/path/to/foo',
+            Tools::foldPath('/path/to/foo/bar/../../foo')
+        );
+    }
+
+    public function testFoldPathCurrentSingle()
+    {
+        $this->assertEquals(
+            '/path/to/foo/',
+            Tools::foldPath('/path/to/foo/./')
+        );
+    }
+
+    public function testFoldPathCurrentThrice()
+    {
+        $this->assertEquals(
+            '/path/to/foo/',
+            Tools::foldPath('/path/././to/foo/./')
+        );
+    }
 }
 ?>
index cd0deaaa51f49912961f6dc786fe940f0e5f27c4..f0be905684d9bd0fb9d270823413351bde390823 100644 (file)
@@ -74,6 +74,7 @@ $out = <<<HTM
      <div class="page-header">
       <h1>phorkie setup check</h1>
      </div>
+     <h3>Check results</h3>
 
      <ul class="list-group">
 HTM;
@@ -91,6 +92,36 @@ foreach ($messages as $arMessage) {
 }
 $out .= <<<HTM
      </ul>
+HTM;
+
+if (array_sum($GLOBALS['phorkie']['cfgfiles']) == 0) {
+    //no config file loaded
+    reset($GLOBALS['phorkie']['cfgfiles']);
+    list($cfgFilePath, ) = each($GLOBALS['phorkie']['cfgfiles']);
+
+    $cfgFilePath = Tools::foldPath($cfgFilePath);
+    $cfgFileTemplate = htmlspecialchars(
+        file_get_contents(__DIR__ . '/../data/config.php.dist')
+    );
+
+    $out .= <<<HTM
+     <h3 id="configfile">Configuration file</h3>
+     <p>
+      Phorkie did not find a configuration file.
+      Please create one at
+     </p>
+     <pre>$cfgFilePath</pre>
+     <p>
+      from the following template:
+     </p>
+     <pre>$cfgFileTemplate</pre>
+     <p>
+      Remove the leading <tt>//</tt> from a line if you want to adjust it.
+     </p>
+HTM;
+}
+
+$out .= <<<HTM
      <p>
       <a href="./">back</a> to the index
      </p>