From 19eea2b3164a1ce3fc77f2c00f323aadb524a220 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 14 Jul 2013 01:18:59 +0200 Subject: [PATCH] Fixing PHP path and request issues. --- src/_h5ai/server/php/inc/App.php | 30 ++++++++++++++---------------- src/_h5ai/server/php/inc/Item.php | 2 +- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/_h5ai/server/php/inc/App.php b/src/_h5ai/server/php/inc/App.php index 28e4ac1c..a47aaa73 100644 --- a/src/_h5ai/server/php/inc/App.php +++ b/src/_h5ai/server/php/inc/App.php @@ -27,9 +27,6 @@ class App { $this->abs_path = $this->get_abs_path($this->abs_href); $this->options = load_commented_json($this->app_abs_path . "/conf/options.json"); - - $this->is_https = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] === 443); - $this->prot_host = 'http' . ($this->is_https ? 's' : '') . '://' . getenv('HTTP_HOST'); } @@ -138,29 +135,30 @@ class App { public function get_http_code($abs_href) { - if (!is_dir($this->get_abs_path($abs_href))) { + $abs_path = $this->get_abs_path($abs_href); + + if (!is_dir($abs_path)) { return 500; } - $abs_path = $this->get_abs_path($abs_href); - foreach ($this->options["view"]["indexFiles"] as $if) { if (file_exists($abs_path . "/" . $if)) { return 200; } } - $rc = 200; - ob_start(); - try { - $res = json_decode(file_get_contents($this->prot_host . $abs_href . '?version')); - if ($res->version === '{{pkg.version}}' && $res->href === $this->app_abs_href) { - $rc = App::$MAGIC_SEQUENCE; + $p = $abs_path; + while ($p !== $this->root_abs_path) { + if (@is_dir($p . "/_h5ai/server")) { + return 200; } - } catch (Exception $e) {} - ob_end_clean(); - - return $rc; + $pp = normalize_path(dirname($p)); + if ($pp === $p) { + return 200; + } + $p = $pp; + } + return App::$MAGIC_SEQUENCE; } diff --git a/src/_h5ai/server/php/inc/Item.php b/src/_h5ai/server/php/inc/Item.php index 4ab58bd4..1a5c6135 100644 --- a/src/_h5ai/server/php/inc/Item.php +++ b/src/_h5ai/server/php/inc/Item.php @@ -88,7 +88,7 @@ class Item { public function get_parent(&$cache) { $parent_abs_path = normalize_path(dirname($this->abs_path)); - if (starts_with($parent_abs_path, $this->app->get_root_abs_path())) { + if ($parent_abs_path !== $this->abs_path && starts_with($parent_abs_path, $this->app->get_root_abs_path())) { return Item::get($this->app, $parent_abs_path, $cache); } return null;