diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2014-07-04 18:25:01 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2014-07-04 18:25:01 +0200 |
| commit | f6e177a89832ba36409ac845eb72522e051bb0f3 (patch) | |
| tree | c1df7e101b30060c3cb406ef19c4c69c985a01a1 | |
| parent | 00d96cfc38f3d1d1d317ee56b4fdab0e9341e792 (diff) | |
| download | phorkie-f6e177a89832ba36409ac845eb72522e051bb0f3.tar.gz phorkie-f6e177a89832ba36409ac845eb72522e051bb0f3.zip | |
config file setup instructions
| -rw-r--r-- | src/phorkie/SetupCheck.php | 7 | ||||
| -rw-r--r-- | src/phorkie/Tools.php | 12 | ||||
| -rw-r--r-- | tests/phorkie/ToolsTest.php | 32 | ||||
| -rw-r--r-- | www/setup.php | 31 |
4 files changed, 80 insertions, 2 deletions
diff --git a/src/phorkie/SetupCheck.php b/src/phorkie/SetupCheck.php index 69cffd8..f8edd86 100644 --- a/src/phorkie/SetupCheck.php +++ b/src/phorkie/SetupCheck.php @@ -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)' + ); } } } diff --git a/src/phorkie/Tools.php b/src/phorkie/Tools.php index 7c9c46e..7819cda 100644 --- a/src/phorkie/Tools.php +++ b/src/phorkie/Tools.php @@ -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; + } } ?> diff --git a/tests/phorkie/ToolsTest.php b/tests/phorkie/ToolsTest.php index 7a5be16..021797d 100644 --- a/tests/phorkie/ToolsTest.php +++ b/tests/phorkie/ToolsTest.php @@ -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/./') + ); + } } ?> diff --git a/www/setup.php b/www/setup.php index cd0deaa..f0be905 100644 --- a/www/setup.php +++ b/www/setup.php @@ -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> |
