|
|
|
@ -23,7 +23,8 @@
|
|
|
|
|
|
|
|
|
|
#include "libraptorsmiface.h"
|
|
|
|
|
|
|
|
|
|
char *server = "localhost";
|
|
|
|
|
//char *server = "localhost";
|
|
|
|
|
char *server = "freyja.starlink.edu";
|
|
|
|
|
char *user = "remotelab";
|
|
|
|
|
char *password = "rlpass123"; /* set me first */
|
|
|
|
|
char *database = "remotelab_sm";
|
|
|
|
@ -349,6 +350,39 @@ char* raptor_sm_get_hostname_for_username(char* username, bool create) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* raptor_sm_get_hostname_for_display(int display) {
|
|
|
|
|
MYSQL_RES *res;
|
|
|
|
|
MYSQL_ROW row;
|
|
|
|
|
char* query;
|
|
|
|
|
|
|
|
|
|
MYSQL *conn = connect_if_needed();
|
|
|
|
|
if (!conn) {
|
|
|
|
|
return strdup("SQLERR100");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
asprintf(&query, "SELECT servername FROM sessions WHERE display='%d'", display);
|
|
|
|
|
if (mysql_query_internal(conn, query)) {
|
|
|
|
|
// Server error
|
|
|
|
|
free(query);
|
|
|
|
|
mysql_close(conn);
|
|
|
|
|
return strdup("SQLERR101");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
free(query);
|
|
|
|
|
res = mysql_store_result(conn);
|
|
|
|
|
while ((row = mysql_fetch_row(res)) != NULL) {
|
|
|
|
|
char* ret = strdup(row[0]);
|
|
|
|
|
mysql_free_result(res);
|
|
|
|
|
mysql_close(conn);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
// Nothing in the DB
|
|
|
|
|
mysql_free_result(res);
|
|
|
|
|
mysql_close(conn);
|
|
|
|
|
return strdup("");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char* raptor_sm_get_ip_for_username(char* username, bool create) {
|
|
|
|
|
char* hostname = raptor_sm_get_hostname_for_username(username, create);
|
|
|
|
|
char err;
|
|
|
|
@ -523,13 +557,25 @@ pid_t raptor_sm_run_remote_server(char* username, char *const argv[], char* dbfi
|
|
|
|
|
}
|
|
|
|
|
char* origstr = command_string;
|
|
|
|
|
|
|
|
|
|
#ifndef RAPTOR_SM_DISABLE_PULSEAUDIO
|
|
|
|
|
if (display >= 0) {
|
|
|
|
|
asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && pulseaudio -D --load=\\\"module-native-protocol-tcp listen=0.0.0.0 auth-ip-acl=%s port=%d\\\"\' &> /dev/null\" &", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), RAPTOR_SM_MANAGEMENT_SERVER_IP_NETRANGE, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display));
|
|
|
|
|
dprint("Running command %s...\n\r", command_string);
|
|
|
|
|
system(command_string);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (strcmp(dbfield, RAPTOR_SM_SERVER_PID_FIELD) == 0) {
|
|
|
|
|
asprintf(&command_string, "ssh root@%s \'%s & echo $! &\'", ipaddr, origstr);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
#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);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
dprint("Running command %s...\n\r", command_string);
|
|
|
|
|
dprint("Running command %s...\n\r", command_string);
|
|
|
|
|
free(origstr);
|
|
|
|
|
|
|
|
|
|
FILE *fp;
|
|
|
|
@ -807,7 +853,11 @@ char raptor_sm_set_session_state(int display, int state) {
|
|
|
|
|
void raptor_sm_run_remote_desktop(char* username, int display, char* executable) {
|
|
|
|
|
char* ipaddr = raptor_sm_get_ip_for_username(username, true);
|
|
|
|
|
char* command_string;
|
|
|
|
|
#if RAPTOR_SM_DISABLE_PULSEAUDIO
|
|
|
|
|
asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && %s && exit\' &> /dev/null\"", ipaddr, username, display, executable);
|
|
|
|
|
#else
|
|
|
|
|
asprintf(&command_string, "ssh root@%s \"su %s -c \'export DISPLAY=:%d && export PULSE_SERVER=tcp:%s:%d && %s && exit\' &> /dev/null\"", ipaddr, username, display, ipaddr, (RAPTOR_SM_BASE_PULSEAUDIO_PORT+display), executable);
|
|
|
|
|
#endif
|
|
|
|
|
system(command_string);
|
|
|
|
|
free(command_string);
|
|
|
|
|
}
|
|
|
|
|