From 6fe4f0e1bfb4d448112b21ac17fe5df4c2bd73e9 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Fri, 16 May 2008 10:04:52 +0000 Subject: [PATCH] * gosa-si-server without bus * not jet finished git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10928 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server-nobus | 55 ++++++++++++-------------- gosa-si/modules/DBsqlite.pm | 2 +- gosa-si/server/events/gosaTriggered.pm | 55 ++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 30 deletions(-) diff --git a/gosa-si/gosa-si-server-nobus b/gosa-si/gosa-si-server-nobus index 9da1bca0c..886d908a1 100755 --- a/gosa-si/gosa-si-server-nobus +++ b/gosa-si/gosa-si-server-nobus @@ -53,6 +53,7 @@ use GOSA::GosaSupportDaemon; use POE qw(Component::Server::TCP Wheel::Run Filter::Reference); use Net::LDAP; use Net::LDAP::Util qw(:escape); +use Time::HiRes qw( usleep); my $modules_path = "/usr/lib/gosa-si/modules"; use lib "/usr/lib/gosa-si/modules"; @@ -464,7 +465,7 @@ sub sig_int_handler { daemon_log("shutting down gosa-si-server", 1); - system("kill `ps -C gosa-si-server -o pid=`"); + system("kill `ps -C gosa-si-server-nobus -o pid=`"); } $SIG{INT} = \&sig_int_handler; @@ -594,7 +595,7 @@ sub input_from_known_server { } my $host_key = $hit->{hostkey}; daemon_log("$session_id DEBUG: input_from_known_server: host_name: $host_name", 7); - daemon_log("DEBUG: input_from_known_server: host_key: $host_key", 7); + daemon_log("$session_id DEBUG: input_from_known_server: host_key: $host_key", 7); # check if module can open msg envelope with module key my ($tmp_msg, $tmp_msg_hash) = &check_key_and_xml_validity($input, $host_key, $session_id); @@ -1067,17 +1068,15 @@ sub msg_to_decrypt { sub next_task { my ($session, $heap) = @_[SESSION, HEAP]; -# if (keys( %{ $heap->{task} } ) < $max_children ) { - my $task = POE::Wheel::Run->new( - Program => sub { process_task($session, $heap) }, - StdioFilter => POE::Filter::Reference->new(), - StdoutEvent => "task_result", - StderrEvent => "task_debug", - CloseEvent => "task_done", - ); + my $task = POE::Wheel::Run->new( + Program => sub { process_task($session, $heap) }, + StdioFilter => POE::Filter::Reference->new(), + StdoutEvent => "task_result", + StderrEvent => "task_debug", + CloseEvent => "task_done", + ); - $heap->{task}->{ $task->ID } = $task; -# } + $heap->{task}->{ $task->ID } = $task; } sub handle_task_result { @@ -1118,10 +1117,6 @@ sub process_task { my ($answer_header, @answer_target_l, $answer_source); my $client_answer = ""; - daemon_log("", 5); - daemon_log("$session_id INFO: Incoming msg with session ID $session_id from '".$heap->{'remote_ip'}."'", 5); - #daemon_log("$session_id DEBUG: Incoming msg:\n$input", 9); - ################################################## # fetch first unprocessed message from incoming_db # sometimes the program is faster than sqlite, so wait until informations are present at db @@ -1135,6 +1130,7 @@ sub process_task { $id_res = $incoming_db->exec_statement($id_sql); $message_id = @{@$id_res[0]}[0]; if (defined $message_id) { last } + usleep(100000); } # fetch new message from incoming_db @@ -1142,9 +1138,9 @@ sub process_task { my $res = $incoming_db->exec_statement($sql); # prepare all variables needed to process message - my $msg = @{@$res[0]}[3]; + my $msg = @{@$res[0]}[4]; my $incoming_id = @{@$res[0]}[0]; - my $module = @{@$res[0]}[4]; + my $module = @{@$res[0]}[5]; my $header = @{@$res[0]}[2]; my $msg_hash = $xml->XMLin($msg, ForceArray=>1); @@ -1160,16 +1156,19 @@ sub process_task { ###################### # process incoming msg if( $error == 0) { - daemon_log("$session_id INFO: Incoming msg with header '".@{$msg_hash->{'header'}}[0]. + daemon_log("$session_id INFO: Incoming msg (session_id=$session_id) with header '".@{$msg_hash->{'header'}}[0]. "' from '".$heap->{'remote_ip'}."'", 5); daemon_log("$session_id DEBUG: Processing module ".$module, 7); $answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id); if ( 0 < @{$answer_l} ) { my $answer_str = join("\n", @{$answer_l}); - daemon_log("$session_id DEBUG: $module: Got answer from module: \n".$answer_str,8); + while ($answer_str =~ /
(\w+)<\/header>/g) { + daemon_log("$session_id INFO: got answer message with header '$1'", 5); + } + daemon_log("$session_id DEBUG: $module: got answer from module: \n".$answer_str,8); } else { - daemon_log("$session_id DEBUG: $module: Got no answer from module!" ,8); + daemon_log("$session_id DEBUG: $module: got no answer from module!" ,8); } } @@ -1182,9 +1181,7 @@ sub process_task { foreach my $answer ( @{$answer_l} ) { # check outgoing msg to xml validity my $answer_hash = &check_outgoing_xml_validity($answer); - if( not defined $answer_hash ) { - next; - } + if( not defined $answer_hash ) { next; } $answer_header = @{$answer_hash->{'header'}}[0]; @answer_target_l = @{$answer_hash->{'target'}}; @@ -1463,13 +1460,13 @@ sub watch_for_new_messages { } elsif ($receiver =~ /^g_([\s\S]*)$/) { my $group_name = $1; # fetch all group members from ldap and add them to receiver hash - my $ldap_handle = &get_ldap_handle($session_id); + my $ldap_handle = &get_ldap_handle(); if (defined $ldap_handle) { my $mesg = $ldap_handle->search( base => $ldap_base, scope => 'sub', attrs => ['memberUid'], - filter => "cn=$group_name"; + filter => "cn=$group_name", ); if ($mesg->count) { my @entries = $mesg->entries; @@ -1482,11 +1479,11 @@ sub watch_for_new_messages { } # translating errors ? if ($mesg->code) { - daemon_log("$session_id ERROR: unable to translate group '$group_name' to user list for message delivery: $mesg->error", 1); + daemon_log("M ERROR: unable to translate group '$group_name' to user list for message delivery: $mesg->error", 1); } # ldap handle error ? } else { - daemon_log("$session_id ERROR: unable to translate group '$group_name' to user list for message delivery: no ldap handle available", 1); + daemon_log("M ERROR: unable to translate group '$group_name' to user list for message delivery: no ldap handle available", 1); } } else { my $sbjct = &encode_base64(@{$hit}[1]); @@ -2691,8 +2688,8 @@ POE::Component::Server::TCP->new( my ($kernel, $input) = @_[KERNEL, ARG0]; push(@tasks, $input); push(@msgs_to_decrypt, $input); - $kernel->yield("next_task"); $kernel->yield("msg_to_decrypt"); + $kernel->yield("next_task"); }, InlineStates => { next_task => \&next_task, diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index 5421f099b..d1bd03d23 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -117,7 +117,7 @@ sub add_dbentry { my $create_id=0; foreach my $col_name (@{$col_names}) { if($col_name eq "id" && (! exists $arg->{$col_name})) { - &main::daemon_log("DEBUG: id field found without value! Creating autoincrement statement!"); + &main::daemon_log("0 DEBUG: id field found without value! Creating autoincrement statement!", 7); $create_id=1; } } diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index bb49c9b3e..7e3676974 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -8,6 +8,7 @@ my @events = ( "gen_smb_hash", "trigger_reload_ldap_config", "ping", + "new_ping", "network_completition", "set_activated_for_installation", "new_key_for_client", @@ -43,6 +44,7 @@ use Crypt::SmbHash; use Net::ARP; use Net::Ping; use Socket; +use Time::HiRes qw( usleep); BEGIN {} @@ -353,6 +355,59 @@ sub ping { my @out_msg_l = ( $out_msg ); return @out_msg_l; } +sub new_ping { + my ($msg, $msg_hash, $session_id) = @_ ; + my ($sql, $res); + my $out_msg = $msg; + my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0]; + if( defined $jobdb_id) { + my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->exec_statement($sql_statement); + } + + $out_msg =~ s/
gosa_/
/; + + # send message + my $header = @{$msg_hash->{header}}[0]; + my $target = @{$msg_hash->{target}}[0]; + + $sql = "SELECT * FROM $main::known_clients_tn WHERE ((hostname='$target') || (macaddress LIKE '$target'))"; + #&main::daemon_log("$sql",1); + $res = $main::known_clients_db->exec_statement($sql); + #&main::daemon_log(Dumper($res), 1); + my $host_name = @{@$res[0]}[0]; + $out_msg =~ s/\S+<\/target>/$host_name<\/target>/; + $out_msg =~ s/\S+<\/source>/$main::server_address<\/source>/; + $out_msg =~ s/<\/xml>/$session_id<\/session_id><\/xml>/; + my $host_key = @{@$res[0]}[2]; + + my $error = &main::send_msg_to_target($out_msg, $host_name, $host_key, $header, $session_id); + #if ($error != 0) {} + + my $message_id; + while (1) { + $sql = "SELECT * FROM $main::incoming_tn WHERE headertag='answer_$session_id'"; + $res = $main::incoming_db->exec_statement($sql); + if (ref @$res[0] eq "ARRAY") { + $message_id = @{@$res[0]}[0]; + last; + } + usleep(100000); + } + my $answer_xml = @{@$res[0]}[3]; + my %data = ( 'answer_xml' => 'bin noch da' ); + my $answer_msg = &build_msg("got_ping", "$main::server_address", "GOSA", \%data); + + $sql = "DELETE FROM $main::incoming_tn WHERE id=$message_id"; + $res = $main::incoming_db->exec_statement($sql); + + + my @answer_msg_l = ( $answer_msg ); + return @answer_msg_l; +} + + sub gen_smb_hash { my ($msg, $msg_hash, $session_id) = @_ ; -- 2.30.2