Initialisation depot
This commit is contained in:
84
RdpBroker/src/main.c
Normal file
84
RdpBroker/src/main.c
Normal file
@@ -0,0 +1,84 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include "rdp_broker.h"
|
||||
|
||||
int global_log_level = LOG_INFO;
|
||||
volatile bool running = true; /* Global running flag */
|
||||
|
||||
void signal_handler(int signum) {
|
||||
if (signum == SIGINT || signum == SIGTERM) {
|
||||
LOG(LOG_INFO, "Received signal %d, shutting down...", signum);
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void print_banner(void) {
|
||||
printf("\n");
|
||||
printf("╔═══════════════════════════════════════════════════════╗\n");
|
||||
printf("║ RDP Broker v1.0.0 ║\n");
|
||||
printf("║ RDP Connection Broker with Samba AD Auth ║\n");
|
||||
printf("╚═══════════════════════════════════════════════════════╝\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
broker_config_t config;
|
||||
session_manager_t session_manager;
|
||||
int ret;
|
||||
|
||||
print_banner();
|
||||
|
||||
/* Install signal handlers */
|
||||
signal(SIGINT, signal_handler);
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGPIPE, SIG_IGN); /* Ignore broken pipe signals */
|
||||
|
||||
/* Load configuration */
|
||||
LOG(LOG_INFO, "Loading configuration...");
|
||||
ret = load_config(&config);
|
||||
if (ret != 0) {
|
||||
LOG(LOG_ERROR, "Failed to load configuration");
|
||||
return 1;
|
||||
}
|
||||
|
||||
LOG(LOG_INFO, "Configuration loaded successfully");
|
||||
LOG(LOG_INFO, "Samba AD Server: %s:%d", config.samba_server, config.samba_port);
|
||||
LOG(LOG_INFO, "RDP Listen Port: %d", config.rdp_listen_port);
|
||||
LOG(LOG_INFO, "Loaded %d target(s)", config.target_count);
|
||||
|
||||
/* Initialize session manager */
|
||||
LOG(LOG_INFO, "Initializing session manager...");
|
||||
ret = init_session_manager(&session_manager);
|
||||
if (ret != 0) {
|
||||
LOG(LOG_ERROR, "Failed to initialize session manager");
|
||||
free_config(&config);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Start RDP server */
|
||||
LOG(LOG_INFO, "Starting RDP server on port %d...", config.rdp_listen_port);
|
||||
ret = start_rdp_server(&config, &session_manager);
|
||||
if (ret != 0) {
|
||||
LOG(LOG_ERROR, "Failed to start RDP server");
|
||||
free_config(&config);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Main loop - monitor sessions */
|
||||
LOG(LOG_INFO, "RDP Broker is running. Press Ctrl+C to stop.");
|
||||
while (running) {
|
||||
sleep(30); /* Log every 30 seconds */
|
||||
log_active_sessions(&session_manager);
|
||||
cleanup_inactive_sessions(&session_manager, 3600); /* 1 hour timeout */
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
LOG(LOG_INFO, "Cleaning up...");
|
||||
free_config(&config);
|
||||
|
||||
LOG(LOG_INFO, "RDP Broker stopped");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user