0d4861e58f302acbf91855e3ef3be737810ffc47
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 "send_user_msg",
32 "get_available_kernel",
33 );
34 @EXPORT = @events;
36 use strict;
37 use warnings;
38 use GOSA::GosaSupportDaemon;
39 use Data::Dumper;
40 use Crypt::SmbHash;
41 use Net::ARP;
42 use Net::Ping;
43 use Socket;
45 BEGIN {}
47 END {}
49 ### Start ######################################################################
51 #&main::read_configfile($main::cfg_file, %cfg_defaults);
53 sub get_events {
54 return \@events;
55 }
57 sub send_user_msg {
58 my ($msg, $msg_hash, $session_id) = @_ ;
59 my $header = @{$msg_hash->{'header'}}[0];
60 my $source = @{$msg_hash->{'source'}}[0];
61 my $target = @{$msg_hash->{'target'}}[0];
63 #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
64 my $subject = @{$msg_hash->{'subject'}}[0];
65 my $from = @{$msg_hash->{'from'}}[0];
66 my $to = @{$msg_hash->{'to'}}[0];
67 my $delivery_time = @{$msg_hash->{'delivery_time'}}[0];
68 #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
69 my $message = @{$msg_hash->{'message'}}[0];
71 # keep job queue uptodate if necessary
72 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
73 if( defined $jobdb_id) {
74 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
75 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
76 my $res = $main::job_db->exec_statement($sql_statement);
77 }
79 # error handling
80 if (not $delivery_time =~ /^\d{14}$/) {
81 my $error_string = "delivery_time '$delivery_time' is not a valid timestamp, please use format 'yyyymmddhhmmss'";
82 &main::daemon_log("$session_id ERROR: $error_string", 1);
83 return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
84 }
86 # add incoming message to messaging_db
87 my $func_dic = {table=>$main::messaging_tn,
88 primkey=>['id'],
89 subject=>$subject,
90 message_from=>$from,
91 message_to=>$to,
92 flag=>"n",
93 direction=>"in",
94 delivery_time=>$delivery_time,
95 message=>$message,
96 timestamp=>&get_time(),
97 };
98 my $res = $main::messaging_db->add_dbentry($func_dic);
99 if (not $res == 0) {
100 &main::daemon_log("$session_id ERROR: gosaTriggered.pm: cannot add message to message_db: $res", 1);
101 } else {
102 &main::daemon_log("$session_id INFO: gosaTriggered.pm: message with subject '$subject' successfully added to message_db", 5);
103 }
105 return;
106 }
108 sub send_user_msg_OLD {
109 my ($msg, $msg_hash, $session_id) = @_ ;
110 my @out_msg_l;
111 my @user_list;
112 my @group_list;
114 my $header = @{$msg_hash->{'header'}}[0];
115 my $source = @{$msg_hash->{'source'}}[0];
116 my $target = @{$msg_hash->{'target'}}[0];
117 my $message = @{$msg_hash->{'message'}}[0];
118 if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; }
119 if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; }
121 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
122 if( defined $jobdb_id) {
123 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
124 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
125 my $res = $main::job_db->exec_statement($sql_statement);
126 }
128 # error handling
129 if( not @user_list && not @group_list ) {
130 &main::daemon_log("$session_id WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
131 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
132 "<error_string>no user-tag or a group-tag specified in 'send_user_msg'</error_string></xml>");
133 }
134 if( not defined $message ) {
135 &main::daemon_log("$session_id WARNING: no message-tag specified in 'send_user_msg'", 3);
136 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
137 "<error_string>no message-tag specified in 'send_user_msg'</error_string></xml>");
139 }
141 # resolve groups to users
142 my $ldap_handle = &main::get_ldap_handle($session_id);
143 if( @group_list ) {
144 if( not defined $ldap_handle ) {
145 &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
146 return ();
147 }
148 foreach my $group (@group_list) { # Perform search
149 my $mesg = $ldap_handle->search(
150 base => $main::ldap_base,
151 scope => 'sub',
152 attrs => ['memberUid'],
153 filter => "(&(objectClass=posixGroup)(cn=$group)(memberUid=*))");
154 if($mesg->code) {
155 &main::daemon_log($mesg->error, 1);
156 return ();
157 }
158 my $entry= $mesg->entry(0);
159 my @users= $entry->get_value("memberUid");
160 foreach my $user (@users) { push(@user_list, $user); }
161 }
162 }
164 # drop multiple users in @user_list
165 my %seen = ();
166 foreach my $user (@user_list) {
167 $seen{$user}++;
168 }
169 @user_list = keys %seen;
171 # build xml messages sended to client where user is logged in
172 foreach my $user (@user_list) {
173 my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user='$user'";
174 my $db_res = $main::login_users_db->select_dbentry($sql_statement);
176 if(0 == keys(%{$db_res})) {
178 } else {
179 while( my($hit, $content) = each %{$db_res} ) {
180 my $out_hash = &create_xml_hash('send_user_msg', $main::server_address, $content->{'client'});
181 &add_content2xml_hash($out_hash, 'message', $message);
182 &add_content2xml_hash($out_hash, 'user', $user);
183 if( exists $msg_hash->{'jobdb_id'} ) {
184 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
185 }
186 my $out_msg = &create_xml_string($out_hash);
187 push(@out_msg_l, $out_msg);
188 }
189 }
190 }
192 return @out_msg_l;
193 }
196 sub recreate_fai_server_db {
197 my ($msg, $msg_hash, $session_id) = @_ ;
198 my $out_msg;
200 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
201 if( defined $jobdb_id) {
202 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
203 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
204 my $res = $main::job_db->exec_statement($sql_statement);
205 }
207 $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
208 &main::create_fai_server_db("new_fai_server");
209 $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
211 my @out_msg_l = ( $out_msg );
212 return @out_msg_l;
213 }
216 sub get_login_usr_for_client {
217 my ($msg, $msg_hash, $session_id) = @_ ;
218 my $header = @{$msg_hash->{'header'}}[0];
219 my $source = @{$msg_hash->{'source'}}[0];
220 my $target = @{$msg_hash->{'target'}}[0];
221 my $client = @{$msg_hash->{'client'}}[0];
223 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
224 if( defined $jobdb_id) {
225 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
226 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
227 my $res = $main::job_db->exec_statement($sql_statement);
228 }
230 $header =~ s/^gosa_//;
232 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
233 my $res = $main::known_clients_db->select_dbentry($sql_statement);
235 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
236 $out_msg .= &db_res2xml($res);
237 $out_msg .= "</xml>";
239 my @out_msg_l = ( $out_msg );
240 return @out_msg_l;
241 }
244 sub get_client_for_login_usr {
245 my ($msg, $msg_hash, $session_id) = @_ ;
246 my $header = @{$msg_hash->{'header'}}[0];
247 my $source = @{$msg_hash->{'source'}}[0];
248 my $target = @{$msg_hash->{'target'}}[0];
250 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
251 if( defined $jobdb_id) {
252 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
253 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
254 my $res = $main::job_db->exec_statement($sql_statement);
255 }
257 my $usr = @{$msg_hash->{'usr'}}[0];
258 $header =~ s/^gosa_//;
260 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
261 my $res = $main::known_clients_db->select_dbentry($sql_statement);
263 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
264 $out_msg .= &db_res2xml($res);
265 $out_msg .= "</xml>";
266 my @out_msg_l = ( $out_msg );
267 return @out_msg_l;
269 }
272 sub ping {
273 my ($msg, $msg_hash, $session_id) = @_ ;
274 my $out_msg = $msg;
275 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
276 if( defined $jobdb_id) {
277 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
278 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
279 my $res = $main::job_db->exec_statement($sql_statement);
280 }
282 $out_msg =~ s/<header>gosa_/<header>/;
284 my @out_msg_l = ( $out_msg );
285 return @out_msg_l;
286 }
288 sub gen_smb_hash {
289 my ($msg, $msg_hash, $session_id) = @_ ;
290 my $source = @{$msg_hash->{source}}[0];
291 my $target = @{$msg_hash->{target}}[0];
292 my $password = @{$msg_hash->{password}}[0];
294 my %data= ('hash' => join(q[:], ntlmgen $password));
295 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
296 return ( $out_msg );
297 }
300 sub network_completition {
301 my ($msg, $msg_hash, $session_id) = @_ ;
302 my $source = @{$msg_hash->{source}}[0];
303 my $target = @{$msg_hash->{target}}[0];
304 my $name = @{$msg_hash->{hostname}}[0];
306 # Can we resolv the name?
307 my %data;
308 if (inet_aton($name)){
309 my $address = inet_ntoa(inet_aton($name));
310 my $p = Net::Ping->new('tcp');
311 my $mac= "";
312 if ($p->ping($address, 1)){
313 $mac = Net::ARP::arp_lookup("", $address);
314 }
316 %data= ('ip' => $address, 'mac' => $mac);
317 } else {
318 %data= ('ip' => '', 'mac' => '');
319 }
321 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
323 return ( $out_msg );
324 }
327 sub detect_hardware {
328 my ($msg, $msg_hash, $session_id) = @_ ;
329 # just forward msg to client, but dont forget to split off 'gosa_' in header
330 my $source = @{$msg_hash->{source}}[0];
331 my $target = @{$msg_hash->{target}}[0];
332 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
333 if( defined $jobdb_id) {
334 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
335 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
336 my $res = $main::job_db->exec_statement($sql_statement);
337 }
339 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
340 if( defined $jobdb_id ) {
341 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
342 }
343 my $out_msg = &create_xml_string($out_hash);
345 my @out_msg_l = ( $out_msg );
346 return @out_msg_l;
348 }
351 sub trigger_reload_ldap_config {
352 my ($msg, $msg_hash, $session_id) = @_ ;
353 my $target = @{$msg_hash->{target}}[0];
355 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
356 if( defined $jobdb_id) {
357 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
358 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
359 my $res = $main::job_db->exec_statement($sql_statement);
360 }
362 my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target);
363 if( defined ) {
364 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
365 }
366 my $out_msg = &create_xml_string($out_hash);
367 my @out_msg_l;
368 push(@out_msg_l, $out_msg);
369 return @out_msg_l;
370 }
373 sub set_activated_for_installation {
374 my ($msg, $msg_hash, $session_id) = @_;
375 my $header = @{$msg_hash->{header}}[0];
376 my $source = @{$msg_hash->{source}}[0];
377 my $target = @{$msg_hash->{target}}[0];
378 my @out_msg_l;
380 # create set_activated_for_installation message
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("set_activated_for_installation", $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);
393 push(@out_msg_l, $out_msg);
395 # create new_ldap_config message, client is waiting for that piece of information
396 my $new_ldap_config_out = &main::new_ldap_config($source, $session_id);
397 push(@out_msg_l, $new_ldap_config_out);
400 return @out_msg_l;
401 }
404 sub trigger_action_faireboot {
405 my ($msg, $msg_hash, $session_id) = @_;
406 my $macaddress = @{$msg_hash->{target}}[0];
407 my $source = @{$msg_hash->{source}}[0];
409 my @out_msg_l;
410 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
411 push(@out_msg_l, $msg);
413 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
414 &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id);
416 # delete all jobs from jobqueue which correspond to fai
417 my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
418 "status='processing')";
419 $main::job_db->del_dbentry($sql_statement );
421 return @out_msg_l;
422 }
425 sub trigger_action_lock {
426 my ($msg, $msg_hash, $session_id) = @_;
427 my $macaddress = @{$msg_hash->{target}}[0];
428 my $source = @{$msg_hash->{source}}[0];
430 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
431 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
432 if( defined $jobdb_id) {
433 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
434 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
435 my $res = $main::job_db->exec_statement($sql_statement);
436 }
438 my @out_msg_l;
439 return @out_msg_l;
440 }
443 sub trigger_action_activate {
444 my ($msg, $msg_hash, $session_id) = @_;
445 my $macaddress = @{$msg_hash->{target}}[0];
446 my $source = @{$msg_hash->{source}}[0];
448 &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id);
449 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
450 if( defined $jobdb_id) {
451 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
452 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
453 my $res = $main::job_db->exec_statement($sql_statement);
454 }
456 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
457 if( exists $msg_hash->{'jobdb_id'} ) {
458 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
459 }
460 my $out_msg = &create_xml_string($out_hash);
462 return ( $out_msg );
463 }
466 sub trigger_action_localboot {
467 my ($msg, $msg_hash, $session_id) = @_;
468 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
469 &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
470 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
471 if( defined $jobdb_id) {
472 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
473 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
474 my $res = $main::job_db->exec_statement($sql_statement);
475 }
477 my @out_msg_l = ($msg);
478 return @out_msg_l;
479 }
482 sub trigger_action_halt {
483 my ($msg, $msg_hash, $session_id) = @_;
484 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
486 &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id);
487 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
488 if( defined $jobdb_id) {
489 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
490 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
491 my $res = $main::job_db->exec_statement($sql_statement);
492 }
494 my @out_msg_l = ($msg);
495 return @out_msg_l;
496 }
499 sub trigger_action_reboot {
500 my ($msg, $msg_hash, $session_id) = @_;
501 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
503 &main::change_fai_state('reboot', \@{$msg_hash->{target}}, $session_id);
504 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
505 if( defined $jobdb_id) {
506 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
507 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
508 my $res = $main::job_db->exec_statement($sql_statement);
509 }
511 my @out_msg_l = ($msg);
512 return @out_msg_l;
513 }
516 sub trigger_action_memcheck {
517 my ($msg, $msg_hash, $session_id) = @_ ;
518 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
520 &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id);
521 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
522 if( defined $jobdb_id) {
523 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
524 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
525 my $res = $main::job_db->exec_statement($sql_statement);
526 }
528 my @out_msg_l = ($msg);
529 return @out_msg_l;
530 }
533 sub trigger_action_reinstall {
534 my ($msg, $msg_hash, $session_id) = @_;
535 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
537 &main::change_fai_state('reinstall', \@{$msg_hash->{target}}, $session_id);
539 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
540 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
541 my @out_msg_l = ($wake_msg, $msg);
542 return @out_msg_l;
543 }
546 sub trigger_action_update {
547 my ($msg, $msg_hash, $session_id) = @_;
548 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
550 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
552 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
553 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
554 my @out_msg_l = ($wake_msg, $msg);
555 return @out_msg_l;
556 }
559 sub trigger_action_instant_update {
560 my ($msg, $msg_hash, $session_id) = @_;
561 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
563 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
565 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
566 if( defined $jobdb_id) {
567 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
568 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
569 my $res = $main::job_db->exec_statement($sql_statement);
570 }
572 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
573 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
574 my @out_msg_l = ($wake_msg, $msg);
575 return @out_msg_l;
576 }
579 sub trigger_action_sysinfo {
580 my ($msg, $msg_hash, $session_id) = @_;
581 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
583 &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id);
584 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
585 if( defined $jobdb_id) {
586 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
587 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
588 my $res = $main::job_db->exec_statement($sql_statement);
589 }
591 my @out_msg_l = ($msg);
592 return @out_msg_l;
593 }
596 sub new_key_for_client {
597 my ($msg, $msg_hash, $session_id) = @_;
599 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
600 if( defined $jobdb_id) {
601 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
602 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
603 my $res = $main::job_db->exec_statement($sql_statement);
604 }
606 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
607 my @out_msg_l = ($msg);
608 return @out_msg_l;
609 }
612 sub trigger_action_rescan {
613 my ($msg, $msg_hash, $session_id) = @_;
615 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
616 if( defined $jobdb_id) {
617 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
618 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
619 my $res = $main::job_db->exec_statement($sql_statement);
620 }
623 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
624 my @out_msg_l = ($msg);
625 return @out_msg_l;
626 }
629 sub trigger_action_wake {
630 my ($msg, $msg_hash, $session_id) = @_;
632 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
633 if( defined $jobdb_id) {
634 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
635 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
636 my $res = $main::job_db->exec_statement($sql_statement);
637 }
640 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
641 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
642 my @out_msg_l = ($out_msg);
643 return @out_msg_l;
644 }
647 sub get_available_kernel {
648 my ($msg, $msg_hash, $session_id) = @_;
650 my $source = @{$msg_hash->{'source'}}[0];
651 my $target = @{$msg_hash->{'target'}}[0];
652 my $server = @{$msg_hash->{'server'}}[0];
654 # Get available Releases for server
655 my $sql_statement = "SELECT * FROM $main::fai_server_tn WHERE server LIKE '%$server%'";
656 my $res_hash = $main::fai_server_db->select_dbentry($sql_statement);
658 my @kernel;
659 foreach my $release (keys %{$res_hash}) {
660 # Get Kernel packages for release
661 my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='".$res_hash->{$release}->{'release'}."' AND package LIKE 'linux\-image\-%'";
662 my $hash = $main::packages_list_db->select_dbentry($sql_statement);
663 foreach my $package (keys %{$hash}) {
664 push @kernel, (%{$res_hash}->{$release}->{'release'})."|".(%{$hash}->{$package}->{'package'});
665 }
666 }
668 my %data = ('available-kernel' => \@kernel);
670 my $out_msg = &build_msg("get_available_kernel", $target, "GOSA", \%data);
671 return ( $out_msg );
672 }
674 1;