├── .gitignore ├── Procfile ├── .travis.yml ├── allowed.js ├── test └── init.js ├── src ├── main.js ├── modules │ ├── redirect │ │ └── index.js │ └── allow │ │ └── index.js ├── message.js ├── modules.js ├── server.js └── proxy.js ├── package.json ├── default.crt ├── default.key ├── index.js ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: node index.js 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.11' 4 | - '0.10' 5 | - '0.8' 6 | - '0.6' 7 | -------------------------------------------------------------------------------- /allowed.js: -------------------------------------------------------------------------------- 1 | // List of allowed server ip 2 | // If empty, will be able to redirect everywhere 3 | // Be aware: can be used for DDOS or forge evil request on other host 4 | module.exports = [ 5 | //"83.xxx.x.1:6900", 6 | //"83.xxx.x.1:5121", 7 | //"83.xxx.x.1:6121" 8 | ]; -------------------------------------------------------------------------------- /test/init.js: -------------------------------------------------------------------------------- 1 | var assert = require('assert'); 2 | 3 | describe('wsProxy', function() { 4 | it('Start server', function(done) { 5 | try { 6 | require('../index.js'); 7 | } 8 | catch(e) { 9 | done(e); 10 | } 11 | 12 | setTimeout(function() { done() }, 1000); 13 | }) 14 | }) 15 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Main entry point for the proxy server 3 | */ 4 | const cluster = require('cluster'); 5 | const Server = require('./server'); 6 | 7 | class ProxyServer { 8 | /** 9 | * Initialize the proxy server 10 | */ 11 | constructor(config) { 12 | this.config = config; 13 | this.init(); 14 | } 15 | 16 | /** 17 | * Initialize server(s) 18 | */ 19 | init() { 20 | if (cluster.isMaster) { 21 | this.initMaster(); 22 | } else { 23 | this.initWorker(); 24 | } 25 | } 26 | 27 | /** 28 | * Initialize master process 29 | */ 30 | initMaster() { 31 | // Fork workers 32 | for (let i = 0; i < this.config.workers; i++) { 33 | cluster.fork({ isWorker: true }); 34 | } 35 | } 36 | 37 | /** 38 | * Initialize worker process 39 | */ 40 | initWorker() { 41 | new Server(this.config); 42 | } 43 | } 44 | 45 | module.exports = config => new ProxyServer(config); 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wsproxy", 3 | "description": "This is a websocket to tcp proxy, written in node.js. It is dynamic and will proxy to various tcp servers.", 4 | "version": "1.2.32", 5 | "author": "roBrowser", 6 | "repository": { 7 | "type": "git", 8 | "url": "https://github.com/herenow/wsProxy.git" 9 | }, 10 | "bugs": { 11 | "url": "https://github.com/herenow/wsProxy/issues" 12 | }, 13 | "main": "index.js", 14 | "bin": { 15 | "wsproxy": "./index.js" 16 | }, 17 | "dependencies": { 18 | "optimist": "0.6.0", 19 | "ws": "^2.3.1" 20 | }, 21 | "devDependencies": { 22 | "mocha": "1.18.x" 23 | }, 24 | "scripts": { 25 | "test": "mocha", 26 | "start": "node index.js" 27 | }, 28 | "engines": { 29 | "node": ">=0.6" 30 | }, 31 | "keywords": [ 32 | "wsproxy", 33 | "roproxy", 34 | "robrowser", 35 | "websocket-proxy", 36 | "ws2tcp" 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /src/modules/redirect/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Redirect module for mapping proxy targets 3 | */ 4 | const mes = require('../../message'); 5 | 6 | class RedirectModule { 7 | constructor() { 8 | this.redirects = new Map(); 9 | } 10 | 11 | /** 12 | * Initialize module with config 13 | */ 14 | init(config) { 15 | if (config.redirects) { 16 | this.redirects = new Map(Object.entries(config.redirects)); 17 | } 18 | } 19 | 20 | /** 21 | * Verify and redirect if needed 22 | */ 23 | verify(info, next) { 24 | const target = info.req.url.substr(1); 25 | const redirect = this.redirects.get(target); 26 | 27 | if (redirect) { 28 | info.req.url = `/${redirect}`; 29 | mes.info("Redirecting from '%s' to '%s'", target, redirect); 30 | } 31 | 32 | next(true); 33 | } 34 | } 35 | 36 | module.exports = new RedirectModule(); 37 | -------------------------------------------------------------------------------- /default.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDBzCCAe+gAwIBAgIJAKhiJIuWU8qWMA0GCSqGSIb3DQEBBQUAMBoxGDAWBgNV 3 | BAMMD3d3dy5leGFtcGxlLmNvbTAeFw0xNDA4MTQxMTI3MDFaFw0yNDA4MTExMTI3 4 | MDFaMBoxGDAWBgNVBAMMD3d3dy5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEB 5 | BQADggEPADCCAQoCggEBAJQpspd5HSF7PM57r4wuNehIWUdPNl47uA3Xj/7Yt0U3 6 | rHlnQj1WtzcWgwMcA+PSDqC4OaskYilaYmyOrzEYqQ5rvoyUyccU0hwOhRcTOlaf 7 | 76H8dyaf/bbHLRdlioxWq0DSQkDKZgdSq1sMljo2iMUZ5e32KIr4PRRe0Qa8UTxV 8 | hLrs+Zo1FY46EKXorVgeI5P68gzLEozgYDoyahUK4t9YwAKLpS92YLAx9Kcnah5K 9 | DNBw9txfs8TaB4YyRn4HQumgL/067zfQh81Lg0YGVwdIeg3uPthsl4K5HDUKFrEy 10 | tCABeRJIh7oiEWig8/E/+waXf95/Fys3ZMwYvx1RKdkCAwEAAaNQME4wHQYDVR0O 11 | BBYEFF7ID0mzTDNCgDlwvK/5Epzg6kdtMB8GA1UdIwQYMBaAFF7ID0mzTDNCgDlw 12 | vK/5Epzg6kdtMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEBABqyEEvD 13 | 7avccrw099y8vz929rW0awOMIBn122Le5uJHI4F1NDO3zSWuN8rUEsSup0YXfxd8 14 | 18i3G3AjatwcqNGGvmWUOl3XIQg1LvRAgjcw1eD3N7VALU9h3C7zDv5e69mzz9i0 15 | pk+EAWm9G+M2sLbqGfsc1Y+a22BMQm1v7o8WPh6dOGWu8DQ/8Z8eM5jDDGsVmzkY 16 | PrcImidf171/DYGq0ojnDzoOiq+zi5wRyYjkAaoxVFUI8ViRRUtpcZ3qQE6k5sLO 17 | eQxo/8ATjY2PZWZgtpzfWdXSVrZjt0u17EV9t3ARViEME5+JRBiLWG3L2m/1au7v 18 | 6D6xy4Hy2ruJ0vQ= 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /src/modules/allow/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Allow module for controlling access to proxy targets 3 | */ 4 | const mes = require('../../message'); 5 | 6 | class AllowModule { 7 | constructor() { 8 | this.allowedTargets = new Set(); 9 | } 10 | 11 | /** 12 | * Initialize module with config 13 | */ 14 | init(config) { 15 | this.allowedTargets = new Set(); // Ensure we always have a Set 16 | if (config && config.allowed) { 17 | config.allowed.forEach(target => this.allowedTargets.add(target)); 18 | } 19 | } 20 | 21 | /** 22 | * Verify if target is allowed 23 | */ 24 | verify(info, next) { 25 | // Get target from current URL (after potential redirect) 26 | const target = info.req.url.substr(1); 27 | const from = info.req.connection.remoteAddress; 28 | 29 | // Allow all if no restrictions set 30 | if (!this.allowedTargets || this.allowedTargets.size === 0) { 31 | next(true); 32 | return; 33 | } 34 | 35 | // Check if target is allowed 36 | const allowed = this.allowedTargets.has(target); 37 | if (!allowed) { 38 | mes.info("Reject requested connection from '%s' to '%s'.", from, target); 39 | } 40 | next(allowed); 41 | } 42 | } 43 | 44 | module.exports = new AllowModule(); 45 | -------------------------------------------------------------------------------- /src/message.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Dependencies 3 | */ 4 | const util = require('util'); 5 | const format = util.format 6 | 7 | /** 8 | * Message logger for the proxy 9 | */ 10 | class Logger { 11 | /** 12 | * Log a status message 13 | */ 14 | status(message, ...args) { 15 | const mes = format.apply(null, this.wrap([message, ...args])); 16 | console.log('\x1b[1;32m[%s]:\x1b[0m %s', 'Status', mes); 17 | } 18 | 19 | /** 20 | * Log an info message 21 | */ 22 | info(message, ...args) { 23 | const mes = format.apply(null, this.wrap([message, ...args])); 24 | console.log('\x1b[1;37m[%s]:\x1b[0m %s', 'Info', mes); 25 | } 26 | 27 | /** 28 | * Log an error message 29 | */ 30 | error(message, ...args) { 31 | const mes = format.apply(null, this.wrap([message, ...args])); 32 | console.log('\x1b[1;31m[%s]:\x1b[0m %s', 'Error', mes); 33 | } 34 | 35 | /** 36 | * Log a warning message 37 | */ 38 | warn(message, ...args) { 39 | const mes = format.apply(null, this.wrap([message, ...args])); 40 | console.log('\x1b[1;33m[%s]:\x1b[0m %s', 'Warn', mes); 41 | } 42 | 43 | /** 44 | * Wrap arguments in white color 45 | */ 46 | wrap(args) { 47 | const wrapped = [args[0]]; 48 | for (let i = 1; i < args.length; i++) { 49 | wrapped.push('\x1b[1;37m' + args[i] + '\x1b[0m'); 50 | } 51 | return wrapped; 52 | } 53 | } 54 | 55 | module.exports = new Logger(); 56 | -------------------------------------------------------------------------------- /src/modules.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Simple module system for the proxy 3 | */ 4 | class ModuleSystem { 5 | constructor() { 6 | this.modules = new Map(); 7 | this.hooks = { 8 | verify: [], // runs before connection is established 9 | connect: [] // runs after connection is established 10 | }; 11 | } 12 | 13 | /** 14 | * Load and initialize a module 15 | */ 16 | load(name, config) { 17 | const module = require(`./modules/${name}`); 18 | this.modules.set(name, module); 19 | 20 | // Initialize if needed 21 | if (typeof module.init === 'function') { 22 | module.init(config); 23 | } 24 | 25 | // Register hooks with proper binding 26 | if (typeof module.verify === 'function') { 27 | this.hooks.verify.push(module.verify.bind(module)); 28 | } 29 | if (typeof module.connect === 'function') { 30 | this.hooks.connect.push(module.connect.bind(module)); 31 | } 32 | } 33 | 34 | /** 35 | * Run verify hooks in sequence 36 | * Returns false if any hook returns false 37 | */ 38 | async verify(info) { 39 | for (const hook of this.hooks.verify) { 40 | const result = await new Promise(resolve => hook(info, resolve)); 41 | if (result === false) return false; 42 | } 43 | return true; 44 | } 45 | 46 | /** 47 | * Run connect hooks in sequence 48 | */ 49 | async connect(ws) { 50 | for (const hook of this.hooks.connect) { 51 | await new Promise(resolve => hook(ws, resolve)); 52 | } 53 | } 54 | } 55 | 56 | module.exports = new ModuleSystem(); 57 | -------------------------------------------------------------------------------- /default.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEogIBAAKCAQEAlCmyl3kdIXs8znuvjC416EhZR082Xju4DdeP/ti3RTeseWdC 3 | PVa3NxaDAxwD49IOoLg5qyRiKVpibI6vMRipDmu+jJTJxxTSHA6FFxM6Vp/vofx3 4 | Jp/9tsctF2WKjFarQNJCQMpmB1KrWwyWOjaIxRnl7fYoivg9FF7RBrxRPFWEuuz5 5 | mjUVjjoQpeitWB4jk/ryDMsSjOBgOjJqFQri31jAAoulL3ZgsDH0pydqHkoM0HD2 6 | 3F+zxNoHhjJGfgdC6aAv/TrvN9CHzUuDRgZXB0h6De4+2GyXgrkcNQoWsTK0IAF5 7 | EkiHuiIRaKDz8T/7Bpd/3n8XKzdkzBi/HVEp2QIDAQABAoIBACYWPfmgQbPMqUnv 8 | E6Z2bpcimgixvSkmMt8kDbkWXq5lbGnc+HMqKnj3yX/wILPc2LPKB9ENzkoRGQIM 9 | /84gJ700R0x+JwyNNqHNvbq7z6BbBs/eRYbhU+g7dUTxblc7JFTKeAuNvAKf5rrG 10 | FowqXqhESw4L3Eo1HAZzhUo0+LEIaq/67OuzDmP/K+KeNr14tMCu3KaFq07yV84f 11 | +TpNxCRXDcsULMeBa3qyq8ObtzvGzVxcI5T90XdAKmwDgRcoMvbk8pFnaK1C/kZ6 12 | GzqXanRg0ixhqlQMkt2EgcRSAL/WNeqR4fjIyl4DrYpdz61lWNPqe5nMYKMJ5Gp9 13 | aIETcJ0CgYEAw5C8tHCuLD5sEMjl/WBZ/KOh52fx3onVx/AQEdp8m4ey2FHniFMW 14 | mi+LU3+kVdZGJBcHXiy3R8ZLRWBoe3yulGIfIHsApCS6kgPb/pnVlVLlMbvbAAyM 15 | yXZaxsIm/qNHCyHASpznugSjb13RSmJLbXvvWduefBYsVaAMyv9uVrsCgYEAwfLt 16 | l+xN6U+ZPgBS0s0HioZZapkkmzIbfwMg6TC9UUNzPa4HJP7N5eUTg5g9o0eLLZaT 17 | nPRCh0y+mVwk28lM+rQPFjB9sxvIXQDZHejThA8tYBk/A1NA0JWnqdE5imNtPJN2 18 | jipUrNgIldMF2WAytvISwLp4gmnXeoICwqXTmnsCgYBUdqGZyQTgpQElaq8ydLfI 19 | zp9xg0pKU/uaA8vc+iFRRxVuKkm2bjRX2WryYDGIxSe8FJohCW0LOdBuoUne86Wu 20 | /oX1EErhmd9eiv4sAyLlAE1u4nSem8z+gfiI2XfgCIL5gtU7JHNMuw4fXkSzPKrZ 21 | GWrxw1G6xBTX0m1UC2gLWwKBgDVZSCeQ9YFmxsU6O44Gnbtp5zCePWZ/KvcN+kCK 22 | ipjOz+U4eHihqitBjtOUzeea51q735C904r5/jebE/xs68LOQpQc9IaO7tc+Q3qp 23 | r3zU2+tiJmYYwWxergbVKVm6rbKK8YJ7fF0q83ma2TII9wpBngzrffiJep8VIgM+ 24 | r+z/AoGAPqBR+X1uSUCo3TeI3/s8+y3cRzsWnmp99GNoGipQoQRXoq0mYZ6ZhfD/ 25 | eLWOeXAL+SMlhol9Rb1eI08UTkS2Hv6XtqQGk/Bz4+iibiI0FjzKPiJ9iDyNmOlG 26 | HgvvAPM2BS6+RuWL7AqeNSacBRP9QaE2iCzbML1b+uta4Uuoaao= 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /src/server.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Dependencies 3 | */ 4 | const http = require('http'); 5 | const https = require('https'); 6 | const fs = require('fs'); 7 | const WebSocket = require('ws'); 8 | const modules = require('./modules'); 9 | const Proxy = require('./proxy'); 10 | const mes = require('./message'); 11 | 12 | /** 13 | * WebSocket proxy server 14 | */ 15 | class Server { 16 | constructor(config) { 17 | this.config = config; 18 | this.init(); 19 | } 20 | 21 | init() { 22 | const opts = { 23 | clientTracking: false, 24 | verifyClient: this.verifyClient.bind(this) 25 | }; 26 | 27 | // Create HTTP(S) server 28 | if (this.config.ssl) { 29 | opts.server = https.createServer({ 30 | key: fs.readFileSync(this.config.key), 31 | cert: fs.readFileSync(this.config.cert) 32 | }, this.handleHttp); 33 | mes.status("Starting a secure wsProxy on port %s...", this.config.port); 34 | } else { 35 | opts.server = http.createServer(this.handleHttp); 36 | mes.status("Starting wsProxy on port %s...", this.config.port); 37 | } 38 | 39 | // Start listening 40 | opts.server.listen(this.config.port); 41 | 42 | // Create WebSocket server 43 | const wss = new WebSocket.Server(opts); 44 | wss.on('connection', this.handleConnection.bind(this)); 45 | } 46 | 47 | /** 48 | * Handle HTTP requests 49 | */ 50 | handleHttp(req, res) { 51 | res.writeHead(200); 52 | res.end("wsProxy running...\n"); 53 | } 54 | 55 | /** 56 | * Verify client connection 57 | */ 58 | async verifyClient(info, callback) { 59 | const result = await modules.verify(info); 60 | callback(result); 61 | } 62 | 63 | /** 64 | * Handle new WebSocket connection 65 | */ 66 | async handleConnection(ws) { 67 | await modules.connect(ws); 68 | new Proxy(ws); 69 | } 70 | } 71 | 72 | module.exports = Server; 73 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Main entry point for the wsProxy 5 | */ 6 | const args = require('optimist').argv; 7 | const main = require('./src/main'); 8 | const Modules = require('./src/modules'); 9 | 10 | // Show help 11 | if (args.h || args.help) { 12 | console.log('Example usage:'); 13 | console.log('wsproxy -p 5999'); 14 | console.log('-p, --port port to run wsProxy on. [Default: 5999]'); 15 | console.log('-a, --allow list of allowed ip:port to proxy to (comma separated) [Default: none] [Example: 127.0.0.1:6900,127.0.0.1:5121,127.0.0.1:6121]'); 16 | console.log('-r, --redirect list of address redirects (comma separated) [Example: localhost:6900=login:6900,localhost:6121=char:6121]'); 17 | console.log('-t, --threads number of "threads" to spawn, set it to the number of cpu\'s you have. [Default: 1]'); 18 | console.log('-s, --ssl enable ssl.'); 19 | console.log('-k, --key path to ssl key file. [Default: ./default.key]'); 20 | console.log('-c, --cert path to ssl cert file. [Default: ./default.crt]'); 21 | process.exit(0); 22 | } 23 | 24 | // Parse allowed ip:port option into array 25 | const allowed = []; 26 | if (args.a || args.allow) { 27 | allowed.push(...(args.a || args.allow).split(',')); 28 | } 29 | 30 | // Parse redirects into a map 31 | const redirects = {}; 32 | if (args.r || args.redirect) { 33 | const redirectList = typeof (args.r || args.redirect) === 'string' ? 34 | (args.r || args.redirect).split(',') : 35 | args._; 36 | 37 | redirectList.forEach(redirect => { 38 | if (typeof redirect === 'string' && redirect.includes('=')) { 39 | const [from, to] = redirect.split('='); 40 | redirects[from] = to; 41 | } 42 | }); 43 | } 44 | 45 | // Create config 46 | const config = { 47 | port: args.port || args.p || process.env.PORT || 5999, 48 | workers: args.threads || args.t || 1, 49 | ssl: args.ssl || args.s || false, 50 | key: args.key || args.k || "./default.key", 51 | cert: args.cert || args.c || "./default.crt", 52 | redirects, 53 | allowed 54 | }; 55 | 56 | // Initialize and load modules 57 | Modules.load('redirect', config); 58 | Modules.load('allow', config); 59 | 60 | // Start server 61 | main(config); 62 | -------------------------------------------------------------------------------- /src/proxy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Dependencies 3 | */ 4 | const net = require('net'); 5 | const mes = require('./message'); 6 | 7 | /** 8 | * WebSocket to TCP proxy 9 | */ 10 | class Proxy { 11 | constructor(ws) { 12 | this.ws = ws; 13 | this.tcp = null; 14 | this.target = ws.upgradeReq.url.substr(1); 15 | this.from = ws.upgradeReq.connection.remoteAddress; 16 | 17 | // Bind event handlers 18 | this.ws.on('message', this.handleClientData.bind(this)); 19 | this.ws.on('close', this.close.bind(this)); 20 | this.ws.on('error', this.close.bind(this)); 21 | 22 | // Connect to target server 23 | this.connect(); 24 | } 25 | 26 | /** 27 | * Connect to target server 28 | */ 29 | connect() { 30 | const [host, port] = this.target.split(':'); 31 | 32 | mes.info("Requested connection from '%s' to '%s' [ACCEPTED].", this.from, this.target); 33 | 34 | this.tcp = net.connect({ 35 | port: parseInt(port, 10), 36 | host: host, 37 | family: 4 // Force IPv4 38 | }, () => { 39 | mes.status("Connection accepted from '%s'.", this.target); 40 | }); 41 | 42 | this.tcp.setTimeout(0); 43 | this.tcp.setNoDelay(true); 44 | this.tcp.on('data', this.handleServerData.bind(this)); 45 | this.tcp.on('close', this.close.bind(this)); 46 | this.tcp.on('error', error => { 47 | mes.error("Connection error from '%s': %s", this.target, error.message); 48 | this.close(); 49 | }); 50 | } 51 | 52 | /** 53 | * Handle data from client 54 | */ 55 | handleClientData(data) { 56 | if (!this.tcp) return; 57 | try { 58 | this.tcp.write(data); 59 | } catch (e) { 60 | mes.error("Error sending to server '%s': %s", this.target, e.message); 61 | this.close(); 62 | } 63 | } 64 | 65 | /** 66 | * Handle data from server 67 | */ 68 | handleServerData(data) { 69 | this.ws.send(data, error => { 70 | if (error) { 71 | mes.error("Error sending to client '%s': %s", this.from, error.message); 72 | this.close(); 73 | } 74 | }); 75 | } 76 | 77 | /** 78 | * Close all connections 79 | */ 80 | close() { 81 | if (this.tcp) { 82 | mes.info("Connection closed from '%s'.", this.target); 83 | this.tcp.removeAllListeners(); 84 | this.tcp.end(); 85 | this.tcp = null; 86 | } 87 | 88 | if (this.ws) { 89 | mes.info("Connection closed from '%s'.", this.from); 90 | this.ws.removeAllListeners(); 91 | this.ws.close(); 92 | this.ws = null; 93 | } 94 | } 95 | } 96 | 97 | module.exports = Proxy; 98 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | wsProxy 2 | ======= 3 | [![Build Status](https://travis-ci.org/herenow/wsProxy.svg?branch=master)](https://travis-ci.org/herenow/wsProxy) 4 | 5 | This is a websocket to tcp proxy, written in node.js. It is dynamic and will proxy to various tcp servers. 6 | 7 | 8 | Installation 9 | ---------- 10 | ``` 11 | npm install wsproxy -g 12 | ``` 13 | 14 | 15 | Usage 16 | ---------- 17 | 18 | ``` 19 | wsproxy [-p PORT] [-t THREADS (# of threads to spawn)] [-s ENABLE_SSL] [-k KEY_FILE] [-c CERT_FILE] 20 | ``` 21 | * `-p` Port to bind wsProxy to 22 | * If no `port` is specified it will default to `process.env.PORT` or port 5999. 23 | * `-a` List of allowed servers to proxy to 24 | * By default wsProxy will proxy to any ip:port, this is a major risk, since malicous users may use your 25 | wsProxy server for illegal activity, or any other use other then connecting to your athena server. 26 | * The list of IP:PORT's should be separate by comma! Ex: 27 | ```bash 28 | wsproxy -a 127.0.0.1:6900,127.0.0.1:6121,127.0.0.1:5121 29 | ``` 30 | * Note: Use the same IP's you configured your server address at ROConfig at roBrowser. 31 | * `-r` List of address redirects 32 | * Allows redirecting connections from one address to another 33 | * The list should be comma-separated with format: source=target 34 | * Example: 35 | ```bash 36 | wsproxy -r localhost:6900=login:6900,localhost:6121=char:6121 37 | ``` 38 | * This will redirect connections to localhost:6900 to login:6900, and localhost:6121 to char:6121 39 | * `-t` Number of cpu cores that wsProxy should use 40 | * `-s` Enable SSL 41 | * `-k` Path to ssl key file 42 | * `-c` Path to ssl cert file 43 | * Use `wsproxy --help` for a list of available commands. 44 | 45 | 46 | Client usage 47 | ---------- 48 | When connecting to this websocket you will give it an IP:PORT uri, for example: 49 | ``` 50 | ws://websocket.example.com:5999/127.0.0.1:6900 51 | ``` 52 | * You can edit allowed.js to only allow proxy to certain IP:PORT 53 | * Note: if you pass in the `-a` or `--allow` option when starting the `wsproxy` this file will be ignored. 54 | * We will soon release a version, with better standards for this. 55 | 56 | 57 | Writing modules for wsProxy guidelines 58 | ------------ 59 | * Simply require and extend current files from the `/src` folder, once done, require them on wsProxy `/index.js`. 60 | * ***BE CAREFUL, MODULES NEED TO BE LIGHTWEIGHT, LIMIT YOURSELF TO SIMPLE I/O OPERATIONS, DON'T BLOCK, AND CREATE LITTLE GARBAGE!*** 61 | * Don't forget that node.js is single threaded, cpu intensive blocks of code will block the entire proxy! 62 | * Don't create to much garbage, or the garbage collector will also block for extended periods of time, thus creating "lag" for the users. 63 | 64 | 65 | Authors 66 | --------- 67 | This was created for and by the roBrowser project. 68 | - [vthibault](https://github.com/vthibault) 69 | - [herenow](https://github.com/herenow) 70 | 71 | 72 | Thank you 73 | ---------- 74 | - Einaros/ws for providing the websocket middleware 75 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | --------------------------------------------------------------------------------