wstun
v0.1.6
Published
A set of tools to establish TCP tunnels (or TCP reverse tunnels) over WebSocket connections for circumventing the problem of directly connect to hosts behind a strict firewall or without public IP. It also supports WebSocket Secure (wss) connections.
Downloads
5
Readme
WSTUN - Modified for Data Gateway Server and Data Gateway Client (for internal use)
Overview
See readme of @mdslab/wstun
Installation (for debug)
- Download source code and go to the root directory.
- Run
npm install
to install all dependencies. - Run
npm link
to exposewstun
cmd globally.
Installation
npm install wstun
Programmatic Usage
Instantiation of a reverse tunnel server
var wstun = require("wstun");
// without security
reverse_server = new wstun.server_reverse();
// or with security (<PRIVATE-KEY-PATH> and <PUBLIC-KEY-PATH> are the paths of the private and public keys in .pem formats)
reverse_server = new wstun.server_reverse({ssl:true, key:"<PRIVATE-KEY-PATH>", cert:"<PUBLIC-KEY-PATH>"});
//start the server (<PORT> is the listening port)
reverse_server.start(<PORT>);
Implementation of a reverse tunnel client
var wstun = require("wstun");
reverse_client = new wstun.client_reverse();
// without security
wstunHost = 'ws://wstunServerIP:wstunPort';
// or with security
wstunHost = 'wss://wstunServerIP:wstunPort';
// <publicPort> is the port on the reverse tunnel server on which the tunneled service will be reachable
// <remoteHost>:<remotePort> is the endpoint of the service to be reverse tunneled
reverse_client.start(<publicPort>, wstunHost, '<remoteHost>:<remotePort>', {
token: '',
trayId: '',
trayName: ''
}, {
success: function(){},
failure: function(error){}
});
Command-Line Usage
Data Gateway Server
// start server
wstun -r -s 8080
1. Get token
GET http://localhost:8080/token
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 38
ETag: W/"26-OnijoHwIHbgqooKaIW/fxvGiQAA"
Date: Wed, 08 Jul 2020 04:23:28 GMT
Connection: keep-alive
"95d9b8e6-39fb-46cd-a401-7d7f9119f710"
2. Get list of registered trays
GET http://localhost:8080/trays
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 2
ETag: W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"
Date: Wed, 08 Jul 2020 04:34:35 GMT
Connection: keep-alive
[{"id": "test","name": "test"}]
3. request available port
POST http://localhost:8080/availableport
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 81
ETag: W/"51-fs6jVncwj5ob5fovjIPuxuKIycQ"
Date: Wed, 08 Jul 2020 04:39:39 GMT
Connection: keep-alive
{
"port": 57255,
"token": "95d9b8e6-39fb-46cd-a401-7d7f9119f710"
}
4. Request available port with optional parameters (trayId, range)
POST http://localhost:8080/availableport
{"trayId":"test", "range": [3000,3100]}
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 81
ETag: W/"51-aZoi+f6MfcSHUwlYvJl2coUBQnY"
Date: Wed, 08 Jul 2020 04:37:06 GMT
Connection: keep-alive
{
"port": 3000,
"token": "95d9b8e6-39fb-46cd-a401-7d7f9119f710",
"trayPort": "3306"
}
5. Close ws tunnel by port
DELETE http://localhost:8080/ws/3306
HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 64
ETag: W/"40-IjZVx+QRCNTrAi8IdDEvyRt4MR0"
Date: Wed, 08 Jul 2020 04:41:21 GMT
Connection: keep-alive
"Web socket tunnel related to port 3306 is closed successfully."
Data Gateway Client
// create a ws tunnel to server with token
wstun -r3306:10.197.34.164:3306 ws://localhost:8080 --token=95d9b8e6-39fb-46cd-a401-7d7f9119f710
// client(tray service) creates a ws tunnel and register itself
wstun -r3306:10.197.34.164:3306 ws://localhost:8080 --token=95d9b8e6-39fb-46cd-a401-7d7f9119f710 --trayid=test --trayname=test