Add --tunnel-host option to wsssht and change default timeout to 5 seconds

- Add --tunnel-host option to specify local IP address for tunnel binding
- Change default timeout from 30 to 5 seconds for wsssht
- Update help text, man page, and config file to reflect changes
- Update setup_tunnel function to accept tunnel_host parameter
- Update socket binding to use specified tunnel_host or default to 127.0.0.1
parent 9a91cb2a
......@@ -7,15 +7,19 @@
# Configuration options:
# port: Default WebSocket server port
# domain: Default domain suffix for hostname parsing
# tunnel-port: Local tunnel port (0 = auto)
# tunnel-host: Local IP address to bind tunnel to (default: 127.0.0.1)
# tunnel: Default transport types for data channel (comma-separated or 'any')
# tunnel-control: Default transport types for control channel (comma-separated or 'any')
# service: Default service type (default: ssh)
# interval: Connection retry interval in seconds (default: 30)
# interval: Connection retry interval in seconds (default: 5)
[default]
port=9898
domain=example.com
tunnel-port=0
tunnel-host=127.0.0.1
tunnel=websocket
tunnel-control=websocket
service=ssh
interval=30
\ No newline at end of file
interval=5
\ No newline at end of file
......@@ -25,11 +25,14 @@ and
does not fork and execute external commands. Instead, it sets up the tunnel and displays connection instructions for manual use.
.SH OPTIONS
.TP
.BR \-\-local\-port " \fIPORT\fR"
.BR \-\-tunnel\-port " \fIPORT\fR"
Specify the local port for the tunnel (default: auto\-assigned)
.TP
.BR \-\-tunnel\-host " \fIHOST\fR"
Specify the local IP address to bind the tunnel to (default: 127.0.0.1)
.TP
.BR \-\-interval " \fISEC\fR"
Connection retry interval in seconds (default: 30)
Connection retry interval in seconds (default: 5)
.TP
.BR \-\-debug
Enable debug output
......@@ -54,7 +57,7 @@ Basic tunnel setup:
.B wsssht user@myclient.example.com
.TP
Specify local port:
.B wsssht \-\-local\-port 2222 user@myclient.example.com
.B wsssht \-\-tunnel\-port 2222 user@myclient.example.com
.TP
Use specific transport:
.B wsssht \-\-tunnel websocket user@myclient.example.com
......
......@@ -45,8 +45,9 @@ void print_usage(const char *program_name) {
fprintf(stderr, "WebSocket SSH Tunnel - Setup WebSocket tunnels for manual connections\n\n");
fprintf(stderr, "Protect the dolls!\n\n");
fprintf(stderr, "Options:\n");
fprintf(stderr, " --local-port PORT Local tunnel port (default: auto)\n");
fprintf(stderr, " --interval SEC Connection retry interval in seconds (default: 30)\n");
fprintf(stderr, " --tunnel-port PORT Local tunnel port (default: auto)\n");
fprintf(stderr, " --tunnel-host HOST Local IP address to bind tunnel to (default: 127.0.0.1)\n");
fprintf(stderr, " --interval SEC Connection retry interval in seconds (default: 5)\n");
fprintf(stderr, " --debug Enable debug output\n");
fprintf(stderr, " --tunnel TYPES Transport types for data channel (comma-separated or 'any', default: any)\n");
fprintf(stderr, " --tunnel-control TYPES Transport types for control channel (comma-separated or 'any', default: any)\n");
......@@ -56,7 +57,7 @@ void print_usage(const char *program_name) {
fprintf(stderr, " --port PORT Same as -p\n");
fprintf(stderr, "\nExamples:\n");
fprintf(stderr, " %s user@myclient.example.com -p 9898\n", program_name);
fprintf(stderr, " %s --local-port 2222 user@myclient.example.com\n", program_name);
fprintf(stderr, " %s --tunnel-port 2222 user@myclient.example.com\n", program_name);
fprintf(stderr, " %s --tunnel websocket --debug user@myclient.example.com\n", program_name);
fprintf(stderr, "\nDonations:\n");
fprintf(stderr, " BTC: bc1q3zlkpu95amtcltsk85y0eacyzzk29v68tgc5hx\n");
......@@ -68,9 +69,13 @@ int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_ar
int target_start = 1; // Skip argv[0]
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "--local-port") == 0 && i + 1 < argc) {
if (strcmp(argv[i], "--tunnel-port") == 0 && i + 1 < argc) {
config->local_port = strdup(argv[i + 1]);
i++; // Skip the argument
} else if (strcmp(argv[i], "--tunnel-host") == 0 && i + 1 < argc) {
if (config->tunnel_host) free(config->tunnel_host);
config->tunnel_host = strdup(argv[i + 1]);
i++; // Skip the argument
} else if (strcmp(argv[i], "-p") == 0 && i + 1 < argc) {
config->wssshd_port = atoi(argv[i + 1]);
i++; // Skip the argument
......@@ -187,13 +192,15 @@ int main(int argc, char *argv[]) {
char *config_tunnel = read_config_value_from_file("tunnel", "wssht");
char *config_tunnel_control = read_config_value_from_file("tunnel-control", "wssht");
char *config_service = read_config_value_from_file("service", "wssht");
char *config_tunnel_host = read_config_value_from_file("tunnel-host", "wssht");
char *config_interval = read_config_value_from_file("interval", "wssht");
wsssh_config_t config = {
.local_port = NULL,
.tunnel_host = config_tunnel_host,
.wssshd_port = 9898,
.debug = 0,
.interval = 30,
.interval = 5,
.dev_tunnel = 0,
.tunnel = config_tunnel,
.tunnel_control = config_tunnel_control,
......@@ -210,6 +217,9 @@ int main(int argc, char *argv[]) {
if (!config.service) {
config.service = strdup("ssh");
}
if (!config.tunnel_host) {
config.tunnel_host = strdup("127.0.0.1");
}
if (config_interval) {
config.interval = atoi(config_interval);
free(config_interval);
......@@ -289,6 +299,7 @@ int main(int argc, char *argv[]) {
free(client_id);
free(wssshd_host);
free(config.local_port);
free(config.tunnel_host);
pthread_mutex_destroy(&tunnel_mutex);
return 1;
}
......@@ -315,7 +326,7 @@ int main(int argc, char *argv[]) {
fflush(stdout);
}
listen_sock = setup_tunnel(wssshd_host, wssshd_port, client_id, local_port, config.debug, 0);
listen_sock = setup_tunnel(wssshd_host, wssshd_port, client_id, local_port, config.debug, 0, config.tunnel_host);
if (listen_sock < 0) {
setup_attempts++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment