Add cmd check caching.
This commit is contained in:
parent
dfd0e65651
commit
48b4b25317
3 changed files with 30 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue