index 43421356e1af2cfe8111dab33fd5281b29d01fce..aa9fada4f2890729333d1ba9d5a51da4dc1ee392 100644 (file)
"trigger_action_rescan",
"trigger_action_wake",
"recreate_fai_server_db",
+ "recreate_fai_release_db",
"send_user_msg",
+ "get_available_kernel",
);
@EXPORT = @events;
use Net::ARP;
use Net::Ping;
use Socket;
-use utf8;
BEGIN {}
}
sub send_user_msg {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+
+ #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
+ my $subject = @{$msg_hash->{'subject'}}[0];
+ my $from = @{$msg_hash->{'from'}}[0];
+ my $to = @{$msg_hash->{'to'}}[0];
+ my $delivery_time = @{$msg_hash->{'delivery_time'}}[0];
+ #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
+ my $message = @{$msg_hash->{'message'}}[0];
+
+ # keep job queue uptodate if necessary
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
+ # error handling
+ if (not $delivery_time =~ /^\d{14}$/) {
+ my $error_string = "delivery_time '$delivery_time' is not a valid timestamp, please use format 'yyyymmddhhmmss'";
+ &main::daemon_log("$session_id ERROR: $error_string", 1);
+ return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
+ }
+
+ # add incoming message to messaging_db
+ my $func_dic = {table=>$main::messaging_tn,
+ primkey=>['id'],
+ subject=>$subject,
+ message_from=>$from,
+ message_to=>$to,
+ flag=>"n",
+ direction=>"in",
+ delivery_time=>$delivery_time,
+ message=>$message,
+ timestamp=>&get_time(),
+ };
+ my $res = $main::messaging_db->add_dbentry($func_dic);
+ if (not $res == 0) {
+ &main::daemon_log("$session_id ERROR: gosaTriggered.pm: cannot add message to message_db: $res", 1);
+ } else {
+ &main::daemon_log("$session_id INFO: gosaTriggered.pm: message with subject '$subject' successfully added to message_db", 5);
+ }
+
+ return;
+}
+
+sub send_user_msg_OLD {
my ($msg, $msg_hash, $session_id) = @_ ;
my @out_msg_l;
my @user_list;
# error handling
if( not @user_list && not @group_list ) {
- &main::daemon_log("WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
+ &main::daemon_log("$session_id WARNING: no user-tag or a group-tag specified in 'send_user_msg'", 3);
return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
"<error_string>no user-tag or a group-tag specified in 'send_user_msg'</error_string></xml>");
}
if( not defined $message ) {
- &main::daemon_log("WARNING: no message-tag specified in 'send_user_msg'", 3);
+ &main::daemon_log("$session_id WARNING: no message-tag specified in 'send_user_msg'", 3);
return ("<xml><header>$header</header><source>GOSA</source><target>GOSA</target>".
"<error_string>no message-tag specified in 'send_user_msg'</error_string></xml>");
}
# resolve groups to users
+ my $ldap_handle = &main::get_ldap_handle($session_id);
if( @group_list ) {
- # build ldap connection
- &main::refresh_ldap_handle();
- if( not defined $main::ldap_handle ) {
- &main::daemon_log("ERROR: cannot connect to ldap", 1);
+ if( not defined $ldap_handle ) {
+ &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
return ();
}
- foreach my $group (@group_list) {
- # Perform search
- my $mesg = $main::ldap_handle->search(
+ foreach my $group (@group_list) { # Perform search
+ my $mesg = $ldap_handle->search(
base => $main::ldap_base,
scope => 'sub',
attrs => ['memberUid'],
}
$main::fai_server_db->create_table("new_fai_server", \@main::fai_server_col_names);
- &main::create_fai_server_db("new_fai_server");
+ &main::create_fai_server_db("new_fai_server",undef,"dont", $session_id);
$main::fai_server_db->move_table("new_fai_server", $main::fai_server_tn);
my @out_msg_l = ( $out_msg );
}
+sub recreate_fai_release_db {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $out_msg;
+
+ my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
+ if( defined $jobdb_id) {
+ my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
+ &main::daemon_log("$session_id DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->exec_statement($sql_statement);
+ }
+
+ $main::fai_server_db->create_table("new_fai_release", \@main::fai_release_col_names);
+ &main::create_fai_release_db("new_fai_release", $session_id);
+ $main::fai_server_db->move_table("new_fai_release", $main::fai_release_tn);
+
+ my @out_msg_l = ( $out_msg );
+ return @out_msg_l;
+}
+
+
sub get_login_usr_for_client {
my ($msg, $msg_hash, $session_id) = @_ ;
my $header = @{$msg_hash->{'header'}}[0];
my $header = @{$msg_hash->{header}}[0];
my $source = @{$msg_hash->{source}}[0];
my $target = @{$msg_hash->{target}}[0];
+ my @out_msg_l;
+ # update status of job
my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
if( defined $jobdb_id) {
my $sql_statement = "UPDATE $main::job_queue_tn SET status='processed' WHERE id='$jobdb_id'";
my $res = $main::job_db->exec_statement($sql_statement);
}
+ # create set_activated_for_installation message for delivery
my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
if( defined $jobdb_id ) {
&add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
}
my $out_msg = &create_xml_string($out_hash);
- my @out_msg_l = ( $out_msg );
+ push(@out_msg_l, $out_msg);
+
return @out_msg_l;
}
push(@out_msg_l, $msg);
&main::change_goto_state('locked', \@{$msg_hash->{target}}, $session_id);
- &main::change_fai_state('localboot', \@{$msg_hash->{target}}, $session_id);
+ &main::change_fai_state('install', \@{$msg_hash->{target}}, $session_id);
# delete all jobs from jobqueue which correspond to fai
my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
}
+sub get_available_kernel {
+ my ($msg, $msg_hash, $session_id) = @_;
+
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $release= @{$msg_hash->{'release'}}[0];
+
+ my @kernel;
+ # Get Kernel packages for release
+ my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$release' AND package LIKE 'linux\-image\-%'";
+ my $res_hash = $main::packages_list_db->select_dbentry($sql_statement);
+ my %data;
+ my $i=1;
+
+ foreach my $package (keys %{$res_hash}) {
+ $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
+ }
+
+ my $out_msg = &build_msg("get_available_kernel", $target, "GOSA", \%data);
+ return ( $out_msg );
+}
+
+
1;