let pendingPid = null; let pendingBtn = null; function getCsrfToken() { return document.querySelector('meta[name="csrf-token"]')?.content || ''; } function killProcess(pid, btn) { pendingPid = pid; pendingBtn = btn; document.getElementById('killPidDisplay').textContent = pid; document.getElementById('killModal').style.display = 'flex'; } function closeKillModal() { pendingPid = null; pendingBtn = null; document.getElementById('killForce').checked = false; document.getElementById('killModal').style.display = 'none'; } function confirmKill() { if (!pendingPid) return; const signal = document.getElementById('killForce').checked ? 9 : 15; const btn = document.getElementById('confirmKillBtn'); const originalText = btn.innerHTML; btn.disabled = true; btn.innerHTML = ' Killing...'; fetch('/servers/' + serverId + '/processes/kill', { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'X-CSRF-Token': getCsrfToken(), }, body: 'pid=' + pendingPid + '&signal=' + signal + '&_csrf_token=' + encodeURIComponent(getCsrfToken()), }) .then(r => r.json()) .then(data => { showToast(data.success ? 'success' : 'error', data.message); if (data.success && pendingBtn) { const row = pendingBtn.closest('tr'); row.style.opacity = '0.4'; pendingBtn.disabled = true; pendingBtn.innerHTML = ' Killed'; } closeKillModal(); }) .catch(err => { showToast('error', 'Request failed: ' + err.message); closeKillModal(); }) .finally(() => { btn.disabled = false; btn.innerHTML = originalText; }); } document.addEventListener('keydown', function(e) { if (e.key === 'Escape') closeKillModal(); });