Add status logging every 15 seconds for wssshd2 and wssshc

- Modified wssshc.c to print status every 15 seconds instead of 60
- Added status printing thread to wssshd2 that prints uptime and active tunnels every 15 seconds when not in debug mode
parent 5d7661dd
......@@ -1465,6 +1465,27 @@ static void *client_handler_thread(void *arg) {
return NULL;
}
// Status printing thread
void *status_thread(void *arg) {
wssshd_state_t *state = (wssshd_state_t *)arg;
while (server_running) {
sleep(15);
if (!state->debug) {
time_t current_time = time(NULL);
time_t uptime = current_time - state->start_time;
int hours = uptime / 3600;
int minutes = (uptime % 3600) / 60;
int seconds = uptime % 60;
pthread_mutex_lock(&state->tunnel_mutex);
int tunnel_count = state->tunnels_count;
pthread_mutex_unlock(&state->tunnel_mutex);
printf("[STATUS] Uptime: %02d:%02d:%02d | Active tunnels: %d\n",
hours, minutes, seconds, tunnel_count);
}
}
return NULL;
}
// WebSocket server functions
int websocket_start_server(const wssshd_config_t *config, wssshd_state_t *state) {
printf("Starting WebSocket server on %s:%d\n", config->host, config->port);
......@@ -1554,6 +1575,11 @@ int websocket_start_server(const wssshd_config_t *config, wssshd_state_t *state)
printf("WebSocket server listening on %s:%d\n", config->host, config->port);
server_running = 1;
// Start status printing thread
pthread_t status_tid;
pthread_create(&status_tid, NULL, status_thread, state);
pthread_detach(status_tid);
printf("Entering accept loop...\n");
// Accept connections in a loop
......
......@@ -1131,10 +1131,6 @@ int connect_to_server(const wssshc_config_t *config, service_config_t ***service
// Don't clean up all tunnels on select failure - this is not a fatal error
break;
} else if (select_result == 0) {
if (config->debug) {
printf("[DEBUG - WebSockets] SSL read timeout\n");
fflush(stdout);
}
continue; // Timeout, try again
}
......@@ -1292,6 +1288,43 @@ int connect_to_server(const wssshc_config_t *config, service_config_t ***service
}
}
printf("[DEBUG - WebSockets] Received message: {\"type\":\"tunnel_data\", \"request_id\":\"%s\", \"data\":\"<size: %zu bytes>\"}\n", request_id, data_size);
} else if (strstr(buffer, "\"type\":\"tunnel_response\"") || strstr(buffer, "\"type\": \"tunnel_response\"")) {
// Extract request_id and data size for tunnel_response messages
char *request_id_start = strstr(buffer, "\"request_id\"");
char request_id[256] = "...";
if (request_id_start) {
char *colon = strchr(request_id_start, ':');
if (colon) {
char *quote = strchr(colon, '"');
if (quote) {
request_id_start = quote + 1;
char *end_quote = strchr(request_id_start, '"');
if (end_quote) {
size_t len = end_quote - request_id_start;
if (len < sizeof(request_id) - 1) {
memcpy(request_id, request_id_start, len);
request_id[len] = '\0';
}
}
}
}
}
char *data_start = strstr(buffer, "\"data\"");
size_t data_size = 0;
if (data_start) {
char *data_colon = strchr(data_start, ':');
if (data_colon) {
char *data_quote = strchr(data_colon, '"');
if (data_quote) {
data_start = data_quote + 1;
char *data_end = strchr(data_start, '"');
if (data_end) {
data_size = data_end - data_start;
}
}
}
}
printf("[DEBUG - WebSockets] Received message: {\"type\":\"tunnel_response\", \"request_id\":\"%s\", \"data\":\"<size: %zu bytes>\"}\n", request_id, data_size);
} else {
printf("[DEBUG - WebSockets] Received message: %.*s\n", payload_len, payload);
}
......@@ -1755,9 +1788,9 @@ int main(int argc, char *argv[]) {
reload_configuration(&config, &services, &num_services);
}
// Print status every 60 seconds
// Print status every 15 seconds
time_t current_time = time(NULL);
if (current_time - last_status_time >= 60) {
if (current_time - last_status_time >= 15) {
print_status();
last_status_time = current_time;
}
......
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