-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.js
executable file
·60 lines (48 loc) · 1.47 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
'use strict';
var info = require('./package.json');
var path = require('path'),
socketio = require('socket.io'),
express = require('express'),
http = require('http'),
webtelnet = require('./webtelnet-proxy.js');
var conf = {
telnet: {
host: '127.0.0.1',
port: 23,
},
web: {
host: '0.0.0.0',
port: 8080,
},
www: path.resolve(__dirname + '/www'),
logTraffic: true,
};
var argv = process.argv;
var me = argv[1];
var args = require('minimist')(argv.slice(2));
process.stdout.write('webtelnet, version ' + info.version + ', by ' + info.author.name + ' <' + info.author.email +'>\n');
if(args._.length < 2) {
process.stdout.write(
'Syntax: webtelnet <http-port> <telnet-port> [options]\n' +
'Options: \n' +
' [-h <telnet-host>]\n' +
' [-w <path/to/www>]\n' +
' [-c <charset>]\n'
);
process.exit(0);
}
conf.web.port = parseInt(args._[0], 10);
conf.telnet.port = parseInt(args._[1], 10);
if(args.h) conf.telnet.host = args.h;
if(args.w) conf.www = path.resolve(args.w);
var app = express().use(express.static(conf.www));
var httpserver = http.createServer(app);
httpserver.listen(conf.web.port, conf.web.host, function(){
console.log('listening on ' + conf.web.host + ':' + conf.web.port);
});
// create socket io
var io = socketio.listen(httpserver);
// create webtelnet proxy and bind to io
var webtelnetd = webtelnet(io, conf.telnet.port, conf.telnet.host);
if(args.c) webtelnetd.setCharset(args.c);