diff --git a/src/_h5ai/client/css/inc/h5ai-info.less b/src/_h5ai/client/css/inc/h5ai-info.less index d33a2f9d..57424a2f 100644 --- a/src/_h5ai/client/css/inc/h5ai-info.less +++ b/src/_h5ai/client/css/inc/h5ai-info.less @@ -17,15 +17,6 @@ body#h5ai-info { } } - .build-version { - display: block; - } - .build-stamp { - display: block; - margin-top: 0.3em; - font-size: 0.6em; - color: #aaa; - } .idx-file { margin-top: 1em; font-size: 0.6em; @@ -61,6 +52,56 @@ body#h5ai-info { line-height: 1.4em; } + #login-wrapper { + margin: 96px 0; + font-size: 14px; + + #pass { + -moz-appearance: none; + -ms-appearance: none; + -webkit-appearance: none; + font-family: @font-family; + font-weight: @font-weight; + color: @col; + background: @col-widget-back-highlight; + border: @border-widget; + outline: none; + display: inline-block; + width: 200px; + height: 30px; + padding: 0 6px; + margin: 8px; + } + #login, #logout { + display: inline-block; + padding: 4px 16px; + margin: 8px; + background-color: @col-widget-back; + border: @border-widget; + cursor: pointer; + + color: @col; + cursor: pointer; + text-decoration: none; + .transition(all 0.2s ease-in-out); + + &:hover, &.hover { + background-color: @col-widget-back-highlight; + color: @col-hover; + } + } + #hint { + margin: 12px auto; + width: 320px; + color: @col; + font-size: 12px; + } + } + + #tests-wrapper { + margin: 96px 0; + } + #tests { display: inline-block; list-style-type: none; @@ -69,16 +110,17 @@ body#h5ai-info { padding: 0; .test { + padding: 6px; + .label { display: inline-block; - width: 370px; + width: 250px; } .result { display: inline-block; - width: 70px; + width: 250px; text-align: right; font-weight: bold; - color: #aaa; &.passed { color: #5a5; @@ -91,7 +133,7 @@ body#h5ai-info { margin: 4px 0 12px 12px; font-size: 0.7em; color: #aaa; - width: 370px; + width: 380px; line-height: 1.2em; } } diff --git a/src/_h5ai/client/js/inc/info.js b/src/_h5ai/client/js/inc/info.js index c5c75c7b..d02387aa 100644 --- a/src/_h5ai/client/js/inc/info.js +++ b/src/_h5ai/client/js/inc/info.js @@ -1,36 +1,59 @@ modulejs.define('info', ['$', 'config'], function ($, config) { - var template = '
ffmpeg
or avconv
available',
- setup.HAS_CMD_FFMPEG || setup.HAS_CMD_AVCONV
+ 'Movie thumbs', 'Command line program avconv
or ffmpeg
available',
+ setup.HAS_CMD_AVCONV || setup.HAS_CMD_FFMPEG
);
addTest(
@@ -69,15 +92,75 @@ modulejs.define('info', ['$', 'config'], function ($, config) {
);
addTest(
- 'Folder sizes', 'Command line program du
available',
+ 'Shell du', 'Command line program du
available',
setup.HAS_CMD_DU
);
},
+ addLogin = function () {
+
+ var request = function (data) {
+
+ $.ajax({
+ url: 'server/php/index.php',
+ type: 'POST',
+ dataType: 'JSON',
+ data: data
+ })
+ .always(function () {
+
+ window.location.reload();
+ });
+ },
+
+ onLogin = function () {
+
+ request({
+ 'action': 'login',
+ 'pass': $('#pass').val()
+ });
+ },
+
+ onLogout = function () {
+
+ request({
+ 'action': 'logout'
+ });
+ },
+
+ onKeydown = function (event) {
+
+ if (event.which === 13) {
+ onLogin();
+ }
+ };
+
+ $(loginTemp).appendTo('body');
+
+ if (setup.AS_ADMIN) {
+ $('#pass').remove();
+ $('#login').remove();
+ $('#logout').on('click', onLogout);
+ } else {
+ $('#pass').on('keydown', onKeydown).focus();
+ $('#login').on('click', onLogin);
+ $('#logout').remove();
+ }
+ if (setup.HAS_CUSTOM_PASSHASH) {
+ $('#hint').remove();
+ }
+ },
+
init = function () {
- $('.idx-file .value').text(setup.INDEX_HREF);
- addTests();
+ $('Index:
')
+ .appendTo('body')
+ .find('.value').text(setup.INDEX_HREF);
+
+ if (setup.AS_ADMIN) {
+ addTests();
+ }
+ addLogin();
};
init();
diff --git a/src/_h5ai/index.html.jade b/src/_h5ai/index.html.jade
index 83e1a86d..31b49efa 100644
--- a/src/_h5ai/index.html.jade
+++ b/src/_h5ai/index.html.jade
@@ -20,13 +20,6 @@ html.no-js.browser( lang="en" )
h1
a( href="{{pkg.url}}" ) {{pkg.name}}
- span.build-version version {{pkg.version}}
- span.build-stamp {{stamp}}
- span.idx-file Index:
- code.value
-
- h2 Server Setup
- ul#tests
div#bottombar.clearfix
span.left
diff --git a/src/_h5ai/server/php/inc/class-api.php b/src/_h5ai/server/php/inc/class-api.php
index 445ccbd3..86db2bc3 100644
--- a/src/_h5ai/server/php/inc/class-api.php
+++ b/src/_h5ai/server/php/inc/class-api.php
@@ -8,7 +8,7 @@ class Api {
public function __construct($app) {
- $this->actions = array("get", "getThumbHref", "download", "upload", "delete", "rename");
+ $this->actions = array("login", "logout", "get", "getThumbHref", "download");
$this->app = $app;
$this->options = $app->get_options();
}
@@ -24,6 +24,21 @@ class Api {
}
+ private function on_login() {
+
+ $pass = use_request_param("pass");
+ $_SESSION[AS_ADMIN_SESSION_KEY] = sha1($pass) === PASSHASH;
+ json_exit(array("as_admin" => $_SESSION[AS_ADMIN_SESSION_KEY]));
+ }
+
+
+ private function on_logout() {
+
+ $_SESSION[AS_ADMIN_SESSION_KEY] = false;
+ json_exit(array("as_admin" => $_SESSION[AS_ADMIN_SESSION_KEY]));
+ }
+
+
private function on_get() {
$response = array();
diff --git a/src/_h5ai/server/php/inc/class-app.php b/src/_h5ai/server/php/inc/class-app.php
index ec0ed64f..8448646d 100644
--- a/src/_h5ai/server/php/inc/class-app.php
+++ b/src/_h5ai/server/php/inc/class-app.php
@@ -26,11 +26,21 @@ class App {
$consts = get_defined_constants(true);
$setup = $consts["user"];
- // $setup["PHP_VERSION"] = PHP_VERSION;
- unset($setup["APP_PATH"]);
- unset($setup["ROOT_PATH"]);
- unset($setup["CURRENT_PATH"]);
- unset($setup["CACHE_PATH"]);
+
+ $setup["PHP_VERSION"] = PHP_VERSION;
+ unset($setup["AS_ADMIN_SESSION_KEY"]);
+ unset($setup["PASSHASH"]);
+
+ if (!AS_ADMIN) {
+ unset($setup["APP_PATH"]);
+ unset($setup["CACHE_PATH"]);
+ unset($setup["CURRENT_PATH"]);
+ unset($setup["PHP_VERSION"]);
+ unset($setup["ROOT_PATH"]);
+ unset($setup["SERVER_NAME"]);
+ unset($setup["SERVER_VERSION"]);
+ }
+
return $setup;
}
diff --git a/src/_h5ai/server/php/inc/setup.php b/src/_h5ai/server/php/inc/setup.php
index 19dc18e0..040544a9 100644
--- a/src/_h5ai/server/php/inc/setup.php
+++ b/src/_h5ai/server/php/inc/setup.php
@@ -10,12 +10,20 @@ function setup() {
define("NAME", "{{pkg.name}}");
define("VERSION", "{{pkg.version}}");
+ define("STAMP", "{{stamp}}");
define("BACKEND", "PHP");
define("API", true);
define("FILE_PREFIX", "_{{pkg.name}}");
+ // ADMIN
+ session_start();
+ define("AS_ADMIN_SESSION_KEY", "__H5AI_AS_ADMIN__");
+ define("AS_ADMIN", isset($_SESSION[AS_ADMIN_SESSION_KEY]) && $_SESSION[AS_ADMIN_SESSION_KEY] === true);
+ define("HAS_CUSTOM_PASSHASH", PASSHASH !== "da39a3ee5e6b4b0d3255bfef95601890afd80709");
+
+
// PHP
define("MIN_PHP_VERSION", "5.3.0");
define("HAS_PHP_VERSION", version_compare(PHP_VERSION, MIN_PHP_VERSION) >= 0);
@@ -38,6 +46,7 @@ function setup() {
}
define("SERVER_NAME", $server_name);
define("SERVER_VERSION", $server_version);
+ define("HAS_SERVER", in_array($server_name, array("apache", "lighttd", "nginx", "cherokee")));
define("HAS_WIN_OS", strtolower(substr(PHP_OS, 0, 3)) === "win");
diff --git a/src/_h5ai/server/php/index.php b/src/_h5ai/server/php/index.php
index 5a99db7b..553764a2 100644
--- a/src/_h5ai/server/php/index.php
+++ b/src/_h5ai/server/php/index.php
@@ -1,5 +1,17 @@