diff --git a/www/commands/site_gitinfo.php b/www/commands/site_gitinfo.php new file mode 100644 index 0000000..5087673 --- /dev/null +++ b/www/commands/site_gitinfo.php @@ -0,0 +1,23 @@ +forceResult(400, "Wrong parameters."); return; } + +$field = strtolower($API_OPTIONS['field']); + +if ($field === 'branch') { echo exec('git rev-parse --abbrev-ref HEAD'); return; } +if ($field === 'head') { echo exec('git rev-parse HEAD'); return; } +if ($field === 'timestamp') { echo (new DateTime(exec('git log -1 --format=%cd --date=iso')))->format('Y-m-d H:i:s'); return; } +if ($field === 'origin') { echo exec('git config --get remote.origin.url'); return; } +if ($field === 'message') { echo trim(shell_exec('git log -1 --format=%B')); return; } + + +$FRAME_OPTIONS->statuscode = 400; +echo 'Unknown field'; + +return; \ No newline at end of file diff --git a/www/data/css/styles.css b/www/data/css/styles.css index fdc36ae..2c94ca4 100644 --- a/www/data/css/styles.css +++ b/www/data/css/styles.css @@ -971,6 +971,10 @@ html, body { padding-bottom: 2px; } +.admin_ajax_gitfield_error { + color: #FF0000; +} + /* 400px */ #loginform div { display: flex; diff --git a/www/data/css/styles.min.css b/www/data/css/styles.min.css index 60df156..5fd2ce4 100644 --- a/www/data/css/styles.min.css +++ b/www/data/css/styles.min.css @@ -188,6 +188,7 @@ html,body{margin:0;padding:0;height:100%} .boxedcontent.graybox .bc_data{padding-top:2px;padding-bottom:2px} .boxedcontent.successbox{background-color:#168b00;color:#222;border:1px solid #444;font-weight:bold;text-align:center} .boxedcontent.successbox .bc_data{padding-top:2px;padding-bottom:2px} +.admin_ajax_gitfield_error{color:red} #loginform div{display:flex;flex-direction:column} #loginform div button{margin:10px 0;padding:0} .loginerror{display:flex;background:#f44;color:#222;border:1px solid #a44;border-radius:2px;font-weight:bold;padding:0 5px;margin:5px 0 20px 0} diff --git a/www/data/css/styles_admin.scss b/www/data/css/styles_admin.scss index 4e921de..687f1d3 100644 --- a/www/data/css/styles_admin.scss +++ b/www/data/css/styles_admin.scss @@ -136,3 +136,7 @@ padding-bottom: 2px; } } + +.admin_ajax_gitfield_error { + color: $COL_ADMIN_ERROR; +} \ No newline at end of file diff --git a/www/data/javascript/admin.js b/www/data/javascript/admin.js index ffb6352..27eb639 100644 --- a/www/data/javascript/admin.js +++ b/www/data/javascript/admin.js @@ -148,8 +148,33 @@ function refreshSingle(apibutton, then) }); } +function queryGitField(dest) +{ + const ddest = $(dest); + + let config = + { + url: '/api/site::gitinfo?field=' + ddest.attr('data-ajax_gitfield'), + type: 'GET', + dataType: 'text', + cache : false, + }; + + $.ajax(config) + .done((data, status, xhr) => + { + ddest.text(data); + }) + .fail((xhr, status, err) => + { + ddest.addClass('admin_ajax_gitfield_error'); + ddest.text('ERROR'); + }); +} + $(function() { - for (let apibutton of $('.selftest_sequential').toArray()) setTimeout(() => refreshConsistencyDisplaySequential(0), 200); - for (let apibutton of $('.selftest_parallel').toArray()) setTimeout(() => refreshConsistencyDisplayParallel(), 200); + for (let elem of $('.selftest_sequential').toArray()) setTimeout(() => refreshConsistencyDisplaySequential(0), 200); + for (let elem of $('.selftest_parallel').toArray()) setTimeout(() => refreshConsistencyDisplayParallel(), 200); + for (let elem of $('.admin_ajax_gitfield').toArray()) setTimeout(() => queryGitField(elem), 0); }); \ No newline at end of file diff --git a/www/pages/admin.php b/www/pages/admin.php index 231279a..6214afe 100644 --- a/www/pages/admin.php +++ b/www/pages/admin.php @@ -41,10 +41,11 @@ $connected = true; try { $SITE->modules->Database(); } catch (Exception $e) { $c
Version
-
Branch:
-
Commit:
-
Date:
-
Message:
+
Branch: ...
+
Commit: ...
+
Date: ...
+
Origin: ...
+
Message:...
diff --git a/www/pages/api.php b/www/pages/api.php index 9a7ebe7..3a82ec3 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -20,6 +20,7 @@ $API_COMMANDS = 'site::createprogramthumbnails' => [ 'src' => __DIR__.'/../commands/site_createProgramThumbnails.php', 'auth' => 'admin' ], 'site::createbookthumbnails' => [ 'src' => __DIR__.'/../commands/site_createBookThumbnails.php', 'auth' => 'admin' ], 'site::selftest' => [ 'src' => __DIR__.'/../commands/site_selftest.php', 'auth' => 'admin' ], + 'site::gitinfo' => [ 'src' => __DIR__.'/../commands/site_gitinfo.php', 'auth' => 'admin' ], 'server::setselfaddress' => [ 'src' => __DIR__.'/../commands/server_setselfaddress.php', 'auth' => 'none' ], 'server::gitwebhook' => [ 'src' => __DIR__.'/../commands/server_gitwebhook.php', 'auth' => 'webhook_secret' ],