mirror of
https://github.com/DeNNiiInc/UltyScan.git
synced 2026-04-17 18:26:00 +00:00
Add git version display with commit ID and age
This commit is contained in:
@@ -5,8 +5,34 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
initModeHandler();
|
initModeHandler();
|
||||||
loadWorkspaces();
|
loadWorkspaces();
|
||||||
checkScanStatus();
|
checkScanStatus();
|
||||||
|
loadVersion();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load Git Version Info
|
||||||
|
async function loadVersion() {
|
||||||
|
const versionDisplay = document.getElementById("version-display");
|
||||||
|
if (!versionDisplay) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("version.php");
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (data.commit) {
|
||||||
|
versionDisplay.innerHTML = `
|
||||||
|
<span style="background: var(--bg-secondary); padding: 0.25rem 0.5rem; border-radius: 4px; margin-right: 0.5rem;">
|
||||||
|
<span style="color: var(--accent-primary);">⎇</span> ${data.branch || 'main'}
|
||||||
|
</span>
|
||||||
|
<span style="background: var(--bg-secondary); padding: 0.25rem 0.5rem; border-radius: 4px;">
|
||||||
|
<span style="color: var(--accent-success);">#</span>${data.commit}
|
||||||
|
</span>
|
||||||
|
<span style="margin-left: 0.5rem; color: var(--text-secondary);">${data.age}</span>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load version:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Tab Navigation
|
// Tab Navigation
|
||||||
function initTabs() {
|
function initTabs() {
|
||||||
const tabs = document.querySelectorAll(".tab");
|
const tabs = document.querySelectorAll(".tab");
|
||||||
|
|||||||
@@ -24,11 +24,16 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<!-- Tabs -->
|
<!-- Tabs -->
|
||||||
<div class="tabs">
|
<div class="tabs" style="display: flex; justify-content: space-between; align-items: center;">
|
||||||
<button class="tab active" data-tab="scan-tab">New Scan</button>
|
<div>
|
||||||
<button class="tab" data-tab="workspaces-tab">Workspaces</button>
|
<button class="tab active" data-tab="scan-tab">New Scan</button>
|
||||||
<button class="tab" data-tab="console-tab">Console</button>
|
<button class="tab" data-tab="workspaces-tab">Workspaces</button>
|
||||||
<button class="tab" data-tab="settings-tab">Settings</button>
|
<button class="tab" data-tab="console-tab">Console</button>
|
||||||
|
<button class="tab" data-tab="settings-tab">Settings</button>
|
||||||
|
</div>
|
||||||
|
<div id="version-display" style="font-size: 0.75rem; color: var(--text-muted); padding-right: 1rem;">
|
||||||
|
<!-- Loaded by JS -->
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Scan Tab -->
|
<!-- Scan Tab -->
|
||||||
|
|||||||
55
webui/version.php
Normal file
55
webui/version.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UltyScan Web Interface - Git Version Info
|
||||||
|
* Returns current git commit ID and age
|
||||||
|
*/
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
|
$gitDir = '/usr/share/sniper';
|
||||||
|
|
||||||
|
// Get commit hash
|
||||||
|
$commitHash = trim(shell_exec("cd $gitDir && git rev-parse --short HEAD 2>/dev/null"));
|
||||||
|
$fullHash = trim(shell_exec("cd $gitDir && git rev-parse HEAD 2>/dev/null"));
|
||||||
|
|
||||||
|
// Get commit date
|
||||||
|
$commitDate = trim(shell_exec("cd $gitDir && git log -1 --format=%ci 2>/dev/null"));
|
||||||
|
$commitTimestamp = strtotime($commitDate);
|
||||||
|
|
||||||
|
// Calculate age
|
||||||
|
$age = '';
|
||||||
|
if ($commitTimestamp) {
|
||||||
|
$diff = time() - $commitTimestamp;
|
||||||
|
|
||||||
|
if ($diff < 60) {
|
||||||
|
$age = $diff . ' seconds ago';
|
||||||
|
} elseif ($diff < 3600) {
|
||||||
|
$mins = floor($diff / 60);
|
||||||
|
$age = $mins . ' minute' . ($mins > 1 ? 's' : '') . ' ago';
|
||||||
|
} elseif ($diff < 86400) {
|
||||||
|
$hours = floor($diff / 3600);
|
||||||
|
$age = $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ago';
|
||||||
|
} elseif ($diff < 604800) {
|
||||||
|
$days = floor($diff / 86400);
|
||||||
|
$age = $days . ' day' . ($days > 1 ? 's' : '') . ' ago';
|
||||||
|
} elseif ($diff < 2592000) {
|
||||||
|
$weeks = floor($diff / 604800);
|
||||||
|
$age = $weeks . ' week' . ($weeks > 1 ? 's' : '') . ' ago';
|
||||||
|
} else {
|
||||||
|
$months = floor($diff / 2592000);
|
||||||
|
$age = $months . ' month' . ($months > 1 ? 's' : '') . ' ago';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get branch
|
||||||
|
$branch = trim(shell_exec("cd $gitDir && git rev-parse --abbrev-ref HEAD 2>/dev/null"));
|
||||||
|
|
||||||
|
echo json_encode([
|
||||||
|
'commit' => $commitHash,
|
||||||
|
'fullCommit' => $fullHash,
|
||||||
|
'branch' => $branch,
|
||||||
|
'date' => $commitDate,
|
||||||
|
'age' => $age,
|
||||||
|
'timestamp' => $commitTimestamp
|
||||||
|
]);
|
||||||
Reference in New Issue
Block a user