Code

Updated some sieve templates
[gosa.git] / gosa-si / server / events / clMessages.pm
index 15120393f2dabf4339fe645b3380de6f80d2a90d..3492e4194e1c76a0e7141ef0385326acd43a8e60 100644 (file)
@@ -3,8 +3,18 @@
 # @details A GOsa-SI event module containing all functions to handle incoming messages from clients.
 
 package clMessages;
+
+
+use strict;
+use warnings;
+
 use Exporter;
-@ISA = qw(Exporter);
+use Data::Dumper;
+use GOSA::GosaSupportDaemon;
+use MIME::Base64;
+
+our @ISA = qw(Exporter);
+
 my @events = (
     "confirm_usr_msg",
     "PROGRESS",
@@ -20,14 +30,7 @@ my @events = (
     "CURRENTLY_LOGGED_IN",
     "save_fai_log",
     );
-@EXPORT = @events;
-
-use strict;
-use warnings;
-use Data::Dumper;
-use GOSA::GosaSupportDaemon;
-use MIME::Base64;
-
+our @EXPORT = @events;
 
 BEGIN {}
 
@@ -101,7 +104,7 @@ sub save_fai_log {
         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"); 
+               open(my $LOG_FILE, ">", "$client_fai_log_file"); 
                print $LOG_FILE &decode_base64($log_string);
                close($LOG_FILE);
                chown($main::root_uid, $main::adm_gid, $client_fai_log_file);
@@ -117,7 +120,7 @@ sub save_fai_log {
 # @param msg_hash - HASHREF - message information parsed into a hash
 # @param session_id - INTEGER - POE session id of the processing of this message
 sub LOGIN {
-    my ($msg, $msg_hash, $session_id, $ldap_handle) = @_;
+    my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
     my $source = @{$msg_hash->{'source'}}[0];
     my $login = @{$msg_hash->{$header}}[0];
@@ -125,7 +128,7 @@ sub LOGIN {
     my $error_str;
 
     # Invoke set_last_system; message sets ldap attributes 'gotoLastSystemLogin' and 'gotoLastSystem'
-       $res = &set_last_system($msg, $msg_hash, $session_id, $ldap_handle);
+       $res = &set_last_system($msg, $msg_hash, $session_id);
 
     # Add user to login_users_db
     my %add_hash = ( table=>$main::login_users_tn, 
@@ -174,7 +177,7 @@ sub LOGOUT {
 # @param msg_hash - HASHREF - message information parsed into a hash
 # @param session_id - INTEGER - POE session id of the processing of this message
 sub CURRENTLY_LOGGED_IN {
-    my ($msg, $msg_hash, $session_id, $ldap_handle) = @_;
+    my ($msg, $msg_hash, $session_id) = @_;
     my ($sql_statement, $db_res);
     my $header = @{$msg_hash->{'header'}}[0];
     my $source = @{$msg_hash->{'source'}}[0];
@@ -186,7 +189,7 @@ sub CURRENTLY_LOGGED_IN {
     }
 
     # Invoke set_last_system; message sets ldap attributes 'gotoLastSystemLogin' and 'gotoLastSystem'
-       my $res = &set_last_system($msg, $msg_hash, $session_id, $ldap_handle);
+       my $res = &set_last_system($msg, $msg_hash, $session_id);
     
     # fetch all user currently assigned to the client at login_users_db
     my %currently_logged_in_user = (); 
@@ -261,7 +264,7 @@ sub CURRENTLY_LOGGED_IN {
 # @param msg_hash - HASHREF - message information parsed into a hash
 # @param session_id - INTEGER - POE session id of the processing of this message
 sub set_last_system {
-       my ($msg, $msg_hash, $session_id, $ldap_handle) = @_;
+       my ($msg, $msg_hash, $session_id) = @_;
        my $header = @{$msg_hash->{'header'}}[0];
        my $source = @{$msg_hash->{'source'}}[0];
     my $login = @{$msg_hash->{$header}}[0];
@@ -307,6 +310,7 @@ sub set_last_system {
        }
 
        # Get system info
+       my $ldap_handle=&main::get_ldap_handle($session_id);
        my $ldap_mesg= $ldap_handle->search(
                                        base => $main::ldap_base,
                                        scope => 'sub',
@@ -315,6 +319,7 @@ sub set_last_system {
        if ($ldap_mesg->count == 0) {
                &main::daemon_log("$session_id ERROR: no system with mac address='$mac' was found in base '".
                                                $main::ldap_base."', setting of 'gotoLastSystem' and 'gotoLastSystemLogin' stopped!", 1);
+               &main::release_ldap_handle($ldap_handle);
                return;
        }
 
@@ -327,7 +332,7 @@ sub set_last_system {
                my $ldap_mesg= $ldap_handle->search(
                                                base => $main::ldap_base,
                                                scope => 'sub',
-                                               filter => "uid=$user",
+                                               filter => "(&(objectClass=gosaAccount)(uid=$user))",
                                                );
                # Sanity check of user search
                if ($ldap_mesg->count == 0) {
@@ -342,7 +347,7 @@ sub set_last_system {
             # Set gotoLastSystem information
             my $last_system_dn = $ldap_entry->get_value('gotoLastSystem');
             if ((defined $last_system_dn) && ($last_system_dn eq $system_dn)) {
-                &main::daemon_log("$session_id INFO: no new 'gotoLastSystem' inforamtion for ladp entry 'uid=$user', do nothing!", 5);
+                &main::daemon_log("$session_id INFO: no new 'gotoLastSystem' information for ldap entry 'uid=$user', do nothing!", 5);
             } elsif ((defined $last_system_dn) && ($last_system_dn ne $system_dn)) {
                 $ldap_entry->replace ( 'gotoLastSystem' => $system_dn );
                 &main::daemon_log("$session_id INFO: update attribute 'gotoLastSystem'='$system_dn' at ldap entry 'uid=$user'!",5);
@@ -357,7 +362,7 @@ sub set_last_system {
             # Attention: only write information if last_system_dn and system_dn differs
             my $last_system_login = $ldap_entry->get_value('gotoLastSystemLogin');
             if ((defined $last_system_login) && ($last_system_dn eq $system_dn)) {
-                &main::daemon_log("$session_id INFO: no new 'gotoLastSystemLogin' inforamtion for ladp entry 'uid=$user', do nothing!", 5);
+                &main::daemon_log("$session_id INFO: no new 'gotoLastSystemLogin' information for ldap entry 'uid=$user', do nothing!", 5);
             } elsif ((defined $last_system_login) && ($last_system_dn ne $system_dn)) {
                 $ldap_entry->replace ( 'gotoLastSystemLogin' => $timestamp );
                 &main::daemon_log("$session_id INFO: update attribute 'gotoLastSystemLogin'='$timestamp' at ldap entry 'uid=$user'!", 5);
@@ -381,6 +386,7 @@ sub set_last_system {
             }
                }
        }
+       &main::release_ldap_handle($ldap_handle);
 
        return;
 }
@@ -507,7 +513,7 @@ sub TASKSKIP {
 # @param msg_hash - HASHREF - message information parsed into a hash
 # @param session_id - INTEGER - POE session id of the processing of this message
 sub TASKBEGIN {
-    my ($msg, $msg_hash, $session_id, $ldap_handle) = @_;
+    my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
     my $source = @{$msg_hash->{'source'}}[0];
     my $target = @{$msg_hash->{'target'}}[0];
@@ -545,7 +551,14 @@ sub TASKBEGIN {
 
        # other TASKBEGIN msgs
     } else {
-               # select processing jobs for host
+               # TASKBEGIN msgs do only occour during a softupdate or a reinstallation
+               # of a host. Set all waiting update- or reinstall-jobs for host to
+               # processing so they can be handled correctly by the rest of the function.
+               my $waiting_sql = "UPDATE $main::job_queue_tn SET status='processing' WHERE status='waiting' AND macaddress LIKE '$macaddress' AND (headertag='trigger_action_update' OR headertag='trigger_action_reinstall')"; 
+               &main::daemon_log("$session_id DEBUB: $waiting_sql", 7);
+               my $waiting_res = $main::job_db->update_dbentry($waiting_sql);
+
+               # 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);
@@ -553,17 +566,15 @@ sub TASKBEGIN {
                # 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', modified='1', siserver='localhost' ".
-                "WHERE status='processing' AND macaddress LIKE '$macaddress'";
+                       my $sql_statement = "UPDATE $main::job_queue_tn SET result='$header $content', modified='1', siserver='localhost' 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
+               # There is no entry in queue or more than one entries in queue for this host
                } else {
-                       # in case of more than one running jobs in queue, delete all jobs
+                       # 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); 
@@ -577,9 +588,11 @@ sub TASKBEGIN {
 
                        }
                
-                       # in case of no and more than one running jobs in queue, add one single job
-                       # resolve plain name for host $macaddress
+                       # In case of no and more than one running jobs in queue, add one single job
+
+                       # Resolve plain name for host $macaddress
                        my $plain_name;
+                       my $ldap_handle=&main::get_ldap_handle($session_id);
                        my $mesg = $ldap_handle->search(
                                        base => $main::ldap_base,
                                        scope => 'sub',
@@ -592,6 +605,7 @@ sub TASKBEGIN {
                                &main::daemon_log($mesg->error, 1);
                                $plain_name = "none";
                        }
+                       &main::release_ldap_handle($ldap_handle);
 
             # In any case add a new job to job queue
                        &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7);