a796deef963a51d6d1e225dce5672ad87910a36a
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 {
61 # msg from gosa
62 # <xml><header>gosa_send_user_msg</header><source>GOSA</source><target>GOSA</target>
63 # <timestamp>20080429151605</timestamp>
64 # <users>andreas.rettenberger</users>
65 # <subject>hallo</subject>
66 # <message>test</message>
67 # <macaddress>GOSA</macaddress>
68 # </xml>
70 my ($msg, $msg_hash, $session_id) = @_ ;
71 my $header = @{$msg_hash->{'header'}}[0];
72 my $source = @{$msg_hash->{'source'}}[0];
73 my $target = @{$msg_hash->{'target'}}[0];
75 #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
76 my $subject = @{$msg_hash->{'subject'}}[0];
77 my $from = @{$msg_hash->{'from'}}[0];
78 my @users = @{$msg_hash->{'users'}};
79 my @groups = @{$msg_hash->{'groups'}}[0];
80 my $delivery_time = @{$msg_hash->{'delivery_time'}}[0];
81 #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
82 my $message = @{$msg_hash->{'message'}}[0];
84 # keep job queue uptodate if necessary
85 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
86 if( defined $jobdb_id) {
87 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
88 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
89 my $res = $main::job_db->exec_statement($sql_statement);
90 }
92 # error handling
93 if (not $delivery_time =~ /^\d{14}$/) {
94 my $error_string = "delivery_time '$delivery_time' is not a valid timestamp, please use format 'yyyymmddhhmmss'";
95 &main::daemon_log("$session_id ERROR: $error_string", 1);
96 return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
97 }
99 # add incoming message to messaging_db
100 my $new_msg_id = 1;
101 my $new_msg_id_sql = "SELECT MAX(id) FROM $main::messaging_tn";
102 my $new_msg_id_res = $main::messaging_db->exec_statement($new_msg_id_sql);
103 if (defined @{@{$new_msg_id_res}[0]}[0] ) {
104 $new_msg_id = int(@{@{$new_msg_id_res}[0]}[0]);
105 $new_msg_id += 1;
106 }
108 # highlight user name and group name
109 my @receiver_l;
110 @users = map(push(@receiver_l, "u_$_"), @users);
111 #@groups = map(push(@receiver_l, "g_$_"), @groups);
112 # TODO
113 # handling, was passiert wenn in einer liste nix drin steht
114 # handling von groups hinzufügen
117 my $func_dic = {table=>$main::messaging_tn,
118 primkey=>[],
119 id=>$new_msg_id,
120 subject=>$subject,
121 message_from=>$from,
122 message_to=>join(",", @receiver_l),
123 flag=>"n",
124 direction=>"in",
125 delivery_time=>$delivery_time,
126 message=>$message,
127 timestamp=>&get_time(),
128 };
129 my $res = $main::messaging_db->add_dbentry($func_dic);
130 if (not $res == 0) {
131 &main::daemon_log("$session_id ERROR: gosaTriggered.pm: cannot add message to message_db: $res", 1);
132 } else {
133 &main::daemon_log("$session_id INFO: gosaTriggered.pm: message with subject '$subject' successfully added to message_db", 5);
134 }
136 return;
137 }
139 sub send_user_msg_OLD {
140 my ($msg, $msg_hash, $session_id) = @_ ;
141 my @out_msg_l;
142 my @user_list;
143 my @group_list;
145 my $header = @{$msg_hash->{'header'}}[0];
146 my $source = @{$msg_hash->{'source'}}[0];
147 my $target = @{$msg_hash->{'target'}}[0];
148 my $message = @{$msg_hash->{'message'}}[0];
149 if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; }
150 if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; }
152 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
153 if( defined $jobdb_id) {
154 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
155 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
156 my $res = $main::job_db->exec_statement($sql_statement);
157 }
159 # error handling
160 if( not @user_list && not @group_list ) {
161 &main::daemon_log("$session_id WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
162 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
163 "<error_string>no user-tag or a group-tag specified in 'send_user_msg'</error_string></xml>");
164 }
165 if( not defined $message ) {
166 &main::daemon_log("$session_id WARNING: no message-tag specified in 'send_user_msg'", 3);
167 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
168 "<error_string>no message-tag specified in 'send_user_msg'</error_string></xml>");
170 }
172 # resolve groups to users
173 my $ldap_handle = &main::get_ldap_handle($session_id);
174 if( @group_list ) {
175 if( not defined $ldap_handle ) {
176 &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
177 return ();
178 }
179 foreach my $group (@group_list) { # Perform search
180 my $mesg = $ldap_handle->search(
181 base => $main::ldap_base,
182 scope => 'sub',
183 attrs => ['memberUid'],
184 filter => "(&(objectClass=posixGroup)(cn=$group)(memberUid=*))");
185 if($mesg->code) {
186 &main::daemon_log($mesg->error, 1);
187 return ();
188 }
189 my $entry= $mesg->entry(0);
190 my @users= $entry->get_value("memberUid");
191 foreach my $user (@users) { push(@user_list, $user); }
192 }
193 }
195 # drop multiple users in @user_list
196 my %seen = ();
197 foreach my $user (@user_list) {
198 $seen{$user}++;
199 }
200 @user_list = keys %seen;
202 # build xml messages sended to client where user is logged in
203 foreach my $user (@user_list) {
204 my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user='$user'";
205 my $db_res = $main::login_users_db->select_dbentry($sql_statement);
207 if(0 == keys(%{$db_res})) {
209 } else {
210 while( my($hit, $content) = each %{$db_res} ) {
211 my $out_hash = &create_xml_hash('send_user_msg', $main::server_address, $content->{'client'});
212 &add_content2xml_hash($out_hash, 'message', $message);
213 &add_content2xml_hash($out_hash, 'user', $user);
214 if( exists $msg_hash->{'jobdb_id'} ) {
215 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
216 }
217 my $out_msg = &create_xml_string($out_hash);
218 push(@out_msg_l, $out_msg);
219 }
220 }
221 }
223 return @out_msg_l;
224 }
227 sub recreate_fai_server_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_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
239 &main::create_fai_server_db("new_fai_server",undef,"dont", $session_id);
240 $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
242 my @out_msg_l = ( $out_msg );
243 return @out_msg_l;
244 }
247 sub recreate_fai_release_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::fai_release_db->create_table("new_fai_release", \@main::fai_release_col_names);
259 &main::create_fai_release_db("new_fai_release", $session_id);
260 $main::fai_release_db->move_table("new_fai_release", $main::fai_release_tn);
262 my @out_msg_l = ( $out_msg );
263 return @out_msg_l;
264 }
267 sub recreate_packages_list_db {
268 my ($msg, $msg_hash, $session_id) = @_ ;
269 my $out_msg;
271 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
272 if( defined $jobdb_id) {
273 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
274 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
275 my $res = $main::job_db->exec_statement($sql_statement);
276 }
278 &main::create_packages_list_db;
280 my @out_msg_l = ( $out_msg );
281 return @out_msg_l;
282 }
285 sub get_login_usr_for_client {
286 my ($msg, $msg_hash, $session_id) = @_ ;
287 my $header = @{$msg_hash->{'header'}}[0];
288 my $source = @{$msg_hash->{'source'}}[0];
289 my $target = @{$msg_hash->{'target'}}[0];
290 my $client = @{$msg_hash->{'client'}}[0];
292 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
293 if( defined $jobdb_id) {
294 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
295 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
296 my $res = $main::job_db->exec_statement($sql_statement);
297 }
299 $header =~ s/^gosa_//;
301 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
302 my $res = $main::known_clients_db->select_dbentry($sql_statement);
304 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
305 $out_msg .= &db_res2xml($res);
306 $out_msg .= "</xml>";
308 my @out_msg_l = ( $out_msg );
309 return @out_msg_l;
310 }
313 sub get_client_for_login_usr {
314 my ($msg, $msg_hash, $session_id) = @_ ;
315 my $header = @{$msg_hash->{'header'}}[0];
316 my $source = @{$msg_hash->{'source'}}[0];
317 my $target = @{$msg_hash->{'target'}}[0];
319 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
320 if( defined $jobdb_id) {
321 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
322 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
323 my $res = $main::job_db->exec_statement($sql_statement);
324 }
326 my $usr = @{$msg_hash->{'usr'}}[0];
327 $header =~ s/^gosa_//;
329 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
330 my $res = $main::known_clients_db->select_dbentry($sql_statement);
332 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
333 $out_msg .= &db_res2xml($res);
334 $out_msg .= "</xml>";
335 my @out_msg_l = ( $out_msg );
336 return @out_msg_l;
338 }
341 sub ping {
342 my ($msg, $msg_hash, $session_id) = @_ ;
343 my $out_msg = $msg;
344 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
345 if( defined $jobdb_id) {
346 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
347 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
348 my $res = $main::job_db->exec_statement($sql_statement);
349 }
351 $out_msg =~ s/<header>gosa_/<header>/;
353 my @out_msg_l = ( $out_msg );
354 return @out_msg_l;
355 }
357 sub gen_smb_hash {
358 my ($msg, $msg_hash, $session_id) = @_ ;
359 my $source = @{$msg_hash->{source}}[0];
360 my $target = @{$msg_hash->{target}}[0];
361 my $password = @{$msg_hash->{password}}[0];
363 my %data= ('hash' => join(q[:], ntlmgen $password));
364 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
365 return ( $out_msg );
366 }
369 sub network_completition {
370 my ($msg, $msg_hash, $session_id) = @_ ;
371 my $source = @{$msg_hash->{source}}[0];
372 my $target = @{$msg_hash->{target}}[0];
373 my $name = @{$msg_hash->{hostname}}[0];
375 # Can we resolv the name?
376 my %data;
377 if (inet_aton($name)){
378 my $address = inet_ntoa(inet_aton($name));
379 my $p = Net::Ping->new('tcp');
380 my $mac= "";
381 if ($p->ping($address, 1)){
382 $mac = Net::ARP::arp_lookup("", $address);
383 }
385 %data= ('ip' => $address, 'mac' => $mac);
386 } else {
387 %data= ('ip' => '', 'mac' => '');
388 }
390 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
392 return ( $out_msg );
393 }
396 sub detect_hardware {
397 my ($msg, $msg_hash, $session_id) = @_ ;
398 # just forward msg to client, but dont forget to split off 'gosa_' in header
399 my $source = @{$msg_hash->{source}}[0];
400 my $target = @{$msg_hash->{target}}[0];
401 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
402 if( defined $jobdb_id) {
403 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
404 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
405 my $res = $main::job_db->exec_statement($sql_statement);
406 }
408 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
409 if( defined $jobdb_id ) {
410 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
411 }
412 my $out_msg = &create_xml_string($out_hash);
414 my @out_msg_l = ( $out_msg );
415 return @out_msg_l;
417 }
420 sub trigger_reload_ldap_config {
421 my ($msg, $msg_hash, $session_id) = @_ ;
422 my $target = @{$msg_hash->{target}}[0];
424 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
425 if( defined $jobdb_id) {
426 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
427 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
428 my $res = $main::job_db->exec_statement($sql_statement);
429 }
431 my $out_msg = &SIPackages::new_ldap_config($target, $session_id);
432 my @out_msg_l = ( $out_msg );
434 return @out_msg_l;
435 }
438 sub set_activated_for_installation {
439 my ($msg, $msg_hash, $session_id) = @_;
440 my $header = @{$msg_hash->{header}}[0];
441 my $source = @{$msg_hash->{source}}[0];
442 my $target = @{$msg_hash->{target}}[0];
443 my @out_msg_l;
445 # update status of job
446 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
447 if( defined $jobdb_id) {
448 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
449 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
450 my $res = $main::job_db->exec_statement($sql_statement);
451 }
453 # create set_activated_for_installation message for delivery
454 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
455 if( defined $jobdb_id ) {
456 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
457 }
458 my $out_msg = &create_xml_string($out_hash);
459 push(@out_msg_l, $out_msg);
461 return @out_msg_l;
462 }
465 sub trigger_action_faireboot {
466 my ($msg, $msg_hash, $session_id) = @_;
467 my $macaddress = @{$msg_hash->{target}}[0];
468 my $source = @{$msg_hash->{source}}[0];
470 my @out_msg_l;
471 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
472 push(@out_msg_l, $msg);
474 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
475 &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id);
477 # delete all jobs from jobqueue which correspond to fai
478 my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
479 "status='processing')";
480 $main::job_db->del_dbentry($sql_statement );
482 return @out_msg_l;
483 }
486 sub trigger_action_lock {
487 my ($msg, $msg_hash, $session_id) = @_;
488 my $macaddress = @{$msg_hash->{target}}[0];
489 my $source = @{$msg_hash->{source}}[0];
491 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
492 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
493 if( defined $jobdb_id) {
494 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
495 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
496 my $res = $main::job_db->exec_statement($sql_statement);
497 }
499 my @out_msg_l;
500 return @out_msg_l;
501 }
504 sub trigger_action_activate {
505 my ($msg, $msg_hash, $session_id) = @_;
506 my $macaddress = @{$msg_hash->{target}}[0];
507 my $source = @{$msg_hash->{source}}[0];
509 &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id);
510 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
511 if( defined $jobdb_id) {
512 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
513 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
514 my $res = $main::job_db->exec_statement($sql_statement);
515 }
517 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
518 if( exists $msg_hash->{'jobdb_id'} ) {
519 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
520 }
521 my $out_msg = &create_xml_string($out_hash);
523 return ( $out_msg );
524 }
527 sub trigger_action_localboot {
528 my ($msg, $msg_hash, $session_id) = @_;
529 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
530 &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
531 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
532 if( defined $jobdb_id) {
533 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
534 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
535 my $res = $main::job_db->exec_statement($sql_statement);
536 }
538 my @out_msg_l = ($msg);
539 return @out_msg_l;
540 }
543 sub trigger_action_halt {
544 my ($msg, $msg_hash, $session_id) = @_;
545 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
547 &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id);
548 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
549 if( defined $jobdb_id) {
550 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
551 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
552 my $res = $main::job_db->exec_statement($sql_statement);
553 }
555 my @out_msg_l = ($msg);
556 return @out_msg_l;
557 }
560 sub trigger_action_reboot {
561 my ($msg, $msg_hash, $session_id) = @_;
562 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
564 &main::change_fai_state('reboot', \@{$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 @out_msg_l = ($msg);
573 return @out_msg_l;
574 }
577 sub trigger_action_memcheck {
578 my ($msg, $msg_hash, $session_id) = @_ ;
579 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
581 &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id);
582 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
583 if( defined $jobdb_id) {
584 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
585 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
586 my $res = $main::job_db->exec_statement($sql_statement);
587 }
589 my @out_msg_l = ($msg);
590 return @out_msg_l;
591 }
594 sub trigger_action_reinstall {
595 my ($msg, $msg_hash, $session_id) = @_;
596 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
598 &main::change_fai_state('reinstall', \@{$msg_hash->{target}}, $session_id);
600 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
601 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
602 my @out_msg_l = ($wake_msg, $msg);
603 return @out_msg_l;
604 }
607 sub trigger_action_update {
608 my ($msg, $msg_hash, $session_id) = @_;
609 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
611 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
613 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
614 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
615 my @out_msg_l = ($wake_msg, $msg);
616 return @out_msg_l;
617 }
620 sub trigger_action_instant_update {
621 my ($msg, $msg_hash, $session_id) = @_;
622 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
624 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
626 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
627 if( defined $jobdb_id) {
628 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
629 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
630 my $res = $main::job_db->exec_statement($sql_statement);
631 }
633 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
634 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
635 my @out_msg_l = ($wake_msg, $msg);
636 return @out_msg_l;
637 }
640 sub trigger_action_sysinfo {
641 my ($msg, $msg_hash, $session_id) = @_;
642 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
644 &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id);
645 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
646 if( defined $jobdb_id) {
647 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
648 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
649 my $res = $main::job_db->exec_statement($sql_statement);
650 }
652 my @out_msg_l = ($msg);
653 return @out_msg_l;
654 }
657 sub new_key_for_client {
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 }
667 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
668 my @out_msg_l = ($msg);
669 return @out_msg_l;
670 }
673 sub trigger_action_rescan {
674 my ($msg, $msg_hash, $session_id) = @_;
676 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
677 if( defined $jobdb_id) {
678 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
679 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
680 my $res = $main::job_db->exec_statement($sql_statement);
681 }
684 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
685 my @out_msg_l = ($msg);
686 return @out_msg_l;
687 }
690 sub trigger_action_wake {
691 my ($msg, $msg_hash, $session_id) = @_;
693 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
694 if( defined $jobdb_id) {
695 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
696 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
697 my $res = $main::job_db->exec_statement($sql_statement);
698 }
701 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
702 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
703 my @out_msg_l = ($out_msg);
704 return @out_msg_l;
705 }
708 sub get_available_kernel {
709 my ($msg, $msg_hash, $session_id) = @_;
711 my $source = @{$msg_hash->{'source'}}[0];
712 my $target = @{$msg_hash->{'target'}}[0];
713 my $release= @{$msg_hash->{'release'}}[0];
715 my @kernel;
716 # Get Kernel packages for release
717 my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
718 my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
719 my %data;
720 my $i=1;
722 foreach my $package (keys %{$res_hash}) {
723 $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
724 }
725 $data{"answer".$i++}= "default";
727 my $out_msg = &build_msg("get_available_kernel", $target, "GOSA", \%data);
728 return ( $out_msg );
729 }
732 1;