fix/policy-container-width #91
@@ -12,6 +12,12 @@ terminalInput.addEventListener('keydown', function(e) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function escapeHtml(str) {
|
||||||
|
const d = document.createElement('div');
|
||||||
|
d.textContent = str;
|
||||||
|
return d.innerHTML;
|
||||||
|
}
|
||||||
|
|
||||||
function executeCommand() {
|
function executeCommand() {
|
||||||
const command = terminalInput.value.trim();
|
const command = terminalInput.value.trim();
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
@@ -46,6 +52,9 @@ function executeCommand() {
|
|||||||
if (data.stderr) {
|
if (data.stderr) {
|
||||||
appendTerminalLine(data.stderr, 'error');
|
appendTerminalLine(data.stderr, 'error');
|
||||||
}
|
}
|
||||||
|
if (data.history) {
|
||||||
|
appendHistoryRow(data.history);
|
||||||
|
}
|
||||||
updateStatus('connected', 'Connected');
|
updateStatus('connected', 'Connected');
|
||||||
} else {
|
} else {
|
||||||
appendTerminalLine(data.message || 'Command failed', 'error');
|
appendTerminalLine(data.message || 'Command failed', 'error');
|
||||||
@@ -84,6 +93,23 @@ function clearTerminal() {
|
|||||||
terminalOutput.innerHTML = '';
|
terminalOutput.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function appendHistoryRow(h) {
|
||||||
|
const tbody = document.querySelector('.card-body .table tbody');
|
||||||
|
if (!tbody) return;
|
||||||
|
const emptyState = tbody.closest('.card-body')?.querySelector('.empty-state');
|
||||||
|
if (emptyState) emptyState.remove();
|
||||||
|
const row = document.createElement('tr');
|
||||||
|
const time = h.executed_at ? new Date(h.executed_at.replace(' ', 'T')).toLocaleTimeString('en-US', { hour12: false }) : '';
|
||||||
|
row.innerHTML =
|
||||||
|
'<td>' + time + '</td>' +
|
||||||
|
'<td><code>' + escapeHtml(h.command) + '</code></td>' +
|
||||||
|
'<td><span class="badge ' + (h.exit_status === 0 ? 'badge-success' : 'badge-danger') + '">' + (h.exit_status === 0 ? 'OK' : 'ERR') + '</span></td>' +
|
||||||
|
'<td>' + escapeHtml(h.username || 'System') + '</td>';
|
||||||
|
tbody.prepend(row);
|
||||||
|
const container = tbody.closest('.table-responsive');
|
||||||
|
if (container) container.scrollTop = 0;
|
||||||
|
}
|
||||||
|
|
||||||
function clearHistory() {
|
function clearHistory() {
|
||||||
if (!confirm('Clear all command history for this server?')) return;
|
if (!confirm('Clear all command history for this server?')) return;
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ class TerminalController
|
|||||||
$ssh->disconnect();
|
$ssh->disconnect();
|
||||||
|
|
||||||
$commandHistory = new CommandHistory();
|
$commandHistory = new CommandHistory();
|
||||||
$commandHistory->log(
|
$historyId = $commandHistory->log(
|
||||||
$id,
|
$id,
|
||||||
Session::get('user_id'),
|
Session::get('user_id'),
|
||||||
$command,
|
$command,
|
||||||
@@ -115,6 +115,13 @@ class TerminalController
|
|||||||
'output' => $result['output'],
|
'output' => $result['output'],
|
||||||
'exit_status' => $result['exit_status'],
|
'exit_status' => $result['exit_status'],
|
||||||
'stderr' => $result['stderr'],
|
'stderr' => $result['stderr'],
|
||||||
|
'history' => [
|
||||||
|
'id' => $historyId,
|
||||||
|
'command' => $command,
|
||||||
|
'exit_status' => $result['exit_status'] ?? 0,
|
||||||
|
'executed_at' => date('Y-m-d H:i:s'),
|
||||||
|
'username' => Session::get('username'),
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
$this->view->json([
|
$this->view->json([
|
||||||
|
|||||||
Reference in New Issue
Block a user