]>
git.proxmox.com Git - mirror_xterm.js.git/blob - example/index.js
c3b3b8baa3815a45f9e676c9e21b85a7d09807fc
5 * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
8 var http
= require('http')
9 , express
= require('express')
10 , io
= require('socket.io')
11 , pty
= require('pty.js')
12 , terminal
= require('../');
18 process
.title
= 'term.js';
25 if (process
.argv
[2] === '--dump') {
26 stream
= require('fs').createWriteStream(__dirname
+ '/dump.log');
37 term
= pty
.fork(process
.env
.SHELL
|| 'sh', [], {
38 name
: require('fs').existsSync('/usr/share/terminfo/x/xterm-256color')
46 term
.on('data', function(data
) {
47 if (stream
) stream
.write('OUT: ' + data
+ '\n-\n');
50 : socket
.emit('data', data
);
54 + 'Created shell with pty master/slave'
55 + ' pair (master: %d, pid: %d)',
63 , server
= http
.createServer(app
);
65 app
.use(function(req
, res
, next
) {
66 var setHeader
= res
.setHeader
;
67 res
.setHeader = function(name
) {
74 return setHeader
.apply(res
, arguments
);
79 app
.use(express
.basicAuth(function(user
, pass
, next
) {
80 if (user
!== 'foo' || pass
!== 'bar') {
83 return next(null, user
);
86 app
.use(express
.static(__dirname
));
87 app
.use(terminal
.middleware());
89 if (!~process
.argv
.indexOf('-n')) {
90 server
.on('connection', function(socket
) {
91 var address
= socket
.remoteAddress
;
92 if (address
!== '127.0.0.1' && address
!== '::1') {
98 console
.log('Attempted connection from %s. Refused.', address
);
109 io
= io
.listen(server
, {
113 io
.sockets
.on('connection', function(sock
) {
116 socket
.on('data', function(data
) {
117 if (stream
) stream
.write('IN: ' + data
+ '\n-\n');
121 socket
.on('disconnect', function() {
125 while (buff
.length
) {
126 socket
.emit('data', buff
.shift());