The branch, master has been updated via e1c3ba9271e5c7cb8223c698b14f90469906c157 (commit) from 2ce2d27c90a930f4c61690a07726c718d52def5e (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 e1c3ba9271e5c7cb8223c698b14f90469906c157 Author: Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Date: Sat Sep 15 23:04:14 2012 +0200 Fix code indentations (spaces replaced by tabs, use proper indentation levels). ----------------------------------------------------------------------- Summary of changes: cgi/x2gobroker-simple.cgi | 55 ++-- debian/changelog | 1 + lib/x2gobroker-command.pl | 99 +++--- lib/x2gobroker-simple.pm | 979 +++++++++++++++++++++++---------------------- 4 files changed, 571 insertions(+), 563 deletions(-) The diff of changes is: diff --git a/cgi/x2gobroker-simple.cgi b/cgi/x2gobroker-simple.cgi index 8f6fe88..8ac7213 100755 --- a/cgi/x2gobroker-simple.cgi +++ b/cgi/x2gobroker-simple.cgi @@ -31,13 +31,17 @@ my $cgi = new CGI; my @formValues = $cgi->param(); -print $cgi->header(-type =>'text/html', - -expires =>'+1h'), - $cgi->start_html( -title =>'X2Go Broker', - -author =>'X2Go Developers <x2go-dev@lists.berlios.de>', - -base =>'true', - -meta =>{'keywords' =>'X2Go', - 'description'=>'X2Go Broker'}); +print $cgi->header( + -type =>'text/html', + -expires =>'+1h' + ), + $cgi->start_html( + -title =>'X2Go Broker', + -author =>'X2Go Developers <x2go-dev@lists.berlios.de>', + -base =>'true', + -meta =>{'keywords' =>'X2Go', 'description'=>'X2Go Broker'} + ); + #open (FL, ">>/tmp/x2gobroker.log"); #print FL `date`; #print FL "called method ".$cgi->param('task')." from ".$ENV{REMOTE_ADDR}."\n"; @@ -45,19 +49,19 @@ print $cgi->header(-type =>'text/html', if($cgi->param('task') eq 'testcon') { - for ( my $i=0;$i<2*1024*1024;$i++ ) - { - print int(rand(9)); - } - print $cgi->end_html(); + for ( my $i=0;$i<2*1024*1024;$i++ ) + { + print int(rand(9)); + } + print $cgi->end_html(); } -if (!checkAccess($cgi->param('user'), $cgi->param('password'), $cgi->param('authid')) == 1) +if ( ! checkAccess($cgi->param('user'), $cgi->param('password'), $cgi->param('authid')) == 1 ) { - printNoAccess(); - print $cgi->end_html(); - exit (0); + printNoAccess(); + print $cgi->end_html(); + exit (0); } print $cgi->start_form(), @@ -65,28 +69,27 @@ $cgi->strong('Access granted'); if ($cgi->param('task') eq 'listsessions') { - listSessions($cgi->param('user')); + listSessions($cgi->param('user')); } if ($cgi->param('task') eq 'selectsession') { - selectSession($cgi->param('user'), $cgi->param('sid')); + selectSession($cgi->param('user'), $cgi->param('sid')); } if ($cgi->param('task') eq 'setpass') { - setPass($cgi->param('user'), $cgi->param('newpass')); + setPass($cgi->param('user'), $cgi->param('newpass')); } - $cgi->hr(), - $cgi->end_form(); +$cgi->hr(), +$cgi->end_form(); print $cgi->end_html(); - sub printNoAccess { - print $cgi->start_form(), - $cgi->hr(), - $cgi->strong('Access denied'), - $cgi->end_form(); + print $cgi->start_form(), + $cgi->hr(), + $cgi->strong('Access denied'), + $cgi->end_form(); } diff --git a/debian/changelog b/debian/changelog index 22bd8c2..832aa39 100644 --- a/debian/changelog +++ b/debian/changelog @@ -4,5 +4,6 @@ x2gobroker (0.0.0.1-0~x2go1) UNRELEASED; urgency=low * Setting up new public X2Go project: x2gohttpbroker. * /debian/control: + Add an initial dependency selection to the various Depends fields. + * Fix code indentations (spaces replaced by tabs, use proper indentation levels). -- Mike Gabriel <mike.gabriel@das-netzwerkteam.de> Wed, 15 Sep 2012 17:30:24 +0200 diff --git a/lib/x2gobroker-command.pl b/lib/x2gobroker-command.pl index e39094d..0bac8de 100755 --- a/lib/x2gobroker-command.pl +++ b/lib/x2gobroker-command.pl @@ -24,45 +24,44 @@ use strict; sub initUser { - my ($user, $uid, $gid, $home)=@_; - if (! -d "$home") - { - mkdir ("$home", 0700); - chown ($uid, $gid, $home); - } - if (! -e "$home/.x2go/sqlpass") - { - open my $save_out, ">&STDOUT"; - close (STDOUT); - system "/usr/lib/x2go/script/x2godbadmin", "--adduser", $user; - open STDOUT, ">&", $save_out; - } + my ($user, $uid, $gid, $home)=@_; + if (! -d "$home") + { + mkdir ("$home", 0700); + chown ($uid, $gid, $home); + } + if (! -e "$home/.x2go/sqlpass") + { + open my $save_out, ">&STDOUT"; + close (STDOUT); + system "/usr/lib/x2go/script/x2godbadmin", "--adduser", $user; + open STDOUT, ">&", $save_out; + } } sub createKey { - my ($uid, $gid, $home)=@_; - if (! -d "$home/.ssh") - { - mkdir ("$home/.ssh", 0700); - chown ($uid, $gid, "$home/.ssh"); - } - if( -e "$home/.ssh/authorized_keys") - { - unlink("$home/.ssh/authorized_keys"); - } - open my $save_out, ">&STDOUT"; - close (STDOUT); - system "/usr/bin/ssh-keygen", "-t", "dsa", "-N","","-f","$home/.ssh/authorized_keys"; - open STDOUT, ">&", $save_out; - open (F,"<$home/.ssh/authorized_keys"); - print <F>; - close (F); - unlink("$home/.ssh/authorized_keys"); - rename("$home/.ssh/authorized_keys.pub", "$home/.ssh/authorized_keys"); + my ($uid, $gid, $home)=@_; + if (! -d "$home/.ssh") + { + mkdir ("$home/.ssh", 0700); + chown ($uid, $gid, "$home/.ssh"); + } + if( -e "$home/.ssh/authorized_keys") + { + unlink("$home/.ssh/authorized_keys"); + } + open my $save_out, ">&STDOUT"; + close (STDOUT); + system "/usr/bin/ssh-keygen", "-t", "dsa", "-N","","-f","$home/.ssh/authorized_keys"; + open STDOUT, ">&", $save_out; + open (F,"<$home/.ssh/authorized_keys"); + print <F>; + close (F); + unlink("$home/.ssh/authorized_keys"); + rename("$home/.ssh/authorized_keys.pub", "$home/.ssh/authorized_keys"); } - $< = $>; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{'PATH'} = '/bin:/usr/bin'; @@ -70,48 +69,46 @@ $ENV{'PATH'} = '/bin:/usr/bin'; my $username=shift or die; my $mode=shift or die; - -my ($name,$passwd,$uid,$gid, - $quota,$comment,$gcos,$home,$shell,$expire) = getpwnam($username); +my ($name,$passwd,$uid,$gid, $quota,$comment,$gcos,$home,$shell,$expire) = getpwnam($username); if($uid < 1000) { - die 'operation on system user'; + die 'operation on system user'; } if($mode eq 'listsessions') { - initUser($name, $uid, $gid, $home); - print "OK\n"; - system "/bin/su", $name, "-c", "/usr/bin/x2golistsessions --all-servers"; + initUser($name, $uid, $gid, $home); + print "OK\n"; + system "/bin/su", $name, "-c", "/usr/bin/x2golistsessions --all-servers"; } if($mode eq 'getservers') { - initUser($name, $uid, $gid, $home); - print "OK\n"; - system "/bin/su", $name, "-c", "/usr/bin/x2gogetservers"; + initUser($name, $uid, $gid, $home); + print "OK\n"; + system "/bin/su", $name, "-c", "/usr/bin/x2gogetservers"; } if($mode eq 'key') { - initUser($name, $uid, $gid, $home); - print "OK\n"; - createKey($uid, $gid, $home); + initUser($name, $uid, $gid, $home); + print "OK\n"; + createKey($uid, $gid, $home); } if($mode eq 'suspend') { - initUser($name, $uid, $gid, $home); - print "OK\n"; - my $sid=shift; - system "/bin/su", $name, "-c", "/usr/bin/x2gosuspend-session $sid"; + initUser($name, $uid, $gid, $home); + print "OK\n"; + my $sid=shift; + system "/bin/su", $name, "-c", "/usr/bin/x2gosuspend-session $sid"; } if($mode eq 'ping') { - print "OK\n"; + print "OK\n"; } diff --git a/lib/x2gobroker-simple.pm b/lib/x2gobroker-simple.pm index f27eb47..5e56c28 100644 --- a/lib/x2gobroker-simple.pm +++ b/lib/x2gobroker-simple.pm @@ -39,588 +39,595 @@ use base 'Exporter'; our @EXPORT = ('checkAccess', 'listSessions', 'selectSession', 'setPass'); sub getBase +### +### FIXME: provide that in /etc/x2go/x2gobroker-simple.cfg +### FIXME: put the pid of this process in the lock files { - my $login=shift; - $login=~s/cn=ldapadmin//; - return $login; + my $login=shift; + $login=~s/cn=ldapadmin,//; + return $login; } sub initLdap +### +### FIXME: lock files have to be in /run or /var/run... +### { - my $masterlocked=0; - my $replicalocked=0; - if((-e "/etc/x2go/x2gobroker/masterldap.lock") &&(-e "/etc/x2go/x2gobroker/replicaldap.lock")) - { - die "Can't connect to LDAP server"; - } - if(-e "/etc/x2go/x2gobroker/replicaldap.lock") - { - $masterlocked=1; - my ($ldap,$error)=initLDAPServer( $ldapuri ); - if(!$ldap) - { - `touch /etc/x2go/x2gobroker/masterldap.lock`; - die "Can't connect to LDAP server"; - } - return $ldap; - } - if(-e "/etc/x2go/x2gobroker/masterldap.lock") - { - $replicalocked=1; - my ($ldap,$error)=initLDAPServer( $replica ); - if(!$ldap) - { - `touch /etc/x2go/x2gobroker/replicaldap.lock`; - die "Can't connect to LDAP server"; - } - return $ldap; - } - if(!int(rand(2))) - { - my ($ldap,$error)=initLDAPServer( $ldapuri ); - if(!$ldap) - { - `touch /etc/x2go/x2gobroker/masterldap.lock`; - return initLdap(); - } - return $ldap; - } - else - { - my ($ldap,$error)=initLDAPServer( $replica ); - if(!$ldap) - { - `touch /etc/x2go/x2gobroker/replicaldap.lock`; - return initLdap(); - } - return $ldap; - } + my $masterlocked=0; + my $replicalocked=0; + if ( ( -e "/etc/x2go/x2gobroker/masterldap.lock") && ( -e "/etc/x2go/x2gobroker/replicaldap.lock" ) ) + { + die "Can't connect to LDAP server"; + } + if ( -e "/etc/x2go/x2gobroker/replicaldap.lock" ) + { + $masterlocked=1; + my ($ldap,$error)=initLDAPServer( $ldapuri ); + if( ! $ldap ) + { + `touch /etc/x2go/x2gobroker/masterldap.lock`; + die "Can't connect to LDAP server"; + } + return $ldap; + } + if( -e "/etc/x2go/x2gobroker/masterldap.lock" ) + { + $replicalocked=1; + my ($ldap,$error)=initLDAPServer( $replica ); + if ( ! $ldap ) + { + `touch /etc/x2go/x2gobroker/replicaldap.lock`; + die "Can't connect to LDAP server"; + } + return $ldap; + } + if( ! int(rand(2)) ) + { + my ($ldap,$error)=initLDAPServer( $ldapuri ); + if( ! $ldap ) + { + `touch /etc/x2go/x2gobroker/masterldap.lock`; + return initLdap(); + } + return $ldap; + } else { + my ($ldap,$error)=initLDAPServer( $replica ); + if(!$ldap) + { + `touch /etc/x2go/x2gobroker/replicaldap.lock`; + return initLdap(); + } + return $ldap; + } } sub initMasterLdap { - if(-e "/etc/x2go/x2gobroker/masterldap.lock") - { - die "Master LDAP server is down\n"; - } - my ($ldap,$error)=initLDAPServer( $ldapuri ); - if(!$ldap) - { - `touch /etc/x2go/x2gobroker/masterldap.lock`; - die $error; - } - return $ldap; + if(-e "/etc/x2go/x2gobroker/masterldap.lock") + { + die "Master LDAP server is down\n"; + } + my ($ldap,$error)=initLDAPServer( $ldapuri ); + if( ! $ldap ) + { + `touch /etc/x2go/x2gobroker/masterldap.lock`; + die $error; + } + return $ldap; } sub initLDAPServer { - my $url=shift; - my $ldap=Net::LDAP->new( $url ); - if(! $ldap) - { - notify("LDAP server $url is down ($@). Please, repair it and remove lock file in /etc/x2go/x2gobroker\n"); - return (0,"$@"); - } - my $message = $ldap->bind($binddn,password=>$bindpw); - if(!$message) - { - notify("LDAP server $url is down ($@). Please, repair it and remove lock file in /etc/x2go/x2gobroker\n"); - return (0,"$@"); - } - return ($ldap,0); + my $url=shift; + my $ldap=Net::LDAP->new( $url ); + if( ! $ldap ) + { + notify("LDAP server $url is down ($@). Please, repair it and remove lock file in /etc/x2go/x2gobroker\n"); + return (0,"$@"); + } + my $message = $ldap->bind($binddn,password=>$bindpw); + if(!$message) + { + notify("LDAP server $url is down ($@). Please, repair it and remove lock file in /etc/x2go/x2gobroker\n"); + return (0,"$@"); + } + return ($ldap,0); } sub setPass { - my ($user, $newpass)=@_; -#check if we have master ldap here - - my $attr; - - my $csh=Crypt::SaltedHash->new(algorithm => 'SHA-1'); - $csh->add($newpass); - $newpass=$csh->generate; - - push(@$attr,'userPassword'=>$newpass); - my $changes; - push(@$changes,'replace'=>$attr); - - my $ldap = initMasterLdap(); - - - my $dn="cn=$user,ou=BrokerUsers".getBase($binddn); - my $message=$ldap->modify($dn, changes => $changes); - - if($message->code) - { - die $message->error.": ".$message->error_desc; - } - print "\n<br>CHANGING PASS OK<br>\n"; + my ($user, $newpass)=@_; + # check if we have master ldap here + + my $attr; + + my $csh=Crypt::SaltedHash->new(algorithm => 'SHA-1'); + $csh->add($newpass); + $newpass=$csh->generate; + + push(@$attr,'userPassword'=>$newpass); + my $changes; + push(@$changes,'replace'=>$attr); + + my $ldap = initMasterLdap(); + + my $dn="cn=$user,ou=BrokerUsers".getBase($binddn); + my $message=$ldap->modify($dn, changes => $changes); + + if($message->code) + { + die $message->error.": ".$message->error_desc; + } + print "\n<br>CHANGING PASS OK<br>\n"; } sub selectSession { - my ($user, $sid)=@_; - my @words=split("\@",$sid); - my $sess_id=@words[1]; - my $host=@words[0]; - checkAndStartSession($user, $host, $sess_id); + my ($user, $sid)=@_; + my @words=split("\@",$sid); + my $sess_id=@words[1]; + my $host=@words[0]; + checkAndStartSession($user, $host, $sess_id); } sub getExtCon { - my $host=shift; - - my $ldap = initLdap(); - - my $dn="cn=$host,ou=Servers,ou=ON".getBase($binddn); - my $message=$ldap->search(base => $dn, - scope => 'base', filter => '(objectClass=ipHost)'); - - if($message->code) - { - die $message->error.": ".$message->error_desc; - } - foreach ($message->entries) - { - my $asn=$_->{'asn'}; - my $attr=$asn->{'attributes'}; - foreach (@$attr) - { - my $type=$_->{'type'}; - my $value=$_->{'vals'}[0]; - if($type eq 'description') - { - my @words=split(":",$value); - return (@words[0], @words[1]); - } - } - } + my $host=shift; + + my $ldap = initLdap(); + + my $dn="cn=$host,ou=Servers,ou=ON".getBase($binddn); + #### + #### FIXME: get scope from config file in /etc/x2go/x2gobroker-*.conf + #### + my $message=$ldap->search(base => $dn, + scope => 'base', + filter => '(objectClass=ipHost)' + ); + + if($message->code) + { + die $message->error.": ".$message->error_desc; + } + foreach ($message->entries) + { + my $asn=$_->{'asn'}; + my $attr=$asn->{'attributes'}; + foreach (@$attr) + { + my $type=$_->{'type'}; + my $value=$_->{'vals'}[0]; + if( $type eq 'description' ) + { + my @words=split(":",$value); + return (@words[0], @words[1]); + } + } + } } sub checkAndStartSession { - my ($uid,$host,$sid)=@_; - my ($status,$sessions)=check_ts($host,$uid); - if(!$status) - { - print "ERROR check TS\n"; - return; - } - my $running=0; - if($sessions) - { - my @sinfo=split("\\|",$sessions); - my $sess_stat=@sinfo[4]; - my $sess_srv=@sinfo[3]; - $sid=@sinfo[1]; - if($sess_stat eq 'R') - { - $running=1; - my $str; - ($status,$str)=remoteBroker($host,$uid,"suspend $sid"); - $sessions=~s/\|R\|/\|S\|/; - } - if($sess_stat eq 'S') - { - $running=1; - } - } - - my($ip,$port)=getExtCon($host); - print "SERVER:$ip:$port\n"; - if($running) - { - print "SESSION_INFO:".(split("\n",$sessions))[0]."\n"; - } + my ($uid,$host,$sid)=@_; + my ($status,$sessions)=check_ts($host,$uid); + if(!$status) + { + print "ERROR check TS\n"; + return; + } + my $running=0; + if( $sessions ) + { + my @sinfo=split("\\|",$sessions); + my $sess_stat=@sinfo[4]; + my $sess_srv=@sinfo[3]; + $sid=@sinfo[1]; + if( $sess_stat eq 'R' ) + { + $running=1; + my $str; + ($status,$str)=remoteBroker($host,$uid,"suspend $sid"); + $sessions=~s/\|R\|/\|S\|/; + } + if( $sess_stat eq 'S' ) + { + $running=1; + } + } + + my($ip,$port)=getExtCon($host); + print "SERVER:$ip:$port\n"; + if($running) + { + print "SESSION_INFO:".(split("\n",$sessions))[0]."\n"; + } } sub checkRunningSession { - my ($sess_srv, $sess_stat, $server_dn, $uid, $sid, $ldap)=@_; - my @dn_el=split(',',$server_dn); - shift(@dn_el); - shift(@dn_el); - my $node_dn="cn=".$sess_srv.",ou=Hosts,".join(',',@dn_el); - my $mesg=$ldap->search(base => $node_dn, - scope => 'base', filter => '(objectClass=X2GoServerNode)'); - if(!$mesg->code) - { - my @entries=$mesg->entries(); - if(@entries[0]->get_value('serverStatus') eq 'TRUE') - { - my $node_ref={}; - $node_ref->{'ip'}=@entries[0]->get_value('ipHostNumber'); - $node_ref->{'dn'}=$node_dn; - my $status; - my $str; - if($sess_stat eq 'R') + my ($sess_srv, $sess_stat, $server_dn, $uid, $sid, $ldap)=@_; + my @dn_el=split(',',$server_dn); + shift(@dn_el); + shift(@dn_el); + my $node_dn="cn=".$sess_srv.",ou=Hosts,".join(',',@dn_el); + #### + #### FIXME: get scope from config file in /etc/x2go/x2gobroker-*.conf + #### + my $mesg=$ldap->search(base => $node_dn, + scope => 'base', + filter => '(objectClass=X2GoServerNode)' + ); + if(!$mesg->code) { - print "session running, suspend session $sid\n"; - ($status,$str)=remoteBroker($node_ref->{'ip'},$uid,"suspend $sid",$node_ref->{'dn'}, $ldap); + my @entries=$mesg->entries(); + if(@entries[0]->get_value('serverStatus') eq 'TRUE') + { + my $node_ref={}; + $node_ref->{'ip'}=@entries[0]->get_value('ipHostNumber'); + $node_ref->{'dn'}=$node_dn; + my $status; + my $str; + if( $sess_stat eq 'R' ) + { + print "session running, suspend session $sid\n"; + ($status,$str)=remoteBroker($node_ref->{'ip'},$uid,"suspend $sid",$node_ref->{'dn'}, $ldap); + } else { + print "session not running, ping node\n"; + ($status,$str)=remoteBroker($node_ref->{'ip'},$uid,'ping',$node_ref->{'dn'}, $ldap); + } + if($status) + { + return $node_ref; + } + print "error executing remote broker \n"; + } + print "node is down \n"; + return 0; } - else - { - print "session not running, ping node\n"; - ($status,$str)=remoteBroker($node_ref->{'ip'},$uid,'ping',$node_ref->{'dn'}, $ldap); - } - if($status) - { - return $node_ref; - } - print "error executing remote broker \n"; - } - print "node is down \n"; - return 0; - } - print "error searching $node_dn: ".$mesg->error."\n"; - return 0; + print "error searching $node_dn: ".$mesg->error."\n"; + return 0; } sub startNewSession { - my ($dn, $ldap, $uid)=@_; - my $mesg=$ldap->search(base => $dn, - scope => 'base', filter => '(objectClass=X2GoServer)'); - - if($mesg->code) - { - return 0; - } - - my @entries=$mesg->entries(); - my $ref = @entries[0]->get_value ( 'serverNode', asref => 1 ); - my $nodes; - foreach(@$ref) - { - my $server=$_; - my @sdn=split(",",$dn); - shift(@sdn); - shift(@sdn); - my $server_dn="cn=$server,ou=Hosts,".join(",",@sdn); - - my $mesg=$ldap->search(base => $server_dn, - scope => 'base', filter => '(objectClass=X2GoServerNode)'); - if(!$mesg->code) - { - my @entries=$mesg->entries(); - if(@entries[0]->get_value('serverStatus') eq 'TRUE') - { - my $node_ref={}; - $node_ref->{'ip'}=@entries[0]->get_value('ipHostNumber'); - $node_ref->{'sessions'}=0; - $node_ref->{'dn'}=$server_dn; - $nodes->{$server}=$node_ref; - } - } - } - return findBestServer($nodes,$ldap, $uid); + my ($dn, $ldap, $uid)=@_; + #### + #### FIXME: get scope from config file in /etc/x2go/x2gobroker-*.conf + #### + my $mesg=$ldap->search(base => $dn, + scope => 'base', + filter => '(objectClass=X2GoServer)' + ); + + if($mesg->code) + { + return 0; + } + + my @entries=$mesg->entries(); + my $ref = @entries[0]->get_value ( 'serverNode', asref => 1 ); + my $nodes; + foreach(@$ref) + { + my $server=$_; + my @sdn=split(",",$dn); + shift(@sdn); + shift(@sdn); + my $server_dn="cn=$server,ou=Hosts,".join(",",@sdn); + + my $mesg=$ldap->search(base => $server_dn, + scope => 'base', + filter => '(objectClass=X2GoServerNode)' + ); + if( ! $mesg->code ) + { + my @entries=$mesg->entries(); + if(@entries[0]->get_value('serverStatus') eq 'TRUE') + { + my $node_ref={}; + $node_ref->{'ip'}=@entries[0]->get_value('ipHostNumber'); + $node_ref->{'sessions'}=0; + $node_ref->{'dn'}=$server_dn; + $nodes->{$server}=$node_ref; + } + } + } + return findBestServer($nodes,$ldap, $uid); } sub findBestServer { - my ($nodes, $ldap, $user)=@_; - my $servers; - my $status; - while( my ($key,$value) = each(%$nodes)) - { - if(!$status) - { - my $ip=$value->{'ip'}; - my $dn=$value->{'dn'}; - ($status,$servers)=remoteBroker($ip,$user,'getservers',$dn, $ldap); - if(!$status) + my ($nodes, $ldap, $user)=@_; + my $servers; + my $status; + while( my ($key,$value) = each(%$nodes)) + { + if( ! $status ) + { + my $ip=$value->{'ip'}; + my $dn=$value->{'dn'}; + ($status,$servers)=remoteBroker($ip,$user,'getservers',$dn, $ldap); + if(!$status) + { + delete $nodes->{$key}; + } + } + } + if( ! $status ) + { + return 0; + } + my @srvlines=split("\n",$servers); + foreach(@srvlines) { - delete $nodes->{$key}; + my @words=split(' ',$_); + my $ref=$nodes->{@words[0]}; + if( $ref ) + { + $ref->{'sessions'}=1*@words[1]; + } } - } - } - if(!$status) - { - return 0; - } - my @srvlines=split("\n",$servers); - foreach(@srvlines) - { - my @words=split(' ',$_); - my $ref=$nodes->{@words[0]}; - if($ref) - { - $ref->{'sessions'}=1*@words[1]; - } - } - return checkServers($nodes, $ldap, $user); + return checkServers($nodes, $ldap, $user); } sub checkServers -{ - my ($nodes, $ldap, $user)=@_; - my $bestnode=0; - my $bestnodekey; - my $key; - my $value; - while( ($key,$value) = each(%$nodes)) - { - if(! $bestnode) - { - $bestnode=$value; - $bestnodekey=$key; - } - else - { - if($value->{'sessions'}<$bestnode->{'sessions'}) +{ + my ($nodes, $ldap, $user)=@_; + my $bestnode=0; + my $bestnodekey; + my $key; + my $value; + while( ($key,$value) = each(%$nodes)) + { + if(! $bestnode) + { + $bestnode=$value; + $bestnodekey=$key; + } else { + if($value->{'sessions'}<$bestnode->{'sessions'}) + { + $bestnode=$value; + $bestnodekey=$key; + } + } + } + if( ! $bestnode ) { - $bestnode=$value; - $bestnodekey=$key; + print "bestnode is null: \n"; + return 0; + } else { + my $ip=$bestnode->{'ip'}; + my $dn=$bestnode->{'dn'}; + my ($status,$fakearr)=remoteBroker($ip,$user,'ping',$dn, $ldap); + if( ! $status ) + { + delete $nodes->{$bestnodekey}; + return checkServers($nodes, $ldap, $user); + } else { + return $bestnode; + } } - } - } - if(!$bestnode) - { - print "bestnode is null: \n"; - return 0; - } - else - { - my $ip=$bestnode->{'ip'}; - my $dn=$bestnode->{'dn'}; - my ($status,$fakearr)=remoteBroker($ip,$user,'ping',$dn, $ldap); - if(!$status) - { - delete $nodes->{$bestnodekey}; - return checkServers($nodes, $ldap, $user); - } - else - { - return $bestnode; - } - } } sub check_ts { - my ($host, $user)=@_; - my $server_dn; - my $ldap; - my($status,$sessions)=getSessionRunning($server_dn, - $host, - $user, $ldap); - if($status) - { - return (1,$sessions); - } - return (0,0); + my ($host, $user)=@_; + my $server_dn; + my $ldap; + my($status,$sessions)=getSessionRunning($server_dn, $host, $user, $ldap); + if( $status ) + { + return (1,$sessions); + } + return (0,0); } sub getSessionRunning { - my ($dn,$ip,$user, $ldap)=@_; - my ($status,$sessions)=remoteBroker($ip,$user,'listsessions', $dn, $ldap); - if(!$status) - { - return (0,0); - } - else - { - return (1,$sessions); - } + my ($dn,$ip,$user, $ldap)=@_; + my ($status,$sessions)=remoteBroker($ip,$user,'listsessions', $dn, $ldap); + if( ! $status ) + { + return (0,0); + } else { + return (1,$sessions); + } } sub remoteBroker { - my ($ip, $user, $cmd, $dn, $ldap)=@_; - my $res=`ssh -o ConnectTimeout=15 -o UserKnownHostsFile=/etc/x2go/x2gobroker/ts_known_hosts x2gobroker\@$ip -i /etc/x2go/x2gobroker/id_x2gobroker_dsa \"/usr/lib/x2go/broker/x2gobroker-command $user $cmd 2>/dev/null\"`; - my @rarr=split("\n",$res); - my $stat; - if(@rarr[0] eq 'OK') - { - $stat=1; - } - else - { - $stat=0; -# setNodeDown($dn, $ldap, $cmd, $user); - } - shift(@rarr); - return($stat,join("\n",@rarr)); + my ($ip, $user, $cmd, $dn, $ldap)=@_; + my $res=`ssh -o ConnectTimeout=15 -o UserKnownHostsFile=/etc/x2go/x2gobroker/ts_known_hosts x2gobroker\@$ip -i /etc/x2go/x2gobroker/id_x2gobroker_dsa \"/usr/lib/x2go/broker/x2gobroker-command $user $cmd 2>/dev/null\"`; + my @rarr=split("\n",$res); + my $stat; + if(@rarr[0] eq 'OK') + { + $stat=1; + } else { + $stat=0; + # setNodeDown($dn, $ldap, $cmd, $user); + } + shift(@rarr); + return($stat,join("\n",@rarr)); } sub notify { - my $message=shift; - open (F,">>/tmp/x2gobroker.log"); - print F `date`.$message."\n"; - close(F); + my $message=shift; + open (F,">>/tmp/x2gobroker.log"); + print F `date`.$message."\n"; + close(F); } sub setNodeDown { - my($dn, $ldap, $cmd, $user)=@_; - my $attr; - push(@$attr,'serverStatus' => 'FALSE'); - my $changes; - push (@$changes, 'replace' => $attr); - $ldap->modify($dn,changes => $changes); - notify ("set status of $dn to \"down\", failed command: \"$cmd\", user: \"$user\"\n"); + my($dn, $ldap, $cmd, $user)=@_; + my $attr; + push(@$attr,'serverStatus' => 'FALSE'); + my $changes; + push (@$changes, 'replace' => $attr); + $ldap->modify($dn,changes => $changes); + notify ("set status of $dn to \"down\", failed command: \"$cmd\", user: \"$user\"\n"); } sub setServerDown { - my($dn, $ldap)=@_; - my $attr; - push(@$attr,'serverStatus' => 'FALSE'); - my $changes; - push (@$changes, 'replace' => $attr); - $ldap->modify($dn,changes => $changes); - notify ("set status of $dn to \"down\", all nodes are down\n"); + my($dn, $ldap)=@_; + my $attr; + push(@$attr,'serverStatus' => 'FALSE'); + my $changes; + push (@$changes, 'replace' => $attr); + $ldap->modify($dn,changes => $changes); + notify ("set status of $dn to \"down\", all nodes are down\n"); } sub checkAccess { - my ($user,$pass)=@_; - - my $ldap = initLdap(); - - - my $dn="uid=$user,ou=People".getBase($binddn); - my $mesg=$ldap->search(base => $dn, - scope => 'base', filter => '(objectClass=posixAccount)'); - - if($mesg->code) + my ($user,$pass)=@_; + + my $ldap = initLdap(); + + my $dn="uid=$user,ou=People".getBase($binddn); + my $mesg=$ldap->search(base => $dn, + scope => 'base', + filter => '(objectClass=posixAccount)' + ); + + if( $mesg->code ) { - return 0; + return 0; } my @entries=$mesg->entries(); my $crypted=@entries[0]->get_value('userPassword'); $mesg = $ldap->unbind; - if(Crypt::SaltedHash->validate($crypted, $pass)) + if ( Crypt::SaltedHash->validate($crypted, $pass) ) { - return 1; + return 1; } return 0; } sub listSessions { - my $user=shift; - - my $ldap = initLdap(); - - my $dn="ou=Servers,ou=ON".getBase($binddn); - my $message=$ldap->search(base => $dn, - scope => 'sub', filter => '(objectClass=ipHost)'); - - if($message->code) - { - die $message->error.": ".$message->error_desc; - } -# print Dumper($message->entries); - print "START_USER_SESSIONS<br>"; - foreach ($message->entries) - { - my $asn=$_->{'asn'}; - my $attr=$asn->{'attributes'}; - my $host; - my $int_ip; - my $ext_ip; - my $ext_port; - foreach (@$attr) - { - my $type=$_->{'type'}; - my $value=$_->{'vals'}[0]; - if($type eq 'cn') - { - $host=$value; - } - } - my($status,$sessions)=getSessionRunning($dn,$host,$user, $ldap); - if($status) - { - my $sess_srv; - if($sessions) - { - my @sinfo=split("\\|",$sessions); - my $sess_stat=@sinfo[4]; - $sess_srv=@sinfo[3]; - my $sid=@sinfo[1]; - print "<br>[$host\@$sid]<br>"; - print "status=$sess_stat<br>"; - #get ip - #get port - } - else - { - my $sessions; - ($sess_srv,$ext_ip,$ext_port, $sessions)=getBestNode($dn, $ldap, $user, $host, $message); - print "<br>[$host]<br>"; - } - #print "host=$ext_ip<br>"; - print "user=$user<br>"; - #print "sshport=$ext_port<br>"; - print "name=Stadt Treuchtlingen<br>"; - goto loop_end; - } - } -loop_end: - print "END_USER_SESSIONS<br>"; - $ldap->unbind(); + my $user=shift; + + my $ldap = initLdap(); + + my $dn="ou=Servers,ou=ON".getBase($binddn); + my $message=$ldap->search(base => $dn, + scope => 'sub', + filter => '(objectClass=ipHost)' + ); + + if($message->code) + { + die $message->error.": ".$message->error_desc; + } + # print Dumper($message->entries); + print "START_USER_SESSIONS<br>"; + foreach ($message->entries) + { + my $asn=$_->{'asn'}; + my $attr=$asn->{'attributes'}; + my $host; + my $int_ip; + my $ext_ip; + my $ext_port; + foreach (@$attr) + { + my $type=$_->{'type'}; + my $value=$_->{'vals'}[0]; + if( $type eq 'cn' ) + { + $host=$value; + } + } + my($status,$sessions)=getSessionRunning($dn,$host,$user, $ldap); + if($status) + { + my $sess_srv; + if($sessions) + { + my @sinfo=split("\\|",$sessions); + my $sess_stat=@sinfo[4]; + $sess_srv=@sinfo[3]; + my $sid=@sinfo[1]; + print "<br>[$host\@$sid]<br>"; + print "status=$sess_stat<br>"; + #get ip + #get port + } else { + my $sessions; + ($sess_srv,$ext_ip,$ext_port, $sessions)=getBestNode($dn, $ldap, $user, $host, $message); + print "<br>[$host]<br>"; + } + #print "host=$ext_ip<br>"; + print "user=$user<br>"; + #print "sshport=$ext_port<br>"; + print "name=Stadt Treuchtlingen<br>"; + goto loop_end; + } + } + loop_end: + print "END_USER_SESSIONS<br>"; + $ldap->unbind(); } sub getBestNode { - my ($dn, $ldap, $user, $ip, $message)=@_; - my $servers; - my $status; - ($status,$servers)=remoteBroker($ip,$user,'getservers',$dn, $ldap); - my $srvref={}; - my @srvlines=split("\n",$servers); - foreach(@srvlines) - { - my @words=split(' ',$_); - $srvref->{@words[0]}=1*@words[1]; - } - my $bestval=-1; - my $bestsrv; - my $bestext_ip; - my $bestext_port; - foreach ($message->entries) - { - my $asn=$_->{'asn'}; - my $attr=$asn->{'attributes'}; - my $host; - my $ext_ip; - my $ext_port; - foreach (@$attr) - { - my $type=$_->{'type'}; - my $value=$_->{'vals'}[0]; - if($type eq 'cn') - { - $host=$value; - } - if($type eq 'description') - { - my @words=split(":",$value); - $ext_ip=@words[0]; - $ext_port=@words[1]; - } - } - my $sess=$srvref->{$host}; - if(! $sess) - { - return($host, $ext_ip, $ext_port,0); - } - if($sess < $bestval || $bestval == -1) - { - $bestval=$sess; - $bestsrv=$host; - $bestext_ip=$ext_ip; - $bestext_port=$ext_port; - } - } - return($bestsrv, $bestext_ip, $bestext_port, $bestval); + my ($dn, $ldap, $user, $ip, $message)=@_; + my $servers; + my $status; + ($status,$servers)=remoteBroker($ip,$user,'getservers',$dn, $ldap); + my $srvref={}; + my @srvlines=split("\n",$servers); + foreach(@srvlines) + { + my @words=split(' ',$_); + $srvref->{@words[0]}=1*@words[1]; + } + my $bestval=-1; + my $bestsrv; + my $bestext_ip; + my $bestext_port; + foreach ($message->entries) + { + my $asn=$_->{'asn'}; + my $attr=$asn->{'attributes'}; + my $host; + my $ext_ip; + my $ext_port; + foreach (@$attr) + { + my $type=$_->{'type'}; + my $value=$_->{'vals'}[0]; + if( $type eq 'cn' ) + { + $host=$value; + } + if($type eq 'description') + { + my @words=split(":",$value); + $ext_ip=@words[0]; + $ext_port=@words[1]; + } + } + my $sess=$srvref->{$host}; + if( ! $sess ) + { + return($host, $ext_ip, $ext_port,0); + } + if($sess < $bestval || $bestval == -1) + { + $bestval=$sess; + $bestsrv=$host; + $bestext_ip=$ext_ip; + $bestext_port=$ext_port; + } + } + return($bestsrv, $bestext_ip, $bestext_port, $bestval); } 1; hooks/post-receive -- x2gobroker.git (HTTP(S) Session broker for X2Go) 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 "x2gobroker.git" (HTTP(S) Session broker for X2Go).