mirror of
https://github.com/DeNNiiInc/UltyScan.git
synced 2026-04-17 20:35:59 +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'] ?? '';
|
||||
|
||||
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';
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user