diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-19 23:39:40 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-19 23:39:40 -0500 |
commit | 880b8ccbe8a9f5bab3035de3c4697152ec539883 (patch) | |
tree | 2375bb2e9d60d0a1fb2b5257634b7a0565b7c0bf | |
parent | 434f65f228fb7dcc6a93471057b47a489ed4690c (diff) | |
download | xrdp-proprietary-880b8ccbe8a9f5bab3035de3c4697152ec539883.tar.gz xrdp-proprietary-880b8ccbe8a9f5bab3035de3c4697152ec539883.zip |
Add statistics reporting
-rw-r--r-- | raptorsmiface/libraptorsmiface.c | 116 | ||||
-rw-r--r-- | raptorsmiface/libraptorsmiface.h | 1 | ||||
-rw-r--r-- | xrdp/xrdp_types.h | 4 |
3 files changed, 119 insertions, 2 deletions
diff --git a/raptorsmiface/libraptorsmiface.c b/raptorsmiface/libraptorsmiface.c index bd751685..98bf2efa 100644 --- a/raptorsmiface/libraptorsmiface.c +++ b/raptorsmiface/libraptorsmiface.c @@ -23,6 +23,12 @@ #include "libraptorsmiface.h" +#define STATISTICS_SERVER_START_EVENT 0 +#define STATISTICS_SERVER_STOP_EVENT 1 +#define STATISTICS_NEW_CONNECTION_EVENT 2 +#define STATISTICS_CONNECTION_STATUS_EVENT 3 +#define STATISTICS_DISCONNECTION_EVENT 4 + //char *server = "localhost"; char *server = "freyja.starlink.edu"; char *user = "remotelab"; @@ -104,6 +110,7 @@ char raptor_sm_deallocate_session(char* username) { return 1; } + int display = raptor_sm_get_display_for_username(username); char* hostname = raptor_sm_get_hostname_for_username(username, false); pid_t serverpid = raptor_sm_get_pid_for_username(username, RAPTOR_SM_SERVER_PID_FIELD); if (serverpid >= 0) { @@ -138,12 +145,28 @@ char raptor_sm_deallocate_session(char* username) { free(safe_username); if (mysql_query_internal(conn, query)) { // Server error + free(hostname); free(query); mysql_close(conn); return 2; } else { free(query); + + // Insert connection information into the statistics database + char* safe_servername = get_mysql_escaped_string(conn, hostname); + char* safe_username = get_mysql_escaped_string(conn, username); + long long timestamp = time(NULL); + asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_DISCONNECTION_EVENT, safe_servername, display, -1, safe_username); + free(safe_servername); + free(safe_username); + free(hostname); + if (mysql_query_internal(conn, query)) { + // Server error + dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn)); + } + free(query); + mysql_close(conn); return 0; } @@ -265,6 +288,20 @@ char* raptor_sm_allocate_session(char* username) { } else { free(query); + + // Insert connection information into the statistics database + char* safe_servername = get_mysql_escaped_string(conn, bestserver); + char* safe_username = get_mysql_escaped_string(conn, username); + long long timestamp = time(NULL); + asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_NEW_CONNECTION_EVENT, safe_servername, -1, SM_STATUS_ALLOCATED, safe_username); + free(safe_servername); + free(safe_username); + if (mysql_query_internal(conn, query)) { + // Server error + dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn)); + } + free(query); + mysql_close(conn); return strdup(bestserver); } @@ -572,7 +609,8 @@ pid_t raptor_sm_run_remote_server(char* username, char *const argv[], char* dbfi #if RAPTOR_SM_DISABLE_PULSEAUDIO asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && %s\' &> /dev/null & echo \\$!\"", ipaddr, username, display, origstr); #else - asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && %s\' &> /dev/null & echo \\$!\"", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), origstr); + //asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && %s\' &> /dev/null & echo \\$!\"", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), origstr); + asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && %s\' &> /var/log/%s_wm_session.log & echo \\$!\"", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), origstr, username); #endif } dprint("Running command %s...\n\r", command_string); @@ -665,6 +703,22 @@ char* raptor_sm_server_started(char* username, pid_t pid, int display, char* dbf } else { free(query); + + // Insert connection information into the statistics database + char* current_server = raptor_sm_get_hostname_for_display(display); + char* safe_servername = get_mysql_escaped_string(conn, current_server); + char* safe_username = get_mysql_escaped_string(conn, username); + long long timestamp = time(NULL); + asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_CONNECTION_STATUS_EVENT, safe_servername, display, SM_STATUS_RUNNING, safe_username); + free(safe_servername); + free(safe_username); + free(current_server); + if (mysql_query_internal(conn, query)) { + // Server error + dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn)); + } + free(query); + mysql_close(conn); return 0; } @@ -739,6 +793,48 @@ int raptor_sm_get_display_for_username(char* username) { } } +char* raptor_sm_get_username_for_display_and_hostname(int display, char* hostname) { + MYSQL_RES *res; + MYSQL_ROW row; + char* query; + + MYSQL *conn = connect_if_needed(); + if (!conn) { + return -1; + } + + char* safe_hostname = get_mysql_escaped_string(conn, hostname); + asprintf(&query, "SELECT username FROM sessions WHERE display='%d' AND servername='%s'", display, safe_hostname); + free(safe_hostname); + if (mysql_query_internal(conn, query)) { + // Server error + free(query); + mysql_close(conn); + return strdup(""); + } + else { + free(query); + res = mysql_store_result(conn); + while ((row = mysql_fetch_row(res)) != NULL) { + if (row[0]) { + char* ret = strdup(row[0]); + mysql_free_result(res); + mysql_close(conn); + return ret; + } + else { + mysql_free_result(res); + mysql_close(conn); + return strdup(""); + } + } + // Nothing in the DB + mysql_free_result(res); + mysql_close(conn); + return strdup(""); + } +} + void raptor_sm_wait_for_pid_exit(char* username, pid_t pid) { char* ipaddr = raptor_sm_get_ip_for_username(username, false); @@ -845,6 +941,24 @@ char raptor_sm_set_session_state(int display, int state) { } else { free(query); + + // Insert connection information into the statistics database + char* hostname = raptor_sm_get_hostname_for_display(display); + char* username = raptor_sm_get_username_for_display_and_hostname(display, hostname); + char* safe_servername = get_mysql_escaped_string(conn, hostname); + char* safe_username = get_mysql_escaped_string(conn, username); + long long timestamp = time(NULL); + asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_CONNECTION_STATUS_EVENT, safe_servername, display, state, safe_username); + free(safe_servername); + free(safe_username); + free(hostname); + free(username); + if (mysql_query_internal(conn, query)) { + // Server error + dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn)); + } + free(query); + mysql_close(conn); return 0; } diff --git a/raptorsmiface/libraptorsmiface.h b/raptorsmiface/libraptorsmiface.h index d0a12a2c..b27110bc 100644 --- a/raptorsmiface/libraptorsmiface.h +++ b/raptorsmiface/libraptorsmiface.h @@ -36,6 +36,7 @@ char* raptor_sm_server_started(char* username, pid_t pid, int display, char* dbf char* raptor_sm_wm_started(char* username, pid_t pid, char* dbfield); int raptor_sm_get_display_for_username(char* username); void raptor_sm_wait_for_pid_exit(char* username, pid_t pid); +char* raptor_sm_get_username_for_display_and_hostname(int display, char* hostname); void raptor_sm_session_terminated(char* username); void raptor_sm_wm_terminated(char* username); int raptor_sm_get_new_unique_display(int mindisplay, int maxdisplay); diff --git a/xrdp/xrdp_types.h b/xrdp/xrdp_types.h index bf698dff..299d0fbf 100644 --- a/xrdp/xrdp_types.h +++ b/xrdp/xrdp_types.h @@ -433,7 +433,9 @@ struct xrdp_bitmap #define DEFAULT_EDIT_W 210 #define DEFAULT_EDIT_H 21 #define DEFAULT_WND_LOGIN_W 500 -#define DEFAULT_WND_LOGIN_H 250 +#define DEFAULT_WND_LOGIN_H 200 +//#define DEFAULT_WND_LOGIN_W 500 +//#define DEFAULT_WND_LOGIN_H 250 #define DEFAULT_WND_HELP_W 340 #define DEFAULT_WND_HELP_H 300 #define DEFAULT_WND_LOG_W 400 |