Fix Update button to git pull and refresh UI

This commit is contained in:
2026-01-01 18:50:09 +11:00
parent 5333f924ac
commit d9faee1114
2 changed files with 57 additions and 7 deletions

View File

@@ -27,10 +27,48 @@ if (!is_dir(LOG_DIR)) {
$action = $_POST['action'] ?? ''; $action = $_POST['action'] ?? '';
if ($action === 'update') { if ($action === 'update') {
$cmd = SNIPER_PATH . ' -u 2>&1'; $installDir = '/usr/share/sniper';
$webDir = '/var/www/html/ultyscan';
$logFile = LOG_DIR . '/update_' . date('Ymd_His') . '.log'; $logFile = LOG_DIR . '/update_' . date('Ymd_His') . '.log';
exec("nohup $cmd > $logFile 2>&1 &");
echo json_encode(['success' => true, 'message' => 'Update started', 'log' => $logFile]); // Commands to update
$commands = [
"cd $installDir && git fetch origin",
"cd $installDir && git reset --hard origin/main",
"cd $installDir && git pull origin main",
"cp -r $installDir/webui/* $webDir/",
"chown -R www-data:www-data $webDir"
];
$output = [];
$output[] = "UltyScan Update - " . date('Y-m-d H:i:s');
$output[] = str_repeat('-', 40);
foreach ($commands as $cmd) {
$output[] = "$ $cmd";
$cmdOutput = shell_exec($cmd . ' 2>&1');
if ($cmdOutput) {
$output[] = trim($cmdOutput);
}
}
$output[] = str_repeat('-', 40);
$output[] = "Update completed at " . date('Y-m-d H:i:s');
// Get new commit info
$newCommit = trim(shell_exec("cd $installDir && git rev-parse --short HEAD 2>/dev/null"));
$output[] = "Now at commit: $newCommit";
// Write log
file_put_contents($logFile, implode("\n", $output));
echo json_encode([
'success' => true,
'message' => 'Update completed',
'commit' => $newCommit,
'log' => $logFile,
'output' => implode("\n", $output)
]);
exit; exit;
} }

View File

@@ -398,8 +398,13 @@
<script> <script>
// Additional inline functions // Additional inline functions
async function updateScanner() { async function updateScanner() {
if (!confirm('Update UltyScan? This may take a while.')) return; if (!confirm('Update UltyScan to latest version from GitHub?')) return;
showNotification('Starting update...', 'info');
const btn = event.target;
btn.disabled = true;
btn.textContent = 'Updating...';
showNotification('Pulling latest changes from GitHub...', 'info');
try { try {
const response = await fetch('execute.php', { const response = await fetch('execute.php', {
method: 'POST', method: 'POST',
@@ -410,10 +415,17 @@
}); });
const result = await response.json(); const result = await response.json();
if (result.success) { if (result.success) {
showNotification('Update started. Check console for progress.', 'success'); showNotification('Updated to commit #' + result.commit + '. Refreshing page...', 'success');
setTimeout(() => window.location.reload(), 2000);
} else {
showNotification('Update failed: ' + (result.error || 'Unknown error'), 'error');
btn.disabled = false;
btn.textContent = 'Update UltyScan';
} }
} catch (e) { } catch (e) {
showNotification('Update failed.', 'error'); showNotification('Update failed: ' + e.message, 'error');
btn.disabled = false;
btn.textContent = 'Update UltyScan';
} }
} }