diff --git a/src/_h5ai/backend/php/class-bootstrap.php b/src/_h5ai/backend/php/class-bootstrap.php index d362e631..02463a2a 100644 --- a/src/_h5ai/backend/php/class-bootstrap.php +++ b/src/_h5ai/backend/php/class-bootstrap.php @@ -24,10 +24,13 @@ class Bootstrap { $setup = new Setup($request->query_boolean('refresh', false)); $context = new Context($session, $request, $setup); - if (strtolower($setup->get('REQUEST_METHOD')) === 'post') { + if ($context->is_api_request()) { (new Api($context))->apply(); + } else if ($context->is_info_request()) { + define('PUBLIC_HREF', $setup->get('PUBLIC_HREF')); + require __DIR__ . '/info.php'; } else { - define('APP_HREF', $setup->get('APP_HREF')); + define('PUBLIC_HREF', $setup->get('PUBLIC_HREF')); define('FALLBACK', (new Fallback($context))->get_html()); require __DIR__ . '/page.php'; } diff --git a/src/_h5ai/backend/php/core/class-context.php b/src/_h5ai/backend/php/core/class-context.php index a50b1b97..afddd945 100644 --- a/src/_h5ai/backend/php/core/class-context.php +++ b/src/_h5ai/backend/php/core/class-context.php @@ -65,6 +65,16 @@ class Context { return $this->session->get(Context::$AS_ADMIN_SESSION_KEY); } + public function is_api_request() { + + return strtolower($this->setup->get('REQUEST_METHOD')) === 'post'; + } + + public function is_info_request() { + + return $this->get_current_path() === $this->setup->get('APP_PATH') . '/public'; + } + public function to_href($path, $trailing_slash = true) { $rel_path = substr($path, strlen($this->setup->get('ROOT_PATH'))); @@ -154,6 +164,18 @@ class Context { return true; } + public function get_current_path() { + + $current_href = Util::normalize_path(parse_url($this->setup->get('REQUEST_URI'), PHP_URL_PATH), true); + $current_path = $this->to_path($current_href); + + if (!is_dir($current_path)) { + $current_path = Util::normalize_path(dirname($current_path), false); + } + + return $current_path; + } + public function get_items($href, $what) { if (!$this->is_managed_href($href)) { diff --git a/src/_h5ai/backend/php/core/class-fallback.php b/src/_h5ai/backend/php/core/class-fallback.php index 4fc2edb5..4c7469f9 100644 --- a/src/_h5ai/backend/php/core/class-fallback.php +++ b/src/_h5ai/backend/php/core/class-fallback.php @@ -3,33 +3,18 @@ class Fallback { private $context; - private $setup; public function __construct($context) { $this->context = $context; - $this->setup = $context->get_setup(); - } - - private function get_current_path() { - - $current_href = Util::normalize_path(parse_url($this->setup->get('REQUEST_URI'), PHP_URL_PATH), true); - $current_path = $this->context->to_path($current_href); - - if (!is_dir($current_path)) { - $current_path = Util::normalize_path(dirname($current_path), false); - } - - return $current_path; } public function get_html($path = null) { if (!$path) { - $path = $this->get_current_path(); + $path = $this->context->get_current_path(); } - - $fallback_images_href = $this->setup->get('APP_HREF') . 'public/images/fallback/'; + $fallback_images_href = $this->context->get_setup()->get('APP_HREF') . 'public/images/fallback/'; $cache = []; $folder = Item::get($this->context, $path, $cache); diff --git a/src/_h5ai/backend/php/core/class-setup.php b/src/_h5ai/backend/php/core/class-setup.php index 85b8a22a..97009620 100644 --- a/src/_h5ai/backend/php/core/class-setup.php +++ b/src/_h5ai/backend/php/core/class-setup.php @@ -18,7 +18,6 @@ class Setup { $this->add_admin_check(); $this->add_server_metadata_and_check(); $this->add_paths(); - $this->add_cache_paths_and_check(); $this->add_sys_cmd_checks(); } @@ -118,14 +117,8 @@ class Setup { $this->set('ROOT_HREF', Util::normalize_path(dirname($this->get('APP_HREF')), true)); $this->set('ROOT_PATH', Util::normalize_path(dirname($this->get('APP_PATH')), false)); - $index_href = null; - if (@is_readable(Util::normalize_path($this->get('APP_PATH') . '/public/index.php', false))) { - $index_href = Util::normalize_path($this->get('APP_HREF') . '/public/index.php', false); - } - $this->set('INDEX_HREF', $index_href); - } - - private function add_cache_paths_and_check() { + $this->set('PUBLIC_HREF', $this->get('APP_HREF') . 'public/'); + $this->set('INDEX_HREF', $this->get('APP_HREF') . 'public/index.php'); $this->set('CACHE_HREF', Util::normalize_path($this->get('APP_HREF') . '/public/cache', true)); $this->set('CACHE_PATH', Util::normalize_path($this->get('APP_PATH') . '/public/cache', false)); diff --git a/src/_h5ai/public/info.html.jade b/src/_h5ai/backend/php/info.php.jade similarity index 77% rename from src/_h5ai/public/info.html.jade rename to src/_h5ai/backend/php/info.php.jade index 5076fe48..496d767f 100644 --- a/src/_h5ai/public/info.html.jade +++ b/src/_h5ai/backend/php/info.php.jade @@ -1,3 +1,6 @@ +- var PUBLIC_HREF = '' + + doctype html @@ -5,14 +8,14 @@ doctype html head meta( charset="utf-8" ) meta( http-equiv="x-ua-compatible", content="ie=edge" ) - title #{pkg.name} #{pkg.version} Server Setup - meta( name="description", content="#{pkg.name} #{pkg.version} Server Setup" ) + title #{pkg.name} #{pkg.version} info page + meta( name="description", content="#{pkg.name} #{pkg.version} info page" ) meta( name="viewport", content="width=device-width, initial-scale=1" ) - link( rel="shortcut icon", href="images/favicon/favicon-16-32.ico" ) - link( rel="apple-touch-icon-precomposed", type="image/png", href="images/favicon/favicon-152.png" ) + link( rel="shortcut icon", href!="#{PUBLIC_HREF}images/favicon/favicon-16-32.ico" ) + link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{PUBLIC_HREF}images/favicon/favicon-152.png" ) link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Roboto:300,400,700" ) - link( rel="stylesheet", href="css/styles.css" ) - script( src="js/scripts.js", data-module="info" ) + link( rel="stylesheet", href!="#{PUBLIC_HREF}css/styles.css" ) + script( src!="#{PUBLIC_HREF}js/scripts.js", data-module="info" ) body#root.info diff --git a/src/_h5ai/backend/php/page.php.jade b/src/_h5ai/backend/php/page.php.jade index f943d6ae..d1a195a8 100644 --- a/src/_h5ai/backend/php/page.php.jade +++ b/src/_h5ai/backend/php/page.php.jade @@ -1,4 +1,4 @@ -- var APP_HREF = '' +- var PUBLIC_HREF = '' - var FALLBACK = '' @@ -12,11 +12,11 @@ head title index ยท powered by #{pkg.name} #{pkg.version} (#{pkg.homepage}) meta( name="description", content="index - powered by #{pkg.name} #{pkg.version} (#{pkg.homepage})" ) meta( name="viewport", content="width=device-width, initial-scale=1" ) - link( rel="shortcut icon", href!="#{APP_HREF}public/images/favicon/favicon-16-32.ico" ) - link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{APP_HREF}public/images/favicon/favicon-152.png" ) + link( rel="shortcut icon", href!="#{PUBLIC_HREF}images/favicon/favicon-16-32.ico" ) + link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{PUBLIC_HREF}images/favicon/favicon-152.png" ) link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Roboto:300,400,700" ) - link( rel="stylesheet", href!="#{APP_HREF}public/css/styles.css" ) - script( src!="#{APP_HREF}public/js/scripts.js", data-module="index" ) + link( rel="stylesheet", href!="#{PUBLIC_HREF}css/styles.css" ) + script( src!="#{PUBLIC_HREF}js/scripts.js", data-module="index" ) body#root diff --git a/src/_h5ai/public/.htaccess b/src/_h5ai/public/.htaccess index 3a4e2b14..c8a3286d 100644 --- a/src/_h5ai/public/.htaccess +++ b/src/_h5ai/public/.htaccess @@ -2,7 +2,7 @@ Satisfy all Order allow,deny Allow from all -DirectoryIndex info.html +DirectoryIndex index.php Options -Indexes diff --git a/src/_h5ai/public/index.php b/src/_h5ai/public/index.php index 5907f1ad..448263a1 100644 --- a/src/_h5ai/public/index.php +++ b/src/_h5ai/public/index.php @@ -3,8 +3,8 @@ define('MIN_PHP_VERSION', '5.4.0'); if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<')) { - header('Content-type: application/json;charset=utf-8'); - echo '{"err":"ERR_PHP","msg":"PHP ' . MIN_PHP_VERSION . '+ required","ver":"' . PHP_VERSION . '"}'; + header('Content-type: text/plain;charset=utf-8'); + echo '[{{pkg.name}} {{pkg.version}}] PHP ' . MIN_PHP_VERSION . '+ required, only found PHP ' . PHP_VERSION; exit; } diff --git a/src/_h5ai/public/js/inc/main/info.js b/src/_h5ai/public/js/inc/main/info.js index 8deeffc5..6a5288ca 100644 --- a/src/_h5ai/public/js/inc/main/info.js +++ b/src/_h5ai/public/js/inc/main/info.js @@ -162,12 +162,6 @@ modulejs.define('main/info', ['$', 'config'], function ($, config) { function init() { - if (config.err === 'ERR_PHP') { - $(testsTemp).appendTo('#content'); - addTest('PHP version', config.msg, false, config.ver); - return; - } - addLogin(); if (setup.AS_ADMIN) { addTests();