Browse Source

Support to run behind nginx reverse proxy. Support to run wetty as user as well as root.

pull/3/head
Krishna Srinivas 11 years ago
parent
commit
190048a2c2
  1. 28
      README.md
  2. 18
      app.js
  3. 6
      public/index.html
  4. 0
      public/wetty/hterm.js
  5. 0
      public/wetty/hterm_all.js
  6. 30
      public/wetty/index.html
  7. 2
      public/wetty/wetty.js

28
README.md

@ -3,8 +3,6 @@ wetty = Web + tty
Terminal over http. Wetty is like ajaxterm but much better because it uses ChromeOS' terminal emulator (hterm) which has much better terminal emulation implementation. Also it uses websockets instead of Ajax.
Note: tested only on Chrome (hterm was written for Chrome.)
Install
-------
@ -16,18 +14,38 @@ Install
Run on http:
-----------
(run as root as it needs to exec /bin/login)
`node app.js -p 3000`
If you run it as root it will launch /bin/login (where you can specify the username), else it will launch ssh to localhost as the node's user as login username.
Run on https:
------------
If you don't have ssl certificates from CA you can create a self signed certificate using this command:
`openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 30000 -nodes`
And then run as root:
And then run:
`node app.js --sslkey key.pem --sslcert cert.pem -p 3000`
Run wetty behind nginx:
----------------------
Put the following config in nginx's conf:
location /wetty {
proxy_pass http://127.0.0.1:3000/wetty;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 43200000;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
}
In the browser you have to use: 'http://yourserver.com/wetty'. Note that if your nginx is configured for https you should run wetty without ssl.

18
app.js

@ -64,11 +64,19 @@ wss.on('request', function(request) {
conn.on('message', function(msg) {
var data = JSON.parse(msg.utf8Data);
if (!term) {
term = pty.spawn('/bin/login', [], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
if (process.getuid() == 0) {
term = pty.spawn('/bin/login', [], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
} else {
term = pty.spawn('ssh', ['localhost'], {
name: 'xterm-256color',
cols: 80,
rows: 30
});
}
term.on('data', function(data) {
conn.send(JSON.stringify({
data: data

6
public/index.html

@ -4,9 +4,9 @@
<head>
<meta charset="UTF-8">
<title>wtf</title>
<script src="hterm_all.js"></script>
<script src="hterm.js"></script>
<script src="wetty.js"></script>
<script src="/wetty/hterm_all.js"></script>
<script src="/wetty/hterm.js"></script>
<script src="/wetty/wetty.js"></script>
<style>
html,
body {

0
public/hterm.js → public/wetty/hterm.js

0
public/hterm_all.js → public/wetty/hterm_all.js

30
public/wetty/index.html

@ -0,0 +1,30 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>wtf</title>
<script src="hterm_all.js"></script>
<script src="hterm.js"></script>
<script src="wetty.js"></script>
<style>
html,
body {
height: 100%;
width: 100%;
margin: 0px;
}
#terminal {
display: block;
position: relative;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="terminal"></div>
</body>
</html>

2
public/wetty.js → public/wetty/wetty.js

@ -30,7 +30,7 @@ Wetty.prototype.onTerminalResize = function(col, row) {
}));
};
ws = new WebSocket(((window.location.protocol === 'https:') ? 'wss://' : 'ws://') + window.location.host, 'wetty');
ws = new WebSocket(((window.location.protocol === 'https:') ? 'wss://' : 'ws://') + window.location.host + '/wetty', 'wetty');
ws.onopen = function() {
lib.init(function() {
term = new hterm.Terminal();
Loading…
Cancel
Save