diff --git a/src/_h5ai/client/js/scripts.js b/src/_h5ai/client/js/scripts.js index 494679e4..2cd41816 100644 --- a/src/_h5ai/client/js/scripts.js +++ b/src/_h5ai/client/js/scripts.js @@ -30,6 +30,7 @@ var $ = jQuery, module = $('script[data-module]').data('module'), + data = {action: 'get', setup: true, options: true, types: true, theme: true, langs: true}, url; if ($('html').hasClass('no-browser')) { @@ -39,6 +40,7 @@ if (module === 'main') { url = '.'; } else if (module === 'info') { + data.updatecmds = true; url = 'server/php/index.php'; } else { return; @@ -46,7 +48,7 @@ $.ajax({ url: url, - data: {action: 'get', setup: true, options: true, types: true, theme: true, langs: true}, + data: data, type: 'POST', dataType: 'json' }).done(function (config) { diff --git a/src/_h5ai/server/php/inc/setup.php b/src/_h5ai/server/php/inc/setup.php index 3d22abc8..4056f281 100644 --- a/src/_h5ai/server/php/inc/setup.php +++ b/src/_h5ai/server/php/inc/setup.php @@ -81,18 +81,29 @@ function setup() { define("CACHE_HREF", normalize_path(APP_HREF . "/cache", true)); define("CACHE_PATH", normalize_path(APP_PATH . "/cache", false)); define("HAS_WRITABLE_CACHE", @is_writable(CACHE_PATH)); + define("CMDS_PATH", normalize_path(CACHE_PATH . "/cmds.json", false)); // EXTERNAL COMMANDS - // todo: cache all cmd tests - $cmd = false; - if (!$cmd && exec_0("command -v command")) { - $cmd = "command -v"; + $cmds = load_commented_json(CMDS_PATH); + if (sizeof($cmds) === 0 || has_request_param("updatecmds")) { + $cmds["command"] = exec_0("command -v command"); + $cmds["which"] = exec_0("which which"); + + $cmd = false; + if ($cmds["command"]) { + $cmd = "command -v"; + } else if ($cmds["which"]) { + $cmd = "which"; + } + + foreach (array("tar", "zip", "convert", "ffmpeg", "avconv", "du") as $c) { + $cmds[$c] = ($cmd !== false) && exec_0($cmd . " " . $c); + } + + safe_json(CMDS_PATH, $cmds); } - if (!$cmd && exec_0("which which")) { - $cmd = "which"; - } - foreach (array("tar", "zip", "convert", "ffmpeg", "avconv", "du") as $c) { - define("HAS_CMD_" . strtoupper($c), ($cmd !== false) && exec_0($cmd . " " . $c)); + foreach ($cmds as $c => $has) { + define("HAS_CMD_" . strtoupper($c), $has); } } diff --git a/src/_h5ai/server/php/inc/util.php b/src/_h5ai/server/php/inc/util.php index 4672bea8..338a9332 100644 --- a/src/_h5ai/server/php/inc/util.php +++ b/src/_h5ai/server/php/inc/util.php @@ -74,6 +74,13 @@ function load_commented_json($path) { } +function safe_json($path, $obj) { + + $json = json_encode($obj); + return file_put_contents($path, $json) !== false; +} + + function passthru_cmd($cmd) { $rc = null;