diff --git a/webui/execute.php b/webui/execute.php index 09fbec1..5b73a5a 100644 --- a/webui/execute.php +++ b/webui/execute.php @@ -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; } diff --git a/webui/index.php b/webui/index.php index cbbdf69..740d467 100644 --- a/webui/index.php +++ b/webui/index.php @@ -398,8 +398,13 @@