-
Notifications
You must be signed in to change notification settings - Fork 22
/
run.js
42 lines (38 loc) · 1.28 KB
/
run.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
const spawn = require('child_process').spawn;
let run = false;
let runParams = 'libev:aes-256-cfb';
let ssConfig = '127.0.0.1:6001';
const argv = process.argv.filter((ele, index) => index > 1);
argv.forEach((f, index) => {
if(f === '--run' || f === '-r') {
run = true;
if(argv[index + 1] && !argv[index + 1].startsWith('-')) { runParams = argv[index + 1]; }
}
if(f === '--shadowsocks' || f === '-s') {
ssConfig = argv[index + 1];
}
});
if(!run) { return; }
let type = 'libev';
let method = 'aes-256-cfb';
if(runParams.indexOf(':') >= 0) {
method = runParams.split(':')[1];
}
let shadowsocks;
if(runParams.indexOf('python') >= 0) {
type = 'python';
const tempPassword = 'qwerASDF' + Math.random().toString().substr(2, 8);
shadowsocks = spawn('ssserver', ['-m', method, '-p', '65535', '-k', tempPassword, '--manager-address', ssConfig ]);
} else {
shadowsocks = spawn('ss-manager', [ '-m', method, '-u', '--manager-address', ssConfig ]);
}
shadowsocks.stdout.on('data', (data) => {
// console.log(`stdout: ${data}`);
});
shadowsocks.stderr.on('data', (data) => {
// console.error(`stderr: ${data}`);
});
shadowsocks.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
console.log(`Run shadowsocks (${ type === 'python' ? 'python' : 'libev'})`);