--- 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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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 postgres@$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}
   ;;
 
 *)
