diff --git a/Dockerfile b/Dockerfile index 97916c8..3b79e97 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ -FROM node:boron +FROM node:boron-apline MAINTAINER Nathan LeClaire ADD . /app WORKDIR /app -RUN apt-get update && apt-get upgrade -y && yarn +RUN apk add --update build-base && yarn EXPOSE 3000 CMD yarn start diff --git a/app.js b/app.js index dfb13af..5e9d08d 100644 --- a/app.js +++ b/app.js @@ -81,9 +81,21 @@ process.on('uncaughtException', e => { let httpserv; const app = express(); +// For using wetty at /wetty on a vhost app.get('/wetty/ssh/:user', (req, res) => { res.sendfile(`${__dirname}/public/wetty/index.html`); }); +app.get('/wetty/', (req, res) => { + res.sendfile(`${__dirname}/public/wetty/index.html`); +}); +// For using wetty on a vhost by itself +app.get('/ssh/:user', (req, res) => { + res.sendfile(`${__dirname}/public/wetty/index.html`); +}); +app.get('/', (req, res) => { + res.sendfile(`${__dirname}/public/wetty/index.html`); +}); +// For serving css and javascript app.use('/', express.static(path.join(__dirname, 'public'))); if (runhttps) { @@ -101,9 +113,9 @@ io.on('connection', socket => { let sshuser = ''; const request = socket.request; console.log(`${new Date()} Connection accepted.`); - const match = request.headers.referer.match('/wetty/ssh/.+$'); + const match = request.headers.referer.match('.+/ssh/.+$'); if (match) { - sshuser = `${match[0].replace('/wetty/ssh/', '')}@`; + sshuser = `${match[0].split('/ssh/').pop()}@`; } else if (globalsshuser) { sshuser = `${globalsshuser}@`; } diff --git a/bin/cleanup b/bin/cleanup index f60ff4f..db9ff90 100755 --- a/bin/cleanup +++ b/bin/cleanup @@ -1 +1,3 @@ +#!/usr/bin/env bash + kill $(ps aux | grep "ssh" | awk '{print $2}') diff --git a/bin/ssh b/bin/ssh index 8ae0be8..7b3ffcb 100755 --- a/bin/ssh +++ b/bin/ssh @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl my $user_at_address = $ARGV[0]; my @u_a = split(/@/, $user_at_address); @@ -6,8 +6,7 @@ if (defined $u_a[1]) { if ( $^O == 'linux' ) { exec ("/usr/bin/ssh $u_a[0]\@$u_a[1]"); } -} -else { +} else { print "Enter your username: "; my $username = ; chomp ( $username ); diff --git a/public/index.html b/public/index.html deleted file mode 100644 index d113cb4..0000000 --- a/public/index.html +++ /dev/null @@ -1,48 +0,0 @@ - - - - - Wetty - The WebTTY Terminal Emulator - - - - - - -
-
- - - diff --git a/public/wetty/index.html b/public/wetty/index.html index d113cb4..0464e6f 100644 --- a/public/wetty/index.html +++ b/public/wetty/index.html @@ -36,13 +36,7 @@ -
+
- diff --git a/public/wetty/wetty.js b/public/wetty/wetty.js index 345ba04..e71306f 100644 --- a/public/wetty/wetty.js +++ b/public/wetty/wetty.js @@ -25,6 +25,8 @@ Wetty.prototype.onTerminalResize = function(col, row) { }; socket.on('connect', function() { + document.getElementById("overlay").style.display = "none"; + window.addEventListener('beforeunload', handler, false); lib.init(function() { hterm.defaultStorage = new lib.Storage.Local(); term = new hterm.Terminal(); @@ -59,10 +61,16 @@ socket.on('output', function(data) { }); socket.on('logout', function(data) { - console.log("user logout"); document.getElementById("overlay").style.display = "block"; + window.removeEventListener('beforeunload', handler, false); }); socket.on('disconnect', function() { - console.log("Socket.io connection closed"); + document.getElementById("overlay").style.display = "block"; + window.removeEventListener('beforeunload', handler, false); }); + +function handler (e) { + e.returnValue = "Are you sure?"; + return e.returnValue; +} diff --git a/yarn.lock b/yarn.lock index 2170a4f..1e5d232 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1149,14 +1149,10 @@ number-is-nan@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" -object-assign@4.1.0: +object-assign@4.1.0, object-assign@^4.0.0, object-assign@^4.0.1, object-assign@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0" -object-assign@^4.0.0, object-assign@^4.0.1, object-assign@^4.1.0: - version "4.1.1" - resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" - object-component@0.0.3: version "0.0.3" resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291" @@ -1573,17 +1569,17 @@ ultron@1.0.x: version "1.0.2" resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.0.2.tgz#ace116ab557cd197386a4e88f4685378c8b2e4fa" -underscore.string@^2.3.3, underscore.string@~2.4.0: - version "2.4.0" - resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b" +underscore.string@^2.3.3, underscore.string@~2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.3.3.tgz#71c08bf6b428b1133f37e78fa3a21c82f7329b0d" underscore.string@~2.2.1: version "2.2.1" resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.2.1.tgz#d7c0fa2af5d5a1a67f4253daee98132e733f0f19" -underscore.string@~2.3.3: - version "2.3.3" - resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.3.3.tgz#71c08bf6b428b1133f37e78fa3a21c82f7329b0d" +underscore.string@~2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b" underscore@^1.6.0: version "1.8.3"