|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|