2
1
mirror of https://git.coolaj86.com/coolaj86/sclient.js synced 2025-04-21 21:50:37 +00:00

Compare commits

..

No commits in common. "master" and "v1.4.1" have entirely different histories.

2 changed files with 17 additions and 43 deletions

View File

@ -1,4 +1,3 @@
#!/usr/bin/env node
'use strict';
var pkg = require('../package.json');
@ -22,6 +21,19 @@ function parseFlags(argv) {
var args = argv.slice();
var flags = {};
args.sort(function (a, b) {
if ('-' === a[0]) {
if ('-' === b[0]) {
return 0;
}
return 1;
}
if ('-' === b[0]) {
return -1;
}
return 0;
});
args.some(function (arg, i) {
if (/^-k|--?insecure$/.test(arg)) {
flags.rejectUnauthorized = false;
@ -58,32 +70,6 @@ function parseFlags(argv) {
return true;
}
});
args.some(function (arg, i) {
if (/^--?socks5$/.test(arg)) {
flags.socks5 = args[i + 1];
if (!flags.socks5 || /^-/.test(flags.socks5)) {
usage();
process.exit(202);
}
args.splice(i, 2);
return true;
}
});
// This works for most (but not all)
// of the ssh and rsync flags - because they mostly don't have arguments
args.sort(function (a, b) {
if ('-' === a[0]) {
if ('-' === b[0]) {
return 0;
}
return 1;
}
if ('-' === b[0]) {
return -1;
}
return 0;
});
return {
flags: flags
@ -123,10 +109,6 @@ function testRemote(opts) {
var remote = args.shift() + ':' + opts.remotePath;
args = [ remote, '-e', 'ssh ' + args.join(' ') ];
}
if (opts.socks5) {
args.push('-D');
args.push('localhost:' + opts.socks5);
}
args = args.concat(opts.args);
var child = spawn(opts.command, args, { stdio: 'inherit' });
child.on('exit', function () {
@ -157,7 +139,7 @@ function main() {
// Re-arrange argument order for ssh
if (cmd.flags.wrapSsh) {
cmd.args.splice(3, 0, 'ssh');
} else if (-1 !== [ 'ssh', 'rsync', 'vpn' ].indexOf((cmd.args[2]||'').split(':')[0])) {
} else if (-1 !== [ 'ssh', 'rsync' ].indexOf((cmd.args[2]||'').split(':')[0])) {
cmd.flags.wrapSsh = true;
binParam = cmd.args.splice(2, 1);
cmd.args.splice(3, 0, binParam[0]);
@ -175,7 +157,7 @@ function main() {
}
local = (cmd.args[3]||'').split(':');
if (-1 !== [ 'ssh', 'rsync', 'vpn' ].indexOf(local[0])) {
if (-1 !== [ 'ssh', 'rsync' ].indexOf(local[0])) {
cmd.flags.wrapSsh = true;
}
@ -230,24 +212,16 @@ function main() {
opts.stdin = process.stdin;
opts.stdout = process.stdout;
// no need for port
} else if (-1 !== [ 'ssh', 'rsync', 'vpn' ].indexOf(localAddress)) {
} else if (-1 !== [ 'ssh', 'rsync' ].indexOf(localAddress)) {
cmd.flags.wrapSsh = true;
opts.localAddress = 'localhost';
opts.localPort = local[1] || 0; // choose at random
opts.command = localAddress;
opts.args = cmd.args.slice(4); // node, sclient, ssh, addr
opts.socks5 = cmd.flags.socks5;
if ('rsync' === opts.command) {
opts.remotePath = opts.remotePort;
opts.remotePort = 0;
}
if ('vpn' === opts.command) {
opts.command = 'ssh';
if (!opts.socks5) {
usage();
return;
}
}
if (!opts.remotePort) {
opts.remotePort = cmd.flags.port || 443;
}

View File

@ -1,6 +1,6 @@
{
"name": "sclient",
"version": "1.4.3",
"version": "1.4.1",
"description": "Secure Client for exposing TLS (aka SSL) secured services as plain-text connections locally. Also ideal for multiplexing a single port with multiple protocols using SNI.",
"main": "index.js",
"homepage": "https://telebit.cloud/sclient/",