From 59641ae69085a6dca3410d0e40a7d9ad7190938b Mon Sep 17 00:00:00 2001 From: janw Date: Fri, 18 Jan 2008 09:45:08 +0000 Subject: [PATCH] Removed unused code. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8487 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si-poe/gosa-si-server | 376 +------------------------- gosa-si-poe/modules/ServerPackages.pm | 182 ++++++------- 2 files changed, 93 insertions(+), 465 deletions(-) diff --git a/gosa-si-poe/gosa-si-server b/gosa-si-poe/gosa-si-server index 505cf01ba..343641e6a 100755 --- a/gosa-si-poe/gosa-si-server +++ b/gosa-si-poe/gosa-si-server @@ -10,6 +10,7 @@ # OPTIONS: --- # REQUIREMENTS: libconfig-inifiles-perl libcrypt-rijndael-perl libxml-simple-perl # libdata-dumper-simple-perl libdbd-sqlite3-perl libnet-ldap-perl +# libpoe-perl # BUGS: --- # NOTES: # AUTHOR: (Andreas Rettenberger), @@ -19,7 +20,6 @@ # REVISION: --- #=============================================================================== - use strict; use warnings; use Getopt::Long; @@ -368,374 +368,6 @@ sub sig_int_handler { $SIG{INT} = \&sig_int_handler; -#=== FUNCTION ================================================================ -# NAME: activating_child -# PARAMETERS: msg - string - incoming message -# host - string - host from which the incomming message comes -# RETURNS: nothing -# DESCRIPTION: handels the distribution of incoming messages to working childs -#=============================================================================== -sub activating_child { - my ($msg, $host, $client) = @_; - my $child = &get_processing_child(); - if(!$child) { - daemon_log("Got no child! Trying again", 5); - sleep(1); - $child = &get_processing_child(); - if(!$child) { - daemon_log("Got no child at the second try! Trying again", 5); - } - } - my $pipe_wr = $$child{'pipe_wr'}; - my $pipe_rd = $$child{'pipe_rd'}; - $$child{client_ref} = $client; - - daemon_log("activating: childpid:$$child{'pid'}", 5); - - print $pipe_wr $msg.".".$host."\n"; - - return; -} - - -#=== FUNCTION ================================================================ -# NAME: get_processing_child -# PARAMETERS: nothing -# RETURNS: child - hash - holding the process id and the references to the pipe -# handles pipe_wr and pipe_rd -# DESCRIPTION: handels the forking, reactivating and keeping alive tasks -#=============================================================================== -sub get_processing_child { - my $child; - - while(my ($key, $val) = each(%free_child)) { - my $exitus_pid = waitpid($key, WNOHANG); - if($exitus_pid != 0) { - delete $free_child{$key}; - } - daemon_log("free child:$key", 5); - } - # check @free_child and @busy_child - my $free_len = scalar(keys(%free_child)); - my $busy_len = scalar(keys(%busy_child)); - daemon_log("free children $free_len, busy children $busy_len", 5); - - # if there is a free child, let the child work - if($free_len > 0){ - my @keys = keys(%free_child); - $child = $free_child{$keys[0]}; - if(defined $child) { - $busy_child{$$child{'pid'}} = $child ; - delete $free_child{$$child{'pid'}}; - } - return $child; - } - - # no free child, try to fork another one - if($free_len + $busy_len < $child_max) { - - daemon_log("not enough children, create a new one", 5); - - # New pipes for communication - my( $PARENT_wr, $PARENT_rd ); - my( $CHILD_wr, $CHILD_rd ); - pipe( $CHILD_rd, $PARENT_wr ); - pipe( $PARENT_rd, $CHILD_wr ); - $PARENT_wr->autoflush(1); - $CHILD_wr->autoflush(1); - - ############ - # fork child - ############ - my $child_pid = fork(); - - #CHILD - if($child_pid == 0) { - # Close unused pipes - close( $CHILD_rd ); - close( $CHILD_wr ); - while( 1 ) { - my $rbits = ""; - vec( $rbits, fileno $PARENT_rd , 1 ) = 1; - my $nf = select($rbits, undef, undef, $child_timeout); - if($nf < 0 ) { - die "select(): $!\n"; - } elsif (! $nf) { - # if already child_min childs are alive, then leave loop - $free_len = scalar(keys(%free_child)); - $busy_len = scalar(keys(%busy_child)); - if($free_len + $busy_len >= $child_min) { - last; - } else { - redo; - } - } - - # a job for a child arise - if ( vec $rbits, fileno $PARENT_rd, 1 ) { - # read everything from pipe - my $msg = ""; - $PARENT_rd->blocking(0); - while(1) { - my $read = <$PARENT_rd>; - if(not defined $read) { last} - $msg .= $read; - } - - ###################################### - # forward msg to all imported modules - no strict "refs"; - my $answer; - my %act_modules = %$known_modules; - while( my ($module, $info) = each(%act_modules)) { - my $tmp = &{ $module."::process_incoming_msg" }($msg); - if (defined $tmp) { - $answer = $tmp; - } - } - daemon_log("processing of msg finished", 5); - - if (defined $answer) { - print $PARENT_wr $answer."\n"; - print $PARENT_wr "ENDMESSAGE\n"; - my $len_answer = length $answer; - daemon_log("with answer: length of answer: $len_answer", 7); - daemon_log("\n$answer", 7); - } else { - print $PARENT_wr "done"."\n"; - print $PARENT_wr "ENDMESSAGE\n"; - } - redo; - } - } - # childs leaving the loop are allowed to die - exit(0); - - - #PARENT - } else { - # Close unused pipes - close( $PARENT_rd ); - close( $PARENT_wr ); - - # add child to child alive hash - my %child_hash = ( - 'pid' => $child_pid, - 'pipe_wr' => $CHILD_wr, - 'pipe_rd' => $CHILD_rd, - 'client_ref' => "", - ); - - $child = \%child_hash; - $busy_child{$$child{'pid'}} = $child; - return $child; - } - } -} - - -#=== FUNCTION ================================================================ -# NAME: read_from_socket -# PARAMETERS: socket fh - -# RETURNS: result string - readed characters from socket -# DESCRIPTION: reads data from socket in 16 byte steps -#=============================================================================== -sub read_from_socket { - my ($socket) = @_; - my $result = ""; - - $socket->blocking(1); - $result = <$socket>; - - $socket->blocking(0); - while ( my $char = <$socket> ) { - if (not defined $char) { last } - $result .= $char; - } - - return $result; -} - - -#=== FUNCTION ================================================================ -# NAME: print_known_daemons -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: nomen est omen -#=============================================================================== -#sub print_known_daemons { -# my ($tmp) = @_ ; -# print "####################################\n"; -# print "# status of known_daemons\n"; -# $shmda->shlock(LOCK_EX); -# my @hosts = keys %$known_daemons; -# foreach my $host (@hosts) { -# my $status = $known_daemons->{$host}->{status} ; -# my $passwd = $known_daemons->{$host}->{passwd}; -# my $timestamp = $known_daemons->{$host}->{timestamp}; -# print "$host\n"; -# print "\tstatus: $status\n"; -# print "\tpasswd: $passwd\n"; -# print "\ttimestamp: $timestamp\n"; -# } -# $shmda->shunlock(LOCK_EX); -# print "####################################\n"; -# return; -#} - - -#=== FUNCTION ================================================================ -# NAME: create_known_daemon -# PARAMETERS: hostname - string - key for the hash known_daemons -# RETURNS: nothing -# DESCRIPTION: creates a dummy entry for hostname in known_daemons -#=============================================================================== -#sub create_known_daemon { -# my ($hostname) = @_; -# $shmda->shlock(LOCK_EX); -# $known_daemons->{$hostname} = {}; -# $known_daemons->{$hostname}->{status} = "none"; -# $known_daemons->{$hostname}->{passwd} = "none"; -# $known_daemons->{$hostname}->{timestamp} = "none"; -# $shmda->shunlock(LOCK_EX); -# return; -#} - - -#=== FUNCTION ================================================================ -# NAME: add_content2known_daemons -# PARAMETERS: hostname - string - ip address and port of host (required) -# status - string - (optional) -# passwd - string - (optional) -# mac_address - string - mac address of host (optional) -# RETURNS: nothing -# DESCRIPTION: nome est omen and updates each time the timestamp of hostname -#=============================================================================== -#sub add_content2known_daemons { -# my $arg = { -# hostname => undef, status => undef, passwd => undef, -# mac_address => undef, events => undef, -# @_ }; -# my $hostname = $arg->{hostname}; -# my $status = $arg->{status}; -# my $passwd = $arg->{passwd}; -# my $mac_address = $arg->{mac_address}; -# my $events = $arg->{events}; -# -# if (not defined $hostname) { -# daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1); -# return; -# } -# -# my ($seconds, $minutes, $hours, $monthday, $month, -# $year, $weekday, $yearday, $sommertime) = localtime(time); -# $hours = $hours < 10 ? $hours = "0".$hours : $hours; -# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes; -# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds; -# $month+=1; -# $month = $month < 10 ? $month = "0".$month : $month; -# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday; -# $year+=1900; -# my $t = "$year$month$monthday$hours$minutes$seconds"; -# -# $shmda->shlock(LOCK_EX); -# if (defined $status) { -# $known_daemons->{$hostname}->{status} = $status; -# } -# if (defined $passwd) { -# $known_daemons->{$hostname}->{passwd} = $passwd; -# } -# if (defined $mac_address) { -# $known_daemons->{$hostname}->{mac_address} = $mac_address; -# } -# if (defined $events) { -# $known_daemons->{$hostname}->{events} = $events; -# } -# $known_daemons->{$hostname}->{timestamp} = $t; -# $shmda->shlock(LOCK_EX); -# return; -#} - - -#=== FUNCTION ================================================================ -# NAME: update_known_daemons -# PARAMETERS: hostname - string - ip address and port of host (required) -# status - string - (optional) -# passwd - string - (optional) -# client - string - ip address and port of client (optional) -# RETURNS: nothing -# DESCRIPTION: nome est omen and updates each time the timestamp of hostname -#=============================================================================== -#sub update_known_daemons { -# my $arg = { -# hostname => undef, status => undef, passwd => undef, -# @_ }; -# my $hostname = $arg->{hostname}; -# my $status = $arg->{status}; -# my $passwd = $arg->{passwd}; -# -# if (not defined $hostname) { -# daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1); -# return; -# } -# -# my ($seconds, $minutes, $hours, $monthday, $month, -# $year, $weekday, $yearday, $sommertime) = localtime(time); -# $hours = $hours < 10 ? $hours = "0".$hours : $hours; -# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes; -# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds; -# $month+=1; -# $month = $month < 10 ? $month = "0".$month : $month; -# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday; -# $year+=1900; -# my $t = "$year$month$monthday$hours$minutes$seconds"; -# -# $shmda->shlock(LOCK_EX); -# if (defined $status) { -# $known_daemons->{$hostname}->{status} = $status; -# } -# if (defined $passwd) { -# $known_daemons->{$hostname}->{passwd} = $passwd; -# } -# $known_daemons->{$hostname}->{timestamp} = $t; -# $shmda->shunlock(LOCK_EX); -# return; -#} - - -#=== FUNCTION ================================================================ -# NAME: print_known_clients -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: nomen est omen -#=============================================================================== -#sub print_known_clients { -# -# print "####################################\n"; -# print "# status of known_clients\n"; -# $shmcl->shlock(LOCK_EX); -# my @hosts = keys %$known_clients; -# if (@hosts) { -# foreach my $host (@hosts) { -# my $status = $known_clients->{$host}->{status} ; -# my $passwd = $known_clients->{$host}->{passwd}; -# my $timestamp = $known_clients->{$host}->{timestamp}; -# my $mac_address = $known_clients->{$host}->{mac_address}; -# my $events = $known_clients->{$host}->{events}; -# print "$host\n"; -# print "\tstatus: $status\n"; -# print "\tpasswd: $passwd\n"; -# print "\ttimestamp: $timestamp\n"; -# print "\tmac_address: $mac_address\n"; -# print "\tevents: $events\n"; -# } -# } -# $shmcl->shunlock(LOCK_EX); -# print "####################################\n"; -# return; -#} - - #=== FUNCTION ================================================================ # NAME: create_known_client # PARAMETERS: hostname - string - key for the hash known_clients @@ -762,7 +394,6 @@ sub create_known_client { } #==== MAIN = main ============================================================== - # parse commandline options Getopt::Long::Configure( "bundling" ); GetOptions("h|help" => \&usage, @@ -778,7 +409,6 @@ GetOptions("h|help" => \&usage, &read_configfile; &check_pid; - $SIG{CHLD} = 'IGNORE'; # forward error messages to logfile @@ -1045,7 +675,7 @@ my $rbits = my $wbits = my $ebits = ""; # # #} -print STDERR "Server Port: $server_port\n"; + POE::Component::Server::TCP->new ( Port => $server_port, @@ -1057,7 +687,6 @@ exit; sub client_input { my ($heap,$input,$wheel) = @_[HEAP, ARG0, ARG1]; - #print STDERR Dumper($heap); ###################################### # forward msg to all imported modules no strict "refs"; @@ -1078,5 +707,4 @@ sub client_input { } else { $heap->{client}->put("done\n"); } - #redo; } diff --git a/gosa-si-poe/modules/ServerPackages.pm b/gosa-si-poe/modules/ServerPackages.pm index d20b66489..95baac87a 100644 --- a/gosa-si-poe/modules/ServerPackages.pm +++ b/gosa-si-poe/modules/ServerPackages.pm @@ -358,7 +358,7 @@ sub process_incoming_msg { my $host_name; my $host_key; -# # check wether incoming msg is a new msg + # check wether incoming msg is a new msg $host_name = $server_address; $host_key = $server_passwd; &main::daemon_log("ServerPackage: host_name: $host_name", 7); @@ -377,34 +377,34 @@ sub process_incoming_msg { $host_key = undef; } -# # check wether incoming msg is from a known_server -# if( not defined $msg ) { -# my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server'} ); -# while( my ($hit_num, $hit) = each %{ $query_res } ) { -# $host_name = $hit->{hostname}; -# if( not $host_name =~ "^$host") { -# next; -# } -# $host_key = $hit->{hostkey}; -# &main::daemon_log("ServerPackage: host_name: $host_name", 7); -# &main::daemon_log("ServerPackage: host_key: $host_key", 7); -# eval{ -# my $key_cipher = &create_ciphering($host_key); -# $msg = &decrypt_msg($crypted_msg, $key_cipher); -# $msg_hash = &transform_msg2hash($msg); -# }; -# if($@) { -# &main::daemon_log("ServerPackage: deciphering raise error", 7); -# &main::daemon_log("$@", 8); -# $msg = undef; -# $msg_hash = undef; -# $host_name = undef; -# $host_key = undef; -# } else { -# last; -# } -# } -# } + # check wether incoming msg is from a known_server + if( not defined $msg ) { + my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server'} ); + while( my ($hit_num, $hit) = each %{ $query_res } ) { + $host_name = $hit->{hostname}; + if( not $host_name =~ "^$host") { + next; + } + $host_key = $hit->{hostkey}; + &main::daemon_log("ServerPackage: host_name: $host_name", 7); + &main::daemon_log("ServerPackage: host_key: $host_key", 7); + eval{ + my $key_cipher = &create_ciphering($host_key); + $msg = &decrypt_msg($crypted_msg, $key_cipher); + $msg_hash = &transform_msg2hash($msg); + }; + if($@) { + &main::daemon_log("ServerPackage: deciphering raise error", 7); + &main::daemon_log("$@", 8); + $msg = undef; + $msg_hash = undef; + $host_name = undef; + $host_key = undef; + } else { + last; + } + } + } # check wether incoming msg is from a known_client if( not defined $msg ) { @@ -445,70 +445,70 @@ sub process_incoming_msg { my $header = @{$msg_hash->{header}}[0]; my $source = @{$msg_hash->{source}}[0]; -# &main::daemon_log("recieve '$header' at ServerPackages from $host", 1); + &main::daemon_log("receive '$header' at ServerPackages from $host", 1); &main::daemon_log("ServerPackages: msg to process: \n$msg", 5); -# my @targets = @{$msg_hash->{target}}; -# my $len_targets = @targets; -# if ($len_targets == 0){ -# &main::daemon_log("ERROR: ServerPackages: no target specified for msg $header", 1); -# -# } elsif ($len_targets == 1){ -# # we have only one target symbol -# my $target = $targets[0]; -# &main::daemon_log("SeverPackages: msg is for: $target", 7); -# -# # msg is for server -# if ($header eq 'new_passwd'){ &new_passwd($msg_hash)} -# elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)} -# elsif ($header eq 'who_has') { &who_has($msg_hash) } -# elsif ($header eq 'who_has_i_do') { &who_has_i_do($msg_hash)} -# elsif ($header eq 'update_status') { &update_status($msg_hash) } -# elsif ($header eq 'got_ping') { &got_ping($msg_hash)} -# elsif ($header eq 'get_load') { &execute_actions($msg_hash)} -# else { -# if ($target eq "*") { -# # msg is for all clients -# my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients'} ); -# while( my ($hit_num, $hit) = each %{ $query_res } ) { -# $host_name = $hit->{hostname}; -# $host_key = $hit->{hostkey}; -# $msg_hash->{target} = [$host_name]; -# &send_msg_hash2address($msg_hash, $host_name, $host_key); -# } -# -# } else { -# # msg is for one host -# my $host_key; -# -# -# if( not defined $host_key ) { -# my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} ); -# if( 1 == keys %{$query_res} ) { -# $host_key = $query_res->{1}->{host_key}; -# } -# } -# -# if( not defined $host_key ) { -# my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} ); -# if( 1 == keys %{$query_res} ) { -# $host_key = $query_res->{1}->{host_key}; -# } -# } -# -# if( not defined $host_key ) { -# &main::daemon_log("ERROR: ServerPackages: target '".$target. -# "' is not known neither in known_clients nor in known_server",1); -# } else { -# &send_msg_hash2address($msg_hash, $target, $host_key); -# } -# } -# } -# -# } elsif ($len_targets > 1 ) { -# # we have more than one target -# # TODO to be implemented -# } + my @targets = @{$msg_hash->{target}}; + my $len_targets = @targets; + if ($len_targets == 0){ + &main::daemon_log("ERROR: ServerPackages: no target specified for msg $header", 1); + + } elsif ($len_targets == 1){ + # we have only one target symbol + my $target = $targets[0]; + &main::daemon_log("SeverPackages: msg is for: $target", 7); + + # msg is for server + if ($header eq 'new_passwd'){ &new_passwd($msg_hash)} + elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)} + elsif ($header eq 'who_has') { &who_has($msg_hash) } + elsif ($header eq 'who_has_i_do') { &who_has_i_do($msg_hash)} + elsif ($header eq 'update_status') { &update_status($msg_hash) } + elsif ($header eq 'got_ping') { &got_ping($msg_hash)} + elsif ($header eq 'get_load') { &execute_actions($msg_hash)} + else { + if ($target eq "*") { + # msg is for all clients + my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients'} ); + while( my ($hit_num, $hit) = each %{ $query_res } ) { + $host_name = $hit->{hostname}; + $host_key = $hit->{hostkey}; + $msg_hash->{target} = [$host_name]; + &send_msg_hash2address($msg_hash, $host_name, $host_key); + } + + } else { + # msg is for one host + my $host_key; + + + if( not defined $host_key ) { + my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} ); + if( 1 == keys %{$query_res} ) { + $host_key = $query_res->{1}->{host_key}; + } + } + + if( not defined $host_key ) { + my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} ); + if( 1 == keys %{$query_res} ) { + $host_key = $query_res->{1}->{host_key}; + } + } + + if( not defined $host_key ) { + &main::daemon_log("ERROR: ServerPackages: target '".$target. + "' is not known neither in known_clients nor in known_server",1); + } else { + &send_msg_hash2address($msg_hash, $target, $host_key); + } + } + } + + } elsif ($len_targets > 1 ) { + # we have more than one target + # TODO to be implemented + } return ; } -- 2.30.2