Here are the patches for implementing a secure shared database - John
--- x2gocreatebase.sh	2009-01-30 02:45:34.000000000 -0500
+++ x2gocreatebase.sh.new	2009-03-25 14:23:41.000000000 -0400
@@ -1,8 +1,117 @@
 #!/bin/bash
 
-su postgres -c "dropdb x2go_sessions"
-su postgres -c "createdb x2go_sessions"
-su postgres -c "echo \"create table sessions(
+if [ $(id -u) -ne 0 ];then
+	echo "$(basename $0) must be run with root privileges."
+	exit 1
+fi
+
+REMOTE=0
+SAVEPASS=0
+ERR=0
+PGPW=
+PGHOME=/var/lib/pgsql/
+
+# Find the database details
+. /etc/x2go/x2godb.conf
+DBNAME=${DBNAME:-x2go_sessions}
+DBUSER=${DBUSER:-postgres}
+SSHPORT=${SSHPORT:-22}
+SCRIPT="/usr/lib/x2go/script/x2gocreatebase.sh"
+
+# If we were not called remotely, we need to obtain the postgres password if necessary
+if [ -z "${1}" ];then 
+	echo
+	echo "If the database administrator requires a password, please enter it."
+	echo "Otherwise, simply press enter."
+	read -s -p "(will not display): " PGPW
+	echo
+fi
+
+# Is this a local or remote database server?
+DBSERVER="$(cat /etc/x2go/sql)"
+if [ "${DBSERVER}" != "local" ]; then
+	echo
+	read -s -p "What is database password for the user, ${DBUSER}? (will not display) " DBPW
+	echo
+	ssh -p ${SSHPORT} ${DBSERVER} "${SCRIPT} ${DBNAME} ${SCHEMA} ${DBUSER} ${DBPW} ${PGPW}"
+	if [ $? -ne 0 ]; then
+		echo "I was not able to create the database on the remote server."
+		exit 2
+	fi
+	TESTS="${DBSERVER}\:\*\:${DBNAME}\:${DBUSER}\:"
+	if [ ! -f /root/.pgpass -o -z "$(grep ${TESTS} /root/.pgpass 2>/dev/null)" ];then
+		# if .pgpass does not exist or it does not already have an entry for this user, add the entry
+		# We must not change an existing password as this routine will not change passwords for 
+		# existing users; it simply the user creation step if the user exists
+		echo "${DBSERVER}:*:${DBNAME}:${DBUSER}:${DBPW}" >> /root/.pgpass
+		chmod 600 /root/.pgpass
+	fi
+	exit 0
+fi
+
+# If we were called remotely, we must use the passed parameters and not the local ones
+if [ -n "${1}" ]; then
+	REMOTE=1
+	DBNAME="${1}"
+	SCHEMA="${2}"
+	DBUSER="${3}"
+	DBPW="${4}"
+	PGPW="${5}"
+	REMOTE=1
+fi
+
+if [ -n "${PGPW}" ];then #postgres uses a password
+	if [ -f ${PGHOME}.pgpass ]; then
+	        su - postgres -c "mv ~/.pgpass ~/.pgpass.x2go"
+                if [ $? != "0" ]; then
+                	echo "Failed to save existing database password file" >&2
+                	exit 1
+                fi
+                SAVEPASS=1
+	fi
+	su - postgres -c "echo -e \"localhost:*:${DBNAME}:postgres:${5}\\\nlocalhost:*:postgres:postgres:${5}\" > ~/.pgpass"
+	if [ ! -f ${PGHOME}.pgpass ]; then
+       		echo "Failed to create database password file" >&2
+	       	ERR=1
+	fi
+	su - postgres -c "chmod 600 ~/.pgpass"
+fi
+
+if [ ${ERR} -eq 0 ];then
+	echo "Creating database in case it does not exist."
+	su - postgres -c "psql -c \"create database \\\"${DBNAME}\\\";\" postgres"
+	ret=$?
+	if [ ${ret} -eq 2 ];then
+		echo "The postres user could not access the database."
+		ERR=2
+	fi
+	if [ ${ret} -eq 1 ];then
+		echo "An error while creating an already extant database is not a problem."
+		echo
+	fi
+fi
+
+if [ ${ERR} -eq 0 ];then
+	echo "Dropping schema in case it already exists."
+	su - postgres -c "psql -c \"drop schema \\\"${SCHEMA}\\\" cascade;\" ${DBNAME}"
+	if [ $? -ne 0 ];then
+		echo "An error while dropping an non-existant schema is not a problem."
+		echo
+	fi
+fi
+
+if [ ${ERR} -eq 0 ];then
+	su - postgres -c "psql -c \"create role \\\"${DBUSER}\\\" with nocreatedb nocreaterole login encrypted password '${DBPW}';\" ${DBNAME}"
+	# We execute the drop schema and create role commands separately because it is acceptable for them to fail
+	# but failing would prevent execution of the other commands if they were all one command
+	if [ $? -ne 0 ];then
+		echo "An error while creating an already existant user is not a problem."
+		echo
+	fi
+	
+	DBCMD="create schema \\\"${SCHEMA}\\\" authorization \\\"${DBUSER}\\\";set search_path to \\\"${SCHEMA}\\\";set role \\\"${DBUSER}\\\";"
+
+	DBCMD="${DBCMD}create table sessions(
 		session_id varchar(500) primary key, 
                 display integer not null, 
 		uname varchar(100) not null, 
@@ -17,26 +126,48 @@
 		sound_port int,
 		fs_port int,
 		unique(display)
-		)\" | psql x2go_sessions"
+		);"
 
-su postgres -c "echo \"create table messages(mess_id varchar(20) primary key, message text)\" | psql x2go_sessions"
+	DBCMD="${DBCMD}create table messages(mess_id varchar(20) primary key, message text);"
 
-su postgres -c "echo \"create table user_messages(
+	DBCMD="${DBCMD}create table user_messages(
                 mess_id varchar(20) not null, 
 		uname varchar(100) not null
-		)\" | psql x2go_sessions"
+		);"
 
-su postgres -c "echo \"create table used_ports(
+	DBCMD="${DBCMD}create table used_ports(
                 server varchar(100) not null,
 		session_id varchar(500) references sessions on delete cascade, 
 		port integer primary key
-		)\" | psql x2go_sessions"
+		);"
 
-su postgres -c "echo \"create table mounts(
+	DBCMD="${DBCMD}create table mounts(
                 session_id varchar(500) references sessions on delete restrict,
 		path varchar(512) not null, 
 		client inet not null, 
 		primary key(path,client)
-		)\" | psql x2go_sessions"
+		);"
+
+	su - postgres -c "psql -c \"${DBCMD}\" ${DBNAME}"
+	if [ $? -ne 0 ];then
+		ERR=3
+	fi
+fi
+
+rm -f ${PGHOME}.pgpass
+if [ $SAVEPASS -eq 1 ]
+# We use SAVEPASS rather than checking for .pgpass.x2go just in case
+# there was not an existing .pgpass but there was an old .pgpass.spm
+then
+        su - postgres -c "mv ~/.pgpass.x2go ~/.pgpass"
+fi
+
+if [ ${ERR} != 0 -a ${REMOTE} == 0 ];then
+	echo "I was not able to create the database."
+fi
 
+# The history file contains user passwords so we delete it
+rm -f ${PGHOME}psql_history
 
+exit ${ERR}
+        

# x2godb.conf
# Copyright 2009-2010 John A. Sullivan III - Pacifera, LP
# Version 0: March 24, 2009 - John Sullivan
# Version 1: March 6, 2010 - John Sullivan: replace "." with "___"
# This file is used to set the X2Go database parameters.

# DBNAME defaults to x2go_sessions (optional)
DBNAME=
# SCHEMA defaults to "" (required if using a shared database)
#SCHEMA="$(hostname) | sed 's/\./___/g'" # "." is the PostgreSQL schema 
delimiter
SCHEMA=

# DBUSER defaults to postgres (optional)
#DBUSER="$(hostname) | sed 's/\./___/g'"
DBUSER=

# If the database server is remote and uses a non-standard SSH port,
# set the port number here
SSHPORT=22
--- x2gopgwrapper_local	2009-03-25 02:28:00.000000000 -0400
+++ x2gopgwrapper_local.new	2009-03-25 13:51:46.000000000 -0400
@@ -2,36 +2,41 @@
 cd ~
 #use only with sudo !!
 
+. /etc/x2go/x2godb.conf
 UNAME=$SUDO_USER
+DBNAME=${DBNAME:-x2go_sessions}
+if [ -n "${SCHEMA}" ];then # SCHEMA is being used
+        SCHEMA="${SCHEMA}."
+fi
 
 case "$1" in
 
 getdisplays)
-  echo "select '|'||display||'|' from sessions;"|psql -t x2go_sessions
+  echo "select '|'||display||'|' from \"${SCHEMA}\"sessions;"|psql -t ${DBNAME}
   ;;
 
 getports)
-  echo "select '|'||port||'|' from used_ports;"|psql -t x2go_sessions
+  echo "select '|'||port||'|' from \"${SCHEMA}\"used_ports;"|psql -t ${DBNAME}
   ;;
 
 getservers)
-  echo "select server,count(*) from sessions where status != 'F' group by server;"|psql -t x2go_sessions
+  echo "select server,count(*) from \"${SCHEMA}\"sessions where status != 'F' group by server;"|psql -t ${DBNAME}
   ;;
 
 listsessions)
   echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
-   to_char(now()-init_time,'SSSS'),fs_port from  sessions  \
-   where status !='F' and server='$2' and uname='$UNAME' order by status desc;"|psql -t x2go_sessions
+   to_char(now()-init_time,'SSSS'),fs_port from  \"${SCHEMA}\"sessions  \
+   where status !='F' and server='$2' and uname='$UNAME' order by status desc;"|psql -t ${DBNAME}
   ;;
 
 listsessions_all)
   echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
-   to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   where status !='F' and uname='$UNAME' order by status desc;"|psql -t x2go_sessions
+   to_char(now()-init_time,'SSSS'),fs_port  from  \"${SCHEMA}\"sessions  \
+   where status !='F' and uname='$UNAME' order by status desc;"|psql -t ${DBNAME}
   ;;
 
 listsessionsroot)
@@ -43,8 +48,8 @@
   echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
-   to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   where server='$2'  order by status desc;"|psql -t x2go_sessions
+   to_char(now()-init_time,'SSSS'),fs_port  from  \"${SCHEMA}\"sessions  \
+   where server='$2'  order by status desc;"|psql -t ${DBNAME}
   ;;
 
 listsessionsroot_all)
@@ -56,8 +61,8 @@
   echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
-   to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   order by status desc;"|psql -t x2go_sessions
+   to_char(now()-init_time,'SSSS'),fs_port  from  \"${SCHEMA}\"sessions  \
+   order by status desc;"|psql -t ${DBNAME}
   ;;
 
 listsusp)
@@ -67,7 +72,7 @@
     exit  
   fi
   echo "select session_id, display, uname, server,extract( day from now()-last_time)*24*60+extract(hour from now()-last_time)*60+extract(minute from now()-last_time)\
-   from sessions where server='$2' and status='S';"|psql -t x2go_sessions
+   from \"${SCHEMA}\"sessions where server='$2' and status='S';"|psql -t ${DBNAME}
   ;;
 
 listallrunning)
@@ -79,8 +84,8 @@
   echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
-   to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   where status='R';"|psql -t x2go_sessions
+   to_char(now()-init_time,'SSSS'),fs_port  from  \"${SCHEMA}\"sessions  \
+   where status='R';"|psql -t ${DBNAME}
   ;;
 
 listmails)
@@ -90,9 +95,9 @@
     exit  
   fi
   echo "select user_messages.mess_id,sessions.session_id,\
-      sessions.uname,sessions.display from sessions,user_messages,\
-      messages where sessions.uname=user_messages.uname and sessions.status!='F'\
-      and messages.mess_id=user_messages.mess_id and sessions.server='$2';"|psql -t x2go_sessions
+      sessions.uname,sessions.display from \"${SCHEMA}\"sessions,\"${SCHEMA}\"user_messages,\
+      \"${SCHEMA}\"messages where sessions.uname=user_messages.uname and sessions.status!='F'\
+      and messages.mess_id=user_messages.mess_id and sessions.server='$2';"|psql -t ${DBNAME}
   ;;
 
 getmail)
@@ -101,7 +106,7 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  echo "select message from messages where mess_id='$2';"|psql -t x2go_sessions
+  echo "select message from \"${SCHEMA}\"messages where mess_id='$2';"|psql -t ${DBNAME}
   ;;
 
 rmmail)
@@ -110,7 +115,7 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  echo "delete from user_messages where mess_id='$2' and uname='$3';"|psql -t x2go_sessions
+  echo "delete from \"${SCHEMA}\"user_messages where mess_id='$2' and uname='$3';"|psql -t ${DBNAME}
   ;;
 
 rmsessionsroot)
@@ -119,52 +124,52 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  echo "delete from  sessions  \
-   where session_id='$2';"|psql -t x2go_sessions
+  echo "delete from  \"${SCHEMA}\"sessions  \
+   where session_id='$2';"|psql -t ${DBNAME}
   ;;
 
 getagent)
-  echo "select agent_pid from sessions  where session_id = '$2';"|psql -t x2go_sessions
+  echo "select agent_pid from \"${SCHEMA}\"sessions  where session_id = '$2';"|psql -t ${DBNAME}
   ;;
 
 getdisplay)
-  echo "select display from sessions  where session_id = '$2';"|psql -t x2go_sessions
+  echo "select display from \"${SCHEMA}\"sessions  where session_id = '$2';"|psql -t ${DBNAME}
   ;;
 
 changestatus)
-  echo "update sessions set last_time=now(),status='$2' where session_id = '$3' and uname='$UNAME';"|psql -t x2go_sessions
+  echo "update \"${SCHEMA}\"sessions set last_time=now(),status='$2' where session_id = '$3' and uname='$UNAME';"|psql -t ${DBNAME}
   ;;
 
 resume)
-  echo "update sessions set last_time=now(),status='R',client='$2' where session_id = '$3' and uname='$UNAME';"|psql -t x2go_sessions
+  echo "update \"${SCHEMA}\"sessions set last_time=now(),status='R',client='$2' where session_id = '$3' and uname='$UNAME';"|psql -t ${DBNAME}
   ;;
 
 insertsession)
-  echo "insert into sessions (display,server,uname,session_id) values \
-  ('$2','$3','$UNAME','$4');"|psql x2go_sessions
+  echo "insert into \"${SCHEMA}\"sessions (display,server,uname,session_id) values \
+  ('$2','$3','$UNAME','$4');"|psql ${DBNAME}
   ;;
 
 createsession)
-  echo "update sessions set status='R',last_time=now(),cookie='$2',agent_pid='$3',\
-   client='$4',gr_port='$5',sound_port='$6',fs_port='$7' where session_id='$8' and uname='$UNAME';"|psql x2go_sessions
+  echo "update \"${SCHEMA}\"sessions set status='R',last_time=now(),cookie='$2',agent_pid='$3',\
+   client='$4',gr_port='$5',sound_port='$6',fs_port='$7' where session_id='$8' and uname='$UNAME';"|psql ${DBNAME}
   ;;
 
 insertport)
-  echo "insert into used_ports (server,session_id,port) values \
-  ('$2','$3','$4');"|psql x2go_sessions
+  echo "insert into \"${SCHEMA}\"used_ports (server,session_id,port) values \
+  ('$2','$3','$4');"|psql ${DBNAME}
   ;;
 
 insertmount)
-  echo "insert into mounts (session_id,path,client) values \
-  ('$2','$3','$4');"|psql x2go_sessions
+  echo "insert into \"${SCHEMA}\"mounts (session_id,path,client) values \
+  ('$2','$3','$4');"|psql ${DBNAME}
   ;;
 
 deletemount)
-  echo "delete from mounts where session_id='$2' and path='$3';"|psql x2go_sessions
+  echo "delete from \"${SCHEMA}\"mounts where session_id='$2' and path='$3';"|psql ${DBNAME}
   ;;
 
 getmounts)
-  echo "select client,path from mounts where session_id = '$2';"|psql -t x2go_sessions
+  echo "select client,path from \"${SCHEMA}\"mounts where session_id = '$2';"|psql -t ${DBNAME}
   ;;
 
 *)
--- x2gopgwrapper_net	2010-02-20 22:23:47.542605382 -0500
+++ x2gopgwrapper_net.new	2010-02-20 23:04:07.076612162 -0500
@@ -3,37 +3,39 @@
 cd ~
 #use only with sudo !!
 
+. /etc/x2go/x2godb.conf
 SERVER=$1
 UNAME=$SUDO_USER
+DBNAME=${DBNAME:-x2go_sessions}
 
 case "$2" in
 
 getdisplays)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select '|'||display||'|' from sessions;\"|psql -t x2go_sessions"
+  echo "select '|'||display||'|' from sessions;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 getports)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select '|'||port||'|' from used_ports;\"|psql -t x2go_sessions"
+  echo "select '|'||port||'|' from used_ports;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 getservers)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select server,count(*) from sessions where status != 'F' group by server;\"|psql -t x2go_sessions"
+  echo "select server,count(*) from sessions where status != 'F' group by server;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 listsessions)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select agent_pid, session_id, display, server, status,\
+  echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
    to_char(now()-init_time,'SSSS'),fs_port from  sessions  \
-   where status !='F' and server='$3' and uname='$UNAME' order by status desc;\"|psql -t x2go_sessions"
+   where status !='F' and server='$3' and uname='$UNAME' order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 listsessions_all)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select agent_pid, session_id, display, server, status,\
+  echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
    to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   where status !='F' and uname='$UNAME' order by status desc;\"|psql -t x2go_sessions"
+   where status !='F' and uname='$UNAME' order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 listsessionsroot)
@@ -42,11 +44,11 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select agent_pid, session_id, display, server, status,\
+  echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
    to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   where server='$3'  order by status desc;\"|psql -t x2go_sessions"
+   where server='$3'  order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 listsessionsroot_all)
@@ -55,11 +57,11 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select agent_pid, session_id, display, server, status,\
+  echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
    to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   order by status desc;\"|psql -t x2go_sessions"
+   order by status desc;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 listsusp)
@@ -68,8 +70,8 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select session_id, display, uname, server,extract( day from now()-last_time)*24*60+extract(hour from now()-last_time)*60+extract(minute from now()-last_time)\
-  from sessions where server='$3' and status='S';\"|psql -t x2go_sessions"
+  echo "select session_id, display, uname, server,extract( day from now()-last_time)*24*60+extract(hour from now()-last_time)*60+extract(minute from now()-last_time)\
+  from sessions where server='$3' and status='S';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 
@@ -79,11 +81,11 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select agent_pid, session_id, display, server, status,\
+  echo "select agent_pid, session_id, display, server, status,\
    to_char(init_time,'DD.MM.YY*HH24:MI:SS'),cookie,client,gr_port,\
    sound_port,to_char(last_time,'DD.MM.YY*HH24:MI:SS'),uname,\
    to_char(now()-init_time,'SSSS'),fs_port  from  sessions  \
-   where status='R';\"|psql -t x2go_sessions"
+   where status='R';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 listmails)
@@ -92,10 +94,10 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select user_messages.mess_id,sessions.session_id,\
+  echo "select user_messages.mess_id,sessions.session_id,\
       sessions.uname,sessions.display from sessions,user_messages,\
       messages where sessions.uname=user_messages.uname and sessions.status!='F'\
-      and messages.mess_id=user_messages.mess_id and sessions.server='$3';\"|psql -t x2go_sessions"
+      and messages.mess_id=user_messages.mess_id and sessions.server='$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 getmail)
@@ -104,8 +106,8 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select message\
-      from messages where mess_id='$3';\"|psql -t x2go_sessions"
+  echo "select message\
+      from messages where mess_id='$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 
@@ -115,8 +117,8 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"delete from \
-  user_messages where mess_id='$3' and uname='$4';\"|psql -t x2go_sessions"
+  echo "delete from \
+  user_messages where mess_id='$3' and uname='$4';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 
@@ -126,53 +128,53 @@
     echo "$UNAME, You have not permission to do this job!"
     exit  
   fi
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"delete from  sessions  \
-   where session_id='$3' ;\"|psql -t x2go_sessions"
+  echo "delete from  sessions  \
+   where session_id='$3' ;"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 
 getagent)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select agent_pid from sessions  where session_id = '$3';\"|psql -t x2go_sessions"
+  echo "select agent_pid from sessions  where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 getdisplay)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select display from sessions  where session_id = '$3';\"|psql -t x2go_sessions"
+  echo "select display from sessions  where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 changestatus)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"update sessions set last_time=now(),status='$3' where session_id = '$4' and uname='$UNAME';\"|psql -t x2go_sessions"
+  echo "update sessions set last_time=now(),status='$3' where session_id = '$4' and uname='$UNAME';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 resume)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"update sessions set last_time=now(),status='R',client='$3' where session_id = '$4' and uname='$UNAME';\"|psql -t x2go_sessions"
+  echo "update sessions set last_time=now(),status='R',client='$3' where session_id = '$4' and uname='$UNAME';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 insertsession)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"insert into sessions (display,server,uname,session_id) values \
-  ('$3','$4','$UNAME','$5');\"|psql x2go_sessions"
+  echo "insert into sessions (display,server,uname,session_id) values \
+  ('$3','$4','$UNAME','$5');"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
   ;;
 
 createsession)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"update sessions set status='R',last_time=now(),cookie='$3',agent_pid='$4',\
-   client='$5',gr_port='$6',sound_port='$7',fs_port='$8' where session_id='$9' and uname='$UNAME';\"|psql x2go_sessions"
+  echo "update sessions set status='R',last_time=now(),cookie='$3',agent_pid='$4',\
+   client='$5',gr_port='$6',sound_port='$7',fs_port='$8' where session_id='$9' and uname='$UNAME';"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
   ;;
 
 insertport)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"insert into used_ports (server,session_id,port) values \
-  ('$3','$4','$5');\"|psql x2go_sessions"
+  echo "insert into used_ports (server,session_id,port) values \
+  ('$3','$4','$5');"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
   ;;
 
 insertmount)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"insert into mounts (session_id,path,client) values \
-  ('$3','$4','$5');\"|psql x2go_sessions"
+  echo "insert into mounts (session_id,path,client) values \
+  ('$3','$4','$5');"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
   ;;
 
 deletemount)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"delete from mounts where session_id='$3' and path='$4';\"|psql x2go_sessions"
+  echo "delete from mounts where session_id='$3' and path='$4';"|psql -U "${DBUSER}" -h ${SERVER} ${DBNAME}
   ;;
 
 getmounts)
-  ssh -i /root/.x2go/ssh/.pg/id_dsa postg...@$server "echo \"select client,path from mounts where session_id = '$3';\"|psql -t x2go_sessions"
+  echo "select client,path from mounts where session_id = '$3';"|psql -U "${DBUSER}" -h ${SERVER} -t ${DBNAME}
   ;;
 
 *)
_______________________________________________
X2go-dev mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/x2go-dev

Reply via email to