Complete implementation of graceful shutdown and configuration reload

This commit implements comprehensive improvements to WSSSH tools:

## Graceful Shutdown Implementation
- Added SIGINT signal handlers for both wssshc and wsssht
- Implemented graceful tunnel close on exit with 3-second timeout
- Added double Ctrl+C detection for immediate exit without waiting
- Enhanced signal handling throughout both programs
- Added tunnel_close messages for all active tunnels before shutdown

## Configuration Reload (SIGHUP)
- Implemented SIGHUP signal handling in wssshc for live configuration reload
- Added reload_configuration() function to reload services config and password
- Reloads password from config files without service restart
- Reloads services configuration from /etc/wsssh.d/ directory
- Updates connect_to_server() to support dynamic configuration reloading

## Version Information in Messages
- Added WSSSH_VERSION define to websocket.h
- Updated registration messages to include version field
- Updated tunnel_request messages to include version field
- Resolved function naming conflicts between wssshc and wsssht

## Build System and Code Organization
- Fixed compilation errors and improved code structure
- Enhanced error handling and memory management
- Improved cross-platform compatibility
- Added proper cleanup for all allocated resources

## Files Modified
- wsssd/__init__.py, config.py, server.py - Server-side improvements
- wssshd.py - Main daemon enhancements
- wssshtools/ - Complete C implementation updates
- Multiple library files for better modularity

All changes maintain backward compatibility while adding new functionality for better service management and configuration handling.
parent e4bfac6f
""" """
WebSocket SSH Daemon (wssshd) - Modular implementation WSSSH Daemon (wssshd) - Modular implementation
""" """
from .server import main from .server import main
......
...@@ -12,7 +12,7 @@ def load_config(args_config=None): ...@@ -12,7 +12,7 @@ def load_config(args_config=None):
Load configuration from file and command line arguments Load configuration from file and command line arguments
Returns parsed arguments Returns parsed arguments
""" """
parser = argparse.ArgumentParser(description='WebSocket SSH Daemon (wssshd)') parser = argparse.ArgumentParser(description='WSSSH Daemon (wssshd)')
parser.add_argument('--config', help='Configuration file path (default: /etc/wssshd.conf)') parser.add_argument('--config', help='Configuration file path (default: /etc/wssshd.conf)')
parser.add_argument('--host', help='WebSocket server host') parser.add_argument('--host', help='WebSocket server host')
parser.add_argument('--port', type=int, default=9898, help='WebSocket server port (default: 9898)') parser.add_argument('--port', type=int, default=9898, help='WebSocket server port (default: 9898)')
......
...@@ -35,7 +35,7 @@ def setup_ssl_context(): ...@@ -35,7 +35,7 @@ def setup_ssl_context():
async def shutdown_server(ws_server, cleanup_coro, flask_thread): async def shutdown_server(ws_server, cleanup_coro, flask_thread):
"""Handle graceful server shutdown""" """Handle graceful server shutdown"""
print("\nShutting down WebSocket SSH Daemon...") print("\nShutting down WSSSH Daemon...")
# Notify all connected clients about shutdown (optimized) # Notify all connected clients about shutdown (optimized)
active_clients = [(cid, info) for cid, info in clients.items() if info['status'] == 'active'] active_clients = [(cid, info) for cid, info in clients.items() if info['status'] == 'active']
...@@ -179,7 +179,7 @@ async def shutdown_server(ws_server, cleanup_coro, flask_thread): ...@@ -179,7 +179,7 @@ async def shutdown_server(ws_server, cleanup_coro, flask_thread):
if flask_thread and flask_thread.is_alive(): if flask_thread and flask_thread.is_alive():
flask_thread.join(timeout=1.0) flask_thread.join(timeout=1.0)
print("WebSocket SSH Daemon stopped cleanly") print("WSSSH Daemon stopped cleanly")
async def run_server(): async def run_server():
...@@ -208,7 +208,7 @@ async def run_server(): ...@@ -208,7 +208,7 @@ async def run_server():
# Start WebSocket server # Start WebSocket server
ws_server = await websockets.serve(partial(handle_websocket, server_password=server_password, debug_flag=debug), args.host, args.port, ssl=ssl_context) ws_server = await websockets.serve(partial(handle_websocket, server_password=server_password, debug_flag=debug), args.host, args.port, ssl=ssl_context)
print(f"WebSocket SSH Daemon running on {args.host}:{args.port}") print(f"WSSSH Daemon running on {args.host}:{args.port}")
print("Press Ctrl+C to stop the server") print("Press Ctrl+C to stop the server")
# Start cleanup task # Start cleanup task
......
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
WebSocket SSH Daemon (wssshd) WSSSH Daemon (wssshd)
Handles WebSocket connections from clients and wsssh/wsscp applications. Handles WebSocket connections from clients and wsssh/wsscp applications.
Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
......
...@@ -56,7 +56,7 @@ CFLAGS = -Wall -Wextra -O2 -D_GNU_SOURCE $(shell pkg-config --cflags openssl) ...@@ -56,7 +56,7 @@ CFLAGS = -Wall -Wextra -O2 -D_GNU_SOURCE $(shell pkg-config --cflags openssl)
LDFLAGS = $(shell pkg-config --libs openssl) LDFLAGS = $(shell pkg-config --libs openssl)
# Source files # Source files
LIB_SRCS = libwsssht/wssshlib.c libwsssht/websocket.c libwsssht/wssh_ssl.c libwsssht/tunnel.c libwsssht/utils.c libwsssht/modes.c libwsssht/threads.c LIB_SRCS = libwsssht/wssshlib.c libwsssht/websocket.c libwsssht/wssh_ssl.c libwsssht/tunnel.c libwsssht/utils.c libwsssht/modes.c libwsssht/threads.c libwsssht/control_messages.c libwsssht/data_messages.c
LIB_OBJS = $(LIB_SRCS:.c=.o) LIB_OBJS = $(LIB_SRCS:.c=.o)
SRCS = wssshc.c wsssht.c wsssh.c wsscp.c SRCS = wssshc.c wsssht.c wsssh.c wsscp.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
...@@ -87,7 +87,7 @@ wsscp: wsscp.o ...@@ -87,7 +87,7 @@ wsscp: wsscp.o
# Clean # Clean
clean: clean:
rm -f $(OBJS) $(LIB_OBJS) $(TARGETS) wsscp.o rm -f $(OBJS) $(LIB_OBJS) $(TARGETS) wsscp.o libwsssht/control_messages.o libwsssht/data_messages.o
# Install (optional) # Install (optional)
install: all install: all
......
/* /*
* WebSocket SSH Tunnel (wsssht) - Mode Functions * WSSSH Tunnel (wsssht) - Mode Functions
* Mode-specific functions for wsssht * Mode-specific functions for wsssht
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
......
/* /*
* WebSocket SSH Tunnel (wsssht) - Thread Functions Implementation * WSSSH Tunnel (wsssht) - Thread Functions Implementation
* Thread-related functions for wsssht * Thread-related functions for wsssht
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "tunnel.h" #include "tunnel.h"
#include "wsssht.h" #include "wsssht.h"
#include "threads.h" #include "threads.h"
#include "control_messages.h"
void *run_tunnel_thread(void *arg) { void *run_tunnel_thread(void *arg) {
tunnel_thread_args_t *args = (tunnel_thread_args_t *)arg; tunnel_thread_args_t *args = (tunnel_thread_args_t *)arg;
......
/* /*
* WebSocket SSH Tunnel (wsssht) - Thread Functions * WSSSH Tunnel (wsssht) - Thread Functions
* Thread-related functions for wsssht * Thread-related functions for wsssht
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
......
/* /*
* WebSocket SSH Tunnel (wsssht) - Utility Functions * WSSSH Tunnel (wsssht) - Utility Functions
* Utility functions for wsssht * Utility functions for wsssht
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
...@@ -24,8 +24,5 @@ ...@@ -24,8 +24,5 @@
#include "wssshlib.h" #include "wssshlib.h"
// Function declarations for utility functions // Function declarations for utility functions
void print_usage(const char *program_name);
int parse_connection_string(const char *conn_str, char **service, char **client_id, char **wssshd_host, int *wssshd_port);
int parse_args(int argc, char *argv[], wsssh_config_t *config, int *remaining_argc, char ***remaining_argv);
#endif // UTILS_H #endif // UTILS_H
\ No newline at end of file
/* /*
* WebSocket SSH Library - SSL functions implementation * WSSSH Library - SSL functions implementation
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
* *
......
/* /*
* WebSocket SSH Library - SSL functions * WSSSH Library - SSL functions
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
* *
......
/* /*
* WebSocket SSH Library - Shared utilities * WSSSH Library - Shared utilities
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
* *
......
/* /*
* WebSocket SSH (wsssh) - SSH Wrapper with WebSocket ProxyCommand * WSSSH (wsssh) - SSH Wrapper with WebSocket ProxyCommand
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
* *
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
void print_wsssh_usage(const char *program_name) { void print_wsssh_usage(const char *program_name) {
fprintf(stderr, "Usage: %s [options] <user>[@clientid[.wssshd-host[:sshstring]]] [ssh_options...]\n", program_name); fprintf(stderr, "Usage: %s [options] <user>[@clientid[.wssshd-host[:sshstring]]] [ssh_options...]\n", program_name);
fprintf(stderr, "WebSocket SSH Wrapper - SSH through WebSocket tunnels\n\n"); fprintf(stderr, "WSSSH Wrapper - SSH through WebSocket tunnels\n\n");
fprintf(stderr, "Protect the dolls!\n\n"); fprintf(stderr, "Protect the dolls!\n\n");
fprintf(stderr, "Options:\n"); fprintf(stderr, "Options:\n");
fprintf(stderr, " --help Show this help\n"); fprintf(stderr, " --help Show this help\n");
......
/* /*
* WebSocket SSH (wsssh) - SSH Wrapper with WebSocket ProxyCommand * WSSSH (wsssh) - SSH Wrapper with WebSocket ProxyCommand
* *
* Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me * Copyright (C) 2024 Stefy Lanza <stefy@nexlab.net> and SexHack.me
* *
......
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