X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fserver%2Fevents%2FclMessages.pm;h=a6fad7e3dd9f17268a07ebb7d4cd69a2803a70ff;hb=9ab60891c47d98a282baa89c21fe830bcb63c666;hp=a7487a3e1fb3e6d7550015a68daf810456a90ae8;hpb=bf9764fece00efc52112f55147ba77fb32e3a929;p=gosa.git diff --git a/gosa-si/server/events/clMessages.pm b/gosa-si/server/events/clMessages.pm index a7487a3e1..a6fad7e3d 100644 --- a/gosa-si/server/events/clMessages.pm +++ b/gosa-si/server/events/clMessages.pm @@ -12,6 +12,8 @@ my @events = ( "GOTOACTIVATION", "LOGIN", "LOGOUT", + "CURRENTLY_LOGGED_IN", + "save_fai_log", ); @EXPORT = @events; @@ -19,7 +21,7 @@ use strict; use warnings; use Data::Dumper; use GOSA::GosaSupportDaemon; -use utf8; +use MIME::Base64; BEGIN {} @@ -53,7 +55,7 @@ sub read_configfile { my ($cfg_file, %cfg_defaults) = @_; my $cfg; - if( defined( $cfg_file) && ( length($cfg_file) > 0 )) { + if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) { if( -r $cfg_file ) { $cfg = Config::IniFiles->new( -file => $cfg_file ); } else { @@ -71,6 +73,46 @@ sub read_configfile { } +sub save_fai_log { + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + my $all_logs = @{$msg_hash->{$header}}[0]; + + # if there is nothing to log + if( ref($all_logs) eq "HASH" ) { return; } + + my $client_fai_log_dir = $main::client_fai_log_dir; + if (not -d $client_fai_log_dir) { + mkdir($client_fai_log_dir, 0755) + } + + $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, $macaddress ); + if (not -d $client_fai_log_dir) { + mkdir($client_fai_log_dir, 0755) + } + + my $time = &get_time; + $time = substr($time, 0, 8)."_".substr($time, 8, 6); + $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, "install_$time" ); + mkdir($client_fai_log_dir, 0755); + + my @all_logs = split(/log_file:/, $all_logs); + foreach my $log (@all_logs) { + if (length $log == 0) { next; }; + my ($log_file, $log_string) = split(":", $log); + my $client_fai_log_file = File::Spec->catfile( $client_fai_log_dir, $log_file); + + open(my $LOG_FILE, ">$client_fai_log_file"); + print $LOG_FILE &decode_base64($log_string); + close($LOG_FILE); + + } + return; +} + + sub LOGIN { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; @@ -82,10 +124,10 @@ sub LOGIN { client=>$source, user=>$login, timestamp=>&get_time, - ); + ); my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash ); if ($res != 0) { - &main::daemon_log("ERROR: cannot add entry to known_clients: $error_str"); + &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str"); return; } @@ -98,232 +140,345 @@ sub LOGOUT { my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $login = @{$msg_hash->{$header}}[0]; + + my $sql_statement = "DELETE FROM $main::login_users_tn WHERE (client='$source' AND user='$login')"; + my $res = $main::login_users_db->del_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: delete user '$login' at client '$source' from login_user_db", 5); + + return; +} - my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'"; - my $res = $main::known_clients_db->select_dbentry($sql_statement); - if( 1 != keys(%$res) ) { - &main::daemon_log("DEBUG: clMessages.pm: LOGOUT: no or more hits found in known_clients_db for host '$source'"); - return; + +sub CURRENTLY_LOGGED_IN { + my ($msg, $msg_hash, $session_id) = @_; + my ($sql_statement, $db_res); + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $login = @{$msg_hash->{$header}}[0]; + + if(ref $login eq "HASH") { + &main::daemon_log("$session_id INFO: no logged in users reported from host '$source'", 5); + return; + } + + # fetch all user currently assigned to the client at login_users_db + my %currently_logged_in_user = (); + $sql_statement = "SELECT * FROM $main::login_users_tn WHERE client='$source'"; + $db_res = $main::login_users_db->select_dbentry($sql_statement); + while( my($hit_id, $hit) = each(%{$db_res}) ) { + $currently_logged_in_user{$hit->{'user'}} = 1; } + &main::daemon_log("$session_id DEBUG: logged in users from login_user_db: ".join(", ", keys(%currently_logged_in_user)), 7); + + # update all reported users in login_user_db + my @logged_in_user = split(/\s+/, $login); + &main::daemon_log("$session_id DEBUG: logged in users reported from client: ".join(", ", @logged_in_user), 7); + foreach my $user (@logged_in_user) { + my %add_hash = ( table=>$main::login_users_tn, + primkey=> ['client', 'user'], + client=>$source, + user=>$user, + timestamp=>&get_time, + ); + my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash ); + if ($res != 0) { + &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str"); + return; + } - my $act_login = $res->{'1'}->{'login'}; - $act_login =~ s/$login,?//gi; + delete $currently_logged_in_user{$user}; + } - if( $act_login eq "" ){ $act_login = "nobody"; } + # if there is still a user in %currently_logged_in_user + # although he is not reported by client + # then delete it from $login_user_db + foreach my $obsolete_user (keys(%currently_logged_in_user)) { + &main::daemon_log("$session_id WARNING: user '$obsolete_user' is currently not logged ". + "in at client '$source' but still found at login_user_db", 3); + my $sql_statement = "DELETE FROM $main::login_users_tn WHERE client='$source' AND user='$obsolete_user'"; + my $res = $main::login_users_db->del_dbentry($sql_statement); + &main::daemon_log("$session_id WARNING: delete user '$obsolete_user' at client '$source' from login_user_db", 3); + } - $sql_statement = "UPDATE known_clients ". - "SET login='$act_login' ". - "WHERE hostname='$source'"; - $res = $main::known_clients_db->update_dbentry($sql_statement); - return; } sub GOTOACTIVATION { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', progress='goto-activation' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress'", 5); + return; } sub PROGRESS { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_progress_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET progress='$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - $content%", 5); + + return; } sub FAIREBOOT { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); + + return; } sub TASKSKIP { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; -} + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } + + # clean up header + $header =~ s/CLMSG_//g; + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); + + return; +} sub TASKBEGIN { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } + + # clean up header + $header =~ s/CLMSG_//g; + + # TASKBEGIN eq finish or faiend + if (($content eq 'finish') || ($content eq 'faiend')){ + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='done', result='$header "."$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); + + # set fai_state to localboot + &main::change_fai_state('localboot', \@{$msg_hash->{'macaddress'}}, $session_id); + + # other TASKBEGIN msgs + } else { + # select processing jobs for host + my $sql_statement = "SELECT * FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->select_dbentry($sql_statement); + + # there is exactly one job entry in queue for this host + if (keys(%$res) == 1) { + &main::daemon_log("$session_id DEBUG: there is already one processing job in queue for host '$macaddress', run an update for this entry", 7); + my $sql_statement = "UPDATE $main::job_queue_tn SET result='$header $content' WHERE status='processing' AND macaddress LIKE '$macaddress'"; + my $err = $main::job_db->update_dbentry($sql_statement); + if (not defined $err) { + &main::daemon_log("$session_id ERROR: cannot update job_db entry: ".Dumper($err), 1); + } + + # there is no entry or more than one enties + } else { + # in case of more than one running jobs in queue, delete all jobs + if (keys(%$res) > 1) { + &main::daemon_log("$session_id DEBUG: there are more than one processing job in queue for host '$macaddress', ". + "delete entries", 7); + + my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; + my ($err) = $main::job_db->del_dbentry($sql_statement); + if (not defined $err) { + &main::daemon_log("$session_id ERROR: can not delete multiple processing queue entries for host '$macaddress': ".Dumper($err), 1); + } + } + + # in case of no and more than one running jobs in queue, add on single job + &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7); + my $func_dic = {table=>$main::job_queue_tn, + primkey=>['id'], + timestamp=>&get_time, + status=>'processing', + result=>"$header $content", + progress=>'none', + headertag=>'trigger_action_reinstall', + targettag=>$source, + xmlmessage=>'none', + macaddress=>$macaddress, + plain_name=>'none', + }; + my ($err, $error_str) = $main::job_db->add_dbentry($func_dic); + if ($err != 0) { + &main::daemon_log("$session_id ERROR: cannot add entry to job_db: $error_str", 1); + } + + } # -----------------------> Update hier # finish #
CLMSG_TASKBEGIN
# macaddress auslesen, Client im LDAP lokalisieren # FAIstate auf "localboot" setzen, wenn FAIstate "install" oder "softupdate" war + } - return @out_msg_l; + return; } sub TASKEND { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'target'}}[0]; + my $macaddress = @{$msg_hash->{'macaddress'}}[0]; -# -----------------------> Update hier -# finish -#
CLMSG_TASKBEGIN
-# macaddress auslesen, Client im LDAP lokalisieren -# FAIstate auf "error" setzen + # test whether content is an empty hash or a string which is required + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } - return @out_msg_l; -} + # clean up header + $header =~ s/CLMSG_//g; + if ($content eq "savelog 0") { + &main::daemon_log("$session_id DEBUG: got savelog from host '$source' - jub done", 7); + my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->del_dbentry($sql_statement); -sub TASKERROR { - my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); + } else { + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); + } # -----------------------> Update hier # finish #
CLMSG_TASKBEGIN
# macaddress auslesen, Client im LDAP lokalisieren # FAIstate auf "error" setzen - return @out_msg_l; + return; } -sub HOOK { +sub TASKERROR { my ($msg, $msg_hash, $session_id) = @_; - my $out_msg = &build_status_result_update_msg($msg_hash); - my @out_msg_l = ($out_msg); - return @out_msg_l; -} - - -sub build_status_result_update_msg { - my ($msg_hash) = @_; - my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'target'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; my $macaddress = @{$msg_hash->{'macaddress'}}[0]; - # test whether content is an empty hash or a string which is required - my $content = @{$msg_hash->{$header}}[0]; - eval{ - if( 0 == keys(%$content) ) { - $content = ""; - } - }; - if( $@ ) { - $content = " $content"; - } - + # clean up header $header =~ s/CLMSG_//g; - my $out_msg = sprintf(" ". - "
gosa_update_status_jobdb_entry
". - "%s ". - "%s". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - "
", $source, "JOBDB", $macaddress, $header.$content); - return $out_msg; -} - - -sub build_progress_update_msg { - my ($msg_hash) = @_; - - my $header = @{$msg_hash->{'header'}}[0]; - my $source = @{$msg_hash->{'target'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; - my $macaddress = @{$msg_hash->{'macaddress'}}[0]; # test whether content is an empty hash or a string which is required my $content = @{$msg_hash->{$header}}[0]; - eval{ - if( 0 == keys(%$content) ) { - $content = ""; - } - }; - if( $@ ) { - $content = "$content"; - } + if(ref($content) eq "HASH") { $content = ""; } + + # set fai_state to localboot + &main::change_fai_state('error', \@{$msg_hash->{'macaddress'}}, $session_id); + + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); - $header =~ s/CLMSG_//g; - my $out_msg = sprintf(" ". - "
gosa_update_status_jobdb_entry
". - "%s ". - "%s". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - " ". - " ". - " ". - "%s ". - " ". - "
", $source, "JOBDB", $macaddress, $content); - return $out_msg; -} +# -----------------------> Update hier +# finish +#
CLMSG_TASKBEGIN
+# macaddress auslesen, Client im LDAP lokalisieren +# FAIstate auf "error" setzen + return; +} -sub build_result_update_msg { - my ($msg_hash) = @_; +sub HOOK { + my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'target'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; my $macaddress = @{$msg_hash->{'macaddress'}}[0]; + # clean up header + $header =~ s/CLMSG_//g; + # test whether content is an empty hash or a string which is required - my $content = @{$msg_hash->{$header}}[0]; - eval{ - if( 0 == keys(%$content) ) { - $content = ""; - } - }; - if( $@ ) { - $content = " $content"; - } + my $content = @{$msg_hash->{$header}}[0]; + if(ref($content) eq "HASH") { $content = ""; } - $header =~ s/CLMSG_//g; - my $out_msg = sprintf(" ". - "
gosa_update_status_jobdb_entry
". - "%s ". - "%s". - " ". - " ". - " ". - "processing ". - "%s ". - " ". - " ". - " ". - " ". - "%s ". - " ". - "
", $source, "JOBDB", $macaddress, $header.$content); - return $out_msg; + my $sql_statement = "UPDATE $main::job_queue_tn ". + "SET status='processing', result='$header "."$content' ". + "WHERE status='processing' AND macaddress LIKE '$macaddress'"; + &main::daemon_log("$session_id DEBUG: $sql_statement", 7); + my $res = $main::job_db->update_dbentry($sql_statement); + &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); + + return; }