Skip to content

Commit a888f3c

Browse files
author
Josh Samuelson
committed
Merge pull request #1 from puppetlabs/minimal
Minimal
2 parents 7d928db + 821f8e4 commit a888f3c

File tree

13 files changed

+6315
-5906
lines changed

13 files changed

+6315
-5906
lines changed

.gitignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
lib-cov
2+
*.seed
3+
*.log
4+
*.csv
5+
*.dat
6+
*.out
7+
*.pid
8+
*.gz
9+
10+
tmp
11+
pids
12+
logs
13+
results
14+
15+
npm-debug.log
16+
node_modules/*

Dockerfile

Lines changed: 0 additions & 15 deletions
This file was deleted.

Gruntfile.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module.exports = function (grunt) {
2+
3+
require('load-grunt-tasks')(grunt);
4+
5+
var config = {
6+
mkdir: {
7+
tmp: {
8+
options: {
9+
create: ['tmp']
10+
}
11+
}
12+
},
13+
gitclone: {
14+
hterm: {
15+
options: {
16+
cwd: './tmp',
17+
repository: 'https://chromium.googlesource.com/apps/libapps'
18+
}
19+
}
20+
},
21+
shell: {
22+
build_hterm: {
23+
command: 'LIBDOT_SEARCH_PATH=$(pwd) ./libdot/bin/concat.sh -i ./hterm/concat/hterm_all.concat -o ../../public/wetty/hterm_all.js',
24+
options: {
25+
execOptions: {
26+
cwd: './tmp/libapps'
27+
}
28+
}
29+
}
30+
},
31+
clean: ['./tmp']
32+
};
33+
34+
grunt.initConfig(config);
35+
36+
grunt.registerTask('update-hterm', ['mkdir:tmp', 'gitclone:hterm', 'shell:build_hterm', 'clean']);
37+
};

README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ Else if you are running `app.js` as a regular user you have to use:
8080

8181
**Note that if your Nginx is configured for HTTPS you should run wetty without SSL.**
8282

83-
Issues
84-
------
85-
86-
Does not work on Firefox as hterm was written for ChromeOS. So works well on Chrome.
87-
8883
Dockerized Version
8984
------------------
9085

@@ -94,8 +89,23 @@ whatever you want!
9489
Just do:
9590

9691
```
97-
docker run --name term -p 3000 -dt nathanleclaire/wetty
92+
docker run --name term -p 3000 -dt nathanleclaire/wetty
9893
```
9994

10095
Visit the appropriate URL in your browser (`[localhost|$(boot2docker ip)]:PORT`).
10196
The username is `term` and the password is `term`.
97+
98+
Run wetty as a service daemon
99+
-----------------------------
100+
101+
Install wetty globally with -g option:
102+
103+
```bash
104+
$ sudo npm install wetty -g
105+
$ sudo cp /usr/local/lib/node_modules/wetty/bin/wetty.conf /etc/init
106+
$ sudo start wetty
107+
```
108+
109+
This will start wetty on port 3000. If you want to change the port or redirect stdout/stderr you should change the last line in `wetty.conf` file, something like this:
110+
111+
exec sudo -u root wetty -p 80 >> /var/log/wetty.log 2>&1

app.js

Lines changed: 42 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,152 +1,75 @@
11
var express = require('express');
22
var http = require('http');
3-
var https = require('https');
43
var path = require('path');
5-
var ws = require('websocket').server;
4+
var server = require('socket.io');
65
var pty = require('pty.js');
7-
var fs = require('fs');
8-
var waitpid = require('waitpid');
96

107
var opts = require('optimist')
118
.options({
12-
sslkey: {
13-
demand: false,
14-
description: 'path to SSL key'
15-
},
16-
sslcert: {
17-
demand: false,
18-
description: 'path to SSL certificate'
19-
},
20-
sshhost: {
21-
demand: false,
22-
description: 'ssh server host'
23-
},
24-
sshport: {
25-
demand: false,
26-
description: 'ssh server port'
27-
},
28-
sshuser: {
29-
demand: false,
30-
description: 'ssh user'
31-
},
32-
sshauth: {
33-
demand: false,
34-
description: 'defaults to "password", you can use "publickey,password" instead'
35-
},
369
port: {
3710
demand: true,
3811
alias: 'p',
3912
description: 'wetty listen port'
4013
},
14+
command: {
15+
demand: false,
16+
alias: 'c',
17+
description: 'command to run in shell, defaults to /bin/login'
18+
},
4119
}).boolean('allow_discovery').argv;
4220

43-
var runhttps = false;
44-
var sshport = 22;
45-
var sshhost = 'localhost';
46-
var sshauth = 'password';
47-
var globalsshuser = '';
48-
49-
if (opts.sshport) {
50-
sshport = opts.sshport;
51-
}
52-
53-
if (opts.sshhost) {
54-
sshhost = opts.sshhost;
55-
}
56-
57-
if (opts.sshauth) {
58-
sshauth = opts.sshauth
59-
}
60-
61-
if (opts.sshuser) {
62-
globalsshuser = opts.sshuser;
63-
}
21+
var command = '/bin/login';
6422

65-
if (opts.sslkey && opts.sslcert) {
66-
runhttps = true;
67-
opts['ssl'] = {};
68-
opts.ssl['key'] = fs.readFileSync(path.resolve(opts.sslkey));
69-
opts.ssl['cert'] = fs.readFileSync(path.resolve(opts.sslcert));
23+
if (opts.command) {
24+
command = opts.command;
7025
}
7126

7227
process.on('uncaughtException', function(e) {
7328
console.error('Error: ' + e);
7429
});
7530

76-
var httpserv;
7731

7832
var app = express();
79-
app.get('/wetty/ssh/:user', function(req, res) {
80-
res.sendfile(__dirname + '/public/wetty/index.html');
33+
app.get('/course/:course', function(req, res) {
34+
var course = req.params.course;
35+
res.sendfile(__dirname + '/public/index.html');
8136
});
8237
app.use('/', express.static(path.join(__dirname, 'public')));
8338

84-
if (runhttps) {
85-
httpserv = https.createServer(opts.ssl, app).listen(opts.port, function() {
86-
console.log('https on port ' + opts.port);
87-
});
88-
} else {
89-
httpserv = http.createServer(app).listen(opts.port, function() {
90-
console.log('http on port ' + opts.port);
91-
});
92-
}
93-
94-
var wss = new ws({
95-
httpServer: httpserv
39+
var httpserv = http.createServer(app).listen(opts.port, function() {
40+
console.log('http on port ' + opts.port);
9641
});
9742

98-
wss.on('request', function(request) {
99-
var term;
100-
var sshuser = '';
101-
var conn = request.accept('wetty', request.origin);
102-
console.log((new Date()) + ' Connection accepted.');
103-
if (request.resource.match('^/wetty/ssh/')) {
104-
sshuser = request.resource;
105-
sshuser = sshuser.replace('/wetty/ssh/', '');
106-
}
107-
if (sshuser) {
108-
sshuser = sshuser + '@';
109-
} else if (globalsshuser) {
110-
sshuser = globalsshuser + '@';
43+
var io = server(httpserv);
44+
io.on('connection', function(socket){
45+
var request = socket.request;
46+
var course = 'default';
47+
if (match = request.headers.referer.match('/course/.+$')) {
48+
course = match[0].replace('/course/', '');
11149
}
112-
conn.on('message', function(msg) {
113-
var data = JSON.parse(msg.utf8Data);
114-
if (!term) {
115-
if (process.getuid() == 0) {
116-
term = pty.spawn('/bin/login', [], {
117-
name: 'xterm-256color',
118-
cols: 80,
119-
rows: 30
120-
});
121-
} else {
122-
term = pty.spawn('ssh', [sshuser + sshhost, '-p', sshport, '-o', 'PreferredAuthentications=' + sshauth], {
123-
name: 'xterm-256color',
124-
cols: 80,
125-
rows: 30
126-
});
127-
}
128-
console.log((new Date()) + " PID=" + term.pid + " STARTED on behalf of user=" + sshuser)
129-
term.on('data', function(data) {
130-
conn.send(JSON.stringify({
131-
data: data
132-
}));
133-
});
134-
term.on('exit', function(code) {
135-
console.log((new Date()) + " PID=" + term.pid + " ENDED")
136-
})
137-
}
138-
if (!data)
139-
return;
140-
if (data.rowcol) {
141-
term.resize(data.col, data.row);
142-
} else if (data.data) {
143-
term.write(data.data);
144-
}
50+
console.log((new Date()) + ' Connection accepted.');
51+
52+
var term;
53+
term = pty.spawn(command, [course], {
54+
name: 'xterm-256color',
55+
cols: 80,
56+
rows: 30
14557
});
146-
conn.on('error', function() {
147-
term.end();
58+
59+
console.log((new Date()) + " PID=" + term.pid + " STARTED")
60+
term.on('data', function(data) {
61+
socket.emit('output', data);
14862
});
149-
conn.on('close', function() {
63+
term.on('exit', function(code) {
64+
console.log((new Date()) + " PID=" + term.pid + " ENDED")
65+
});
66+
socket.on('resize', function(data) {
67+
term.resize(data.col, data.row);
68+
});
69+
socket.on('input', function(data) {
70+
term.write(data);
71+
});
72+
socket.on('disconnect', function() {
15073
term.end();
151-
})
74+
});
15275
})

bin/wetty.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Upstart script
2+
# /etc/init/wetty.conf
3+
4+
description "Web TTY"
5+
author "Wetty"
6+
7+
start on started mountall
8+
stop on shutdown
9+
10+
respawn
11+
respawn limit 20 5
12+
13+
exec sudo -u root wetty -p 3000

bin/wetty.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env node
2+
3+
require("../app");

package.json

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
{
2-
"name": "wetty",
3-
"version": "0.0.8",
4-
"dependencies": {
5-
"express": "3.5.1",
6-
"websocket": "",
7-
"pty.js": "git+https://github.com/terryschen/pty.js",
8-
"optimist": "",
9-
"waitpid": ""
10-
},
11-
"description": "Wetty = Web + tty. Terminal access in browser over http/https ",
12-
"main": "app.js",
13-
"devDependencies": {},
14-
"repository": {
15-
"type": "git",
16-
"url": "git://github.com/krishnasrinivas/wetty.git"
17-
},
18-
"author": "Krishna Srinivas <[email protected]> (https://github.com/krishnasrinivas)",
19-
"license": "MIT",
20-
"bugs": {
21-
"url": "https://github.com/krishnasrinivas/wetty/issues"
22-
},
23-
"homepage": "https://github.com/krishnasrinivas/wetty"
2+
"name": "wetty",
3+
"version": "0.2.0",
4+
"dependencies": {
5+
"express": "3.5.1",
6+
"socket.io": "^1.3.7",
7+
"pty.js": "^0.3.0",
8+
"optimist": "^0.6"
9+
},
10+
"devDependencies": {
11+
"load-grunt-tasks": "^3.0",
12+
"grunt": "^0.4",
13+
"grunt-shell": "^1.1",
14+
"grunt-mkdir": "^0.1",
15+
"grunt-git": "^0.3",
16+
"grunt-contrib-clean": "^0.6"
17+
},
18+
"description": "Wetty = Web + tty. Terminal access in browser over http/https ",
19+
"main": "app.js",
20+
"repository": {
21+
"type": "git",
22+
"url": "git://github.com/krishnasrinivas/wetty.git"
23+
},
24+
"author": "Krishna Srinivas <[email protected]> (https://github.com/krishnasrinivas)",
25+
"license": "MIT",
26+
"bugs": {
27+
"url": "https://github.com/krishnasrinivas/wetty/issues"
28+
},
29+
"homepage": "https://github.com/krishnasrinivas/wetty",
30+
"preferGlobal": "true",
31+
"bin": {
32+
"wetty": "./bin/wetty.js"
33+
}
2434
}

0 commit comments

Comments
 (0)