mirror of
https://github.com/DeNNiiInc/UltyScan.git
synced 2026-04-17 18:26:00 +00:00
Fix Update button to git pull and refresh UI
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user