Files
ai-station-portal/templates/terminal.html
T

47 lines
3.4 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="ru" data-bs-theme="dark">
<head>
<meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">
<title>Терминал — AI Station</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.css">
<link href="/static/style.css" rel="stylesheet">
<style>
html,body{height:100%;margin:0;background:#0b1220}
.terminal-shell{height:calc(100vh - 120px);min-height:360px;background:#080d16;border:1px solid #29364a;border-radius:10px;padding:10px}
#terminal{height:100%;width:100%}
</style>
</head>
<body>
<main class="container-fluid p-3 p-lg-4">
<header class="d-flex align-items-center justify-content-between gap-3 mb-3">
<div><div class="text-secondary small text-uppercase">AI Station · {{ admin_user }}</div><h1 class="h4 mb-0">Терминал</h1></div>
<div class="d-flex align-items-center gap-2"><span id="connection" class="badge text-bg-secondary">Подключение…</span><a class="btn btn-outline-secondary btn-sm" href="/admin">К администрированию</a></div>
</header>
<div class="alert alert-warning py-2 small">Shell работает от имени пользователя веб-приложения ({{ admin_user }}), не от root. Для системных команд используйте sudo.</div>
<section class="terminal-shell"><div id="terminal"></div></section>
</main>
<script src="https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.min.js"></script>
<script>
const statusEl=document.getElementById('connection');
const term=new Terminal({cursorBlink:true,convertEol:true,scrollback:5000,fontFamily:'ui-monospace,SFMono-Regular,Consolas,monospace',fontSize:14,theme:{background:'#080d16',foreground:'#d8e1ef',cursor:'#62d6ff',selectionBackground:'#29435c'}});
const fit=new FitAddon.FitAddon(); term.loadAddon(fit); term.open(document.getElementById('terminal'));
let ws;
function connect(){
const proto=location.protocol==='https:'?'wss':'ws';
ws=new WebSocket(`${proto}://${location.host}/admin/terminal/ws`);
ws.onopen=()=>{statusEl.className='badge text-bg-success';statusEl.textContent='Подключено';fit.fit();ws.send(JSON.stringify({type:'resize',cols:term.cols,rows:term.rows}));term.focus();};
ws.onmessage=e=>term.write(e.data);
ws.onclose=e=>{statusEl.className='badge text-bg-danger';statusEl.textContent=e.code===4401?'Сессия истекла':'Отключено';term.write('\r\n\r\n[Соединение закрыто]\r\n');};
ws.onerror=()=>{statusEl.className='badge text-bg-danger';statusEl.textContent='Ошибка соединения';};
}
term.onData(data=>{if(ws&&ws.readyState===WebSocket.OPEN)ws.send(JSON.stringify({type:'input',data}));});
const resizeObserver=new ResizeObserver(()=>{fit.fit();if(ws&&ws.readyState===WebSocket.OPEN)ws.send(JSON.stringify({type:'resize',cols:term.cols,rows:term.rows}));});
resizeObserver.observe(document.getElementById('terminal'));
window.addEventListener('beforeunload',()=>{resizeObserver.disconnect();if(ws)ws.close();});
connect();
</script>
</body>
</html>