8f55b3368790ae2e04026774363508f62da5b4e7
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 "new_ping",
12 "network_completition",
13 "set_activated_for_installation",
14 "new_key_for_client",
15 "detect_hardware",
16 "get_login_usr",
17 "get_login_client",
18 "trigger_action_localboot",
19 "trigger_action_faireboot",
20 "trigger_action_reboot",
21 "trigger_action_activate",
22 "trigger_action_lock",
23 "trigger_action_halt",
24 "trigger_action_update",
25 "trigger_action_reinstall",
26 "trigger_action_memcheck",
27 "trigger_action_sysinfo",
28 "trigger_action_instant_update",
29 "trigger_action_rescan",
30 "trigger_action_wake",
31 "recreate_fai_server_db",
32 "recreate_fai_release_db",
33 "recreate_packages_list_db",
34 "send_user_msg",
35 "get_available_kernel",
36 );
37 @EXPORT = @events;
39 use strict;
40 use warnings;
41 use GOSA::GosaSupportDaemon;
42 use Data::Dumper;
43 use Crypt::SmbHash;
44 use Net::ARP;
45 use Net::Ping;
46 use Socket;
47 use Time::HiRes qw( usleep);
49 BEGIN {}
51 END {}
53 ### Start ######################################################################
55 #&main::read_configfile($main::cfg_file, %cfg_defaults);
57 sub get_events {
58 return \@events;
59 }
61 sub send_user_msg {
63 # msg from gosa
64 # <xml><header>gosa_send_user_msg</header><source>GOSA</source><target>GOSA</target>
65 # <timestamp>20080429151605</timestamp>
66 # <users>andreas.rettenberger</users>
67 # <subject>hallo</subject>
68 # <message>test</message>
69 # <macaddress>GOSA</macaddress>
70 # </xml>
72 my ($msg, $msg_hash, $session_id) = @_ ;
73 my $header = @{$msg_hash->{'header'}}[0];
74 my $source = @{$msg_hash->{'source'}}[0];
75 my $target = @{$msg_hash->{'target'}}[0];
77 #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
78 my $subject = @{$msg_hash->{'subject'}}[0];
79 my $from = @{$msg_hash->{'from'}}[0];
80 my @users = @{$msg_hash->{'users'}};
81 my @groups = @{$msg_hash->{'groups'}}[0];
82 my $delivery_time = @{$msg_hash->{'delivery_time'}}[0];
83 #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
84 my $message = @{$msg_hash->{'message'}}[0];
86 # keep job queue uptodate if necessary
87 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
88 if( defined $jobdb_id) {
89 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
90 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
91 my $res = $main::job_db->exec_statement($sql_statement);
92 }
94 # error handling
95 if (not $delivery_time =~ /^\d{14}$/) {
96 my $error_string = "delivery_time '$delivery_time' is not a valid timestamp, please use format 'yyyymmddhhmmss'";
97 &main::daemon_log("$session_id ERROR: $error_string", 1);
98 return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
99 }
101 # add incoming message to messaging_db
102 my $new_msg_id = 1;
103 my $new_msg_id_sql = "SELECT MAX(CAST(id AS INTEGER)) FROM $main::messaging_tn";
104 my $new_msg_id_res = $main::messaging_db->exec_statement($new_msg_id_sql);
105 if (defined @{@{$new_msg_id_res}[0]}[0] ) {
106 $new_msg_id = int(@{@{$new_msg_id_res}[0]}[0]);
107 $new_msg_id += 1;
108 }
110 # highlight user name and group name
111 my @receiver_l;
112 @users = map(push(@receiver_l, "u_$_"), @users);
113 #@groups = map(push(@receiver_l, "g_$_"), @groups);
114 # TODO
115 # handling, was passiert wenn in einer liste nix drin steht
116 # handling von groups hinzufügen
119 my $func_dic = {table=>$main::messaging_tn,
120 primkey=>[],
121 id=>$new_msg_id,
122 subject=>$subject,
123 message_from=>$from,
124 message_to=>join(",", @receiver_l),
125 flag=>"n",
126 direction=>"in",
127 delivery_time=>$delivery_time,
128 message=>$message,
129 timestamp=>&get_time(),
130 };
131 my $res = $main::messaging_db->add_dbentry($func_dic);
132 if (not $res == 0) {
133 &main::daemon_log("$session_id ERROR: gosaTriggered.pm: cannot add message to message_db: $res", 1);
134 } else {
135 &main::daemon_log("$session_id INFO: gosaTriggered.pm: message with subject '$subject' successfully added to message_db", 5);
136 }
138 return;
139 }
141 sub send_user_msg_OLD {
142 my ($msg, $msg_hash, $session_id) = @_ ;
143 my @out_msg_l;
144 my @user_list;
145 my @group_list;
147 my $header = @{$msg_hash->{'header'}}[0];
148 my $source = @{$msg_hash->{'source'}}[0];
149 my $target = @{$msg_hash->{'target'}}[0];
150 my $message = @{$msg_hash->{'message'}}[0];
151 if( exists $msg_hash->{'user'} ) { @user_list = @{$msg_hash->{'user'}}; }
152 if( exists $msg_hash->{'group'} ) { @group_list = @{$msg_hash->{'group'}}; }
154 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
155 if( defined $jobdb_id) {
156 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
157 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
158 my $res = $main::job_db->exec_statement($sql_statement);
159 }
161 # error handling
162 if( not @user_list && not @group_list ) {
163 &main::daemon_log("$session_id WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
164 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
165 "<error_string>no user-tag or a group-tag specified in 'send_user_msg'</error_string></xml>");
166 }
167 if( not defined $message ) {
168 &main::daemon_log("$session_id WARNING: no message-tag specified in 'send_user_msg'", 3);
169 return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
170 "<error_string>no message-tag specified in 'send_user_msg'</error_string></xml>");
172 }
174 # resolve groups to users
175 my $ldap_handle = &main::get_ldap_handle($session_id);
176 if( @group_list ) {
177 if( not defined $ldap_handle ) {
178 &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
179 return ();
180 }
181 foreach my $group (@group_list) { # Perform search
182 my $mesg = $ldap_handle->search(
183 base => $main::ldap_base,
184 scope => 'sub',
185 attrs => ['memberUid'],
186 filter => "(&(objectClass=posixGroup)(cn=$group)(memberUid=*))");
187 if($mesg->code) {
188 &main::daemon_log($mesg->error, 1);
189 return ();
190 }
191 my $entry= $mesg->entry(0);
192 my @users= $entry->get_value("memberUid");
193 foreach my $user (@users) { push(@user_list, $user); }
194 }
195 }
197 # drop multiple users in @user_list
198 my %seen = ();
199 foreach my $user (@user_list) {
200 $seen{$user}++;
201 }
202 @user_list = keys %seen;
204 # build xml messages sended to client where user is logged in
205 foreach my $user (@user_list) {
206 my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user='$user'";
207 my $db_res = $main::login_users_db->select_dbentry($sql_statement);
209 if(0 == keys(%{$db_res})) {
211 } else {
212 while( my($hit, $content) = each %{$db_res} ) {
213 my $out_hash = &create_xml_hash('send_user_msg', $main::server_address, $content->{'client'});
214 &add_content2xml_hash($out_hash, 'message', $message);
215 &add_content2xml_hash($out_hash, 'user', $user);
216 if( exists $msg_hash->{'jobdb_id'} ) {
217 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
218 }
219 my $out_msg = &create_xml_string($out_hash);
220 push(@out_msg_l, $out_msg);
221 }
222 }
223 }
225 return @out_msg_l;
226 }
229 sub recreate_fai_server_db {
230 my ($msg, $msg_hash, $session_id) = @_ ;
231 my $out_msg;
233 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
234 if( defined $jobdb_id) {
235 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
236 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
237 my $res = $main::job_db->exec_statement($sql_statement);
238 }
240 $main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
241 &main::create_fai_server_db("new_fai_server",undef,"dont", $session_id);
242 $main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
244 my @out_msg_l = ( $out_msg );
245 return @out_msg_l;
246 }
249 sub recreate_fai_release_db {
250 my ($msg, $msg_hash, $session_id) = @_ ;
251 my $out_msg;
253 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
254 if( defined $jobdb_id) {
255 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
256 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
257 my $res = $main::job_db->exec_statement($sql_statement);
258 }
260 $main::fai_release_db->create_table("new_fai_release", \@main::fai_release_col_names);
261 &main::create_fai_release_db("new_fai_release", $session_id);
262 $main::fai_release_db->move_table("new_fai_release", $main::fai_release_tn);
264 my @out_msg_l = ( $out_msg );
265 return @out_msg_l;
266 }
269 sub recreate_packages_list_db {
270 my ($msg, $msg_hash, $session_id) = @_ ;
271 my $out_msg;
273 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
274 if( defined $jobdb_id) {
275 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
276 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
277 my $res = $main::job_db->exec_statement($sql_statement);
278 }
280 &main::create_packages_list_db;
282 my @out_msg_l = ( $out_msg );
283 return @out_msg_l;
284 }
287 sub get_login_usr_for_client {
288 my ($msg, $msg_hash, $session_id) = @_ ;
289 my $header = @{$msg_hash->{'header'}}[0];
290 my $source = @{$msg_hash->{'source'}}[0];
291 my $target = @{$msg_hash->{'target'}}[0];
292 my $client = @{$msg_hash->{'client'}}[0];
294 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
295 if( defined $jobdb_id) {
296 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
297 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
298 my $res = $main::job_db->exec_statement($sql_statement);
299 }
301 $header =~ s/^gosa_//;
303 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
304 my $res = $main::known_clients_db->select_dbentry($sql_statement);
306 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
307 $out_msg .= &db_res2xml($res);
308 $out_msg .= "</xml>";
310 my @out_msg_l = ( $out_msg );
311 return @out_msg_l;
312 }
315 sub get_client_for_login_usr {
316 my ($msg, $msg_hash, $session_id) = @_ ;
317 my $header = @{$msg_hash->{'header'}}[0];
318 my $source = @{$msg_hash->{'source'}}[0];
319 my $target = @{$msg_hash->{'target'}}[0];
321 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
322 if( defined $jobdb_id) {
323 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
324 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
325 my $res = $main::job_db->exec_statement($sql_statement);
326 }
328 my $usr = @{$msg_hash->{'usr'}}[0];
329 $header =~ s/^gosa_//;
331 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
332 my $res = $main::known_clients_db->select_dbentry($sql_statement);
334 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
335 $out_msg .= &db_res2xml($res);
336 $out_msg .= "</xml>";
337 my @out_msg_l = ( $out_msg );
338 return @out_msg_l;
340 }
343 sub ping {
344 my ($msg, $msg_hash, $session_id) = @_ ;
345 my $out_msg = $msg;
346 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
347 if( defined $jobdb_id) {
348 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
349 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
350 my $res = $main::job_db->exec_statement($sql_statement);
351 }
353 $out_msg =~ s/<header>gosa_/<header>/;
355 my @out_msg_l = ( $out_msg );
356 return @out_msg_l;
357 }
358 sub new_ping {
359 my ($msg, $msg_hash, $session_id) = @_ ;
360 my ($sql, $res);
361 my $out_msg = $msg;
362 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
363 if( defined $jobdb_id) {
364 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
365 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
366 my $res = $main::job_db->exec_statement($sql_statement);
367 }
369 $out_msg =~ s/<header>gosa_/<header>/;
371 # send message
372 my $header = @{$msg_hash->{header}}[0];
373 my $target = @{$msg_hash->{target}}[0];
375 $sql = "SELECT * FROM $main::known_clients_tn WHERE ((hostname='$target') || (macaddress LIKE '$target'))";
376 $res = $main::known_clients_db->exec_statement($sql);
377 my $host_name = @{@$res[0]}[0];
378 $out_msg =~ s/<target>\S+<\/target>/<target>$host_name<\/target>/;
379 $out_msg =~ s/<source>\S+<\/source>/<source>$main::server_address<\/source>/;
380 $out_msg =~ s/<\/xml>/<session_id>$session_id<\/session_id><\/xml>/;
381 my $host_key = @{@$res[0]}[2];
383 my $error = &main::send_msg_to_target($out_msg, $host_name, $host_key, $header, $session_id);
384 #if ($error != 0) {}
386 my $message_id;
387 while (1) {
388 $sql = "SELECT * FROM $main::incoming_tn WHERE headertag='answer_$session_id'";
389 $res = $main::incoming_db->exec_statement($sql);
390 if (ref @$res[0] eq "ARRAY") {
391 $message_id = @{@$res[0]}[0];
392 last;
393 }
394 usleep(100000);
395 }
396 my $answer_xml = @{@$res[0]}[3];
397 my %data = ( 'answer_xml' => 'bin noch da' );
398 my $answer_msg = &build_msg("got_new_ping", "$main::server_address", "GOSA", \%data);
400 $sql = "DELETE FROM $main::incoming_tn WHERE id=$message_id";
401 $res = $main::incoming_db->exec_statement($sql);
404 my @answer_msg_l = ( $answer_msg );
405 return @answer_msg_l;
406 }
410 sub gen_smb_hash {
411 my ($msg, $msg_hash, $session_id) = @_ ;
412 my $source = @{$msg_hash->{source}}[0];
413 my $target = @{$msg_hash->{target}}[0];
414 my $password = @{$msg_hash->{password}}[0];
416 my %data= ('hash' => join(q[:], ntlmgen $password));
417 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
418 return ( $out_msg );
419 }
422 sub network_completition {
423 my ($msg, $msg_hash, $session_id) = @_ ;
424 my $source = @{$msg_hash->{source}}[0];
425 my $target = @{$msg_hash->{target}}[0];
426 my $name = @{$msg_hash->{hostname}}[0];
428 # Can we resolv the name?
429 my %data;
430 if (inet_aton($name)){
431 my $address = inet_ntoa(inet_aton($name));
432 my $p = Net::Ping->new('tcp');
433 my $mac= "";
434 if ($p->ping($address, 1)){
435 $mac = Net::ARP::arp_lookup("", $address);
436 }
438 %data= ('ip' => $address, 'mac' => $mac);
439 } else {
440 %data= ('ip' => '', 'mac' => '');
441 }
443 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
445 return ( $out_msg );
446 }
449 sub detect_hardware {
450 my ($msg, $msg_hash, $session_id) = @_ ;
451 # just forward msg to client, but dont forget to split off 'gosa_' in header
452 my $source = @{$msg_hash->{source}}[0];
453 my $target = @{$msg_hash->{target}}[0];
454 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
455 if( defined $jobdb_id) {
456 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
457 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
458 my $res = $main::job_db->exec_statement($sql_statement);
459 }
461 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
462 if( defined $jobdb_id ) {
463 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
464 }
465 my $out_msg = &create_xml_string($out_hash);
467 my @out_msg_l = ( $out_msg );
468 return @out_msg_l;
470 }
473 sub trigger_reload_ldap_config {
474 my ($msg, $msg_hash, $session_id) = @_ ;
475 my $target = @{$msg_hash->{target}}[0];
477 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
478 if( defined $jobdb_id) {
479 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
480 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
481 my $res = $main::job_db->exec_statement($sql_statement);
482 }
484 my $out_msg = &ClientPackages::new_ldap_config($target, $session_id);
485 my @out_msg_l = ( $out_msg );
487 return @out_msg_l;
488 }
491 sub set_activated_for_installation {
492 my ($msg, $msg_hash, $session_id) = @_;
493 my $header = @{$msg_hash->{header}}[0];
494 my $source = @{$msg_hash->{source}}[0];
495 my $target = @{$msg_hash->{target}}[0];
496 my @out_msg_l;
498 # update status of job
499 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
500 if( defined $jobdb_id) {
501 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
502 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
503 my $res = $main::job_db->exec_statement($sql_statement);
504 }
506 # create set_activated_for_installation message for delivery
507 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
508 if( defined $jobdb_id ) {
509 &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
510 }
511 my $out_msg = &create_xml_string($out_hash);
512 push(@out_msg_l, $out_msg);
514 return @out_msg_l;
515 }
518 sub trigger_action_faireboot {
519 my ($msg, $msg_hash, $session_id) = @_;
520 my $macaddress = @{$msg_hash->{target}}[0];
521 my $source = @{$msg_hash->{source}}[0];
523 my @out_msg_l;
524 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
525 push(@out_msg_l, $msg);
527 &main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
528 &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id);
530 # delete all jobs from jobqueue which correspond to fai
531 my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
532 "status='processing')";
533 $main::job_db->del_dbentry($sql_statement );
535 return @out_msg_l;
536 }
539 sub trigger_action_lock {
540 my ($msg, $msg_hash, $session_id) = @_;
541 my $macaddress = @{$msg_hash->{target}}[0];
542 my $source = @{$msg_hash->{source}}[0];
544 &main::change_goto_state('locked', \@{$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;
553 return @out_msg_l;
554 }
557 sub trigger_action_activate {
558 my ($msg, $msg_hash, $session_id) = @_;
559 my $macaddress = @{$msg_hash->{target}}[0];
560 my $source = @{$msg_hash->{source}}[0];
562 &main::change_goto_state('active', \@{$msg_hash->{target}}, $session_id);
563 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
564 if( defined $jobdb_id) {
565 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
566 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
567 my $res = $main::job_db->exec_statement($sql_statement);
568 }
570 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
571 if( exists $msg_hash->{'jobdb_id'} ) {
572 &add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
573 }
574 my $out_msg = &create_xml_string($out_hash);
576 return ( $out_msg );
577 }
580 sub trigger_action_localboot {
581 my ($msg, $msg_hash, $session_id) = @_;
582 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
583 &main::change_fai_state('localboot', \@{$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 trigger_action_halt {
597 my ($msg, $msg_hash, $session_id) = @_;
598 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
600 &main::change_fai_state('halt', \@{$msg_hash->{target}}, $session_id);
601 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
602 if( defined $jobdb_id) {
603 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
604 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
605 my $res = $main::job_db->exec_statement($sql_statement);
606 }
608 my @out_msg_l = ($msg);
609 return @out_msg_l;
610 }
613 sub trigger_action_reboot {
614 my ($msg, $msg_hash, $session_id) = @_;
615 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
617 &main::change_fai_state('reboot', \@{$msg_hash->{target}}, $session_id);
618 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
619 if( defined $jobdb_id) {
620 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
621 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
622 my $res = $main::job_db->exec_statement($sql_statement);
623 }
625 my @out_msg_l = ($msg);
626 return @out_msg_l;
627 }
630 sub trigger_action_memcheck {
631 my ($msg, $msg_hash, $session_id) = @_ ;
632 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
634 &main::change_fai_state('memcheck', \@{$msg_hash->{target}}, $session_id);
635 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
636 if( defined $jobdb_id) {
637 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
638 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
639 my $res = $main::job_db->exec_statement($sql_statement);
640 }
642 my @out_msg_l = ($msg);
643 return @out_msg_l;
644 }
647 sub trigger_action_reinstall {
648 my ($msg, $msg_hash, $session_id) = @_;
649 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
651 &main::change_fai_state('reinstall', \@{$msg_hash->{target}}, $session_id);
653 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
654 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
655 my @out_msg_l = ($wake_msg, $msg);
656 return @out_msg_l;
657 }
660 sub trigger_action_update {
661 my ($msg, $msg_hash, $session_id) = @_;
662 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
664 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
666 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
667 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
668 my @out_msg_l = ($wake_msg, $msg);
669 return @out_msg_l;
670 }
673 sub trigger_action_instant_update {
674 my ($msg, $msg_hash, $session_id) = @_;
675 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
677 &main::change_fai_state('update', \@{$msg_hash->{target}}, $session_id);
679 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
680 if( defined $jobdb_id) {
681 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
682 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
683 my $res = $main::job_db->exec_statement($sql_statement);
684 }
686 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
687 my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
688 my @out_msg_l = ($wake_msg, $msg);
689 return @out_msg_l;
690 }
693 sub trigger_action_sysinfo {
694 my ($msg, $msg_hash, $session_id) = @_;
695 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
697 &main::change_fai_state('sysinfo', \@{$msg_hash->{target}}, $session_id);
698 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
699 if( defined $jobdb_id) {
700 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
701 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
702 my $res = $main::job_db->exec_statement($sql_statement);
703 }
705 my @out_msg_l = ($msg);
706 return @out_msg_l;
707 }
710 sub new_key_for_client {
711 my ($msg, $msg_hash, $session_id) = @_;
713 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
714 if( defined $jobdb_id) {
715 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
716 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
717 my $res = $main::job_db->exec_statement($sql_statement);
718 }
720 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
721 my @out_msg_l = ($msg);
722 return @out_msg_l;
723 }
726 sub trigger_action_rescan {
727 my ($msg, $msg_hash, $session_id) = @_;
729 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
730 if( defined $jobdb_id) {
731 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
732 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
733 my $res = $main::job_db->exec_statement($sql_statement);
734 }
737 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
738 my @out_msg_l = ($msg);
739 return @out_msg_l;
740 }
743 sub trigger_action_wake {
744 my ($msg, $msg_hash, $session_id) = @_;
746 my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
747 if( defined $jobdb_id) {
748 my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id=jobdb_id";
749 &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
750 my $res = $main::job_db->exec_statement($sql_statement);
751 }
754 my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
755 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
756 my @out_msg_l = ($out_msg);
757 return @out_msg_l;
758 }
761 sub get_available_kernel {
762 my ($msg, $msg_hash, $session_id) = @_;
764 my $source = @{$msg_hash->{'source'}}[0];
765 my $target = @{$msg_hash->{'target'}}[0];
766 my $release= @{$msg_hash->{'release'}}[0];
768 my @kernel;
769 # Get Kernel packages for release
770 my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
771 my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
772 my %data;
773 my $i=1;
775 foreach my $package (keys %{$res_hash}) {
776 $data{"answer".$i++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
777 }
778 $data{"answer".$i++}= "default";
780 my $out_msg = &build_msg("get_available_kernel", $target, "GOSA", \%data);
781 return ( $out_msg );
782 }
785 1;