c788754e2e9ccf216a4d32b167235f4dcad9e7c3
1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 "get_events",
6 "get_login_usr_for_client",
7 "get_client_for_login_usr",
8 "gen_smb_hash",
9 "trigger_reload_ldap_config",
10 "ping",
11 "network_completition",
12 "set_activated_for_installation",
13 "new_key_for_client",
14 "detect_hardware",
15 "get_login_usr",
16 "get_login_client",
17 "trigger_action_localboot",
18 "trigger_action_faireboot",
19 "trigger_action_reboot",
20 "trigger_action_activate",
21 "trigger_action_lock",
22 "trigger_action_halt",
23 "trigger_action_update",
24 "trigger_action_reinstall",
25 "trigger_action_memcheck",
26 "trigger_action_sysinfo",
27 "trigger_action_instant_update",
28 "trigger_action_rescan",
29 "trigger_action_wake",
30 "recreate_fai_server_db",
31 "recreate_fai_release_db",
32 "recreate_packages_list_db",
33 "send_user_msg",
34 "get_available_kernel",
35 );
36 @EXPORT = @events;
38 use strict;
39 use warnings;
40 use GOSA::GosaSupportDaemon;
41 use Data::Dumper;
42 use Crypt::SmbHash;
43 use Net::ARP;
44 use Net::Ping;
45 use Socket;
47 BEGIN {}
49 END {}
51 ### Start ######################################################################
53 #&main::read_configfile($main::cfg_file, %cfg_defaults);
55 sub get_events {
56 return \@events;
57 }
59 sub send_user_msg {
60 my ($msg, $msg_hash, $session_id) = @_ ;
61 my $header = @{$msg_hash->{'header'}}[0];
62 my $source = @{$msg_hash->{'source'}}[0];
63 my $target = @{$msg_hash->{'target'}}[0];
65 #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
66 my $subject = @{$msg_hash->{'subject'}}[0];
67 my $from = @{$msg_hash->{'from'}}[0];
68 my @to = @{$msg_hash->{'to'}};
69 my $delivery_time = @{$msg_hash->{'delivery_time'}}[0];
70 #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
71 my $message = @{$msg_hash->{'message'}}[0];
73 # keep job queue uptodate if necessary
74 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
75 if( defined $jobdb_id) {
76 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
77 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
78 my $res = $main::job_db->exec_statement($sql_statement);
79 }
81 # error handling
82 if (not $delivery_time =~ /^\d{14}$/) {
83 my $error_string = "delivery_time '$delivery_time' is not a valid timestamp, please use format 'yyyymmddhhmmss'";
84 &main::daemon_log("$session_id ERROR: $error_string", 1);
85 return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
86 }
88 # add incoming message to messaging_db
89 my $new_msg_id = 1;
90 my $new_msg_id_sql = "SELECT MAX(id) FROM $main::messaging_tn";
91 my $new_msg_id_res = $main::messaging_db->exec_statement($new_msg_id_sql);
92 if (defined @{@{$new_msg_id_res}[0]}[0] ) {
93 $new_msg_id = int(@{@{$new_msg_id_res}[0]}[0]);
94 $new_msg_id += 1;
95 }
97 my $func_dic = {table=>$main::messaging_tn,
98 primkey=>[],
99 id=>$new_msg_id,
100 subject=>$subject,
101 message_from=>$from,
102 message_to=>join(",",@to),
103 flag=>"n",
104 direction=>"in",
105 delivery_time=>$delivery_time,
106 message=>$message,
107 timestamp=>&get_time(),
108 };
109 my $res = $main::messaging_db->add_dbentry($func_dic);
110 if (not $res == 0) {
111 &main::daemon_log("$session_id ERROR: gosaTriggered.pm: cannot add message to message_db: $res", 1);
112 } else {
113 &main::daemon_log("$session_id INFO: gosaTriggered.pm: message with subject '$subject' successfully added to message_db", 5);
114 }
116 return;
117 }
119 sub send_user_msg_OLD {
120 my ($msg, $msg_hash, $session_id) = @_ ;
121 my @out_msg_l;
122 my @user_list;
123 my @group_list;
125 my $header = @{$msg_hash->{'header'}}[0];
126 my $source = @{$msg_hash->{'source'}}[0];
127 my $target = @{$msg_hash->{'target'}}[0];
128 my $message = @{$msg_hash->{'message'}}[0];
129 if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; }
130 if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; }
132 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
133 if( defined $jobdb_id) {
134 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
135 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
136 my $res = $main::job_db->exec_statement($sql_statement);
137 }
139 # error handling
140 if( not @user_list && not @group_list ) {
141 &main::daemon_log("$session_id WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
142 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
143 "<error_string>no user-tag or a group-tag specified in 'send_user_msg'</error_string></xml>");
144 }
145 if( not defined $message ) {
146 &main::daemon_log("$session_id WARNING: no message-tag specified in 'send_user_msg'", 3);
147 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
148 "<error_string>no message-tag specified in 'send_user_msg'</error_string></xml>");
150 }
152 # resolve groups to users
153 my $ldap_handle = &main::get_ldap_handle($session_id);
154 if( @group_list ) {
155 if( not defined $ldap_handle ) {
156 &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
157 return ();
158 }
159 foreach my $group (@group_list) { # Perform search
160 my $mesg = $ldap_handle->search(
161 base => $main::ldap_base,
162 scope => 'sub',
163 attrs => ['memberUid'],
164 filter => "(&(objectClass=posixGroup)(cn=$group)(memberUid=*))");
165 if($mesg->code) {
166 &main::daemon_log($mesg->error, 1);
167 return ();
168 }
169 my $entry= $mesg->entry(0);
170 my @users= $entry->get_value("memberUid");
171 foreach my $user (@users) { push(@user_list, $user); }
172 }
173 }
175 # drop multiple users in @user_list
176 my %seen = ();
177 foreach my $user (@user_list) {
178 $seen{$user}++;
179 }
180 @user_list = keys %seen;
182 # build xml messages sended to client where user is logged in
183 foreach my $user (@user_list) {
184 my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user='$user'";
185 my $db_res = $main::login_users_db->select_dbentry($sql_statement);
187 if(0 == keys(%{$db_res})) {
189 } else {
190 while( my($hit, $content) = each %{$db_res} ) {
191 my $out_hash = &create_xml_hash('send_user_msg', $main::server_address, $content->{'client'});
192 &add_content2xml_hash($out_hash, 'message', $message);
193 &add_content2xml_hash($out_hash, 'user', $user);
194 if( exists $msg_hash->{'jobdb_id'} ) {
195 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
196 }
197 my $out_msg = &create_xml_string($out_hash);
198 push(@out_msg_l, $out_msg);
199 }
200 }
201 }
203 return @out_msg_l;
204 }
207 sub recreate_fai_server_db {
208 my ($msg, $msg_hash, $session_id) = @_ ;
209 my $out_msg;
211 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
212 if( defined $jobdb_id) {
213 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
214 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
215 my $res = $main::job_db->exec_statement($sql_statement);
216 }
218 $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
219 &main::create_fai_server_db("new_fai_server",undef,"dont", $session_id);
220 $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
222 my @out_msg_l = ( $out_msg );
223 return @out_msg_l;
224 }
227 sub recreate_fai_release_db {
228 my ($msg, $msg_hash, $session_id) = @_ ;
229 my $out_msg;
231 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
232 if( defined $jobdb_id) {
233 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
234 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
235 my $res = $main::job_db->exec_statement($sql_statement);
236 }
238 $main::fai_release_db->create_table("new_fai_release", \@main::fai_release_col_names);
239 &main::create_fai_release_db("new_fai_release", $session_id);
240 $main::fai_release_db->move_table("new_fai_release", $main::fai_release_tn);
242 my @out_msg_l = ( $out_msg );
243 return @out_msg_l;
244 }
247 sub recreate_packages_list_db {
248 my ($msg, $msg_hash, $session_id) = @_ ;
249 my $out_msg;
251 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
252 if( defined $jobdb_id) {
253 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
254 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
255 my $res = $main::job_db->exec_statement($sql_statement);
256 }
258 &main::create_packages_list_db;
260 my @out_msg_l = ( $out_msg );
261 return @out_msg_l;
262 }
265 sub get_login_usr_for_client {
266 my ($msg, $msg_hash, $session_id) = @_ ;
267 my $header = @{$msg_hash->{'header'}}[0];
268 my $source = @{$msg_hash->{'source'}}[0];
269 my $target = @{$msg_hash->{'target'}}[0];
270 my $client = @{$msg_hash->{'client'}}[0];
272 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
273 if( defined $jobdb_id) {
274 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
275 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
276 my $res = $main::job_db->exec_statement($sql_statement);
277 }
279 $header =~ s/^gosa_//;
281 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
282 my $res = $main::known_clients_db->select_dbentry($sql_statement);
284 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
285 $out_msg .= &db_res2xml($res);
286 $out_msg .= "</xml>";
288 my @out_msg_l = ( $out_msg );
289 return @out_msg_l;
290 }
293 sub get_client_for_login_usr {
294 my ($msg, $msg_hash, $session_id) = @_ ;
295 my $header = @{$msg_hash->{'header'}}[0];
296 my $source = @{$msg_hash->{'source'}}[0];
297 my $target = @{$msg_hash->{'target'}}[0];
299 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
300 if( defined $jobdb_id) {
301 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
302 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
303 my $res = $main::job_db->exec_statement($sql_statement);
304 }
306 my $usr = @{$msg_hash->{'usr'}}[0];
307 $header =~ s/^gosa_//;
309 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
310 my $res = $main::known_clients_db->select_dbentry($sql_statement);
312 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
313 $out_msg .= &db_res2xml($res);
314 $out_msg .= "</xml>";
315 my @out_msg_l = ( $out_msg );
316 return @out_msg_l;
318 }
321 sub ping {
322 my ($msg, $msg_hash, $session_id) = @_ ;
323 my $out_msg = $msg;
324 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
325 if( defined $jobdb_id) {
326 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
327 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
328 my $res = $main::job_db->exec_statement($sql_statement);
329 }
331 $out_msg =~ s/<header>gosa_/<header>/;
333 my @out_msg_l = ( $out_msg );
334 return @out_msg_l;
335 }
337 sub gen_smb_hash {
338 my ($msg, $msg_hash, $session_id) = @_ ;
339 my $source = @{$msg_hash->{source}}[0];
340 my $target = @{$msg_hash->{target}}[0];
341 my $password = @{$msg_hash->{password}}[0];
343 my %data= ('hash' => join(q[:], ntlmgen $password));
344 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
345 return ( $out_msg );
346 }
349 sub network_completition {
350 my ($msg, $msg_hash, $session_id) = @_ ;
351 my $source = @{$msg_hash->{source}}[0];
352 my $target = @{$msg_hash->{target}}[0];
353 my $name = @{$msg_hash->{hostname}}[0];
355 # Can we resolv the name?
356 my %data;
357 if (inet_aton($name)){
358 my $address = inet_ntoa(inet_aton($name));
359 my $p = Net::Ping->new('tcp');
360 my $mac= "";
361 if ($p->ping($address, 1)){
362 $mac = Net::ARP::arp_lookup("", $address);
363 }
365 %data= ('ip' => $address, 'mac' => $mac);
366 } else {
367 %data= ('ip' => '', 'mac' => '');
368 }
370 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
372 return ( $out_msg );
373 }
376 sub detect_hardware {
377 my ($msg, $msg_hash, $session_id) = @_ ;
378 # just forward msg to client, but dont forget to split off 'gosa_' in header
379 my $source = @{$msg_hash->{source}}[0];
380 my $target = @{$msg_hash->{target}}[0];
381 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
382 if( defined $jobdb_id) {
383 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
384 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
385 my $res = $main::job_db->exec_statement($sql_statement);
386 }
388 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
389 if( defined $jobdb_id ) {
390 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
391 }
392 my $out_msg = &create_xml_string($out_hash);
394 my @out_msg_l = ( $out_msg );
395 return @out_msg_l;
397 }
400 sub trigger_reload_ldap_config {
401 my ($msg, $msg_hash, $session_id) = @_ ;
402 my $target = @{$msg_hash->{target}}[0];
404 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
405 if( defined $jobdb_id) {
406 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
407 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
408 my $res = $main::job_db->exec_statement($sql_statement);
409 }
411 my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target);
412 if( defined ) {
413 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
414 }
415 my $out_msg = &create_xml_string($out_hash);
416 my @out_msg_l;
417 push(@out_msg_l, $out_msg);
418 return @out_msg_l;
419 }
422 sub set_activated_for_installation {
423 my ($msg, $msg_hash, $session_id) = @_;
424 my $header = @{$msg_hash->{header}}[0];
425 my $source = @{$msg_hash->{source}}[0];
426 my $target = @{$msg_hash->{target}}[0];
427 my @out_msg_l;
429 # update status of job
430 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
431 if( defined $jobdb_id) {
432 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
433 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
434 my $res = $main::job_db->exec_statement($sql_statement);
435 }
437 # create set_activated_for_installation message for delivery
438 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
439 if( defined $jobdb_id ) {
440 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
441 }
442 my $out_msg = &create_xml_string($out_hash);
443 push(@out_msg_l, $out_msg);
445 return @out_msg_l;
446 }
449 sub trigger_action_faireboot {
450 my ($msg, $msg_hash, $session_id) = @_;
451 my $macaddress = @{$msg_hash->{target}}[0];
452 my $source = @{$msg_hash->{source}}[0];
454 my @out_msg_l;
455 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
456 push(@out_msg_l, $msg);
458 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
459 &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id);
461 # delete all jobs from jobqueue which correspond to fai
462 my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
463 "status='processing')";
464 $main::job_db->del_dbentry($sql_statement );
466 return @out_msg_l;
467 }
470 sub trigger_action_lock {
471 my ($msg, $msg_hash, $session_id) = @_;
472 my $macaddress = @{$msg_hash->{target}}[0];
473 my $source = @{$msg_hash->{source}}[0];
475 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
476 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
477 if( defined $jobdb_id) {
478 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
479 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
480 my $res = $main::job_db->exec_statement($sql_statement);
481 }
483 my @out_msg_l;
484 return @out_msg_l;
485 }
488 sub trigger_action_activate {
489 my ($msg, $msg_hash, $session_id) = @_;
490 my $macaddress = @{$msg_hash->{target}}[0];
491 my $source = @{$msg_hash->{source}}[0];
493 &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id);
494 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
495 if( defined $jobdb_id) {
496 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
497 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
498 my $res = $main::job_db->exec_statement($sql_statement);
499 }
501 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
502 if( exists $msg_hash->{'jobdb_id'} ) {
503 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
504 }
505 my $out_msg = &create_xml_string($out_hash);
507 return ( $out_msg );
508 }
511 sub trigger_action_localboot {
512 my ($msg, $msg_hash, $session_id) = @_;
513 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
514 &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
515 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
516 if( defined $jobdb_id) {
517 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
518 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
519 my $res = $main::job_db->exec_statement($sql_statement);
520 }
522 my @out_msg_l = ($msg);
523 return @out_msg_l;
524 }
527 sub trigger_action_halt {
528 my ($msg, $msg_hash, $session_id) = @_;
529 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
531 &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id);
532 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
533 if( defined $jobdb_id) {
534 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
535 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
536 my $res = $main::job_db->exec_statement($sql_statement);
537 }
539 my @out_msg_l = ($msg);
540 return @out_msg_l;
541 }
544 sub trigger_action_reboot {
545 my ($msg, $msg_hash, $session_id) = @_;
546 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
548 &main::change_fai_state('reboot', \@{$msg_hash->{target}}, $session_id);
549 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
550 if( defined $jobdb_id) {
551 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
552 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
553 my $res = $main::job_db->exec_statement($sql_statement);
554 }
556 my @out_msg_l = ($msg);
557 return @out_msg_l;
558 }
561 sub trigger_action_memcheck {
562 my ($msg, $msg_hash, $session_id) = @_ ;
563 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
565 &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id);
566 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
567 if( defined $jobdb_id) {
568 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
569 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
570 my $res = $main::job_db->exec_statement($sql_statement);
571 }
573 my @out_msg_l = ($msg);
574 return @out_msg_l;
575 }
578 sub trigger_action_reinstall {
579 my ($msg, $msg_hash, $session_id) = @_;
580 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
582 &main::change_fai_state('reinstall', \@{$msg_hash->{target}}, $session_id);
584 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
585 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
586 my @out_msg_l = ($wake_msg, $msg);
587 return @out_msg_l;
588 }
591 sub trigger_action_update {
592 my ($msg, $msg_hash, $session_id) = @_;
593 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
595 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
597 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
598 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
599 my @out_msg_l = ($wake_msg, $msg);
600 return @out_msg_l;
601 }
604 sub trigger_action_instant_update {
605 my ($msg, $msg_hash, $session_id) = @_;
606 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
608 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
610 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
611 if( defined $jobdb_id) {
612 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
613 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
614 my $res = $main::job_db->exec_statement($sql_statement);
615 }
617 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
618 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
619 my @out_msg_l = ($wake_msg, $msg);
620 return @out_msg_l;
621 }
624 sub trigger_action_sysinfo {
625 my ($msg, $msg_hash, $session_id) = @_;
626 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
628 &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id);
629 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
630 if( defined $jobdb_id) {
631 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
632 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
633 my $res = $main::job_db->exec_statement($sql_statement);
634 }
636 my @out_msg_l = ($msg);
637 return @out_msg_l;
638 }
641 sub new_key_for_client {
642 my ($msg, $msg_hash, $session_id) = @_;
644 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
645 if( defined $jobdb_id) {
646 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
647 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
648 my $res = $main::job_db->exec_statement($sql_statement);
649 }
651 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
652 my @out_msg_l = ($msg);
653 return @out_msg_l;
654 }
657 sub trigger_action_rescan {
658 my ($msg, $msg_hash, $session_id) = @_;
660 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
661 if( defined $jobdb_id) {
662 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
663 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
664 my $res = $main::job_db->exec_statement($sql_statement);
665 }
668 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
669 my @out_msg_l = ($msg);
670 return @out_msg_l;
671 }
674 sub trigger_action_wake {
675 my ($msg, $msg_hash, $session_id) = @_;
677 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
678 if( defined $jobdb_id) {
679 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
680 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
681 my $res = $main::job_db->exec_statement($sql_statement);
682 }
685 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
686 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
687 my @out_msg_l = ($out_msg);
688 return @out_msg_l;
689 }
692 sub get_available_kernel {
693 my ($msg, $msg_hash, $session_id) = @_;
695 my $source = @{$msg_hash->{'source'}}[0];
696 my $target = @{$msg_hash->{'target'}}[0];
697 my $release= @{$msg_hash->{'release'}}[0];
699 my @kernel;
700 # Get Kernel packages for release
701 my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
702 my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
703 my %data;
704 my $i=1;
706 foreach my $package (keys %{$res_hash}) {
707 $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
708 }
709 $data{"answer".$i++}= "default";
711 my $out_msg = &build_msg("get_available_kernel", $target, "GOSA", \%data);
712 return ( $out_msg );
713 }
716 1;