Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resume session upon disconnect #376

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/bun.lockb
100755 → 100644
Binary file not shown.
1 change: 1 addition & 0 deletions app/client/public/client.htm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<div id="dropupContent" class="dropup-content">
<a id="logBtn"><i class="fas fa-clipboard fa-fw"></i> Start Log</a>
<a id="downloadLogBtn"><i class="fas fa-download fa-fw"></i> Download Log</a>
<a id="restartBtn"><i class="fas fa-rotate-right fa-fw"></i> Restart Session</a>
<a id="reauthBtn" style="display: none;"><i class="fas fa-key fa-fw"></i> Switch User</a>
<a id="credentialsBtn" style="display: none;"><i class="fas fa-key fa-fw"></i> Credentials</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/client/public/webssh2.bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/client/public/webssh2.css
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ body, html {
#menu:hover .dropup-content {
display: block;
}
#logBtn, #credentialsBtn, #reauthBtn {
#logBtn, #credentialsBtn, #reauthBtn, #restartBtn {
color: #000;
}

Expand All @@ -341,7 +341,7 @@ body, html {
position: absolute;
background-color: #f1f1f1;
font-size: 16px;
min-width: 160px;
min-width: 180px;
bottom: 18px;
z-index: 101;
}
Expand Down
1 change: 1 addition & 0 deletions app/client/src/client.htm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<div id="dropupContent" class="dropup-content">
<a id="logBtn"><i class="fas fa-clipboard fa-fw"></i> Start Log</a>
<a id="downloadLogBtn"><i class="fas fa-download fa-fw"></i> Download Log</a>
<a id="restartBtn"><i class="fas fa-rotate-right fa-fw"></i> Restart Session</a>
<a id="reauthBtn" style="display: none;"><i class="fas fa-key fa-fw"></i> Switch User</a>
<a id="credentialsBtn" style="display: none;"><i class="fas fa-key fa-fw"></i> Credentials</a>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/client/src/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ body, html {
#menu:hover .dropup-content {
display: block;
}
#logBtn, #credentialsBtn, #reauthBtn {
#logBtn, #credentialsBtn, #reauthBtn, #restartBtn {
color: #000;
}

Expand All @@ -122,7 +122,7 @@ body, html {
position: absolute;
background-color: #f1f1f1;
font-size: 16px;
min-width: 160px;
min-width: 180px;
bottom: 18px;
z-index: 101;
}
Expand Down
56 changes: 38 additions & 18 deletions app/client/src/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { io } from 'socket.io-client';
import { Terminal } from '@xterm/xterm';
import { FitAddon } from '@xterm/addon-fit';
import { library, dom } from '@fortawesome/fontawesome-svg-core';
import { faBars, faClipboard, faDownload, faKey, faCog } from '@fortawesome/free-solid-svg-icons';
import { faBars, faClipboard, faDownload, faRotateRight, faKey, faCog } from '@fortawesome/free-solid-svg-icons';

library.add(faBars, faClipboard, faDownload, faKey, faCog);
library.add(faBars, faClipboard, faDownload, faRotateRight, faKey, faCog);
dom.watch();

const debug = require('debug')('WebSSH2');
Expand Down Expand Up @@ -35,6 +35,7 @@ const term = new Terminal();
const logBtn = document.getElementById('logBtn');
const credentialsBtn = document.getElementById('credentialsBtn');
const reauthBtn = document.getElementById('reauthBtn');
const restartBtn = document.getElementById('restartBtn');
const downloadLogBtn = document.getElementById('downloadLogBtn');
const status = document.getElementById('status');
const header = document.getElementById('header');
Expand All @@ -52,20 +53,26 @@ const socket = io({
});

// reauthenticate
function reauthSession () { // eslint-disable-line
function reauthSession() { // eslint-disable-line
debug('re-authenticating');
socket.emit('control', 'reauth');
window.location.href = '/ssh/reauth';
return false;
}

function restartSession() { // eslint-disable-line
debug('restarting');
socket.emit('control', 'reauth');
window.location.reload();
return false;
}

// cross browser method to "download" an element to the local system
// used for our client-side logging feature
function downloadLog () { // eslint-disable-line
function downloadLog() { // eslint-disable-line
if (loggedData === true) {
myFile = `WebSSH2-${logDate.getFullYear()}${
logDate.getMonth() + 1
}${logDate.getDate()}_${logDate.getHours()}${logDate.getMinutes()}${logDate.getSeconds()}.log`;
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(
[
Expand All @@ -91,15 +98,14 @@ function downloadLog () { // eslint-disable-line
}
// Set variable to toggle log data from client/server to a varialble
// for later download
function toggleLog () { // eslint-disable-line
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`;
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;
Expand All @@ -110,16 +116,15 @@ function toggleLog () { // eslint-disable-line
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`;
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;
}

// replay password to server, requires
function replayCredentials () { // eslint-disable-line
function replayCredentials() { // eslint-disable-line
socket.emit('control', 'replayCredentials');
debug(`control: replayCredentials`);
term.focus();
Expand All @@ -130,6 +135,7 @@ function replayCredentials () { // eslint-disable-line
// when dom is changed, listeners are abandonded
function drawMenu() {
logBtn.addEventListener('click', toggleLog);
restartBtn.addEventListener('click', restartSession)
if (allowreauth) {
reauthBtn.addEventListener('click', reauthSession);
reauthBtn.style.display = 'block';
Expand All @@ -144,19 +150,27 @@ function drawMenu() {
}
}

function resizeScreen() {
function resizeScreen(warmup = false) {
fitAddon.fit();
if (warmup) {
socket.emit('resize', { cols: term.cols - 1, rows: term.rows });
}
socket.emit('resize', { cols: term.cols, rows: term.rows });
debug(`resize: ${JSON.stringify({ cols: term.cols, rows: term.rows })}`);
}

window.addEventListener('resize', resizeScreen, false);
window.addEventListener('resize', () => resizeScreen(), false);

var hasResize = false;
term.onData((data) => {
socket.emit('data', data);
});

socket.on('data', (data: string | Uint8Array) => {
if (!hasResize) {
hasResize = true;
setTimeout(() => resizeScreen(true), 1000);
}
term.write(data);
if (sessionLogEnable) {
sessionLog += data;
Expand Down Expand Up @@ -252,7 +266,13 @@ socket.on('disconnect', (err: any) => {
status.style.backgroundColor = 'red';
status.innerHTML = `WEBSOCKET SERVER DISCONNECTED: ${err}`;
}
socket.io.reconnection(false);
var i = setInterval(() => {
if (!socket.connected) {
socket.connect()
} else {
clearInterval(i);
}
}, 3000);
countdown.classList.remove('active');
});

Expand Down
2 changes: 1 addition & 1 deletion app/config.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"user": {
"name": null,
"password": null,
"privatekey": null,
"privateKey": null,
"overridebasic": false
},
"ssh": {
Expand Down
2 changes: 1 addition & 1 deletion app/server/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const configDefault = {
user: {
name: null,
password: null,
privatekey: null,
privateKey: null,
overridebasic: false,
},
ssh: {
Expand Down
Loading