summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e8a4565)
raw | patch | inline | side by side (parent: e8a4565)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 28 May 2009 09:58:23 +0000 (09:58 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 28 May 2009 09:58:23 +0000 (09:58 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13676 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/gosa-si-server | patch | blob | history | |
gosa-si/server/events/gosaTriggered.pm | patch | blob | history |
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 296ae6fb1360fdbb6b1d498eaebb6c0f1340f12f..32e99c71af0410842e3d43e952f2b6c550885813 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
my $own_source_address = &get_local_ip_for_remote_ip(sprintf("%s", $address =~ /^([0-9\.]*?):.*$/));
$own_source_address .= ":".$server_port;
- # Patch the source ip
- if($msg =~ /<source>0\.0\.0\.0:\d*?<\/source>/) {
- $msg =~ s/<source>(0\.0\.0\.0):(\d*?)<\/source>/<source>$own_source_address<\/source>/s;
- }
+ # Patch 0.0.0.0 source to real address
+ $msg =~ s/<source>(0\.0\.0\.0):(\d*?)<\/source>/<source>$own_source_address<\/source>/s;
+ # Patch GOSA source to real address and add forward_to_gosa tag
+ $msg =~ s/<source>GOSA<\/source>/<source>$own_source_address<\/source> <forward_to_gosa>$own_source_address,$session_id<\/forward_to_gosa>/ ;
# encrypt xml msg
my $crypted_msg = &encrypt_msg($msg, $encrypt_key);
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
- daemon_log("$session_id WARNING: cannot send ".$header."msg to '$address' , host not reachable! Message: '$msg'", 3);
+ daemon_log("$session_id ERROR: Cannot open socket to host '$address'. Message processing aborted!", 1);
$error++;
}
}
}
+ # If header has a 'job_' prefix, do always process message locally
+ # which means put it into job queue
+ if ((not $done) && ($header =~ /job_/))
+ {
+ $done = 1;
+ &daemon_log("$session_id DEBUG: Header has a 'job_' prefix. Put it into job queue. -> process here", 7);
+ }
+
# if message should be processed here -> add message to incoming_db
if ($done) {
- # if a job or a gosa message comes from a foreign server, fake module to GosaPackages
- # so gosa-si-server knows how to process this kind of messages
+ # if a 'job_' or a 'gosa_' message comes from a foreign server, fake module from
+ # ServerPackages to GosaPackages so gosa-si-server knows how to process this kind of messages
if ($header =~ /^gosa_/ || $header =~ /^job_/) {
$module = "GosaPackages";
}
$sql = "SELECT * FROM $known_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
$res = $known_clients_db->select_dbentry($sql);
if (keys(%$res) > 0) {
+ &daemon_log("$session_id DEBUG: target is a client address in known_clients -> forward to client", 7);
$done = 1;
- my $key = $res->{1}->{'hostkey'};
- my $error= &send_msg_to_target($msg, $target, $key, $header, $session_id);
+ my $hostkey = $res->{1}->{'hostkey'};
+ my $hostname = $res->{1}->{'hostname'};
+ $msg =~ s/<target>\S*<\/target>/<target>$hostname<\/target>/;
+ $msg =~ s/<header>gosa_/<header>/;
+ my $error= &send_msg_to_target($msg, $hostname, $hostkey, $header, $session_id);
if ($error) {
- &daemon_log("$session_id ERROR: some problems (error=$error) occurred while trying to send msg to client: $msg", 1);
+ &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostkey': $msg", 1);
}
-
- &daemon_log("$session_id DEBUG: target is a client address in known_clients -> forward to client", 7);
-
} else {
$not_found_in_known_clients_db = 1;
}
}
my $error= &send_msg_to_target($msg, $regserver, $regserver_key, $header, $session_id);
if ($error) {
- &daemon_log("$session_id ERROR: some problems (error=$error) occurred while trying to send msg to registration server: $msg", 1);
+ &daemon_log("$session_id ERROR: some problems occurred while trying to send msg to registration server: $msg", 1);
}
}
$done = 1;
chown($root_uid, $adm_gid, $job_queue_file_name);
# connect to known_clients_db
- unlink($known_clients_file_name);
+ #unlink($known_clients_file_name);
$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
chmod(0640, $known_clients_file_name);
chown($root_uid, $adm_gid, $known_clients_file_name);
# connect to foreign_clients_db
- unlink($foreign_clients_file_name);
+ #unlink($foreign_clients_file_name);
$foreign_clients_db = GOSA::DBsqlite->new($foreign_clients_file_name);
chmod(0640, $foreign_clients_file_name);
chown($root_uid, $adm_gid, $foreign_clients_file_name);
# connect to known_server_db
- unlink($known_server_file_name);
+ #unlink($known_server_file_name);
$known_server_db = GOSA::DBsqlite->new($known_server_file_name);
chmod(0640, $known_server_file_name);
chown($root_uid, $adm_gid, $known_server_file_name);
# connect to login_usr_db
- unlink($login_users_file_name);
+ #unlink($login_users_file_name);
$login_users_db = GOSA::DBsqlite->new($login_users_file_name);
chmod(0640, $login_users_file_name);
chown($root_uid, $adm_gid, $login_users_file_name);
chown($root_uid, $adm_gid, $packages_list_file_name);
# connect to messaging_db
- unlink($messaging_file_name);
+ #unlink($messaging_file_name);
$messaging_db = GOSA::DBsqlite->new($messaging_file_name);
chmod(0640, $messaging_file_name);
chown($root_uid, $adm_gid, $messaging_file_name);
index 9cf0852c73bdddaf24d4e18bcfab4f7ae3c4d60f..2377762218170180e1fdb5e8a24b3f854254f39d 100644 (file)
"trigger_reload_syslog_config",
"trigger_reload_ntp_config",
"trigger_reload_ldap_config",
- "ping",
"network_completition",
"set_activated_for_installation",
"new_key_for_client",
"trigger_action_halt",
"trigger_action_update",
"trigger_action_reinstall",
- "trigger_action_memcheck",
"trigger_action_sysinfo",
"trigger_action_instant_update",
"trigger_action_rescan",
"get_available_kernel",
"trigger_activate_new",
"get_hosts_with_module",
-# "get_dak_keyring",
-# "import_dak_key",
-# "remove_dak_key",
-# "get_dak_queue",
);
@EXPORT = @events;
use strict;
use warnings;
use GOSA::GosaSupportDaemon;
-use Data::Dumper;
use Crypt::SmbHash;
use Net::ARP;
use Net::Ping;
use Socket;
use Time::HiRes qw( usleep);
use MIME::Base64;
+use Data::Dumper;
BEGIN {}
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
- #my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]); # just for debugging
my $subject = @{$msg_hash->{'subject'}}[0];
my $from = @{$msg_hash->{'from'}}[0];
my @users = exists $msg_hash->{'user'} ? @{$msg_hash->{'user'}} : () ;
my @groups = exists $msg_hash->{'group'} ? @{$msg_hash->{'group'}} : ();
my $delivery_time = @{$msg_hash->{'delivery_time'}}[0];
- #my $message = &decode_base64(@{$msg_hash->{'message'}}[0]); # just for debugging
my $message = @{$msg_hash->{'message'}}[0];
# keep job queue uptodate if necessary
sub get_login_usr_for_client {
my ($msg, $msg_hash, $session_id) = @_ ;
my $header = @{$msg_hash->{'header'}}[0];
+ $header =~ s/^gosa_//;
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
my $client = @{$msg_hash->{'client'}}[0];
+ # Set job status
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);
}
- $header =~ s/^gosa_//;
+ # If $client is a mac address
+ if ($client =~ /^\w\w:\w\w:\w\w:\w\w:\w\w:\w\w$/i)
+ {
+ # Search for hostname of $client within known_clients_db
+ my $sql = "SELECT * FROM $main::known_clients_tn WHERE macaddress LIKE '$client'";
+ my $res = $main::known_clients_db->select_dbentry($sql);
+ my $found = 0;
+ if (keys(%$res) == 1)
+ {
+ $found = 1;
+ $client = $res->{1}->{hostname};
+ }
+ if (not $found) # Do only if the first search results in nothing
+ {
+ # Search for hostname of $client within known_foreign_db
+ $sql = "SELECT * FROM $main::foreign_clients_tn WHERE macaddress LIKE '$client'";
+ $res = $main::foreign_clients_db->select_dbentry($sql);
+ if (keys(%$res) == 1)
+ {
+ $client = $res->{1}->{hostname};
+ }
+ }
+ }
- my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress LIKE '$client'";
- my $res = $main::known_clients_db->select_dbentry($sql_statement);
+ # Search for logged in users at hostname
+ my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE client LIKE '$client'";
+ my $res = $main::login_users_db->select_dbentry($sql_statement);
- my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
- $out_msg .= &db_res2xml($res);
- $out_msg .= "</xml>";
+ # Create answer message for GOsa
+ my $out_msg;
+ if (keys(%$res) == 0)
+ {
+ my $info = "INFO: No hits found in login_users_db for client '$client'";
+ $out_msg = &create_xml_string(&create_xml_hash($header, $target, $source, $info));
+ &main::daemon_log("$session_id ".$info, 5);
+ }
+ else
+ {
+ $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
+ $out_msg .= &db_res2xml($res);
+ $out_msg .= "</xml>";
+ }
- my @out_msg_l = ( $out_msg );
- return @out_msg_l;
+ return ($out_msg);
}
sub get_client_for_login_usr {
my ($msg, $msg_hash, $session_id) = @_ ;
my $header = @{$msg_hash->{'header'}}[0];
+ $header =~ s/^gosa_//;
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
+ my $usr = @{$msg_hash->{'usr'}}[0];
+ # Set job status
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);
}
- my $usr = @{$msg_hash->{'usr'}}[0];
- $header =~ s/^gosa_//;
-
- my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
- my $res = $main::known_clients_db->select_dbentry($sql_statement);
+ # Search for clients where $usr is logged in
+ my $sql_statement = "SELECT * FROM $main::login_users_tn WHERE user LIKE '%$usr%'";
+ my $res = $main::login_users_db->select_dbentry($sql_statement);
+ # Create answer message for GOsa
my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
$out_msg .= &db_res2xml($res);
$out_msg .= "</xml>";
- my @out_msg_l = ( $out_msg );
- return @out_msg_l;
-
-}
-
-
-sub ping {
- my ($msg, $msg_hash, $session_id) = @_ ;
- my $header = @{$msg_hash->{header}}[0];
- my $target = @{$msg_hash->{target}}[0];
- my $source = @{$msg_hash->{source}}[0];
- my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
- my $error = 0;
- my $answer_msg;
- my ($sql, $res);
-
- 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);
- }
-
- # send message
- $sql = "SELECT * FROM $main::known_clients_tn WHERE ((hostname='$target') || (macaddress LIKE '$target'))";
- $res = $main::known_clients_db->exec_statement($sql);
-
- # sanity check of db result
- my ($host_name, $host_key);
- if ((defined $res) && (@$res > 0) && @{@$res[0]} > 0) {
- $host_name = @{@$res[0]}[0];
- $host_key = @{@$res[0]}[2];
- } else {
- &main::daemon_log("$session_id ERROR: cannot determine host_name and host_key from known_clients_db at function ping\n$msg", 1);
- $error = 1;
- }
-
- if (not $error) {
- my $client_hash = &create_xml_hash("ping", $main::server_address, $host_name);
- &add_content2xml_hash($client_hash, 'session_id', $session_id);
- my $client_msg = &create_xml_string($client_hash);
- &main::send_msg_to_target($client_msg, $host_name, $host_key, $header, $session_id);
-
- my $message_id;
- my $i = 0;
- while (1) {
- $i++;
- $sql = "SELECT * FROM $main::incoming_tn WHERE headertag='answer_$session_id'";
- $res = $main::incoming_db->exec_statement($sql);
- if (ref @$res[0] eq "ARRAY") {
- $message_id = @{@$res[0]}[0];
- last;
- }
-
- # do not run into a endless loop
- if ($i > 100) { last; }
- usleep(100000);
- }
- # if an answer to the question exists
- if (defined $message_id) {
- my $answer_xml = @{@$res[0]}[3];
- my %data = ( 'answer_xml' => 'bin noch da' );
- $answer_msg = &build_msg("got_ping", $target, $source, \%data);
- my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
- if (defined $forward_to_gosa){
- $answer_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
- }
- $sql = "DELETE FROM $main::incoming_tn WHERE id=$message_id";
- $res = $main::incoming_db->exec_statement($sql);
- }
-
- }
+ return ( $out_msg );
- return ( $answer_msg );
}
-
sub gen_smb_hash {
my ($msg, $msg_hash, $session_id) = @_ ;
my $source = @{$msg_hash->{source}}[0];
# Can we resolv the name?
my %data;
if (inet_aton($name)){
- my $address = inet_ntoa(inet_aton($name));
+ my $tmp = (inet_aton($name));
+ my $address = inet_ntoa($tmp);
my $p = Net::Ping->new('tcp');
my $mac= "";
if ($p->ping($address, 1)){
my ($msg, $msg_hash, $session_id) = @_ ;
# just forward msg to client, but dont forget to split off 'gosa_' in header
my $source = @{$msg_hash->{source}}[0];
- my $target = @{$msg_hash->{target}}[0];
+ my $mac = @{$msg_hash->{macaddress}}[0];
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);
}
- my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
+ my $out_hash = &create_xml_hash("detect_hardware", $source, $mac);
if( defined $jobdb_id ) {
&add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
}
sub trigger_reload_ldap_config {
my ($msg, $msg_hash, $session_id) = @_ ;
- my $target = @{$msg_hash->{target}}[0];
+ my $mac = @{$msg_hash->{macaddress}}[0];
my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
if( defined $jobdb_id) {
my $res = $main::job_db->exec_statement($sql_statement);
}
- my $out_msg = &ClientPackages::new_ldap_config($target, $session_id);
+ my $out_msg = &ClientPackages::new_ldap_config($mac, $session_id);
my @out_msg_l = ( $out_msg );
return @out_msg_l;
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 $mac= (defined($msg_hash->{'macaddress'}))?@{$msg_hash->{'macaddress'}}[0]:undef;
my @out_msg_l;
+ # TODO Sanity check macAddress defined
+
# update status of job
my $jobdb_id = @{$msg_hash->{'jobdb_id'}}[0];
if( defined $jobdb_id) {
push(@out_msg_l, $ldap_out_msg);
# create set_activated_for_installation message for delivery
- my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
+ my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $mac);
if( defined $jobdb_id ) {
&add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id);
}
sub trigger_action_faireboot {
my ($msg, $msg_hash, $session_id) = @_;
- my $macaddress = @{$msg_hash->{macaddress}}[0];
+ my $mac = @{$msg_hash->{macaddress}}[0];
my $source = @{$msg_hash->{source}}[0];
- my @out_msg_l;
- $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
- push(@out_msg_l, $msg);
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_faireboot", $source, $mac));
+ # Set LDAP states
&main::change_goto_state('locked', \@{$msg_hash->{macaddress}}, $session_id);
&main::change_fai_state('install', \@{$msg_hash->{macaddress}}, $session_id);
- # set job to status 'done', job will be deleted automatically
+ # Set job to status 'done', job will be deleted automatically
my $sql_statement = "UPDATE $main::job_queue_tn ".
"SET status='done', modified='1'".
- "WHERE (macaddress LIKE '$macaddress' AND status='processing')";
+ "WHERE (macaddress LIKE '$mac' AND status='processing')";
&main::daemon_log("$session_id DEBUG: $sql_statement", 7);
my $res = $main::job_db->update_dbentry( $sql_statement );
- return @out_msg_l;
+ return ( $out_msg );
}
sub trigger_action_lock {
my ($msg, $msg_hash, $session_id) = @_;
- my $macaddress = @{$msg_hash->{macaddress}}[0];
- my $source = @{$msg_hash->{source}}[0];
+ # Set LDAP state
&main::change_goto_state('locked', \@{$msg_hash->{macaddress}}, $session_id);
+
+ # Set job status
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);
}
- my @out_msg_l;
- return @out_msg_l;
+ return;
}
sub trigger_action_activate {
my ($msg, $msg_hash, $session_id) = @_;
- my $macaddress = @{$msg_hash->{macaddress}}[0];
+ my $mac = @{$msg_hash->{macaddress}}[0];
my $source = @{$msg_hash->{source}}[0];
+ # Set LDAP state
&main::change_goto_state('active', \@{$msg_hash->{macaddress}}, $session_id);
+
+ # Set job status
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);
}
-
- my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
+
+ # Create message for client
+ my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $mac);
if( exists $msg_hash->{'jobdb_id'} ) {
&add_content2xml_hash($out_hash, 'jobdb_id', @{$msg_hash->{'jobdb_id'}}[0]);
}
my $out_msg = &create_xml_string($out_hash);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
+ return ( $out_msg );
}
sub trigger_action_localboot {
my ($msg, $msg_hash, $session_id) = @_;
- my $macaddress= $msg_hash->{macaddress}[0];
- my $target= $msg_hash->{target}[0];
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+ my $target = $msg_hash->{target}[0];
my @out_msg_l;
- $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
+
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_localboot", $source, $mac));
+ push(@out_msg_l, $out_msg);
# Check for running jobs. In that case return a message to GOsa that running jobs have to be deleted/aborted
# befor trigger_action_localboot could be effective. Running jobs usually sets FAIstate and GOtomode to
# what they need again and again and overwrite the 'trigger_action_localboot' setting
- my $job_sql= "SELECT * FROM $main::job_queue_tn WHERE macaddress LIKE '$macaddress'";
+ my $job_sql= "SELECT * FROM $main::job_queue_tn WHERE macaddress LIKE '$mac'";
my $job_res = $main::job_db->select_dbentry($job_sql);
my $job_res_count = keys(%$job_res);
if ($job_res_count) {
push(@out_msg_l, "<xml><header>answer</header><source>$target</source><target>GOSA</target><answer1>existing_job_in_queue</answer1></xml>");
}
+ # Set LDAP state
&main::change_fai_state('localboot', \@{$msg_hash->{macaddress}}, $session_id);
+
+ # Set job status
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);
}
- push(@out_msg_l, $msg);
return @out_msg_l;
}
sub trigger_action_halt {
my ($msg, $msg_hash, $session_id) = @_;
- $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_halt", $source, $mac));
+
+ # Set job status
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);
}
- my @out_msg_l = ($msg);
- return @out_msg_l;
+ return ($out_msg);
}
sub trigger_action_reboot {
my ($msg, $msg_hash, $session_id) = @_;
- $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
-
- &main::change_fai_state('reboot', \@{$msg_hash->{macaddress}}, $session_id);
- 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);
- }
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
- my @out_msg_l = ($msg);
- return @out_msg_l;
-}
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_reboot", $source, $mac));
+ # Set LDAP state
+ &main::change_fai_state('reboot', \@{$msg_hash->{macaddress}}, $session_id);
-sub trigger_action_memcheck {
- my ($msg, $msg_hash, $session_id) = @_ ;
- $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
-
- &main::change_fai_state('memcheck', \@{$msg_hash->{macaddress}}, $session_id);
+ # Set job status
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);
}
- my @out_msg_l = ($msg);
- return @out_msg_l;
+ return ($out_msg);
}
sub trigger_action_reinstall {
my ($msg, $msg_hash, $session_id) = @_;
- $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_reinstall", $source, $mac));
+
+ # Set LDAP state
&main::change_fai_state('reinstall', \@{$msg_hash->{macaddress}}, $session_id);
+ # Create wakeup message for all foreign server
my %data = ( 'macaddress' => \@{$msg_hash->{macaddress}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
- # invoke trigger wake for this gosa-si-server
+
+ # Invoke trigger wake for this gosa-si-server
&main::server_server_com::trigger_wake($msg, $msg_hash, $session_id);
- my @out_msg_l = ($wake_msg, $msg);
- return @out_msg_l;
+ return ($wake_msg, $msg);
}
sub trigger_action_update {
my ($msg, $msg_hash, $session_id) = @_;
- $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_update", $source, $mac));
+ # Set LDAP state
&main::change_fai_state('update', \@{$msg_hash->{macaddress}}, $session_id);
+ # Create wakeup message for all foreign server
my %data = ( 'macaddress' => \@{$msg_hash->{macaddress}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
- # invoke trigger wake for this gosa-si-server
+
+ # Invoke trigger wake for this gosa-si-server
&main::server_server_com::trigger_wake($msg, $msg_hash, $session_id);
- my @out_msg_l = ($wake_msg, $msg);
- return @out_msg_l;
+ return ($wake_msg, $msg);
}
sub trigger_action_instant_update {
my ($msg, $msg_hash, $session_id) = @_;
- $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("trigger_action_instant_update", $source, $mac));
+
+ # Set LDAP state
&main::change_fai_state('update', \@{$msg_hash->{macaddress}}, $session_id);
+ # Set job status
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 wakeup message for all foreign server
my %data = ( 'macaddress' => \@{$msg_hash->{macaddress}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
- # invoke trigger wake for this gosa-si-server
- &main::server_server_com::trigger_wake($msg, $msg_hash, $session_id);
- my @out_msg_l = ($wake_msg, $msg);
- return @out_msg_l;
-}
-
-
-sub trigger_action_sysinfo {
- my ($msg, $msg_hash, $session_id) = @_;
- $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
-
- &main::change_fai_state('sysinfo', \@{$msg_hash->{macaddress}}, $session_id);
- 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);
- }
+ # Invoke trigger wake for this gosa-si-server
+ &main::server_server_com::trigger_wake($msg, $msg_hash, $session_id);
- my @out_msg_l = ($msg);
- return @out_msg_l;
+ return ($wake_msg, $msg);
}
sub new_key_for_client {
my ($msg, $msg_hash, $session_id) = @_;
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("new_key", $source, $mac));
+ # Set job status
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);
}
-
- $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
- my @out_msg_l = ($msg);
- return @out_msg_l;
+
+ return ($out_msg);
}
sub trigger_action_rescan {
my ($msg, $msg_hash, $session_id) = @_;
+ my $source = $msg_hash->{source}[0];
+ my $mac = $msg_hash->{macaddress}[0];
+
+ # Create message for client
+ my $out_msg = &main::create_xml_string(&main::create_xml_hash("detect_hardware", $source, $mac));
+ # Set job status
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);
}
-
- $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>detect_hardware<header>/;
- my @out_msg_l = ($msg);
- return @out_msg_l;
+ return ( $out_msg );
}
sub trigger_action_wake {
my ($msg, $msg_hash, $session_id) = @_;
-
+
+ # Set job status
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);
}
- # build out message
+ # Create wakeup message for all foreign server
my $out_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER");
foreach (@{$msg_hash->{'macaddress'}}) {
&add_content2xml_hash($out_hash, 'macaddress', $_);
}
my $out_msg = &create_xml_string($out_hash);
- # invoke trigger wake for this gosa-si-server
+ # Invoke trigger wake for this gosa-si-server
&main::server_server_com::trigger_wake($out_msg, $out_hash, $session_id);
- # send trigger wake to all other gosa-si-server
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
+ return ( $out_msg );
}
sub get_available_kernel {
my ($msg, $msg_hash, $session_id) = @_;
-
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
my $fai_release= @{$msg_hash->{'fai_release'}}[0];
-
my @kernel;
+
# Get Kernel packages for release
my $sql_statement = "SELECT * FROM $main::packages_list_tn WHERE distribution='$fai_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++}= $data{"answer".$i++}= ${$res_hash}{$package}->{'package'};
}
$data{"answer".$i++}= "default";
+ # Create answer for GOsa
my $out_msg = &build_msg("get_available_kernel", $target, $source, \%data);
my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
if (defined $forward_to_gosa) {
sub trigger_activate_new {
my ($msg, $msg_hash, $session_id) = @_;
-
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
my $header= @{$msg_hash->{'header'}}[0];
$main::job_db->exec_statement("UPDATE jobs SET status = 'done' WHERE id = $jobdb_id");
# create set_activated_for_installation message for delivery
- my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
+ my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $mac);
my $out_msg = &create_xml_string($out_hash);
push(@out_msg_l, $out_msg);
}
-#sub get_dak_keyring {
-# my ($msg, $msg_hash) = @_;
-# my $source = @{$msg_hash->{'source'}}[0];
-# my $target = @{$msg_hash->{'target'}}[0];
-# my $header= @{$msg_hash->{'header'}}[0];
-# my $session_id = @{$msg_hash->{'session_id'}}[0];
-#
-# # build return message with twisted target and source
-# my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
-# &add_content2xml_hash($out_hash, "session_id", $session_id);
-#
-# my @keys;
-# my %data;
-#
-# my $keyring = $main::dak_signing_keys_directory."/keyring.gpg";
-#
-# my $gpg_cmd = `which gpg`; chomp $gpg_cmd;
-# my $gpg = "$gpg_cmd --no-default-keyring --no-random-seed --keyring $keyring";
-#
-# # Check if the keyrings are in place and readable
-# if(
-# &run_as($main::dak_user, "test -r $keyring")->{'resultCode'} != 0
-# ) {
-# &add_content2xml_hash($out_hash, "error", "DAK Keyring is not readable");
-# } else {
-# my $command = "$gpg --list-keys";
-# my $output = &run_as($main::dak_user, $command);
-# &main::daemon_log("$session_id DEBUG: ".$output->{'command'}, 7);
-#
-# my $i=0;
-# foreach (@{$output->{'output'}}) {
-# if ($_ =~ m/^pub\s.*$/) {
-# ($keys[$i]->{'pub'}->{'length'}, $keys[$i]->{'pub'}->{'uid'}, $keys[$i]->{'pub'}->{'created'}) = ($1, $2, $3)
-# if $_ =~ m/^pub\s*?(\w*?)\/(\w*?)\s(\d{4}-\d{2}-\d{2})/;
-# $keys[$i]->{'pub'}->{'expires'} = $1 if $_ =~ m/^pub\s*?\w*?\/\w*?\s\d{4}-\d{2}-\d{2}\s\[expires:\s(\d{4}-\d{2}-\d{2})\]/;
-# $keys[$i]->{'pub'}->{'expired'} = $1 if $_ =~ m/^pub\s*?\w*?\/\w*?\s\d{4}-\d{2}-\d{2}\s\[expired:\s(\d{4}-\d{2}-\d{2})\]/;
-# } elsif ($_ =~ m/^sub\s.*$/) {
-# ($keys[$i]->{'sub'}->{'length'}, $keys[$i]->{'sub'}->{'uid'}, $keys[$i]->{'sub'}->{'created'}) = ($1, $2, $3)
-# if $_ =~ m/^sub\s*?(\w*?)\/(\w*?)\s(\d{4}-\d{2}-\d{2})/;
-# $keys[$i]->{'sub'}->{'expires'} = $1 if $_ =~ m/^pub\s*?\w*?\/\w*?\s\d{4}-\d{2}-\d{2}\s\[expires:\s(\d{4}-\d{2}-\d{2})\]/;
-# $keys[$i]->{'sub'}->{'expired'} = $1 if $_ =~ m/^pub\s*?\w*?\/\w*?\s\d{4}-\d{2}-\d{2}\s\[expired:\s(\d{4}-\d{2}-\d{2})\]/;
-# } elsif ($_ =~ m/^uid\s.*$/) {
-# push @{$keys[$i]->{'uid'}}, $1 if $_ =~ m/^uid\s*?([^\s].*?)$/;
-# } elsif ($_ =~ m/^$/) {
-# $i++;
-# }
-# }
-# }
-#
-# my $i=0;
-# foreach my $key (@keys) {
-# # &main::daemon_log(Dumper($key));
-# &add_content2xml_hash($out_hash, "answer".$i++, $key);
-# }
-# my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
-# if (defined $forward_to_gosa) {
-# &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
-# }
-# return &create_xml_string($out_hash);
-#}
-#
-#
-#sub import_dak_key {
-# my ($msg, $msg_hash) = @_;
-# my $source = @{$msg_hash->{'source'}}[0];
-# my $target = @{$msg_hash->{'target'}}[0];
-# my $header= @{$msg_hash->{'header'}}[0];
-# my $session_id = @{$msg_hash->{'session_id'}}[0];
-# my $key = &decode_base64(@{$msg_hash->{'key'}}[0]);
-#
-# # build return message with twisted target and source
-# my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
-# &add_content2xml_hash($out_hash, "session_id", $session_id);
-#
-# my %data;
-#
-# my $keyring = $main::dak_signing_keys_directory."/keyring.gpg";
-#
-# my $gpg_cmd = `which gpg`; chomp $gpg_cmd;
-# my $gpg = "$gpg_cmd --no-default-keyring --no-random-seed --keyring $keyring";
-#
-# # Check if the keyrings are in place and writable
-# if(
-# &run_as($main::dak_user, "test -w $keyring")->{'resultCode'} != 0
-# ) {
-# &add_content2xml_hash($out_hash, "error", "DAK Keyring is not writable");
-# } else {
-# my $keyfile;
-# open($keyfile, ">/tmp/gosa_si_tmp_dak_key");
-# print $keyfile $key;
-# close($keyfile);
-# my $command = "$gpg --import /tmp/gosa_si_tmp_dak_key";
-# my $output = &run_as($main::dak_user, $command);
-# &main::daemon_log("$session_id DEBUG: ".$output->{'command'}, 7);
-# unlink("/tmp/gosa_si_tmp_dak_key");
-#
-# if($output->{'resultCode'} != 0) {
-# &add_content2xml_hash($out_hash, "error", "Import of DAK key failed! Output was '".$output->{'output'}."'");
-# } else {
-# &add_content2xml_hash($out_hash, "answer", "Import of DAK key successfull! Output was '".$output->{'output'}."'");
-# }
-# }
-#
-# my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
-# if (defined $forward_to_gosa) {
-# &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
-# }
-# return &create_xml_string($out_hash);
-#}
-#
-#
-#sub remove_dak_key {
-# my ($msg, $msg_hash) = @_;
-# my $source = @{$msg_hash->{'source'}}[0];
-# my $target = @{$msg_hash->{'target'}}[0];
-# my $header= @{$msg_hash->{'header'}}[0];
-# my $session_id = @{$msg_hash->{'session_id'}}[0];
-# my $key = @{$msg_hash->{'keyid'}}[0];
-# # build return message with twisted target and source
-# my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
-# &add_content2xml_hash($out_hash, "session_id", $session_id);
-#
-# my %data;
-#
-# my $keyring = $main::dak_signing_keys_directory."/keyring.gpg";
-#
-# my $gpg_cmd = `which gpg`; chomp $gpg_cmd;
-# my $gpg = "$gpg_cmd --no-default-keyring --no-random-seed --homedir ".$main::dak_signing_keys_directory." --keyring $keyring";
-#
-# # Check if the keyrings are in place and writable
-# if(
-# &run_as($main::dak_user, "test -w $keyring")->{'resultCode'} != 0
-# ) {
-# &add_content2xml_hash($out_hash, "error", "DAK keyring is not writable");
-# } else {
-# # Check if the key is present in the keyring
-# if(&run_as($main::dak_user, "$gpg --list-keys $key")->{'resultCode'} == 0) {
-# my $command = "$gpg --batch --yes --delete-key $key";
-# my $output = &run_as($main::dak_user, $command);
-# &main::daemon_log("$session_id DEBUG: ".$output->{'command'}, 7);
-# } else {
-# &add_content2xml_hash($out_hash, "error", "DAK key with id '$key' was not found in keyring");
-# }
-# }
-#
-# my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
-# if (defined $forward_to_gosa) {
-# &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
-# }
-# return &create_xml_string($out_hash);
-#}
-
-
-#sub get_dak_queue {
-# my ($msg, $msg_hash, $session_id) = @_;
-# my %data;
-# my $source = @{$msg_hash->{'source'}}[0];
-# my $target = @{$msg_hash->{'target'}}[0];
-# my $header= @{$msg_hash->{'header'}}[0];
-#
-# my %data;
-#
-# foreach my $dir ("unchecked", "new", "accepted") {
-# foreach my $file(<"$main::dak_queue_directory/$dir/*.changes">) {
-# }
-# }
-#
-# my $out_msg = &build_msg("get_dak_queue", $target, $source, \%data);
-# my @out_msg_l = ($out_msg);
-# return @out_msg_l;
-#}
-
## @method get_hosts_with_module
# Reports all GOsa-si-server providing the given module.
# @param msg - STRING - xml message with tag get_hosts_with_module