update xterm.js to 3.0.2, switch to webpack, move javascript out of html

fixes #40
fixes #41
moved /js/client.js to /js/index.js
todo: rework build scripts to utilize webpack vs gulp
This commit is contained in:
billchurch 2018-02-06 10:24:53 -05:00
parent 88ad8210f3
commit 397b3c0068
22 changed files with 14824 additions and 9564 deletions

View file

@ -21,6 +21,7 @@ module.exports = function (grunt) {
'node_modules/xterm/dist/xterm.js',
'node_modules/xterm/dist/xterm.js.map',
'node_modules/xterm/dist/addons/fit/fit.js',
'node_modules/xterm/dist/addons/fit/fit.js.map',
'node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js',
'node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js.map',
'src/js/client.js'

View file

@ -1,4 +0,0 @@
{
"localhost": "ff1d6fd1e63bf07ed1c801692f9e5a44e57cb9ce",
"127.0.0.1": "ff1d6fd1e63bf07ed1c801692f9e5a44e57cb9ce"
}

View file

@ -48,6 +48,7 @@
},
"devDependencies": {
"bithound": "^1.7.0",
"css-loader": "^0.28.9",
"grunt": "^1.0.1",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-copy": "^1.0.0",
@ -56,7 +57,10 @@
"snazzy": "^7.0.0",
"snyk": "^1.39.1",
"standard": "^10.0.3",
"xterm": "^2.9.2"
"style-loader": "^0.20.1",
"webpack": "^3.10.0",
"webpack-stream": "^4.0.0",
"xterm": "^3.0.2"
},
"standard": {
"ignore": [

7240
public/bundle.js Normal file

File diff suppressed because one or more lines are too long

1
public/bundle.js.map Normal file

File diff suppressed because one or more lines are too long

1
public/bundle.map Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,8 +1,7 @@
<html>
<head>
<title>Web SSH</title>
<link rel="stylesheet" href="/webssh2.css" />
<script src="/webssh2.js" defer></script>
<title>Web SSH full</title>
<script src="/bundle.js" defer></script>
</head>
<body>
<div class="box">
@ -11,12 +10,9 @@
<div id="bottomdiv">
<div id="footer"></div>
<div id="status"></div>
<div id="credentials"><a class="credentials" href="javascript:void(0);"
onclick="replayCredentials()">CREDENTIALS</a></div>
<div id="downloadLog"><a class="downloadLog" href="javascript:void(0);"
onclick="downloadLog()">Download Log</a></div>
<div id="toggleLog"><a class="toggleLog" href="javascript:void(0);"
onclick="toggleLog();">Start Log</a></div>
<div id="credentials"><a class="credentials" href="javascript:void(0);">CREDENTIALS</a></div>
<div id="downloadLog"><a class="downloadLog" href="javascript:void(0);">Download Log</a></div>
<div id="toggleLog"><a class="toggleLog" href="javascript:void(0);">Start Log</a></div>
</div>
</div>
</body>

View file

@ -1,8 +1,7 @@
<html>
<head>
<title>Web SSH</title>
<link rel="stylesheet" href="/webssh2.css" />
<script src="/webssh2.min.js" defer></script>
<title>Web SSH min</title>
<script src="/bundle.js" defer></script>
</head>
<body>
<div class="box">
@ -11,12 +10,9 @@
<div id="bottomdiv">
<div id="footer"></div>
<div id="status"></div>
<div id="credentials"><a class="credentials" href="javascript:void(0);"
onclick="replayCredentials()">CREDENTIALS</a></div>
<div id="downloadLog"><a class="downloadLog" href="javascript:void(0);"
onclick="downloadLog()">Download Log</a></div>
<div id="toggleLog"><a class="toggleLog" href="javascript:void(0);"
onclick="toggleLog();">Start Log</a></div>
<div id="credentials"><a class="credentials" href="javascript:void(0);">CREDENTIALS</a></div>
<div id="downloadLog"><a class="downloadLog" href="javascript:void(0);">Download Log</a></div>
<div id="toggleLog"><a class="toggleLog" href="javascript:void(0);">Start Log</a></div>
</div>
</div>
</body>

File diff suppressed because it is too large Load diff

View file

@ -70,10 +70,9 @@ var term = new Terminal({
cursorBlink: true
})
var socket, termid // eslint-disable-line
term.open(terminalContainer, {
focus: true
})
term.fit()
term.open(terminalContainer)
term.focus()
term.applyAddon(fit)
if (document.location.pathname) {
var parts = document.location.pathname.split('/')

View file

@ -1,86 +1,49 @@
/**
* Fit terminal columns and rows to the dimensions of its DOM element.
*
* ## Approach
* - Rows: Truncate the division of the terminal parent element height by the terminal row height.
*
* - Columns: Truncate the division of the terminal parent element width by the terminal character
* width (apply display: inline at the terminal row and truncate its width with the current
* number of columns).
* @module xterm/addons/fit/fit
* @license MIT
*/
(function (fit) {
if (typeof exports === 'object' && typeof module === 'object') {
/*
* CommonJS environment
*/
module.exports = fit(require('../../xterm'));
} else if (typeof define == 'function') {
/*
* Require.js is available
*/
define(['../../xterm'], fit);
} else {
/*
* Plain browser environment
*/
fit(window.Terminal);
}
})(function (Xterm) {
var exports = {};
exports.proposeGeometry = function (term) {
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.fit = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function proposeGeometry(term) {
if (!term.element.parentElement) {
return null;
}
var parentElementStyle = window.getComputedStyle(term.element.parentElement),
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17),
elementStyle = window.getComputedStyle(term.element),
elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
availableHeight = parentElementHeight - elementPaddingVer,
availableWidth = parentElementWidth - elementPaddingHor,
container = term.rowContainer,
subjectRow = term.rowContainer.firstElementChild,
contentBuffer = subjectRow.innerHTML,
characterHeight,
rows,
characterWidth,
cols,
geometry;
subjectRow.style.display = 'inline';
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
characterWidth = subjectRow.getBoundingClientRect().width;
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
characterHeight = subjectRow.getBoundingClientRect().height;
subjectRow.innerHTML = contentBuffer;
rows = parseInt(availableHeight / characterHeight);
cols = parseInt(availableWidth / characterWidth);
geometry = {cols: cols, rows: rows};
return geometry;
var parentElementStyle = window.getComputedStyle(term.element.parentElement);
var parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
var parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17);
var elementStyle = window.getComputedStyle(term.element);
var elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom'));
var elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left'));
var availableHeight = parentElementHeight - elementPaddingVer;
var availableWidth = parentElementWidth - elementPaddingHor;
var geometry = {
cols: Math.floor(availableWidth / term.renderer.dimensions.actualCellWidth),
rows: Math.floor(availableHeight / term.renderer.dimensions.actualCellHeight)
};
exports.fit = function (term) {
var geometry = exports.proposeGeometry(term);
return geometry;
}
exports.proposeGeometry = proposeGeometry;
;
function fit(term) {
var geometry = proposeGeometry(term);
if (geometry) {
if (term.rows !== geometry.rows || term.cols !== geometry.cols) {
term.renderer.clear();
term.resize(geometry.cols, geometry.rows);
}
}
}
exports.fit = fit;
;
function apply(terminalConstructor) {
terminalConstructor.prototype.proposeGeometry = function () {
return proposeGeometry(this);
};
Xterm.prototype.proposeGeometry = function () {
return exports.proposeGeometry(this);
terminalConstructor.prototype.fit = function () {
return fit(this);
};
}
exports.apply = apply;
Xterm.prototype.fit = function () {
return exports.fit(this);
};
return exports;
},{}]},{},[1])(1)
});
//# sourceMappingURL=fit.js.map

View file

@ -1 +1 @@
{"version":3,"sources":["../../../src/addons/fit/fit.ts"],"names":[],"mappings":";;AAeA,yBAAgC,IAAI;IAClC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC;IACd,CAAC;IACD,IAAI,kBAAkB,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC7E,IAAI,mBAAmB,GAAG,QAAQ,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAClF,IAAI,kBAAkB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC;IAClG,IAAI,YAAY,GAAG,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,iBAAiB,GAAG,QAAQ,CAAC,YAAY,CAAC,gBAAgB,CAAC,aAAa,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC3I,IAAI,iBAAiB,GAAG,QAAQ,CAAC,YAAY,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,gBAAgB,CAAC,cAAc,CAAC,CAAC,CAAC;IAC3I,IAAI,eAAe,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;IAC9D,IAAI,cAAc,GAAG,kBAAkB,GAAG,iBAAiB,CAAC;IAC5D,IAAI,QAAQ,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,eAAe,CAAC;QAC3E,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,eAAe,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,gBAAgB,CAAC;KAC9E,CAAC;IAEF,MAAM,CAAC,QAAQ,CAAC;AAClB,CAAC;AAlBD,0CAkBC;AAAA,CAAC;AAEF,aAAoB,IAAI;IACtB,IAAI,QAAQ,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IACrC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC;QAEb,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;YAC/D,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;IACH,CAAC;AACH,CAAC;AATD,kBASC;AAAA,CAAC;AAEF,eAAsB,mBAAmB;IACvC,mBAAmB,CAAC,SAAS,CAAC,eAAe,GAAG;QAC9C,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC,CAAA;IAED,mBAAmB,CAAC,SAAS,CAAC,GAAG,GAAG;QAClC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC,CAAA;AACH,CAAC;AARD,sBAQC","file":"fit.js","sourceRoot":"."}
{"version":3,"file":"fit.js","sources":["../../../src/addons/fit/fit.ts","../../../node_modules/browser-pack/_prelude.js"],"sourcesContent":["/**\n * Copyright (c) 2014 The xterm.js authors. All rights reserved.\n * @license MIT\n *\n * Fit terminal columns and rows to the dimensions of its DOM element.\n *\n * ## Approach\n *\n * Rows: Truncate the division of the terminal parent element height by the\n * terminal row height.\n * Columns: Truncate the division of the terminal parent element width by the\n * terminal character width (apply display: inline at the terminal\n * row and truncate its width with the current number of columns).\n */\n\nexport function proposeGeometry(term) {\n if (!term.element.parentElement) {\n return null;\n }\n var parentElementStyle = window.getComputedStyle(term.element.parentElement);\n var parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));\n var parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17);\n var elementStyle = window.getComputedStyle(term.element);\n var elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom'));\n var elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left'));\n var availableHeight = parentElementHeight - elementPaddingVer;\n var availableWidth = parentElementWidth - elementPaddingHor;\n var geometry = {\n cols: Math.floor(availableWidth / term.renderer.dimensions.actualCellWidth),\n rows: Math.floor(availableHeight / term.renderer.dimensions.actualCellHeight)\n };\n\n return geometry;\n};\n\nexport function fit(term) {\n var geometry = proposeGeometry(term);\n if (geometry) {\n // Force a full render\n if (term.rows !== geometry.rows || term.cols !== geometry.cols) {\n term.renderer.clear();\n term.resize(geometry.cols, geometry.rows);\n }\n }\n};\n\nexport function apply(terminalConstructor) {\n terminalConstructor.prototype.proposeGeometry = function() {\n return proposeGeometry(this);\n }\n\n terminalConstructor.prototype.fit = function() {\n return fit(this);\n }\n}\n",null],"names":[],"mappings":"ACAA;;;ADeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAlBA;AAkBC;AAED;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AATA;AASC;AAED;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AARA;;;"}

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because one or more lines are too long

124
src/css/xterm.css Normal file
View file

@ -0,0 +1,124 @@
/**
* Copyright (c) 2014 The xterm.js authors. All rights reserved.
* Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
* https://github.com/chjj/term.js
* @license MIT
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* Originally forked from (with the author's permission):
* Fabrice Bellard's javascript vt100 for jslinux:
* http://bellard.org/jslinux/
* Copyright (c) 2011 Fabrice Bellard
* The original design remains. The terminal itself
* has been extended to include xterm CSI codes, among
* other features.
*/
/**
* Default styles for xterm.js
*/
.xterm {
font-family: courier-new, courier, monospace;
font-feature-settings: "liga" 0;
position: relative;
user-select: none;
-ms-user-select: none;
-webkit-user-select: none;
}
.xterm.focus,
.xterm:focus {
outline: none;
}
.xterm .xterm-helpers {
position: absolute;
top: 0;
/**
* The z-index of the helpers must be higher than the canvases in order for
* IMEs to appear on top.
*/
z-index: 10;
}
.xterm .xterm-helper-textarea {
/*
* HACK: to fix IE's blinking cursor
* Move textarea out of the screen to the far left, so that the cursor is not visible.
*/
position: absolute;
opacity: 0;
left: -9999em;
top: 0;
width: 0;
height: 0;
z-index: -10;
/** Prevent wrapping so the IME appears against the textarea at the correct position */
white-space: nowrap;
overflow: hidden;
resize: none;
}
.xterm .composition-view {
/* TODO: Composition position got messed up somewhere */
background: #000;
color: #FFF;
display: none;
position: absolute;
white-space: nowrap;
z-index: 1;
}
.xterm .composition-view.active {
display: block;
}
.xterm .xterm-viewport {
/* On OS X this is required in order for the scroll bar to appear fully opaque */
background-color: #000;
overflow-y: scroll;
}
.xterm canvas {
position: absolute;
left: 0;
top: 0;
}
.xterm .xterm-scroll-area {
visibility: hidden;
}
.xterm .xterm-char-measure-element {
display: inline-block;
visibility: hidden;
position: absolute;
left: -9999em;
}
.xterm.enable-mouse-events {
/* When mouse events are enabled (eg. tmux), revert to the standard pointer cursor */
cursor: default;
}
.xterm:not(.enable-mouse-events) {
cursor: text;
}

View file

@ -1,79 +1,43 @@
require('../../node_modules/xterm/dist/xterm.css')
require('../css/style.css')
import * as io from '../../node_modules/socket.io/node_modules/socket.io-client/dist/socket.io.js'
import * as Terminal from '../../node_modules/xterm/dist/xterm'
// import * as attach from 'node_modules/xterm/dist/addons/attach/attach'
import * as fit from '../../node_modules/xterm/dist/addons/fit/fit'
// import * as fullscreen from 'node_modules/xterm/dist/addons/fullscreen/fullscreen'
// import * as search from 'node_modules/xterm/dist/addons/search/search'
// import * as winptyCompat from 'node_modules/xterm/dist/addons/winptyCompat/winptyCompat'
// import * as client from './client.js'
// Terminal.applyAddon(attach);
Terminal.applyAddon(fit)
// Terminal.applyAddon(fullscreen);
// Terminal.applyAddon(search);
// Terminal.applyAddon(winptyCompat);
/* global io, Terminal, Blob */
var sessionLogEnable = false
var sessionLog, sessionFooter, logDate, currentDate, myFile, errorExists
var sessionLog, sessionFooter, logDate, currentDate, myFile, errorExist
// replay password to server, requires
function replayCredentials () { // eslint-disable-line
socket.emit('control', 'replayCredentials')
console.log('replaying credentials')
return false
}
var downloadLogButton = document.getElementById('downloadLog')
var credentialsButton = document.getElementById('credentials')
var toggleLogButton = document.getElementById('toggleLog')
// 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
document.getElementById('toggleLog').innerHTML =
'<a class="toggleLog" href="javascript:void(0);" onclick="toggleLog();">Start Log</a>'
console.log('stopping log, ' + sessionLogEnable)
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
return false
} else {
sessionLogEnable = true
document.getElementById('toggleLog').innerHTML =
'<a class="toggleLog" href="javascript:void(0)" onclick="toggleLog();">Logging - STOP LOG</a>'
document.getElementById('downloadLog').style.display = 'inline'
console.log('starting log, ' + sessionLogEnable)
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
return false
}
}
toggleLogButton.addEventListener('click', toggleLog)
// cross browser method to "download" an element to the local system
// used for our client-side logging feature
function downloadLog () { // eslint-disable-line
myFile = 'WebSSH2-' + logDate.getFullYear() + (logDate.getMonth() + 1) +
logDate.getDate() + '_' + logDate.getHours() + logDate.getMinutes() +
logDate.getSeconds() + '.log'
// regex should eliminate escape sequences from being logged.
var blob = new Blob([sessionLog.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')], {
type: 'text/plain'
})
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, myFile)
} else {
var elem = window.document.createElement('a')
elem.href = window.URL.createObjectURL(blob)
elem.download = myFile
document.body.appendChild(elem)
elem.click()
document.body.removeChild(elem)
}
}
document.getElementById('downloadLog').style.display = 'none'
document.getElementById('credentials').style.display = 'none'
downloadLogButton.style.display = 'none'
credentialsButton.style.display = 'none'
var terminalContainer = document.getElementById('terminal-container')
var term = new Terminal({
cursorBlink: true
})
var socket, termid // eslint-disable-line
term.open(terminalContainer, {
focus: true
})
term.fit()
term.open(terminalContainer)
term.focus()
// term.applyAddon(fit)
if (document.location.pathname) {
var parts = document.location.pathname.split('/')
@ -111,9 +75,10 @@ socket.on('connect', function () {
}).on('allowreplay', function (data) {
if (data === true) {
console.log('allowreplay: ' + data)
document.getElementById('credentials').style.display = 'inline'
credentialsButton.style.display = 'inline'
credentialsButton.addEventListener('click', replayCredentials)
} else {
document.getElementById('credentials').style.display = 'none'
credentialsButton.style.display = 'none'
}
}).on('data', function (data) {
term.write(data)
@ -134,3 +99,70 @@ socket.on('connect', function () {
}
})
})
// replay password to server, requires
// bill test
function replayCredentials () { // eslint-disable-line
socket.emit('control', 'replayCredentials')
console.log('replaying credentials')
term.focus()
return false
}
// 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
toggleLogButton.innerHTML =
'<a class="toggleLog" href="javascript:void(0);">Start Log</a>'
console.log('stopping log, ' + sessionLogEnable)
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
} else {
sessionLogEnable = true
toggleLogButton.innerHTML =
'<a class="toggleLog" href="javascript:void(0)">Logging - STOP LOG</a>'
downloadLogButton.style.display = 'inline'
downloadLogButton.addEventListener('click', downloadLog)
console.log('starting log, ' + sessionLogEnable)
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
}
}
// cross browser method to "download" an element to the local system
// used for our client-side logging feature
function downloadLog () { // eslint-disable-line
myFile = 'WebSSH2-' + logDate.getFullYear() + (logDate.getMonth() + 1) +
logDate.getDate() + '_' + logDate.getHours() + logDate.getMinutes() +
logDate.getSeconds() + '.log'
// regex should eliminate escape sequences from being logged.
var blob = new Blob([sessionLog.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')], {
type: 'text/plain'
})
if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, myFile)
} else {
var 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()
}

16
webpack.config.js Normal file
View file

@ -0,0 +1,16 @@
const path = require('path')
module.exports = {
entry: './src/js/index.js',
output: {
path: path.resolve(__dirname, 'public/'),
filename: 'bundle.js',
sourceMapFilename: 'bundle.map'
},
devtool: 'source-map',
module: {
loaders: [
{ test: /\.css$/, loader: 'style-loader!css-loader' }
]
}
}