This commit is contained in:
Alexander Dines 2024-09-04 16:08:30 -07:00
parent 17d9c480cf
commit 57997473d6
2 changed files with 2 additions and 102 deletions

View file

@ -13,25 +13,9 @@ require('@xterm/xterm/css/xterm.css');
require('../css/style.css'); require('../css/style.css');
/* global Blob, logBtn, credentialsBtn, reauthBtn, downloadLogBtn */ // eslint-disable-line /* global Blob, logBtn, credentialsBtn, reauthBtn, downloadLogBtn */ // eslint-disable-line
let sessionLogEnable = false;
let loggedData = false;
let sessionLog: string;
let sessionFooter: any;
let logDate: {
getFullYear: () => any;
getMonth: () => number;
getDate: () => any;
getHours: () => any;
getMinutes: () => any;
getSeconds: () => any;
};
let currentDate: Date;
let myFile: string;
let errorExists: boolean; let errorExists: boolean;
const term = new Terminal(); const term = new Terminal();
// DOM properties // DOM properties
const logBtn = document.getElementById('logBtn');
const downloadLogBtn = document.getElementById('downloadLogBtn');
const status = document.getElementById('status'); const status = document.getElementById('status');
const fitAddon = new FitAddon(); const fitAddon = new FitAddon();
const terminalContainer = document.getElementById('terminal-container'); const terminalContainer = document.getElementById('terminal-container');
@ -62,67 +46,6 @@ const socket = io({
}, },
}); });
// cross browser method to "download" an element to the local system
// used for our client-side logging feature
function downloadLog() {
// eslint-disable-line
if (loggedData === true) {
myFile = `WebSSH2-${logDate.getFullYear()}${
logDate.getMonth() + 1
}${logDate.getDate()}_${logDate.getHours()}${logDate.getMinutes()}${logDate.getSeconds()}.log`;
// regex should eliminate escape sequences from being logged.
const blob = new Blob(
[
sessionLog.replace(
// eslint-disable-next-line no-control-regex
/[\u001b\u009b][[\]()#;?]*(?:\d{1,4}(?:;\d{0,4})*)?[0-9A-ORZcf-nqry=><;]/g,
'',
),
],
{
// eslint-disable-line no-control-regex
type: 'text/plain',
},
);
const elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = myFile;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
term.focus();
}
// Set variable to toggle log data from client/server to a varialble
// for later download
function toggleLog() {
// eslint-disable-line
if (sessionLogEnable === true) {
sessionLogEnable = false;
loggedData = true;
logBtn.innerHTML = '<i class="fas fa-clipboard fa-fw"></i> Start Log';
currentDate = new Date();
sessionLog = `${sessionLog}\r\n\r\nLog End for ${sessionFooter}: ${currentDate.getFullYear()}/${
currentDate.getMonth() + 1
}/${currentDate.getDate()} @ ${currentDate.getHours()}:${currentDate.getMinutes()}:${currentDate.getSeconds()}\r\n`;
logDate = currentDate;
term.focus();
return false;
}
sessionLogEnable = true;
loggedData = true;
logBtn.innerHTML = '<i class="fas fa-cog fa-spin fa-fw"></i> Stop Log';
downloadLogBtn.style.color = '#000';
downloadLogBtn.addEventListener('click', downloadLog);
currentDate = new Date();
sessionLog = `Log Start for ${sessionFooter}: ${currentDate.getFullYear()}/${
currentDate.getMonth() + 1
}/${currentDate.getDate()} @ ${currentDate.getHours()}:${currentDate.getMinutes()}:${currentDate.getSeconds()}\r\n\r\n`;
logDate = currentDate;
term.focus();
return false;
}
function resizeScreen() { function resizeScreen() {
fitAddon.fit(); fitAddon.fit();
socket.emit('resize', { cols: term.cols, rows: term.rows }); socket.emit('resize', { cols: term.cols, rows: term.rows });
@ -137,9 +60,6 @@ term.onData((data) => {
socket.on('data', (data: string | Uint8Array) => { socket.on('data', (data: string | Uint8Array) => {
term.write(data); term.write(data);
if (sessionLogEnable) {
sessionLog += data;
}
}); });
socket.on('connect', () => { socket.on('connect', () => {
@ -171,23 +91,3 @@ socket.on('disconnect', (err: any) => {
// status.innerHTML = `ERROR: ${err}`; // status.innerHTML = `ERROR: ${err}`;
// } // }
// }); // });
// socket.on('reauth', () => {
// if (allowreauth) {
// reauthSession();
// }
// });
// safe shutdown
// socket.on('shutdownCountdownUpdate', (remainingSeconds: any) => {
// if (!hasCountdownStarted) {
// countdown.classList.add('active');
// hasCountdownStarted = true;
// }
// countdown.innerText = `Shutting down in ${remainingSeconds}s`;
// });
// term.onTitleChange((title) => {
// document.title = title;
// });

View file

@ -40,13 +40,13 @@ function startServer() {
app.disable('x-powered-by'); app.disable('x-powered-by');
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));
app.post('/ssh/host/:host?', connectTerminalWS); app.post('/ssh/devbox/', connectTerminalWS);
// ======== To remove ======== // ======== To remove ========
// Static files.. // Static files..
app.post('/ssh', express.static(publicPath, staticFileConfig)); app.post('/ssh', express.static(publicPath, staticFileConfig));
app.use('/ssh', express.static(publicPath, staticFileConfig)); app.use('/ssh', express.static(publicPath, staticFileConfig));
// =========================== // ===========================
app.get('/ssh/host/:host?', connectTerminalWS); app.get('/ssh/devbox/', connectTerminalWS);
io.on('connection', appSocket); io.on('connection', appSocket);