/
peer-vnc
executable file
·119 lines (98 loc) · 3.36 KB
/
peer-vnc
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env node
//
// Please install node-httpp binary in your system exec dir, like /usr/bin/ or /usr/local/bin/
//
var util = require('util'),
argv = require('optimist').argv,
Proxy = require('../index');
var help = [
"usage: peer-vnc [options] ",
"",
"Starts a peer-vnc server using the specified command-line options",
"",
"options:",
" -t, --target localhost:5900,localhost:5901-5918 Host:port pairs of VNC server, the multiple VNC separate by comma",
" -k, --key User key Key for the registered user on ivncbox.com",
" -s --secmode ssl or acl Secure mode: ssl or host-based ACL",
" -a --authmode srv or both SSL auth mode: srv or both",
" -b --basicauth user:pass Http basic-auth as username:password",
" -d --directory /xxx/yy/ File upload directory",
" -u, --user USER User to drop privileges once server socket is bound",
" -h, --help You're staring at it"
].join('\n');
if (argv.h || argv.help || Object.keys(argv).length === 2) {
return util.puts(help);
}
var target = argv.t || argv.target,
usrkey = argv.k || argv.key,
secmode = argv.s || argv.secmode,
authmode = argv.a || argv.authmode,
basicauth = argv.b || argv.basicauth,
directory = argv.d || argv.directory,
user = argv.u || argv.user;
//
// Check target VNC server
//
var vncsrvs = [], options = {};
if (target) {
var vncs = target.split(',');
if (!Array.isArray(vncs)) vncs = [vncs];
// normalize port range
for (var idx = 0; idx < vncs.length; idx ++) {
var vncstrs = vncs[idx].split(':');
var vnchost = vncstrs[0];
// support port range like localhost:5901-5910
var port_range = [];
if (vncstrs[1]) {
var pstr = vncstrs[1].split('-');
if (pstr.length > 1) {
port_range.push(parseInt(pstr[0], 10));
port_range.push(parseInt(pstr[1], 10));
} else {
port_range.push(parseInt(pstr[0], 10));
port_range.push(parseInt(pstr[0], 10));
}
} else {
port_range.push(5900);
port_range.push(5900);
}
for (var vncport = port_range[0]; vncport <= port_range[1]; vncport ++) {
vncsrvs.push(vnchost + ':' + vncport)
}
}
} else {
return util.puts(help);
}
if (secmode) {
options.secmode = secmode;
}
if (authmode) {
options.sslmode = authmode;
}
if (basicauth) {
options.auth = basicauth;
} else {
console.log('Warning: Please set http auth with -b username:password');
}
if (directory) {
options.upload = directory;
console.log('Warning: File will upload to ' + directory);
}
if (usrkey) {
options.usrkey = usrkey;
}
//
// Create the VNC client server with the specified options
//
var server = new Proxy(vncsrvs, function(err, proxyURL){
console.log('VNC Proxy URL(please open it on browser)');
for (var k in proxyURL) {
console.log(k+' '+proxyURL[k]);
}
}, options);
//
// Drop privileges if requested
//
if (typeof user === 'string') {
process.setuid(user);
}