1 ## @file
2 # @brief Implementation of a GOsa-SI event module.
3 # @details A GOsa-SI event module containing all functions to handle incoming messages from clients.
5 package clMessages;
6 use Exporter;
7 @ISA = qw(Exporter);
8 my @events = (
9 "confirm_usr_msg",
10 "PROGRESS",
11 "FAIREBOOT",
12 "TASKSKIP",
13 "TASKBEGIN",
14 "TASKEND",
15 "TASKERROR",
16 "HOOK",
17 "GOTOACTIVATION",
18 "LOGIN",
19 "LOGOUT",
20 "CURRENTLY_LOGGED_IN",
21 "save_fai_log",
22 );
23 @EXPORT = @events;
25 use strict;
26 use warnings;
27 use Data::Dumper;
28 use GOSA::GosaSupportDaemon;
29 use MIME::Base64;
32 BEGIN {}
34 END {}
37 ## @method get_events()
38 # @details A brief function returning a list of functions which are exported by importing the module.
39 # @return List of all provided functions
40 sub get_events {
41 return \@events;
42 }
44 ## @method confirm_usr_msg()
45 # @details Confirmed messages are set in the messaging_db from d (deliverd) to s(seen).
46 # @param msg - STRING - xml message with tags 'message', 'subject' and 'usr'
47 # @param msg_hash - HASHREF - message information parsed into a hash
48 # @param session_id - INTEGER - POE session id of the processing of this message
49 sub confirm_usr_msg {
50 my ($msg, $msg_hash, $session_id) = @_;
51 my $message = @{$msg_hash->{'message'}}[0];
52 my $subject = @{$msg_hash->{'subject'}}[0];
53 my $usr = @{$msg_hash->{'usr'}}[0];
55 # set update for this message
56 my $sql = "UPDATE $main::messaging_tn SET flag='s' WHERE (message='$message' AND subject='$subject' AND message_to='$usr')";
57 &main::daemon_log("$session_id DEBUG: $sql", 7);
58 my $res = $main::messaging_db->exec_statement($sql);
61 return;
62 }
65 ## @method save_fai_log()
66 # @details Creates under /var/log/fai/ the directory '$macaddress' and stores within all FAI log files from client.
67 # @param msg - STRING - xml message with tags 'macaddress' and 'save_fai_log'
68 # @param msg_hash - HASHREF - message information parsed into a hash
69 # @param session_id - INTEGER - POE session id of the processing of this message
70 sub save_fai_log {
71 my ($msg, $msg_hash, $session_id) = @_;
72 my $header = @{$msg_hash->{'header'}}[0];
73 my $source = @{$msg_hash->{'source'}}[0];
74 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
75 my $all_logs = @{$msg_hash->{$header}}[0];
77 # if there is nothing to log
78 if( ref($all_logs) eq "HASH" ) { return; }
80 my $client_fai_log_dir = $main::client_fai_log_dir;
81 if (not -d $client_fai_log_dir) {
82 mkdir($client_fai_log_dir, 0755)
83 }
85 $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, $macaddress );
86 if (not -d $client_fai_log_dir) {
87 mkdir($client_fai_log_dir, 0755)
88 }
90 my $time = &get_time;
91 $time = substr($time, 0, 8)."_".substr($time, 8, 6);
92 $client_fai_log_dir = File::Spec->catfile( $client_fai_log_dir, "install_$time" );
93 mkdir($client_fai_log_dir, 0755);
95 my @all_logs = split(/log_file:/, $all_logs);
96 foreach my $log (@all_logs) {
97 if (length $log == 0) { next; };
98 my ($log_file, $log_string) = split(":", $log);
99 my $client_fai_log_file = File::Spec->catfile( $client_fai_log_dir, $log_file);
101 open(my $LOG_FILE, ">$client_fai_log_file");
102 print $LOG_FILE &decode_base64($log_string);
103 close($LOG_FILE);
105 }
106 return;
107 }
109 ## @method LOGIN()
110 # @details Reported user from client is added to login_users_db.
111 # @param msg - STRING - xml message with tag 'LOGIN'
112 # @param msg_hash - HASHREF - message information parsed into a hash
113 # @param session_id - INTEGER - POE session id of the processing of this message
114 sub LOGIN {
115 my ($msg, $msg_hash, $session_id) = @_;
116 my $header = @{$msg_hash->{'header'}}[0];
117 my $source = @{$msg_hash->{'source'}}[0];
118 my $login = @{$msg_hash->{$header}}[0];
120 my %add_hash = ( table=>$main::login_users_tn,
121 primkey=> ['client', 'user'],
122 client=>$source,
123 user=>$login,
124 timestamp=>&get_time,
125 );
126 my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
127 if ($res != 0) {
128 &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str");
129 return;
130 }
132 return;
133 }
136 ## @method LOGOUT()
137 # @details Reported user from client is deleted from login_users_db.
138 # @param msg - STRING - xml message with tag 'LOGOUT'
139 # @param msg_hash - HASHREF - message information parsed into a hash
140 # @param session_id - INTEGER - POE session id of the processing of this message
141 sub LOGOUT {
142 my ($msg, $msg_hash, $session_id) = @_;
143 my $header = @{$msg_hash->{'header'}}[0];
144 my $source = @{$msg_hash->{'source'}}[0];
145 my $login = @{$msg_hash->{$header}}[0];
147 my $sql_statement = "DELETE FROM $main::login_users_tn WHERE (client='$source' AND user='$login')";
148 my $res = $main::login_users_db->del_dbentry($sql_statement);
149 &main::daemon_log("$session_id INFO: delete user '$login' at client '$source' from login_user_db", 5);
151 return;
152 }
155 ## @method CURRENTLY_LOGGED_IN()
156 # @details Reported users from client are updated in login_users_db. Users which are no longer logged in are deleted from DB.
157 # @param msg - STRING - xml message
158 # @param msg_hash - HASHREF - message information parsed into a hash
159 # @param session_id - INTEGER - POE session id of the processing of this message
160 sub CURRENTLY_LOGGED_IN {
161 my ($msg, $msg_hash, $session_id) = @_;
162 my ($sql_statement, $db_res);
163 my $header = @{$msg_hash->{'header'}}[0];
164 my $source = @{$msg_hash->{'source'}}[0];
165 my $login = @{$msg_hash->{$header}}[0];
167 if(ref $login eq "HASH") {
168 &main::daemon_log("$session_id INFO: no logged in users reported from host '$source'", 5);
169 return;
170 }
172 # Invoke set_last_system
173 my $res = &set_last_system($msg, $msg_hash, $session_id);
175 # fetch all user currently assigned to the client at login_users_db
176 my %currently_logged_in_user = ();
177 $sql_statement = "SELECT * FROM $main::login_users_tn WHERE client='$source'";
178 $db_res = $main::login_users_db->select_dbentry($sql_statement);
179 while( my($hit_id, $hit) = each(%{$db_res}) ) {
180 $currently_logged_in_user{$hit->{'user'}} = 1;
181 }
182 &main::daemon_log("$session_id DEBUG: logged in users from login_user_db: ".join(", ", keys(%currently_logged_in_user)), 7);
184 # update all reported users in login_user_db
185 my @logged_in_user = split(/\s+/, $login);
186 &main::daemon_log("$session_id DEBUG: logged in users reported from client: ".join(", ", @logged_in_user), 7);
187 foreach my $user (@logged_in_user) {
188 my %add_hash = ( table=>$main::login_users_tn,
189 primkey=> ['client', 'user'],
190 client=>$source,
191 user=>$user,
192 timestamp=>&get_time,
193 );
194 my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
195 if ($res != 0) {
196 &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str");
197 return;
198 }
200 delete $currently_logged_in_user{$user};
201 }
203 # if there is still a user in %currently_logged_in_user
204 # although he is not reported by client
205 # then delete it from $login_user_db
206 foreach my $obsolete_user (keys(%currently_logged_in_user)) {
207 &main::daemon_log("$session_id WARNING: user '$obsolete_user' is currently not logged ".
208 "in at client '$source' but still found at login_user_db", 3);
209 my $sql_statement = "DELETE FROM $main::login_users_tn WHERE client='$source' AND user='$obsolete_user'";
210 my $res = $main::login_users_db->del_dbentry($sql_statement);
211 &main::daemon_log("$session_id WARNING: delete user '$obsolete_user' at client '$source' from login_user_db", 3);
212 }
214 # Delete all users which logged in information is older than their logged_in_user_date_of_expiry
215 my $act_time = &get_time();
216 my $expiry_date = &calc_timestamp($act_time, "minus", $main::logged_in_user_date_of_expiry);
218 $sql_statement = "SELECT * FROM $main::login_users_tn WHERE CAST(timestamp as UNSIGNED)<$expiry_date";
219 $db_res = $main::login_users_db->select_dbentry($sql_statement);
221 while( my($hit_id, $hit) = each(%{$db_res}) ) {
222 &main::daemon_log("$session_id INFO: user '".$hit->{'user'}."' is no longer reported to be logged in at host '".$hit->{'client'}."'", 5);
223 my $sql = "DELETE FROM $main::login_users_tn WHERE (client='".$hit->{'client'}."' AND user='".$hit->{'user'}."')";
224 my $res = $main::login_users_db->del_dbentry($sql);
225 &main::daemon_log("$session_id INFO: delete user '".$hit->{'user'}."' at client '".$hit->{'client'}."' from login_user_db", 5);
226 }
228 return;
229 }
232 ## @method set_last_system()
233 # @details Message set ldap attributes 'gosaLastSystemLogin' and 'gosaLastSystem'
234 # @param msg - STRING - xml message with tag 'last_system_login' and 'last_system'
235 # @param msg_hash - HASHREF - message information parsed into a hash
236 # @param session_id - INTEGER - POE session id of the processing of this message
237 sub set_last_system {
238 my ($msg, $msg_hash, $session_id) = @_;
239 my $header = @{$msg_hash->{'header'}}[0];
240 my $source = @{$msg_hash->{'source'}}[0];
241 my $login = @{$msg_hash->{$header}}[0];
243 # Sanity check of needed parameter
244 if (not exists $msg_hash->{'timestamp'}){
245 &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'timestamp', ".
246 "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1);
247 &main::daemon_log($msg, 1);
248 return;
249 }
250 if (@{$msg_hash->{'timestamp'}} != 1) {
251 &main::daemon_log("$session_id ERROR: xml tag 'timestamp' has no content or exists more than one time, ".
252 "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1);
253 &ymain::daemon_log($msg, 1);
254 return;
255 }
256 if (not exists $msg_hash->{'macaddress'}){
257 &main::daemon_log("$session_id ERROR: message does not contain needed xml tag 'mac_address', ".
258 "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1);
259 &main::daemon_log($msg, 1);
260 return;
261 }
262 if (@{$msg_hash->{'macaddress'}} != 1) {
263 &main::daemon_log("$session_id ERROR: xml tag 'macaddress' has no content or exists more than one time, ".
264 "setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1);
265 &ymain::daemon_log($msg, 1);
266 return;
267 }
269 # Fetch needed parameter
270 my $mac = @{$msg_hash->{'macaddress'}}[0];
271 my $timestamp = @{$msg_hash->{'timestamp'}}[0];
273 # Prepare login list
274 my @login_list = split(' ', @{$msg_hash->{$header}}[0] );
276 # Sanity check of login list
277 if (@login_list == 0) {
278 # TODO
279 return;
280 }
282 # Fetch ldap handle
283 my $ldap_handle = &main::get_ldap_handle();
285 # Get system info
286 my $ldap_mesg= $ldap_handle->search(
287 base => $main::ldap_base,
288 scope => 'sub',
289 filter => "macAddress=$mac",
290 );
291 if ($ldap_mesg->count == 0) {
292 &main::daemon_log("$session_id ERROR: no system with mac address='$mac' was found in base '".
293 $main::ldap_base."', setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1);
294 return;
295 }
296 my $ldap_entry = $ldap_mesg->pop_entry();
297 my $system_dn = $ldap_entry->get_value('dn');
299 # For each logged in user set gosaLastSystem and gosaLastSystemLogin
300 foreach my $user (@login_list) {
301 # Search user
302 my $ldap_mesg= $ldap_handle->search(
303 base => $main::ldap_base,
304 scope => 'sub',
305 filter => "uid=$user",
306 );
307 # Sanity check of user search
308 if ($ldap_mesg->count == 0) {
309 &main::daemon_log("$session_id ERROR: no user with uid='$user' was found in base '".
310 $main::ldap_base."', setting of 'gosaLastSystem' and 'gosaLastSystemLogin' stopped!", 1);
312 # Set gosaLastSystem and gosaLastSystemLogin
313 } else {
314 my $ldap_entry= $ldap_mesg->pop_entry();
315 if (defined($ldap_entry->get_value('gosaLastSystem'))) {
316 $ldap_entry->replace ( 'gosaLastSystem' => $system_dn );
317 } else {
318 $ldap_entry->add( 'gosaLastSystem' => $system_dn );
319 }
320 if (defined($ldap_entry->get_value('gosaLastSystemLogin'))) {
321 $ldap_entry->replace ( 'gosaLastSystemLogin' => $timestamp );
322 } else {
323 $ldap_entry->add( 'gosaLastSystemLogin' => $timestamp );
324 }
325 my $result = $ldap_entry->update($ldap_handle);
326 if ($result->code() != 0) {
327 &main::daemon_log("$session_id ERROR: setting 'gosaLastSystem' and 'gosaLastSystemLogin' at user '$user' failed: ".
328 $result->{'errorMessage'}, 1);
329 &main::daemon_log("$session_id ERROR: $msg", 1);
330 }
331 }
332 }
334 return;
335 }
338 ## @method GOTOACTIVATION()
339 # @details Client is set at job_queue_db to status 'processing' and 'modified'.
340 # @param msg - STRING - xml message with tag 'macaddress'
341 # @param msg_hash - HASHREF - message information parsed into a hash
342 # @param session_id - INTEGER - POE session id of the processing of this message
343 sub GOTOACTIVATION {
344 my ($msg, $msg_hash, $session_id) = @_;
345 my $header = @{$msg_hash->{'header'}}[0];
346 my $source = @{$msg_hash->{'source'}}[0];
347 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
349 # test whether content is an empty hash or a string which is required
350 my $content = @{$msg_hash->{$header}}[0];
351 if(ref($content) eq "HASH") { $content = ""; }
353 # clean up header
354 $header =~ s/CLMSG_//g;
356 my $sql_statement = "UPDATE $main::job_queue_tn ".
357 "SET status='processing', progress='goto-activation', modified='1' ".
358 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
359 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
360 my $res = $main::job_db->update_dbentry($sql_statement);
361 &main::daemon_log("$session_id INFO: $header at '$macaddress'", 5);
362 return;
363 }
366 ## @method PROGRESS()
367 # @details Message reports installation progress of the client. Installation job at job_queue_db is going to be updated.
368 # @param msg - STRING - xml message with tags 'macaddress' and 'PROGRESS'
369 # @param msg_hash - HASHREF - message information parsed into a hash
370 # @param session_id - INTEGER - POE session id of the processing of this message
371 sub PROGRESS {
372 my ($msg, $msg_hash, $session_id) = @_;
373 my $header = @{$msg_hash->{'header'}}[0];
374 my $source = @{$msg_hash->{'source'}}[0];
375 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
377 # test whether content is an empty hash or a string which is required
378 my $content = @{$msg_hash->{$header}}[0];
379 if(ref($content) eq "HASH") { $content = ""; }
381 # clean up header
382 $header =~ s/CLMSG_//g;
384 my $sql_statement = "UPDATE $main::job_queue_tn ".
385 "SET progress='$content', modified='1' ".
386 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
387 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
388 my $res = $main::job_db->update_dbentry($sql_statement);
389 &main::daemon_log("$session_id INFO: $header at '$macaddress' - $content%", 5);
391 return;
392 }
395 ## @method FAIREBOOT()
396 # @details Message reports a FAI reboot. Job at job_queue_db is going to be updated.
397 # @param msg - STRING - xml message with tag 'macaddress' and 'FAIREBOOT'
398 # @param msg_hash - HASHREF - message information parsed into a hash
399 # @param session_id - INTEGER - POE session id of the processing of this message
400 sub FAIREBOOT {
401 my ($msg, $msg_hash, $session_id) = @_;
402 my $header = @{$msg_hash->{'header'}}[0];
403 my $source = @{$msg_hash->{'source'}}[0];
404 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
406 # test whether content is an empty hash or a string which is required
407 my $content = @{$msg_hash->{$header}}[0];
408 if(ref($content) eq "HASH") { $content = ""; }
410 # clean up header
411 $header =~ s/CLMSG_//g;
413 my $sql_statement = "UPDATE $main::job_queue_tn ".
414 "SET status='processing', result='$header "."$content', modified='1' ".
415 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
416 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
417 my $res = $main::job_db->update_dbentry($sql_statement);
418 &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5);
420 return;
421 }
424 ## @method TASKSKIP()
425 # @details Message reports a skipped FAI task. Job at job_queue_db is going to be updated.
426 # @param msg - STRING - xml message with tag 'macaddress'.
427 # @param msg_hash - HASHREF - message information parsed into a hash
428 # @param session_id - INTEGER - POE session id of the processing of this message
429 sub TASKSKIP {
430 my ($msg, $msg_hash, $session_id) = @_;
431 my $header = @{$msg_hash->{'header'}}[0];
432 my $source = @{$msg_hash->{'source'}}[0];
433 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
435 # test whether content is an empty hash or a string which is required
436 my $content = @{$msg_hash->{$header}}[0];
437 if(ref($content) eq "HASH") { $content = ""; }
439 # clean up header
440 $header =~ s/CLMSG_//g;
442 my $sql_statement = "UPDATE $main::job_queue_tn ".
443 "SET status='processing', result='$header "."$content', modified='1' ".
444 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
445 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
446 my $res = $main::job_db->update_dbentry($sql_statement);
447 &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5);
449 return;
450 }
453 ## @method TASKBEGIN()
454 # @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.
455 # @param msg - STRING - xml message with tag 'macaddress'.
456 # @param msg_hash - HASHREF - message information parsed into a hash
457 # @param session_id - INTEGER - POE session id of the processing of this message
458 sub TASKBEGIN {
459 my ($msg, $msg_hash, $session_id) = @_;
460 my $header = @{$msg_hash->{'header'}}[0];
461 my $source = @{$msg_hash->{'source'}}[0];
462 my $target = @{$msg_hash->{'target'}}[0];
463 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
465 # test whether content is an empty hash or a string which is required
466 my $content = @{$msg_hash->{$header}}[0];
467 if(ref($content) eq "HASH") { $content = ""; }
469 # clean up header
470 $header =~ s/CLMSG_//g;
472 # TASKBEGIN eq finish or faiend
473 if (($content eq 'finish')
474 || ($content eq 'faiend')
475 || ($content eq 'savelog')
476 ) {
477 my $sql_statement = "UPDATE $main::job_queue_tn ".
478 "SET status='done', result='$header "."$content', modified='1' ".
479 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
480 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
481 my $res = $main::job_db->update_dbentry($sql_statement);
482 &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5);
484 # set fai_state to localboot
485 &main::change_fai_state('localboot', \@{$msg_hash->{'macaddress'}}, $session_id);
487 # TASKBEGIN eq chboot
488 } elsif (($content eq 'chboot')
489 || ($content eq 'test')
490 || ($content eq 'confdir')
491 ) {
492 # just ignor this client message
493 # do nothing
495 # other TASKBEGIN msgs
496 } else {
497 # select processing jobs for host
498 my $sql_statement = "SELECT * FROM $main::job_queue_tn WHERE status='processing' AND macaddress LIKE '$macaddress'";
499 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
500 my $res = $main::job_db->select_dbentry($sql_statement);
502 # there is exactly one job entry in queue for this host
503 if (keys(%$res) == 1) {
504 &main::daemon_log("$session_id DEBUG: there is already one processing job in queue for host '$macaddress', run an update for this entry", 7);
505 my $sql_statement = "UPDATE $main::job_queue_tn ".
506 "SET result='$header $content', modified='1', siserver='localhost' ".
507 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
508 my $err = $main::job_db->update_dbentry($sql_statement);
509 if (not defined $err) {
510 &main::daemon_log("$session_id ERROR: cannot update job_db entry: ".Dumper($err), 1);
511 }
513 # there is no entry or more than one enties
514 } else {
515 # in case of more than one running jobs in queue, delete all jobs
516 if (keys(%$res) > 1) {
517 &main::daemon_log("$session_id DEBUG: there are more than one processing job in queue for host '$macaddress', ".
518 "delete entries", 7);
520 # set job to status 'done', job will be deleted automatically
521 my $sql_statement = "UPDATE $main::job_queue_tn ".
522 "SET status='done', modified='1'".
523 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
524 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
525 my $res = $main::job_db->update_dbentry( $sql_statement );
527 }
529 # in case of no and more than one running jobs in queue, add one single job
530 # resolve plain name for host $macaddress
531 my $plain_name;
532 my $ldap_handle = &main::get_ldap_handle($session_id);
533 if( not defined $ldap_handle ) {
534 &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
535 $plain_name = "none";
537 # try to fetch a 'real name'
538 } else {
539 my $mesg = $ldap_handle->search(
540 base => $main::ldap_base,
541 scope => 'sub',
542 attrs => ['cn'],
543 filter => "(macAddress=$macaddress)");
544 if($mesg->code) {
545 &main::daemon_log($mesg->error, 1);
546 $plain_name = "none";
547 } else {
548 my $entry= $mesg->entry(0);
549 $plain_name = $entry->get_value("cn");
550 }
551 }
553 # In any case add a new job to job queue
554 &main::daemon_log("$session_id DEBUG: add job to queue for host '$macaddress'", 7);
555 my $func_dic = {table=>$main::job_queue_tn,
556 primkey=>['macaddress', 'headertag'],
557 timestamp=>&get_time,
558 status=>'processing',
559 result=>"$header $content",
560 progress=>'none',
561 headertag=>'trigger_action_reinstall',
562 targettag=>$target,
563 xmlmessage=>'none',
564 macaddress=>$macaddress,
565 plainname=>$plain_name,
566 modified=>'1',
567 siserver=>'localhost',
568 };
569 my ($err, $error_str) = $main::job_db->add_dbentry($func_dic);
570 if ($err != 0) {
571 &main::daemon_log("$session_id ERROR: cannot add entry to job_db: $error_str", 1);
572 }
573 }
574 }
576 return;
577 }
580 ## @method TASKEND()
581 # @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.
582 # @param msg - STRING - xml message with tag 'macaddress'.
583 # @param msg_hash - HASHREF - message information parsed into a hash
584 # @param session_id - INTEGER - POE session id of the processing of this message
585 sub TASKEND {
586 my ($msg, $msg_hash, $session_id) = @_;
587 my $header = @{$msg_hash->{'header'}}[0];
588 my $target = @{$msg_hash->{'target'}}[0];
589 my $source = @{$msg_hash->{'source'}}[0];
590 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
592 # test whether content is an empty hash or a string which is required
593 my $content = @{$msg_hash->{$header}}[0];
594 if(ref($content) eq "HASH") { $content = ""; }
596 # clean up header
597 $header =~ s/CLMSG_//g;
599 if ($content eq "savelog 0") {
600 &main::daemon_log("$session_id DEBUG: got savelog from host '$target' - job done", 7);
602 # set job to status 'done', job will be deleted automatically
603 my $sql_statement = "UPDATE $main::job_queue_tn ".
604 "SET status='done', modified='1'".
605 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
606 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
607 my $res = $main::job_db->update_dbentry( $sql_statement );
609 } else {
610 my $sql_statement = "UPDATE $main::job_queue_tn ".
611 "SET status='processing', result='$header "."$content', modified='1' ".
612 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
613 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
614 my $res = $main::job_db->update_dbentry($sql_statement);
615 &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5);
616 }
618 return;
619 }
622 ## @method TASKERROR()
623 # @details Message reports a FAI error. Job at job_queue_db is going to be updated.
624 # @param msg - STRING - xml message with tag 'macaddress' and 'TASKERROR'
625 # @param msg_hash - HASHREF - message information parsed into a hash
626 # @param session_id - INTEGER - POE session id of the processing of this message
627 sub TASKERROR {
628 my ($msg, $msg_hash, $session_id) = @_;
629 my $header = @{$msg_hash->{'header'}}[0];
630 my $source = @{$msg_hash->{'source'}}[0];
631 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
633 # clean up header
634 $header =~ s/CLMSG_//g;
636 # test whether content is an empty hash or a string which is required
637 my $content = @{$msg_hash->{$header}}[0];
638 if(ref($content) eq "HASH") { $content = ""; }
640 # set fai_state to localboot
641 &main::change_fai_state('error', \@{$msg_hash->{'macaddress'}}, $session_id);
643 my $sql_statement = "UPDATE $main::job_queue_tn ".
644 "SET status='processing', result='$header "."$content', modified='1' ".
645 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
646 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
647 my $res = $main::job_db->update_dbentry($sql_statement);
648 &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5);
650 return;
651 }
654 ## @method HOOK()
655 # @details Message reports a FAI hook. Job at job_queue_db is going to be updated.
656 # @param msg - STRING - xml message with tag 'macaddress' and 'HOOK'
657 # @param msg_hash - HASHREF - message information parsed into a hash
658 # @param session_id - INTEGER - POE session id of the processing of this message
659 sub HOOK {
660 my ($msg, $msg_hash, $session_id) = @_;
661 my $header = @{$msg_hash->{'header'}}[0];
662 my $source = @{$msg_hash->{'source'}}[0];
663 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
665 # clean up header
666 $header =~ s/CLMSG_//g;
668 # test whether content is an empty hash or a string which is required
669 my $content = @{$msg_hash->{$header}}[0];
670 if(not ref($content) eq "STRING") { $content = ""; }
672 my $sql_statement = "UPDATE $main::job_queue_tn ".
673 "SET status='processing', result='$header "."$content', modified='1' ".
674 "WHERE status='processing' AND macaddress LIKE '$macaddress'";
675 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
676 my $res = $main::job_db->update_dbentry($sql_statement);
677 &main::daemon_log("$session_id INFO: $header at '$macaddress' - '$content'", 5);
679 return;
680 }
683 =pod
685 =head1 NAME
687 clMessages - Implementation of a GOsa-SI event module for GOsa-SI-server.
689 =head1 SYNOPSIS
691 use GOSA::GosaSupportDaemon;
692 use MIME::Base64;
694 =head1 DESCRIPTION
696 This GOsa-SI event module containing all functions to handle messages coming from GOsa-SI-clients.
698 This module will be automatically imported by GOsa-SI if it is under F</usr/lib/gosa-si/server/E<lt>PACKAGEMODULEE<gt>/> .
700 =head1 METHODS
702 =over 4
704 =item get_events ( )
706 =item confirm_usr_msg ( )
708 =item PROGRESS ( )
710 =item FAIREBOOT ( )
712 =item TASKSKIP ( )
714 =item TASKBEGIN ( )
716 =item TASKEND ( )
718 =item TASKERROR ( )
720 =item HOOK ( )
722 =item GOTOACTIVATION ( )
724 =item LOGIN ( )
726 =item LOGOUT ( )
728 =item CURRENTLY_LOGGED_IN ( )
730 =item save_fai_log ( )
732 =back
734 =head1 BUGS
736 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>
738 =head1 COPYRIGHT
740 This code is part of GOsa (L<http://www.gosa-project.org>)
742 Copyright (C) 2003-2008 GONICUS GmbH
744 This program is distributed in the hope that it will be useful,
745 but WITHOUT ANY WARRANTY; without even the implied warranty of
746 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
747 GNU General Public License for more details.
749 =cut
752 1;