The branch, master has been updated via d845b630f85954350ff1ff3a767b384976b0a09b (commit) from d34d3656f53de76f961f5c85feb1882b98effab8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit d845b630f85954350ff1ff3a767b384976b0a09b Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Tue Sep 18 00:43:27 2012 +0200 Transform x2gosqlitewrapper.pl into small wrapper script and move the SQLite3 into Perl package X2Go::Server::DB::SQLite3. ----------------------------------------------------------------------- Summary of changes: .../Server/DB/SQLite3.pm | 219 ++++++---- debian/changelog | 2 + x2goserver/lib/x2gosqlitewrapper.pl | 467 ++------------------ 3 files changed, 170 insertions(+), 518 deletions(-) copy x2goserver/lib/x2gosqlitewrapper.pl => X2Go/Server/DB/SQLite3.pm (76%) The diff of changes is: diff --git a/x2goserver/lib/x2gosqlitewrapper.pl b/X2Go/Server/DB/SQLite3.pm similarity index 76% copy from x2goserver/lib/x2gosqlitewrapper.pl copy to X2Go/Server/DB/SQLite3.pm index 94d8f91..a1edb22 100755 --- a/x2goserver/lib/x2gosqlitewrapper.pl +++ b/X2Go/Server/DB/SQLite3.pm @@ -20,11 +20,15 @@ # Copyright (C) 2007-2012 Oleksandr Shneyder <oleksandr.shneyder@obviously-nice.de> # Copyright (C) 2007-2012 Heinz-Markus Graesing <heinz-m.graesing@obviously-nice.de> +package X2Go::Server::DB::SQLite3; + use strict; use DBI; use POSIX; -#### NOTE: this script is run setgid <group> and it cannot do system() calls. +#### NOTE: the default X2Go server setups runs the code in this package +#### via a setgid <group> wrapper (where <group> is group ,,x2gouser''). +#### It is intended that the code in this package cannot do system() calls. use Config::Simple; use Sys::Syslog qw( :standard :macros ); @@ -33,28 +37,31 @@ use X2Go::Log qw(loglevel); openlog($0,'cons,pid','user'); setlogmask( LOG_UPTO(loglevel()) ); -#### -#### end of duplicated syslogging code -#### - -# retrieve home dir of x2gouser -my $x2gouser='x2gouser'; -my ($uname, $pass, $uid, $pgid, $quota, $comment, $gcos, $homedir, $shell, $expire) = getpwnam($x2gouser); -my $dbfile="$homedir/x2go_sessions"; - -# retrieve account data of real user my ($uname, $pass, $uid, $pgid, $quota, $comment, $gcos, $homedir, $shell, $expire) = getpwuid($<); my $realuser=$uname; -my $dbh=DBI->connect("dbi:SQLite:dbname=$dbfile","","",{sqlite_use_immediate_transaction => 1, AutoCommit => 1, }) or die $_; -$dbh->sqlite_busy_timeout( 2000 ); +use base 'Exporter'; -my $cmd=shift or die "command not specified"; -my $rc=0; +our @EXPORT=('db_listsessions','db_listsessions_all', 'db_getservers', 'db_getagent', 'db_resume', 'db_changestatus', 'db_getstatus', + 'db_getdisplays', 'db_insertsession', 'db_getports', 'db_insertport', 'db_rmport', 'db_createsession', 'db_insertmount', + 'db_getmounts', 'db_deletemount', 'db_getdisplay', 'dbsys_getmounts', 'dbsys_listsessionsroot', + 'dbsys_listsessionsroot_all', 'dbsys_rmsessionsroot', 'dbsys_deletemounts'); -if($cmd eq "rmsessionsroot") +sub init_db { - checkroot(); + # retrieve home dir of x2gouser + my $x2gouser='x2gouser'; + my ($uname, $pass, $uid, $pgid, $quota, $comment, $gcos, $homedir, $shell, $expire) = getpwnam($x2gouser); + my $dbfile="$homedir/x2go_sessions"; + my $dbh=DBI->connect("dbi:SQLite:dbname=$dbfile","","",{sqlite_use_immediate_transaction => 1, AutoCommit => 1, }) or die $_; + $dbh->sqlite_busy_timeout( 2000 ); + return $dbh; +} + +sub dbsys_rmsessionsroot +{ + my $dbh = init_db(); + check_root(); my $sid=shift or die "argument \"session_id\" missed"; my $sth=$dbh->prepare("delete from sessions where session_id=?"); $sth->execute($sid); @@ -64,11 +71,13 @@ if($cmd eq "rmsessionsroot") die; } $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "listsessionsroot") +sub dbsys_listsessionsroot { - checkroot(); + my $dbh = init_db(); + check_root(); my $server=shift or die "argument \"server\" missed"; my @strings; my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, @@ -83,12 +92,16 @@ elsif($cmd eq "listsessionsroot") syslog('error', "listsessionsroot (SQLite3 session db backend) failed with exitcode: $sth->err()"); die(); } - fetchrow_printall_array($sth); + my @sessions = fetchrow_array_session_entries($sth); + $sth->finish(); + $dbh->disconnect(); + return @sessions; } -elsif($cmd eq "listsessionsroot_all") +sub listsessionsroot_all { - checkroot(); + my $dbh = init_db(); + check_root(); my @strings; my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, strftime('%Y-%m-%dT%H:%M:%S',init_time), @@ -103,11 +116,15 @@ elsif($cmd eq "listsessionsroot_all") syslog('error', "listsessionsroot_all (SQLite3 session db backend) failed with exitcode: $sth->err()"); die(); } - fetchrow_printall_array($sth); + my @sessions = fetchrow_array_datasets($sth); + $sth->finish(); + $dbh->disconnect(); + return @sessions; } -elsif($cmd eq "getmounts") +sub db_getmounts { + my $dbh = init_db(); my $sid=shift or die "argument \"session_id\" missed"; check_user($sid); my @strings; @@ -118,11 +135,15 @@ elsif($cmd eq "getmounts") syslog('error', "getmounts (SQLite3 session db backend) failed with exitcode: $sth->err()"); die; } - fetchrow_printall_array($sth); + my @mounts = fetchrow_array_datasets($sth); + $sth->finish(); + $dbh->disconnect(); + return @mounts; } -elsif($cmd eq "deletemount") +sub db_deletemount { + my $dbh = init_db(); my $sid=shift or die "argument \"session_id\" missed"; my $path=shift or die "argument \"path\" missed"; check_user($sid); @@ -134,41 +155,49 @@ elsif($cmd eq "deletemount") die(); } $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "deletemounts") +sub db_deletemounts { - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my $sth=$dbh->prepare("delete from mounts where session_id=?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "deletemounts (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); + my $dbh = init_db(); + my $sid=shift or die "argument \"session_id\" missed"; + check_user($sid); + my $sth=$dbh->prepare("delete from mounts where session_id=?"); + $sth->execute($sid); + if ($sth->err()) + { + syslog('error', "deletemounts (SQLite3 session db backend) failed with exitcode: $sth->err()"); + die(); + } + $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "insertmount") +sub db_insertmount { + my $dbh = init_db(); my $sid=shift or die "argument \"session_id\" missed"; my $path=shift or die "argument \"path\" missed"; my $client=shift or die "argument \"client\" missed"; check_user($sid); my $sth=$dbh->prepare("insert into mounts (session_id,path,client) values (?, ?, ?)"); $sth->execute($sid, $path, $client); + my $success = 0; if(! $sth->err()) { - print "ok"; + $success = 1; } else { syslog('debug', "insertmount (SQLite3 session db backend) failed with exitcode: $sth->err(), this issue will be interpreted as: SSHFS share already mounted"); } $sth->finish(); + $dbh->disconnect(); + return $success; } -elsif($cmd eq "insertsession") +sub db_insertsession { + my $dbh = init_db(); my $display=shift or die "argument \"display\" missed"; my $server=shift or die "argument \"server\" missed"; my $sid=shift or die "argument \"session_id\" missed"; @@ -177,11 +206,13 @@ elsif($cmd eq "insertsession") (?, ?, ?, ?, datetime('now','localtime'), datetime('now','localtime'))"); $sth->execute($display, $server, $realuser, $sid) or die $_; $sth->finish(); - print "ok"; + $dbh->disconnect(); + return 1; } -elsif($cmd eq "createsession") +sub db_createsession { + my $dbh = init_db(); my $cookie=shift or die"argument \"cookie\" missed"; my $pid=shift or die"argument \"pid\" missed"; my $client=shift or die"argument \"client\" missed"; @@ -199,11 +230,13 @@ elsif($cmd eq "createsession") die(); } $sth->finish(); - print "ok"; + $dbh->disconnect(); + return 1; } -elsif($cmd eq "insertport") +sub db_insertport { + my $dbh = init_db(); my $server=shift or die "argument \"server\" missed"; my $sid=shift or die "argument \"session_id\" missed"; my $sshport=shift or die "argument \"port\" missed"; @@ -216,10 +249,12 @@ elsif($cmd eq "insertport") die(); } $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "rmport") +sub db_rmport { + my $dbh = init_db(); my $server=shift or die "argument \"server\" missed"; my $sid=shift or die "argument \"session_id\" missed"; my $sshport=shift or die "argument \"port\" missed"; @@ -231,10 +266,12 @@ elsif($cmd eq "rmport") die(); } $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "resume") +sub db_resume { + my $dbh = init_db(); my $client=shift or die "argument \"client\" missed"; my $sid=shift or die "argument \"session_id\" missed"; my $gr_port=shift or die "argument \"gr_port\" missed"; @@ -250,10 +287,12 @@ elsif($cmd eq "resume") die(); } $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "changestatus") +sub db_changestatus { + my $dbh = init_db(); my $status=shift or die "argument \"status\" missed"; my $sid=shift or die "argument \"session_id\" missed"; check_user($sid); @@ -266,10 +305,12 @@ elsif($cmd eq "changestatus") die(); } $sth->finish(); + $dbh->disconnect(); } -elsif($cmd eq "getstatus") +sub db_getstatus { + my $dbh = init_db(); my $sid=shift or die "argument \"session_id\" missed"; check_user($sid); my $sth=$dbh->prepare("select status from sessions where session_id = ?"); @@ -283,14 +324,16 @@ elsif($cmd eq "getstatus") my $status; @data = $sth->fetchrow_array; { - $status = @data[0]; + $status = $data[0]; } $sth->finish(); - print $status; + $dbh->disconnect(); + return $status; } -elsif($cmd eq "getdisplays") +sub db_getdisplays { + my $dbh = init_db(); #ignore $server my @strings; my $sth=$dbh->prepare("select display from sessions"); @@ -304,15 +347,16 @@ elsif($cmd eq "getdisplays") my $i=0; while (@data = $sth->fetchrow_array) { - @strings[$i++]='|'.@data[0].'|'; + $strings[$i++]='|'.$data[0].'|'; } $sth->finish(); - print join("\n",@strings); + $dbh->disconnect(); + return join("\n",@strings); } -elsif($cmd eq "getports") +sub db_getports { - + my $dbh = init_db(); #ignore $server my $server=shift or die "argument \"server\" missed"; my @strings; @@ -327,14 +371,16 @@ elsif($cmd eq "getports") my $i=0; while (@data = $sth->fetchrow_array) { - @strings[$i++]='|'.@data[0].'|'; + $strings[$i++]='|'.$data[0].'|'; } $sth->finish(); - print join("\n",@strings); + $dbh->disconnect(); + return join("\n",@strings); } -elsif($cmd eq "getservers") +sub db_getservers { + my $dbh = init_db(); my @strings; my $sth=$dbh->prepare("select server,count(*) from sessions where status != 'F' group by server"); $sth->execute(); @@ -347,14 +393,16 @@ elsif($cmd eq "getservers") my $i=0; while (@data = $sth->fetchrow_array) { - @strings[$i++]=@data[0]; + $strings[$i++]=$data[0]; } $sth->finish(); - print join("\n",@strings); + $dbh->disconnect(); + return join("\n",@strings); } -elsif($cmd eq "getagent") +sub db_getagent { + my $dbh = init_db(); my $sid=shift or die "argument \"session_id\" missed"; my $agent; check_user($sid); @@ -370,14 +418,16 @@ elsif($cmd eq "getagent") my $i=0; if(@data = $sth->fetchrow_array) { - $agent=@data[0]; + $agent=$data[0]; } $sth->finish(); - print $agent; + $dbh->disconnect(); + return $agent; } -elsif($cmd eq "getdisplay") +sub db_getdisplay { + my $dbh = init_db(); my $sid=shift or die "argument \"session_id\" missed"; my $display; check_user($sid); @@ -393,14 +443,16 @@ elsif($cmd eq "getdisplay") my $i=0; if(@data = $sth->fetchrow_array) { - $display=@data[0]; + $display=$data[0]; } $sth->finish(); - print $display; + $dbh->disconnect(); + return $display; } -elsif($cmd eq "listsessions") +sub db_listsessions { + my $dbh = init_db(); my $server=shift or die "argument \"server\" missed"; my @strings; my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, @@ -417,11 +469,15 @@ elsif($cmd eq "listsessions") syslog('error', "listsessions (SQLite3 session db backend) failed with exitcode: $sth->err()"); die(); } - fetchrow_printall_array($sth); + my @sessions = fetchrow_array_datasets($sth); + $sth->finish(); + $dbh->disconnect(); + return @sessions; } -elsif($cmd eq "listsessions_all") +sub listsessions_all { + my $dbh = init_db(); my @strings; my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, strftime('%Y-%m-%dT%H:%M:%S',init_time), @@ -437,16 +493,13 @@ elsif($cmd eq "listsessions_all") syslog('error', "listsessions_all (SQLite3 session db backend) failed with exitcode: $sth->err()"); die(); } - fetchrow_printall_array($sth); -} -else -{ - print "unknown command $cmd\n"; + my @sessions = fetchrow_array_datasets($sth); + $sth->finish(); + $dbh->disconnect(); + return @sessions; } -$dbh->disconnect(); - -sub checkroot +sub check_root { if ($realuser ne "root") { @@ -465,16 +518,16 @@ sub check_user $user eq $realuser or die "$realuser is not authorized"; } -sub fetchrow_printall_array +sub fetchrow_array_datasets { - # print all arrays separated by the pipe symbol - local $, = '|'; - my $sth = shift; + my @lines; my @data; while (@data = $sth->fetchrow_array()) { - print @data, "\n"; + push @lines, join('|', @data); } - $sth->finish(); + return @lines; } + +1; diff --git a/debian/changelog b/debian/changelog index a83f152..e215b2f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -19,6 +19,8 @@ x2goserver (3.2.0.0-0~x2go1) UNRELEASED; urgency=low that the LD_LIBRARY_PATH variable stays intact. Closes #29. - Transform x2gologlevel.pm into proper Perl module X2Go::Log. - Transform x2godbwrapper.pm into proper Perl module X2Go::Server::DB. + - Transform x2gosqlitewrapper.pl into small wrapper script and move the + SQLite3 into Perl package X2Go::Server::DB::SQLite3. * /debian/control: + Maintainer change in package: X2Go Developers <x2go-dev@lists.berlios.de>. + Depend on nx-libs (>=3.5.0.15-0~) which has the Xrandr symlinks folder. diff --git a/x2goserver/lib/x2gosqlitewrapper.pl b/x2goserver/lib/x2gosqlitewrapper.pl index 94d8f91..5247fee 100755 --- a/x2goserver/lib/x2gosqlitewrapper.pl +++ b/x2goserver/lib/x2gosqlitewrapper.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/perl -XU # Copyright (C) 2007-2012 X2Go Project - http://wiki.x2go.org # @@ -21,460 +21,57 @@ # Copyright (C) 2007-2012 Heinz-Markus Graesing <heinz-m.graesing@obviously-nice.de> use strict; -use DBI; -use POSIX; +use Switch; -#### NOTE: this script is run setgid <group> and it cannot do system() calls. - -use Config::Simple; -use Sys::Syslog qw( :standard :macros ); -use X2Go::Log qw(loglevel); - -openlog($0,'cons,pid','user'); -setlogmask( LOG_UPTO(loglevel()) ); - -#### -#### end of duplicated syslogging code -#### - -# retrieve home dir of x2gouser -my $x2gouser='x2gouser'; -my ($uname, $pass, $uid, $pgid, $quota, $comment, $gcos, $homedir, $shell, $expire) = getpwnam($x2gouser); -my $dbfile="$homedir/x2go_sessions"; - -# retrieve account data of real user -my ($uname, $pass, $uid, $pgid, $quota, $comment, $gcos, $homedir, $shell, $expire) = getpwuid($<); -my $realuser=$uname; - -my $dbh=DBI->connect("dbi:SQLite:dbname=$dbfile","","",{sqlite_use_immediate_transaction => 1, AutoCommit => 1, }) or die $_; -$dbh->sqlite_busy_timeout( 2000 ); - -my $cmd=shift or die "command not specified"; -my $rc=0; - -if($cmd eq "rmsessionsroot") -{ - checkroot(); - my $sid=shift or die "argument \"session_id\" missed"; - my $sth=$dbh->prepare("delete from sessions where session_id=?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "rmsessionsroot (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die; - } - $sth->finish(); -} - -elsif($cmd eq "listsessionsroot") -{ - checkroot(); - my $server=shift or die "argument \"server\" missed"; - my @strings; - my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, - strftime('%Y-%m-%dT%H:%M:%S',init_time), - cookie,client,gr_port,sound_port, - strftime('%Y-%m-%dT%H:%M:%S',last_time), - uname, - strftime('%s','now','localtime') - strftime('%s',init_time),fs_port from sessions - where server=? order by status desc"); - $sth->execute($server); - if ($sth->err()) { - syslog('error', "listsessionsroot (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - fetchrow_printall_array($sth); -} - -elsif($cmd eq "listsessionsroot_all") -{ - checkroot(); - my @strings; - my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, - strftime('%Y-%m-%dT%H:%M:%S',init_time), - cookie,client,gr_port,sound_port, - strftime('%Y-%m-%dT%H:%M:%S',last_time), - uname, - strftime('%s','now','localtime') - strftime('%s',init_time),fs_port from sessions - order by status desc"); - $sth->execute(); - if ($sth->err()) - { - syslog('error', "listsessionsroot_all (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - fetchrow_printall_array($sth); -} - -elsif($cmd eq "getmounts") -{ - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my @strings; - my $sth=$dbh->prepare("select client, path from mounts where session_id=?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "getmounts (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die; - } - fetchrow_printall_array($sth); -} - -elsif($cmd eq "deletemount") -{ - my $sid=shift or die "argument \"session_id\" missed"; - my $path=shift or die "argument \"path\" missed"; - check_user($sid); - my $sth=$dbh->prepare("delete from mounts where session_id=? and path=?"); - $sth->execute($sid, $path); - if ($sth->err()) - { - syslog('error', "deletemount (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); -} +use X2Go::Server::DB::SQLite3; -elsif($cmd eq "deletemounts") -{ - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my $sth=$dbh->prepare("delete from mounts where session_id=?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "deletemounts (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); -} +#### NOTE: this script is run setgid <group> and it cannot do system() calls. -elsif($cmd eq "insertmount") +sub print_result { - my $sid=shift or die "argument \"session_id\" missed"; - my $path=shift or die "argument \"path\" missed"; - my $client=shift or die "argument \"client\" missed"; - check_user($sid); - my $sth=$dbh->prepare("insert into mounts (session_id,path,client) values (?, ?, ?)"); - $sth->execute($sid, $path, $client); - if(! $sth->err()) + my $retval = shift; + if ( $retval =~ /^(0|1)/ ) { - print "ok"; + if ( $retval ) + { + print "ok"; + } } else { - syslog('debug', "insertmount (SQLite3 session db backend) failed with exitcode: $sth->err(), this issue will be interpreted as: SSHFS share already mounted"); - } - $sth->finish(); -} - -elsif($cmd eq "insertsession") -{ - my $display=shift or die "argument \"display\" missed"; - my $server=shift or die "argument \"server\" missed"; - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my $sth=$dbh->prepare("insert into sessions (display,server,uname,session_id, init_time, last_time) values - (?, ?, ?, ?, datetime('now','localtime'), datetime('now','localtime'))"); - $sth->execute($display, $server, $realuser, $sid) or die $_; - $sth->finish(); - print "ok"; -} - -elsif($cmd eq "createsession") -{ - my $cookie=shift or die"argument \"cookie\" missed"; - my $pid=shift or die"argument \"pid\" missed"; - my $client=shift or die"argument \"client\" missed"; - my $gr_port=shift or die"argument \"gr_port\" missed"; - my $snd_port=shift or die"argument \"snd_port\" missed"; - my $fs_port=shift or die"argument \"fs_port\" missed"; - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my $sth=$dbh->prepare("update sessions set status='R',last_time=datetime('now','localtime'),cookie=?,agent_pid=?, - client=?,gr_port=?,sound_port=?,fs_port=? where session_id=? and uname=?"); - $sth->execute($cookie, $pid, $client, $gr_port, $snd_port, $fs_port, $sid, $realuser); - if ($sth->err()) - { - syslog('error', "createsession (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); - print "ok"; -} - -elsif($cmd eq "insertport") -{ - my $server=shift or die "argument \"server\" missed"; - my $sid=shift or die "argument \"session_id\" missed"; - my $sshport=shift or die "argument \"port\" missed"; - my $sth=$dbh->prepare("insert into used_ports (server,session_id,port) values (?, ?, ?)"); - check_user($sid); - $sth->execute($server, $sid, $sshport); - if ($sth->err()) - { - syslog('error', "insertport (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); -} - -elsif($cmd eq "rmport") -{ - my $server=shift or die "argument \"server\" missed"; - my $sid=shift or die "argument \"session_id\" missed"; - my $sshport=shift or die "argument \"port\" missed"; - my $sth=$dbh->prepare("delete from used_ports where server=? and session_id=? and port=?"); - check_user($sid); - $sth->execute($server, $sid, $sshport); - if ($sth->err()) { - syslog('error', "rmport (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); -} - -elsif($cmd eq "resume") -{ - my $client=shift or die "argument \"client\" missed"; - my $sid=shift or die "argument \"session_id\" missed"; - my $gr_port=shift or die "argument \"gr_port\" missed"; - my $sound_port=shift or die "argument \"sound_port\" missed"; - my $fs_port=shift or die "argument \"fs_port\" missed"; - check_user($sid); - my $sth=$dbh->prepare("update sessions set last_time=datetime('now','localtime'),status='R', - client=?,gr_port=?,sound_port=?,fs_port=? where session_id = ? and uname=?"); - $sth->execute($client, $gr_port, $sound_port, $fs_port, $sid, $realuser); - if ($sth->err()) - { - syslog('error', "resume (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); -} - -elsif($cmd eq "changestatus") -{ - my $status=shift or die "argument \"status\" missed"; - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my $sth=$dbh->prepare("update sessions set last_time=datetime('now','localtime'), - status=? where session_id = ? and uname=?"); - $sth->execute($status, $sid, $realuser); - if ($sth->err()) - { - syslog('error', "changestatus (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - $sth->finish(); -} - -elsif($cmd eq "getstatus") -{ - my $sid=shift or die "argument \"session_id\" missed"; - check_user($sid); - my $sth=$dbh->prepare("select status from sessions where session_id = ?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "changestatus (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - my @data; - my $status; - @data = $sth->fetchrow_array; - { - $status = @data[0]; - } - $sth->finish(); - print $status; -} - -elsif($cmd eq "getdisplays") -{ - #ignore $server - my @strings; - my $sth=$dbh->prepare("select display from sessions"); - $sth->execute(); - if ($sth->err()) - { - syslog('error', "getdisplays (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - my @data; - my $i=0; - while (@data = $sth->fetchrow_array) - { - @strings[$i++]='|'.@data[0].'|'; - } - $sth->finish(); - print join("\n",@strings); -} - -elsif($cmd eq "getports") -{ - - #ignore $server - my $server=shift or die "argument \"server\" missed"; - my @strings; - my $sth=$dbh->prepare("select port from used_ports"); - $sth->execute(); - if ($sth->err()) - { - syslog('error', "getports (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - my @data; - my $i=0; - while (@data = $sth->fetchrow_array) - { - @strings[$i++]='|'.@data[0].'|'; - } - $sth->finish(); - print join("\n",@strings); -} - -elsif($cmd eq "getservers") -{ - my @strings; - my $sth=$dbh->prepare("select server,count(*) from sessions where status != 'F' group by server"); - $sth->execute(); - if ($sth->err()) - { - syslog('error', "getservers (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - my @data; - my $i=0; - while (@data = $sth->fetchrow_array) - { - @strings[$i++]=@data[0]; - } - $sth->finish(); - print join("\n",@strings); -} - -elsif($cmd eq "getagent") -{ - my $sid=shift or die "argument \"session_id\" missed"; - my $agent; - check_user($sid); - my $sth=$dbh->prepare("select agent_pid from sessions - where session_id=?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "getagent (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); + print $retval; } - my @data; - my $i=0; - if(@data = $sth->fetchrow_array) - { - $agent=@data[0]; - } - $sth->finish(); - print $agent; } -elsif($cmd eq "getdisplay") +sub print_array { - my $sid=shift or die "argument \"session_id\" missed"; - my $display; - check_user($sid); - my $sth=$dbh->prepare("select display from sessions - where session_id =?"); - $sth->execute($sid); - if ($sth->err()) - { - syslog('error', "getdisplay (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - my @data; - my $i=0; - if(@data = $sth->fetchrow_array) + # print all arrays separated by the pipe symbol + local $, = '|'; + print "THIS IS AN ARRAY!!!!"; + while (<>) { - $display=@data[0]; + print $_, "\n"; } - $sth->finish(); - print $display; } -elsif($cmd eq "listsessions") -{ - my $server=shift or die "argument \"server\" missed"; - my @strings; - my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, - strftime('%Y-%m-%dT%H:%M:%S',init_time), - cookie,client,gr_port,sound_port, - strftime('%Y-%m-%dT%H:%M:%S',last_time), - uname, - strftime('%s','now','localtime') - strftime('%s',init_time),fs_port from sessions - where status !='F' and server=? and uname=? - and ( session_id not like '%XSHAD%') order by status desc"); - $sth->execute($server, $realuser); - if ($sth->err()) - { - syslog('error', "listsessions (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - fetchrow_printall_array($sth); -} +my $result; +my $cmd=shift or die "command not specified"; -elsif($cmd eq "listsessions_all") +# call the corresponding function in the X2Go::Server:DB:SQLite3 package +switch ($cmd) { - my @strings; - my $sth=$dbh->prepare("select agent_pid, session_id, display, server, status, - strftime('%Y-%m-%dT%H:%M:%S',init_time), - cookie,client,gr_port,sound_port, - strftime('%Y-%m-%dT%H:%M:%S',last_time), - uname, - strftime('%s','now','localtime') - strftime('%s',init_time),fs_port from sessions - where status !='F' and uname=? and ( session_id not like '%XSHAD%') order by status desc"); - - $sth->execute($realuser); - if ($sth->err()) - { - syslog('error', "listsessions_all (SQLite3 session db backend) failed with exitcode: $sth->err()"); - die(); - } - fetchrow_printall_array($sth); -} -else -{ - print "unknown command $cmd\n"; + case /.*root/ { $result = eval("X2Go::Server::DB::SQLite3::dbsys_$cmd(\@ARGV)") } + else { $result = eval("X2Go::Server::DB::SQLite3::db_$cmd(\@ARGV)") } } -$dbh->disconnect(); - -sub checkroot +# depending on the type of $result we do different things... +print $result; +if ( defined($result) ) { - if ($realuser ne "root") + if ( ref($result) eq "ARRAY" ) { - die "$realuser, you can not do this job"; + print_array($result); + } else { + print_result($result); } } -sub check_user -{ - my $sid=shift or die "argument \"session_id\" missed"; - return if $realuser eq "root"; - # session id looks like someuser-51-1304005895_stDgnome-session_dp24 - # during DB insertsession it only looks like someuser-51-1304005895 - my $user = "$sid"; - $user =~ s/$realuser-[0-9]{2,}-[0-9]{10,}.*/$realuser/; - $user eq $realuser or die "$realuser is not authorized"; -} - -sub fetchrow_printall_array -{ - # print all arrays separated by the pipe symbol - local $, = '|'; - - my $sth = shift; - my @data; - while (@data = $sth->fetchrow_array()) - { - print @data, "\n"; - } - $sth->finish(); -} +exit (0); hooks/post-receive -- x2goserver.git (X2Go Server) This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "x2goserver.git" (X2Go Server).