Browse Source

move event listener to wetty.js and add removeEventListener, add better support for dedicated vhosts

pull/126/head
butlerx 8 years ago
parent
commit
43c4d041c4
No known key found for this signature in database GPG Key ID: B37CA765BAA89170
  1. 4
      Dockerfile
  2. 16
      app.js
  3. 2
      bin/cleanup
  4. 5
      bin/ssh
  5. 48
      public/index.html
  6. 8
      public/wetty/index.html
  7. 12
      public/wetty/wetty.js
  8. 18
      yarn.lock

4
Dockerfile

@ -1,7 +1,7 @@
FROM node:boron
FROM node:boron-apline
MAINTAINER Nathan LeClaire <nathan@docker.com>
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

16
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}@`;
}

2
bin/cleanup

@ -1 +1,3 @@
#!/usr/bin/env bash
kill $(ps aux | grep "ssh" | awk '{print $2}')

5
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 = <STDIN>;
chomp ( $username );

48
public/index.html

@ -1,48 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Wetty - The WebTTY Terminal Emulator</title>
<script src="/wetty/hterm_all.js"></script>
<script src="/wetty/socket.io/socket.io.js"></script>
<script src="/wetty/wetty.js"></script>
<style>
html, body {
height: 100%;
width: 100%;
margin: 0px;
}
#overlay {
position: absolute;
height: 100%;
width: 100%;
background-color: rgba(0,0,0,0.75);;
display: none;
z-index: 100;
}
#overlay input {
display: block;
margin: auto;
position: relative;
top: 50%;
transform: translateY(-50%);
}
#terminal {
display: block;
position: relative;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="overlay"><input type="button" onclick="javascript:location.reload();" value="reconnect" /></div>
<div id="terminal" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></div>
<script type="application/javascript">
window.addEventListener('beforeunload', function(e) {
e.returnValue = "Are you sure?";
return e.returnValue;
});
</script>
</body>
</html>

8
public/wetty/index.html

@ -36,13 +36,7 @@
</style>
</head>
<body>
<div id="overlay"><input type="button" onclick="javascript:location.reload();" value="reconnect" /></div>
<div id="overlay"><input type="button" onclick="location.reload();" value="reconnect" /></div>
<div id="terminal" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></div>
<script type="application/javascript">
window.addEventListener('beforeunload', function(e) {
e.returnValue = "Are you sure?";
return e.returnValue;
});
</script>
</body>
</html>

12
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;
}

18
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"

Loading…
Cancel
Save