Code

update: ownership of installing jobs can be switch among si-server
[gosa.git] / gosa-si / server / events / clMessages.pm
index 70da956b5d6a72b08945a84a2a5f55607593f3aa..fde8b36b43a555b3a70b53f4977a6b1b1cf5aab4 100644 (file)
@@ -1,3 +1,7 @@
+## @file
+# @brief Implementation of a GOsa-SI event module. 
+# @details A GOsa-SI event module containing all functions to handle incoming messages from clients.
+
 package clMessages;
 use Exporter;
 @ISA = qw(Exporter);
@@ -29,29 +33,19 @@ BEGIN {}
 
 END {}
 
-### Start ######################################################################
-
-my $ldap_uri;
-my $ldap_base;
-my $ldap_admin_dn;
-my $ldap_admin_password;
-
-my %cfg_defaults = (
-"server" => {
-   "ldap-uri" => [\$ldap_uri, ""],
-   "ldap-base" => [\$ldap_base, ""],
-   "ldap-admin-dn" => [\$ldap_admin_dn, ""],
-   "ldap-admin-password" => [\$ldap_admin_password, ""],
-   },
-);
-&read_configfile($main::cfg_file, %cfg_defaults);
-
 
+## @method get_events()
+# @details A brief function returning a list of functions which are exported by importing the module.
+# @return List of all provided functions
 sub get_events {
     return \@events;
 }
 
-
+## @method confirm_usr_msg()
+# @details Confirmed messages are set in the messaging_db from d (deliverd) to s(seen). 
+# @param msg - STRING - xml message with tags 'message', 'subject' and 'usr'
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub confirm_usr_msg {
     my ($msg, $msg_hash, $session_id) = @_;
     my $message = @{$msg_hash->{'message'}}[0];
@@ -68,29 +62,11 @@ sub confirm_usr_msg {
 }
 
 
-
-sub read_configfile {
-    my ($cfg_file, %cfg_defaults) = @_;
-    my $cfg;
-
-    if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
-        if( -r $cfg_file ) {
-            $cfg = Config::IniFiles->new( -file => $cfg_file );
-        } else {
-            &main::daemon_log("ERROR: clMessages.pm couldn't read config file!", 1);
-        }
-    } else {
-        $cfg = Config::IniFiles->new() ;
-    }
-    foreach my $section (keys %cfg_defaults) {
-        foreach my $param (keys %{$cfg_defaults{ $section }}) {
-            my $pinfo = $cfg_defaults{ $section }{ $param };
-            ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] );
-        }
-    }
-}
-
-
+## @method save_fai_log()
+# @details Creates under /var/log/fai/ the directory '$macaddress' and stores within all FAI log files from client.
+# @param msg - STRING - xml message with tags 'macaddress' and '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 save_fai_log {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -130,7 +106,11 @@ sub save_fai_log {
     return;
 }
 
-
+## @method LOGIN()
+# @details Reported user from client is added to login_users_db.
+# @param msg - STRING - xml message with tag 'LOGIN'
+# @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) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -153,6 +133,11 @@ sub LOGIN {
 }
 
 
+## @method LOGOUT()
+# @details Reported user from client is deleted from login_users_db.
+# @param msg - STRING - xml message with tag '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 LOGOUT {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -167,6 +152,11 @@ sub LOGOUT {
 }
 
 
+## @method CURRENTLY_LOGGED_IN()
+# @details Reported users from client are updated in login_users_db. Users which are no longer logged in are deleted from DB. 
+# @param msg - STRING - xml message
+# @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) = @_;
     my ($sql_statement, $db_res);
@@ -222,6 +212,11 @@ sub CURRENTLY_LOGGED_IN {
 }
 
 
+## @method GOTOACTIVATION()
+# @details Client is set at job_queue_db to status 'processing' and 'modified'.
+# @param msg - STRING - xml message with tag 'macaddress'
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub GOTOACTIVATION {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -245,6 +240,11 @@ sub GOTOACTIVATION {
 }
 
 
+## @method PROGRESS()
+# @details Message reports installation progress of the client. Installation job at job_queue_db is going to be updated.
+# @param msg - STRING - xml message with tags 'macaddress' and 'PROGRESS'
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub PROGRESS {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -269,6 +269,11 @@ sub PROGRESS {
 }
 
 
+## @method FAIREBOOT()
+# @details Message reports a FAI reboot. Job at job_queue_db is going to be updated.
+# @param msg - STRING - xml message with tag 'macaddress' and 'FAIREBOOT'
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub FAIREBOOT {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -293,6 +298,11 @@ sub FAIREBOOT {
 }
 
 
+## @method TASKSKIP()
+# @details Message reports a skipped FAI task. Job at job_queue_db is going to be updated. 
+# @param msg - STRING - xml message with tag 'macaddress'.
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub TASKSKIP {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -317,6 +327,11 @@ sub TASKSKIP {
 }
 
 
+## @method TASKBEGIN()
+# @details Message reports a starting FAI task. If the task is equal to 'finish', 'faiend' or 'savelog', job at job_queue_db is being set to status 'done' and FAI state is being set to 'localboot'. If task is equal to 'chboot', 'test' or 'confdir', just do nothing. In all other cases, job at job_queue_db is going to be updated or created if not exists. 
+# @param msg - STRING - xml message with tag 'macaddress'.
+# @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) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -365,7 +380,7 @@ sub TASKBEGIN {
                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' ".
+                "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) {
@@ -412,7 +427,7 @@ sub TASKBEGIN {
                                }
                        }
 
-
+            # In any case add a new job to job queue
                        &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7); 
                        my $func_dic = {table=>$main::job_queue_tn,
                                        primkey=>['macaddress', 'headertag'],
@@ -426,26 +441,24 @@ sub TASKBEGIN {
                                        macaddress=>$macaddress,
                                        plainname=>$plain_name,
                     modified=>'1',
-                    siserver=>$source,
+                    siserver=>'localhost',
                        };
                        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
-#  <CLMSG_TASKBEGIN>finish</CLMSG_TASKBEGIN>
-#  <header>CLMSG_TASKBEGIN</header>
-# macaddress auslesen, Client im LDAP lokalisieren
-# FAIstate auf "localboot" setzen, wenn FAIstate "install" oder "softupdate" war
     }
 
     return; 
 }
 
 
+## @method TASKEND()
+# @details Message reports a finished FAI task. If task is equal to 'savelog', job at job_queue_db is going to be set to status 'done'. Otherwise, job is going to be updated. 
+# @param msg - STRING - xml message with tag 'macaddress'.
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub TASKEND {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -483,6 +496,11 @@ sub TASKEND {
 }
 
 
+## @method TASKERROR()
+# @details Message reports a FAI error. Job at job_queue_db is going to be updated. 
+# @param msg - STRING - xml message with tag 'macaddress' and 'TASKERROR'
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub TASKERROR {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -506,16 +524,15 @@ sub TASKERROR {
     my $res = $main::job_db->update_dbentry($sql_statement);
     &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5); 
 
-# -----------------------> Update hier
-#  <CLMSG_TASKBEGIN>finish</CLMSG_TASKBEGIN>
-#  <header>CLMSG_TASKBEGIN</header>
-# macaddress auslesen, Client im LDAP lokalisieren
-# FAIstate auf "error" setzen
-
     return; 
 }
 
 
+## @method HOOK()
+# @details Message reports a FAI hook. Job at job_queue_db is going to be updated. 
+# @param msg - STRING - xml message with tag 'macaddress' and 'HOOK'
+# @param msg_hash - HASHREF - message information parsed into a hash
+# @param session_id - INTEGER - POE session id of the processing of this message
 sub HOOK {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{'header'}}[0];
@@ -539,5 +556,73 @@ sub HOOK {
     return;
 }
 
+=pod
+
+=head1 NAME
+
+clMessages - Implementation of a GOsa-SI event module for GOsa-SI-server.
+
+=head1 SYNOPSIS
+
+ use GOSA::GosaSupportDaemon;
+ use MIME::Base64;
+
+=head1 DESCRIPTION
+
+This GOsa-SI event module containing all functions to handle messages coming from GOsa-SI-clients. 
+
+This module will be automatically imported by GOsa-SI if it is under F</usr/lib/gosa-si/server/E<lt>PACKAGEMODULEE<gt>/> .
+
+=head1 METHODS
+
+=over 4
+
+=item get_events ( )
+
+=item confirm_usr_msg ( )
+
+=item PROGRESS ( )
+
+=item FAIREBOOT ( )
+
+=item TASKSKIP ( )
+
+=item TASKBEGIN ( )
+
+=item TASKEND ( )
+
+=item TASKERROR ( )
+
+=item HOOK ( )
+
+=item GOTOACTIVATION ( )
+
+=item LOGIN ( )
+
+=item LOGOUT ( )
+
+=item CURRENTLY_LOGGED_IN ( )
+
+=item save_fai_log ( )
+
+=back
+
+=head1 BUGS
+
+Please report any bugs, or post any suggestions, to the GOsa mailing list E<lt>gosa-devel@oss.gonicus.deE<gt> or to L<https://oss.gonicus.de/labs/gosa>
+
+=head1 COPYRIGHT
+
+This code is part of GOsa (L<http://www.gosa-project.org>)
+
+Copyright (C) 2003-2008 GONICUS GmbH
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+=cut
+
 
 1;