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 b6204a1a..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
@@ -38,5 +31,5 @@ html.no-js.browser( lang="en" )
| ! ⚡
span.right
a( href="{{pkg.url}}", title="{{pkg.name}} {{pkg.version}} · {{pkg.description}}" )
- | powered by h5ai {{pkg.version}}
+ | powered by {{pkg.name}} {{pkg.version}}
span.center
diff --git a/src/_h5ai/server/php/inc/class-api.php b/src/_h5ai/server/php/inc/class-api.php
index 445ccbd3..a52d8971 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();
}
@@ -19,11 +19,26 @@ class Api {
$action = use_request_param("action");
json_fail(100, "unsupported request", !in_array($action, $this->actions));
- $methodname = "on_$action";
+ $methodname = "on_${action}";
$this->$methodname();
}
+ 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();
@@ -88,7 +103,7 @@ class Api {
$response["all_items"] = $this->app->get_all_items();
}
- if (count($_REQUEST)) {
+ if (AS_ADMIN && count($_REQUEST)) {
$response["unused"] = $_REQUEST;
}
diff --git a/src/_h5ai/server/php/inc/class-app.php b/src/_h5ai/server/php/inc/class-app.php
index fd16ede9..6b786c32 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"]);
+ 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;
}
@@ -134,7 +144,7 @@ class App {
public function is_managed_path($path) {
- if (!is_dir($path) || strpos($path, '../') || strpos($path, '/..') || $path == '..') {
+ if (!is_dir($path) || strpos($path, '../') !== false || strpos($path, '/..') !== false || $path === '..') {
return false;
}
diff --git a/src/_h5ai/server/php/inc/class-archive.php b/src/_h5ai/server/php/inc/class-archive.php
index a78a107a..dcc099a1 100644
--- a/src/_h5ai/server/php/inc/class-archive.php
+++ b/src/_h5ai/server/php/inc/class-archive.php
@@ -23,7 +23,11 @@ class Archive {
$this->add_hrefs($urls);
if (count($this->dirs) === 0 && count($this->files) === 0) {
- $this->add_dir(CURRENT_PATH, "/");
+ if ($type === "php-tar") {
+ $this->add_dir(CURRENT_PATH, "/");
+ } else {
+ $this->add_dir(CURRENT_PATH, ".");
+ }
}
if ($type === "php-tar") {
diff --git a/src/_h5ai/server/php/inc/page.php.jade b/src/_h5ai/server/php/inc/page.php.jade
index c5bc1b24..82ddb9dc 100644
--- a/src/_h5ai/server/php/inc/page.php.jade
+++ b/src/_h5ai/server/php/inc/page.php.jade
@@ -1,7 +1,8 @@
-- var app_href = "= APP_HREF ?>"
-- var fallback = "= FALLBACK ?>"
+- var app_href = ""
+- var fallback = ""
+
doctype 5
//if lt IE 10
@@ -35,7 +36,7 @@ html.no-js.browser( lang="en" )
| ! ⚡
span.right
a( href="{{pkg.url}}", title="{{pkg.name}} {{pkg.version}} · {{pkg.description}}" )
- | powered by h5ai {{pkg.version}}
+ | powered by {{pkg.name}} {{pkg.version}}
span.center
div#sidebar
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/inc/util.php b/src/_h5ai/server/php/inc/util.php
index f3e040d4..fc2d091f 100644
--- a/src/_h5ai/server/php/inc/util.php
+++ b/src/_h5ai/server/php/inc/util.php
@@ -1,9 +1,20 @@
$code, "msg" => $msg));
- exit;
+ json_exit(array("code" => $code, "msg" => $msg));
}
}
@@ -86,28 +96,10 @@ function exec_cmdv($cmdv) {
}
-function delete_path($path, $recursive = false) {
- if (is_file($path)) {
- return @unlink($path);
- }
-
- if (is_dir($path)) {
- if ($recursive === true && $dir = opendir($path)) {
- while (($name = readdir($dir)) !== false) {
- delete_path($path . "/" . $name);
- }
- closedir($dir);
- }
-
- return @rmdir($path);
- }
-
- return false;
-}
-
-
-// debug tools
+/*********************************************************************
+ Debug Tools
+*********************************************************************/
function err_log($message, $obj = null) {
diff --git a/src/_h5ai/server/php/index.php b/src/_h5ai/server/php/index.php
index b5459e9c..bfd13c08 100644
--- a/src/_h5ai/server/php/index.php
+++ b/src/_h5ai/server/php/index.php
@@ -1,14 +1,19 @@
apply();
-
} else {
-
- header("Content-type: text/html;charset=utf-8");
define("FALLBACK", $app->get_fallback());
normalized_require_once("page");
}