Download installation files from correct locations

Keep track of arbiter(s) in use per connection
ulab-original
Timothy Pearson 10 years ago
parent a23666fa3c
commit 2a5e4eb541

@ -41,23 +41,27 @@
#include "list.h"
#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
#define RAPTORSMIFACE_CFG_DATABASE "Database"
#define RAPTORSMIFACE_CFG_DATABASE_SERVER "Server"
#define RAPTORSMIFACE_CFG_DATABASE_NAME "Database"
#define RAPTORSMIFACE_CFG_DATABASE_USER "User"
#define RAPTORSMIFACE_CFG_DATABASE_PASSWORD "Password"
#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
#define RAPTORSMIFACE_CFG_DATABASE "Database"
#define RAPTORSMIFACE_CFG_DATABASE_SERVER "Server"
#define RAPTORSMIFACE_CFG_DATABASE_NAME "Database"
#define RAPTORSMIFACE_CFG_DATABASE_USER "User"
#define RAPTORSMIFACE_CFG_DATABASE_PASSWORD "Password"
#define RAPTORSMIFACE_CFG_DATABASE_SCHEMA_VERSION 1
char *server = NULL;
char *user = NULL;
char *password = NULL;
char *database = NULL;
char *local_machine_fqdn = NULL;
void dprint(const char *fmt, ...)
{
va_list argp;
@ -126,6 +130,10 @@ void read_ini_configuration() {
struct list* param_n;
struct list* param_v;
/* set global variables */
local_machine_fqdn = raptor_sm_get_local_machine_fqdn();
/* open configuration file */
char cfg_file[256];
g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
@ -160,6 +168,39 @@ MYSQL * connect_if_needed() {
dprint("[ERROR] MySQL connection FAILED [%s]\n\r", mysql_error(conn));
conn = 0;
}
else {
// Check schema version
char* query;
MYSQL_RES *res;
MYSQL_ROW row;
asprintf(&query, "SELECT value FROM dbschema WHERE skey='revision'");
if (mysql_query_internal(conn, query)) {
// Server error
free(query);
mysql_close(conn);
dprint("[ERROR] MySQL connection FAILED [%s]\n\r", mysql_error(conn));
conn = 0;
}
else {
free(query);
res = mysql_store_result(conn);
if ((row = mysql_fetch_row(res)) == NULL) {
dprint("[ERROR] Mandatory schema version key not found\n\r");
conn = 0;
}
else if (!row[0]) {
dprint("[ERROR] Mandatory schema version key not found\n\r");
conn = 0;
}
else {
int schema_version = atoi(row[0]);
if (schema_version != RAPTORSMIFACE_CFG_DATABASE_SCHEMA_VERSION) {
dprint("[ERROR] Schema version key mismatch (%d:%d)\n\r", schema_version, RAPTORSMIFACE_CFG_DATABASE_SCHEMA_VERSION);
conn = 0;
}
}
}
}
return conn;
}
@ -285,10 +326,12 @@ char raptor_sm_deallocate_session(char* username) {
// 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);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
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);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, arbiter, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_DISCONNECTION_EVENT, safe_local_machine_fqdn, safe_servername, display, -1, safe_username);
free(safe_servername);
free(safe_username);
free(safe_local_machine_fqdn);
free(hostname);
if (mysql_query_internal(conn, query)) {
// Server error
@ -409,7 +452,9 @@ char* raptor_sm_allocate_session(char* username) {
// Insert new information into the sessions database and set status to ALLOCATED
char* safe_servername = get_mysql_escaped_string(conn, bestserver);
char* safe_username = get_mysql_escaped_string(conn, username);
asprintf(&query, "INSERT INTO sessions (username, servername, state) VALUES ('%s', '%s', '%d')", safe_username, safe_servername, SM_STATUS_ALLOCATED);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
asprintf(&query, "INSERT INTO sessions (username, arbiter, servername, state) VALUES ('%s', '%s', '%s', '%d')", safe_username, safe_local_machine_fqdn, safe_servername, SM_STATUS_ALLOCATED);
free(safe_local_machine_fqdn);
free(safe_servername);
free(safe_username);
if (mysql_query_internal(conn, query)) {
@ -424,8 +469,10 @@ char* raptor_sm_allocate_session(char* username) {
// 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);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
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);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, arbiter, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_NEW_CONNECTION_EVENT, safe_local_machine_fqdn, safe_servername, -1, SM_STATUS_ALLOCATED, safe_username);
free(safe_local_machine_fqdn);
free(safe_servername);
free(safe_username);
if (mysql_query_internal(conn, query)) {
@ -455,6 +502,28 @@ char* raptor_sm_allocate_session(char* username) {
}
}
char* raptor_sm_get_local_machine_fqdn() {
struct addrinfo hints, *res;
int err;
char hostname[1024];
hostname[1023] = '\0';
gethostname(hostname, 1023);
memset(&hints, 0, sizeof hints);
hints.ai_socktype = SOCK_STREAM;
hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_CANONNAME;
if ((err = getaddrinfo(hostname, NULL, &hints, &res)) != 0) {
return strdup("");
}
char* ret = strdup(res->ai_canonname);
freeaddrinfo(res);
return ret;
}
char* raptor_sm_get_ip_for_hostname(char* hostname, char* error) {
struct addrinfo hints, *res;
struct in_addr addr;
@ -868,10 +937,12 @@ int raptor_sm_server_started(char* username, pid_t pid, int display, char* dbfie
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);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
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);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, arbiter, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_CONNECTION_STATUS_EVENT, safe_local_machine_fqdn, safe_servername, display, SM_STATUS_RUNNING, safe_username);
free(safe_servername);
free(safe_username);
free(safe_local_machine_fqdn);
free(current_server);
if (mysql_query_internal(conn, query)) {
// Server error
@ -1107,10 +1178,12 @@ char raptor_sm_set_session_state(int display, int state) {
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);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
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);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, arbiter, servername, display, typeid, username) VALUES ('%lld', '%d', '%s', '%s', '%d', '%d', '%s')", timestamp, STATISTICS_CONNECTION_STATUS_EVENT, safe_local_machine_fqdn, safe_servername, display, state, safe_username);
free(safe_servername);
free(safe_username);
free(safe_local_machine_fqdn);
free(hostname);
free(username);
if (mysql_query_internal(conn, query)) {
@ -1161,9 +1234,11 @@ int raptor_sm_stats_report_server_start(char* hostname) {
// Insert information into the statistics database
char* safe_servername = get_mysql_escaped_string(conn, hostname);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
long long timestamp = time(NULL);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_START_EVENT, safe_servername, -1, -1);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, arbiter, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_START_EVENT, safe_local_machine_fqdn, safe_servername, -1, -1);
free(safe_servername);
free(safe_local_machine_fqdn);
if (mysql_query_internal(conn, query)) {
// Server error
dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn));
@ -1186,9 +1261,11 @@ int raptor_sm_stats_report_server_stop(char* hostname) {
// Insert information into the statistics database
char* safe_servername = get_mysql_escaped_string(conn, hostname);
char* safe_local_machine_fqdn = get_mysql_escaped_string(conn, local_machine_fqdn);
long long timestamp = time(NULL);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_STOP_EVENT, safe_servername, -1, -1);
asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, arbiter, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_STOP_EVENT, safe_local_machine_fqdn, safe_servername, -1, -1);
free(safe_servername);
free(safe_local_machine_fqdn);
if (mysql_query_internal(conn, query)) {
// Server error
dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn));

@ -41,6 +41,8 @@ enum raptor_sm_status {
#define RAPTOR_SM_BASE_PULSEAUDIO_PORT 2000
#define RAPTOR_SM_MANAGEMENT_SERVER_IP_NETRANGE "10.0.0.0/8"
char* raptor_sm_get_local_machine_fqdn();
char* raptor_sm_get_ip_for_hostname(char* hostname, char* err);
char* raptor_sm_get_hostname_for_username(char* username, bool create);

@ -34,7 +34,27 @@ download_file()
cd downloads
echo "downloading file $file"
if [ "$file" = "pixman-0.15.20.tar.bz2" ]; then
wget -cq $download_url/$file
status=$?
cd ..
return $status
if [ "$file" = "libpthread-stubs-0.3.tar.bz2" ]; then
wget -cq http://xcb.freedesktop.org/dist/$file
status=$?
cd ..
return $status
elif [ "$file" = "libxcb-1.7.tar.bz2" ]; then
wget -cq http://xcb.freedesktop.org/dist/$file
status=$?
cd ..
return $status
elif [ "$file" = "xcb-proto-1.6.tar.bz2" ]; then
wget -cq http://xcb.freedesktop.org/dist/$file
status=$?
cd ..
return $status
elif [ "$file" = "pixman-0.15.20.tar.bz2" ]; then
wget -cq http://ftp.x.org/pub/individual/lib/$file
status=$?
cd ..
@ -266,7 +286,8 @@ make_it()
data_file=x11_file_list.txt
# this is the default download location for most modules
download_url=http://www.x.org/releases/X11R7.6/src/everything
# download_url=http://www.x.org/releases/X11R7.6/src/everything
download_url=http://server1.xrdp.org/xrdp/X11R7.6
num_modules=`cat $data_file | wc -l`
count=0

Loading…
Cancel
Save