Fixing PHP path and request issues.

This commit is contained in:
Lars Jung 2013-07-14 01:18:59 +02:00
parent bfba6c084c
commit 19eea2b316
2 changed files with 15 additions and 17 deletions

View file

@ -27,9 +27,6 @@ class App {
$this->abs_path = $this->get_abs_path($this->abs_href); $this->abs_path = $this->get_abs_path($this->abs_href);
$this->options = load_commented_json($this->app_abs_path . "/conf/options.json"); $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) { 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; return 500;
} }
$abs_path = $this->get_abs_path($abs_href);
foreach ($this->options["view"]["indexFiles"] as $if) { foreach ($this->options["view"]["indexFiles"] as $if) {
if (file_exists($abs_path . "/" . $if)) { if (file_exists($abs_path . "/" . $if)) {
return 200; return 200;
} }
} }
$rc = 200; $p = $abs_path;
ob_start(); while ($p !== $this->root_abs_path) {
try { if (@is_dir($p . "/_h5ai/server")) {
$res = json_decode(file_get_contents($this->prot_host . $abs_href . '?version')); return 200;
if ($res->version === '{{pkg.version}}' && $res->href === $this->app_abs_href) {
$rc = App::$MAGIC_SEQUENCE;
} }
} catch (Exception $e) {} $pp = normalize_path(dirname($p));
ob_end_clean(); if ($pp === $p) {
return 200;
return $rc; }
$p = $pp;
}
return App::$MAGIC_SEQUENCE;
} }

View file

@ -88,7 +88,7 @@ class Item {
public function get_parent(&$cache) { public function get_parent(&$cache) {
$parent_abs_path = normalize_path(dirname($this->abs_path)); $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 Item::get($this->app, $parent_abs_path, $cache);
} }
return null; return null;