371d408f00da7cc0470b59b213bb53ee8efbb026
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 @users = map("u_", @users);
110 my $users_list = join(",", @users);
111 @groups = map("g_", @groups);
112 my $groups_list = join(",", @groups);
114 my $func_dic = {table=>$main::messaging_tn,
115 primkey=>[],
116 id=>$new_msg_id,
117 subject=>$subject,
118 message_from=>$from,
119 message_to=>"$users_list,$groups_list",
120 flag=>"n",
121 direction=>"in",
122 delivery_time=>$delivery_time,
123 message=>$message,
124 timestamp=>&get_time(),
125 };
126 my $res = $main::messaging_db->add_dbentry($func_dic);
127 if (not $res == 0) {
128 &main::daemon_log("$session_id ERROR: gosaTriggered.pm: cannot add message to message_db: $res", 1);
129 } else {
130 &main::daemon_log("$session_id INFO: gosaTriggered.pm: message with subject '$subject' successfully added to message_db", 5);
131 }
133 return;
134 }
136 sub send_user_msg_OLD {
137 my ($msg, $msg_hash, $session_id) = @_ ;
138 my @out_msg_l;
139 my @user_list;
140 my @group_list;
142 my $header = @{$msg_hash->{'header'}}[0];
143 my $source = @{$msg_hash->{'source'}}[0];
144 my $target = @{$msg_hash->{'target'}}[0];
145 my $message = @{$msg_hash->{'message'}}[0];
146 if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; }
147 if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; }
149 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
150 if( defined $jobdb_id) {
151 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
152 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
153 my $res = $main::job_db->exec_statement($sql_statement);
154 }
156 # error handling
157 if( not @user_list && not @group_list ) {
158 &main::daemon_log("$session_id WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
159 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
160 "<error_string>no user-tag or a group-tag specified in 'send_user_msg'</error_string></xml>");
161 }
162 if( not defined $message ) {
163 &main::daemon_log("$session_id WARNING: no message-tag specified in 'send_user_msg'", 3);
164 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
165 "<error_string>no message-tag specified in 'send_user_msg'</error_string></xml>");
167 }
169 # resolve groups to users
170 my $ldap_handle = &main::get_ldap_handle($session_id);
171 if( @group_list ) {
172 if( not defined $ldap_handle ) {
173 &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
174 return ();
175 }
176 foreach my $group (@group_list) { # Perform search
177 my $mesg = $ldap_handle->search(
178 base => $main::ldap_base,
179 scope => 'sub',
180 attrs => ['memberUid'],
181 filter => "(&(objectClass=posixGroup)(cn=$group)(memberUid=*))");
182 if($mesg->code) {
183 &main::daemon_log($mesg->error, 1);
184 return ();
185 }
186 my $entry= $mesg->entry(0);
187 my @users= $entry->get_value("memberUid");
188 foreach my $user (@users) { push(@user_list, $user); }
189 }
190 }
192 # drop multiple users in @user_list
193 my %seen = ();
194 foreach my $user (@user_list) {
195 $seen{$user}++;
196 }
197 @user_list = keys %seen;
199 # build xml messages sended to client where user is logged in
200 foreach my $user (@user_list) {
201 my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user='$user'";
202 my $db_res = $main::login_users_db->select_dbentry($sql_statement);
204 if(0 == keys(%{$db_res})) {
206 } else {
207 while( my($hit, $content) = each %{$db_res} ) {
208 my $out_hash = &create_xml_hash('send_user_msg', $main::server_address, $content->{'client'});
209 &add_content2xml_hash($out_hash, 'message', $message);
210 &add_content2xml_hash($out_hash, 'user', $user);
211 if( exists $msg_hash->{'jobdb_id'} ) {
212 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
213 }
214 my $out_msg = &create_xml_string($out_hash);
215 push(@out_msg_l, $out_msg);
216 }
217 }
218 }
220 return @out_msg_l;
221 }
224 sub recreate_fai_server_db {
225 my ($msg, $msg_hash, $session_id) = @_ ;
226 my $out_msg;
228 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
229 if( defined $jobdb_id) {
230 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
231 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
232 my $res = $main::job_db->exec_statement($sql_statement);
233 }
235 $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
236 &main::create_fai_server_db("new_fai_server",undef,"dont", $session_id);
237 $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
239 my @out_msg_l = ( $out_msg );
240 return @out_msg_l;
241 }
244 sub recreate_fai_release_db {
245 my ($msg, $msg_hash, $session_id) = @_ ;
246 my $out_msg;
248 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
249 if( defined $jobdb_id) {
250 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
251 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
252 my $res = $main::job_db->exec_statement($sql_statement);
253 }
255 $main::fai_release_db->create_table("new_fai_release", \@main::fai_release_col_names);
256 &main::create_fai_release_db("new_fai_release", $session_id);
257 $main::fai_release_db->move_table("new_fai_release", $main::fai_release_tn);
259 my @out_msg_l = ( $out_msg );
260 return @out_msg_l;
261 }
264 sub recreate_packages_list_db {
265 my ($msg, $msg_hash, $session_id) = @_ ;
266 my $out_msg;
268 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
269 if( defined $jobdb_id) {
270 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
271 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
272 my $res = $main::job_db->exec_statement($sql_statement);
273 }
275 &main::create_packages_list_db;
277 my @out_msg_l = ( $out_msg );
278 return @out_msg_l;
279 }
282 sub get_login_usr_for_client {
283 my ($msg, $msg_hash, $session_id) = @_ ;
284 my $header = @{$msg_hash->{'header'}}[0];
285 my $source = @{$msg_hash->{'source'}}[0];
286 my $target = @{$msg_hash->{'target'}}[0];
287 my $client = @{$msg_hash->{'client'}}[0];
289 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
290 if( defined $jobdb_id) {
291 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
292 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
293 my $res = $main::job_db->exec_statement($sql_statement);
294 }
296 $header =~ s/^gosa_//;
298 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
299 my $res = $main::known_clients_db->select_dbentry($sql_statement);
301 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
302 $out_msg .= &db_res2xml($res);
303 $out_msg .= "</xml>";
305 my @out_msg_l = ( $out_msg );
306 return @out_msg_l;
307 }
310 sub get_client_for_login_usr {
311 my ($msg, $msg_hash, $session_id) = @_ ;
312 my $header = @{$msg_hash->{'header'}}[0];
313 my $source = @{$msg_hash->{'source'}}[0];
314 my $target = @{$msg_hash->{'target'}}[0];
316 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
317 if( defined $jobdb_id) {
318 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
319 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
320 my $res = $main::job_db->exec_statement($sql_statement);
321 }
323 my $usr = @{$msg_hash->{'usr'}}[0];
324 $header =~ s/^gosa_//;
326 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
327 my $res = $main::known_clients_db->select_dbentry($sql_statement);
329 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
330 $out_msg .= &db_res2xml($res);
331 $out_msg .= "</xml>";
332 my @out_msg_l = ( $out_msg );
333 return @out_msg_l;
335 }
338 sub ping {
339 my ($msg, $msg_hash, $session_id) = @_ ;
340 my $out_msg = $msg;
341 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
342 if( defined $jobdb_id) {
343 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
344 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
345 my $res = $main::job_db->exec_statement($sql_statement);
346 }
348 $out_msg =~ s/<header>gosa_/<header>/;
350 my @out_msg_l = ( $out_msg );
351 return @out_msg_l;
352 }
354 sub gen_smb_hash {
355 my ($msg, $msg_hash, $session_id) = @_ ;
356 my $source = @{$msg_hash->{source}}[0];
357 my $target = @{$msg_hash->{target}}[0];
358 my $password = @{$msg_hash->{password}}[0];
360 my %data= ('hash' => join(q[:], ntlmgen $password));
361 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
362 return ( $out_msg );
363 }
366 sub network_completition {
367 my ($msg, $msg_hash, $session_id) = @_ ;
368 my $source = @{$msg_hash->{source}}[0];
369 my $target = @{$msg_hash->{target}}[0];
370 my $name = @{$msg_hash->{hostname}}[0];
372 # Can we resolv the name?
373 my %data;
374 if (inet_aton($name)){
375 my $address = inet_ntoa(inet_aton($name));
376 my $p = Net::Ping->new('tcp');
377 my $mac= "";
378 if ($p->ping($address, 1)){
379 $mac = Net::ARP::arp_lookup("", $address);
380 }
382 %data= ('ip' => $address, 'mac' => $mac);
383 } else {
384 %data= ('ip' => '', 'mac' => '');
385 }
387 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
389 return ( $out_msg );
390 }
393 sub detect_hardware {
394 my ($msg, $msg_hash, $session_id) = @_ ;
395 # just forward msg to client, but dont forget to split off 'gosa_' in header
396 my $source = @{$msg_hash->{source}}[0];
397 my $target = @{$msg_hash->{target}}[0];
398 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
399 if( defined $jobdb_id) {
400 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
401 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
402 my $res = $main::job_db->exec_statement($sql_statement);
403 }
405 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
406 if( defined $jobdb_id ) {
407 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
408 }
409 my $out_msg = &create_xml_string($out_hash);
411 my @out_msg_l = ( $out_msg );
412 return @out_msg_l;
414 }
417 sub trigger_reload_ldap_config {
418 my ($msg, $msg_hash, $session_id) = @_ ;
419 my $target = @{$msg_hash->{target}}[0];
421 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
422 if( defined $jobdb_id) {
423 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
424 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
425 my $res = $main::job_db->exec_statement($sql_statement);
426 }
428 my $out_msg = &SIPackages::new_ldap_config($target, $session_id);
429 my @out_msg_l = ( $out_msg );
431 return @out_msg_l;
432 }
435 sub set_activated_for_installation {
436 my ($msg, $msg_hash, $session_id) = @_;
437 my $header = @{$msg_hash->{header}}[0];
438 my $source = @{$msg_hash->{source}}[0];
439 my $target = @{$msg_hash->{target}}[0];
440 my @out_msg_l;
442 # update status of job
443 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
444 if( defined $jobdb_id) {
445 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
446 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
447 my $res = $main::job_db->exec_statement($sql_statement);
448 }
450 # create set_activated_for_installation message for delivery
451 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
452 if( defined $jobdb_id ) {
453 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
454 }
455 my $out_msg = &create_xml_string($out_hash);
456 push(@out_msg_l, $out_msg);
458 return @out_msg_l;
459 }
462 sub trigger_action_faireboot {
463 my ($msg, $msg_hash, $session_id) = @_;
464 my $macaddress = @{$msg_hash->{target}}[0];
465 my $source = @{$msg_hash->{source}}[0];
467 my @out_msg_l;
468 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
469 push(@out_msg_l, $msg);
471 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
472 &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id);
474 # delete all jobs from jobqueue which correspond to fai
475 my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
476 "status='processing')";
477 $main::job_db->del_dbentry($sql_statement );
479 return @out_msg_l;
480 }
483 sub trigger_action_lock {
484 my ($msg, $msg_hash, $session_id) = @_;
485 my $macaddress = @{$msg_hash->{target}}[0];
486 my $source = @{$msg_hash->{source}}[0];
488 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
489 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
490 if( defined $jobdb_id) {
491 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
492 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
493 my $res = $main::job_db->exec_statement($sql_statement);
494 }
496 my @out_msg_l;
497 return @out_msg_l;
498 }
501 sub trigger_action_activate {
502 my ($msg, $msg_hash, $session_id) = @_;
503 my $macaddress = @{$msg_hash->{target}}[0];
504 my $source = @{$msg_hash->{source}}[0];
506 &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id);
507 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
508 if( defined $jobdb_id) {
509 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
510 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
511 my $res = $main::job_db->exec_statement($sql_statement);
512 }
514 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
515 if( exists $msg_hash->{'jobdb_id'} ) {
516 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
517 }
518 my $out_msg = &create_xml_string($out_hash);
520 return ( $out_msg );
521 }
524 sub trigger_action_localboot {
525 my ($msg, $msg_hash, $session_id) = @_;
526 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
527 &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
528 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
529 if( defined $jobdb_id) {
530 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
531 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
532 my $res = $main::job_db->exec_statement($sql_statement);
533 }
535 my @out_msg_l = ($msg);
536 return @out_msg_l;
537 }
540 sub trigger_action_halt {
541 my ($msg, $msg_hash, $session_id) = @_;
542 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
544 &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id);
545 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
546 if( defined $jobdb_id) {
547 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
548 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
549 my $res = $main::job_db->exec_statement($sql_statement);
550 }
552 my @out_msg_l = ($msg);
553 return @out_msg_l;
554 }
557 sub trigger_action_reboot {
558 my ($msg, $msg_hash, $session_id) = @_;
559 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
561 &main::change_fai_state('reboot', \@{$msg_hash->{target}}, $session_id);
562 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
563 if( defined $jobdb_id) {
564 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
565 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
566 my $res = $main::job_db->exec_statement($sql_statement);
567 }
569 my @out_msg_l = ($msg);
570 return @out_msg_l;
571 }
574 sub trigger_action_memcheck {
575 my ($msg, $msg_hash, $session_id) = @_ ;
576 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
578 &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id);
579 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
580 if( defined $jobdb_id) {
581 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
582 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
583 my $res = $main::job_db->exec_statement($sql_statement);
584 }
586 my @out_msg_l = ($msg);
587 return @out_msg_l;
588 }
591 sub trigger_action_reinstall {
592 my ($msg, $msg_hash, $session_id) = @_;
593 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
595 &main::change_fai_state('reinstall', \@{$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_update {
605 my ($msg, $msg_hash, $session_id) = @_;
606 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
608 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
610 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
611 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
612 my @out_msg_l = ($wake_msg, $msg);
613 return @out_msg_l;
614 }
617 sub trigger_action_instant_update {
618 my ($msg, $msg_hash, $session_id) = @_;
619 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
621 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
623 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
624 if( defined $jobdb_id) {
625 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
626 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
627 my $res = $main::job_db->exec_statement($sql_statement);
628 }
630 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
631 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
632 my @out_msg_l = ($wake_msg, $msg);
633 return @out_msg_l;
634 }
637 sub trigger_action_sysinfo {
638 my ($msg, $msg_hash, $session_id) = @_;
639 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
641 &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id);
642 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
643 if( defined $jobdb_id) {
644 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
645 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
646 my $res = $main::job_db->exec_statement($sql_statement);
647 }
649 my @out_msg_l = ($msg);
650 return @out_msg_l;
651 }
654 sub new_key_for_client {
655 my ($msg, $msg_hash, $session_id) = @_;
657 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
658 if( defined $jobdb_id) {
659 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
660 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
661 my $res = $main::job_db->exec_statement($sql_statement);
662 }
664 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
665 my @out_msg_l = ($msg);
666 return @out_msg_l;
667 }
670 sub trigger_action_rescan {
671 my ($msg, $msg_hash, $session_id) = @_;
673 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
674 if( defined $jobdb_id) {
675 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
676 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
677 my $res = $main::job_db->exec_statement($sql_statement);
678 }
681 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
682 my @out_msg_l = ($msg);
683 return @out_msg_l;
684 }
687 sub trigger_action_wake {
688 my ($msg, $msg_hash, $session_id) = @_;
690 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
691 if( defined $jobdb_id) {
692 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
693 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
694 my $res = $main::job_db->exec_statement($sql_statement);
695 }
698 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
699 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
700 my @out_msg_l = ($out_msg);
701 return @out_msg_l;
702 }
705 sub get_available_kernel {
706 my ($msg, $msg_hash, $session_id) = @_;
708 my $source = @{$msg_hash->{'source'}}[0];
709 my $target = @{$msg_hash->{'target'}}[0];
710 my $release= @{$msg_hash->{'release'}}[0];
712 my @kernel;
713 # Get Kernel packages for release
714 my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
715 my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
716 my %data;
717 my $i=1;
719 foreach my $package (keys %{$res_hash}) {
720 $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
721 }
722 $data{"answer".$i++}= "default";
724 my $out_msg = &build_msg("get_available_kernel", $target, "GOSA", \%data);
725 return ( $out_msg );
726 }
729 1;