diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm
index 686d9f7687b09a54f9f69edfd2688545196948d9..98f11a5675ec325034860c88aaf62f1396de9123 100644 (file)
package server_server_com;
-use Exporter;
-@ISA = qw(Exporter);
-my @events = (
- 'new_server',
- 'confirm_new_server',
- 'new_foreign_client',
- 'trigger_wake',
- 'foreign_job_updates',
- );
-@EXPORT = @events;
use strict;
use warnings;
+
+use Exporter;
use Data::Dumper;
use GOSA::GosaSupportDaemon;
use Time::HiRes qw( usleep);
use Socket;
+our @ISA = qw(Exporter);
+
+my @events = (
+ 'information_sharing',
+ 'new_server',
+ 'confirm_new_server',
+ 'new_foreign_client',
+ 'trigger_wake',
+ 'foreign_job_updates',
+ 'confirm_usr_msg',
+ );
+
+our @EXPORT = @events;
BEGIN {}
}
+sub information_sharing {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+
+ # Handling of msg tag 'new_user'
+ if (exists $msg_hash->{'new_user'}) {
+ my $new_user_list = $msg_hash->{'new_user'};
+
+ # Sanity check of new_user_list
+ if (ref($new_user_list) eq 'HASH') {
+ &main::daemon_log("$session_id ERROR: 'new_user'-tag in incoming msg has no content!", 1);
+
+ } else {
+ my @user_list;
+ # Add each user to login_users_db
+ foreach my $new_user_info (@$new_user_list) {
+ my ($client, $user) = split(/;/, $new_user_info);
+ my %add_hash = ( table=>$main::login_users_tn,
+ primkey=> ['client', 'user'],
+ client=>$client,
+ user=>$user,
+ timestamp=>&get_time,
+ regserver=>$source,
+ );
+ my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
+ if ($res != 0)
+ {
+ &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str", 1);
+ }
+ else
+ {
+ push(@user_list, "'$user' at '$client'");
+ }
+ }
+ &main::daemon_log("$session_id INFO: server '$source' reports the following logged in user: ".join(", ", @user_list), 5);
+ }
+ }
+
+ # Handling of msg tag 'user_db'
+ if (exists $msg_hash->{'user_db'}) {
+ my $user_db_list = $msg_hash->{'user_db'};
+
+ # Sanity check of user_db_list
+ if (ref($user_db_list) eq 'HASH') {
+ &main::daemon_log("$session_id ERROR: 'user_db'-tag in incoming msg has no content!", 1);
+
+ } else {
+ # Delete all old login information
+ my $sql = "DELETE FROM $main::login_users_tn WHERE regserver='$source'";
+ my $res = $main::login_users_db->exec_statement($sql);
+
+ # Add each user to login_users_db
+ my @user_list;
+ foreach my $user_db_info (@$user_db_list) {
+ my ($client, $user) = split(/;/, $user_db_info);
+ my %add_hash = ( table=>$main::login_users_tn,
+ primkey=> ['client', 'user'],
+ client=>$client,
+ user=>$user,
+ timestamp=>&get_time,
+ regserver=>$source,
+ );
+ my ($res, $error_str) = $main::login_users_db->add_dbentry( \%add_hash );
+ if ($res != 0) {
+ &main::daemon_log("$session_id ERROR: cannot add entry to known_clients: $error_str", 1);
+ }
+ else
+ {
+ push(@user_list, "'$user' at '$client'");
+ }
+ }
+ &main::daemon_log("$session_id INFO: server '$source' reports the following logged in user: ".join(", ", @user_list), 5);
+ }
+ }
+
+ return;
+}
+
sub foreign_job_updates {
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 $key = @{$msg_hash->{'key'}}[0];
+ my $mac = exists $msg_hash->{'macaddress'} ? @{$msg_hash->{'macaddress'}}[0] : "" ;
my @clients = exists $msg_hash->{'client'} ? @{$msg_hash->{'client'}} : qw();
+ my @loaded_modules = exists $msg_hash->{'loaded_modules'} ? @{$msg_hash->{'loaded_modules'}} : qw();
+
+ # Ignor message if I'm already within a registration process for server $source
+ my $check_statement = "SELECT * FROM $main::known_server_tn WHERE status='new_server' AND hostname='$source'";
+ &main::daemon_log("$session_id DEBUG $check_statement", 7);
+ my $check_res = $main::known_server_db->select_dbentry($check_statement);
+ my $blocking_process = keys(%$check_res);
+ if ($blocking_process)
+ {
+ return;
+ }
- # sanity check
+ # Sanity check
if (ref $key eq 'HASH') {
&main::daemon_log("$session_id ERROR: 'new_server'-message from host '$source' contains no key!", 1);
return;
}
-
- # add foreign server to known_server_db
+ # Add foreign server to known_server_db
+ my $new_update_time = &calc_timestamp(&get_time(), 'plus', $main::foreign_servers_register_delay);
my $func_dic = {table=>$main::known_server_tn,
primkey=>['hostname'],
hostname => $source,
+ macaddress => $mac,
status => "new_server",
hostkey => $key,
+ loaded_modules => join(',', @loaded_modules),
timestamp=>&get_time(),
+ update_time=>$new_update_time,
};
my $res = $main::known_server_db->add_dbentry($func_dic);
if (not $res == 0) {
&main::daemon_log("$session_id DEBUG: Inserting ".$len." entries to foreign_clients_db", 8);
my $res = $main::foreign_clients_db->exec_statementlist(\@sql_list);
}
-
+
# fetch all registered clients
my $client_sql = "SELECT * FROM $main::known_clients_tn";
my $client_res = $main::known_clients_db->exec_statement($client_sql);
&add_content2xml_hash($myhash, 'key', $key);
map(&add_content2xml_hash($myhash, 'client', @{$_}[0].",".@{$_}[4]), @$client_res);
- # build registration message and send it
- my $out_msg = &create_xml_string($myhash);
+ # add locally loaded gosa-si modules to registration message
+ my $loaded_modules = {};
+ while (my ($package, $pck_info) = each %$main::known_modules) {
+ foreach my $act_module (keys(%{@$pck_info[2]})) {
+ $loaded_modules->{$act_module} = "";
+ }
+ }
+ map(&add_content2xml_hash($myhash, "loaded_modules", $_), keys(%$loaded_modules));
+ # add macaddress to registration message
+ my ($host_ip, $host_port) = split(/:/, $source);
+ my $local_ip = &get_local_ip_for_remote_ip($host_ip);
+ my $network_interface= &get_interface_for_ip($local_ip);
+ my $host_mac = &get_mac_for_interface($network_interface);
+ &add_content2xml_hash($myhash, 'macaddress', $host_mac);
- # build confirm_new_server message
- #my %data = ( key=>$key );
- #my $out_msg = &build_msg('confirm_new_server', $main::server_address, $source, \%data);
+ # build registration message and send it
+ my $out_msg = &create_xml_string($myhash);
my $error = &main::send_msg_to_target($out_msg, $source, $main::ServerPackages_key, 'confirm_new_server', $session_id);
-
+
return;
}
my $header = @{$msg_hash->{'header'}}[0];
my $source = @{$msg_hash->{'source'}}[0];
my $key = @{$msg_hash->{'key'}}[0];
+ my $mac = exists $msg_hash->{'macaddress'} ? @{$msg_hash->{'macaddress'}}[0] : "" ;
my @clients = exists $msg_hash->{'client'} ? @{$msg_hash->{'client'}} : qw();
+ my @loaded_modules = exists $msg_hash->{'loaded_modules'} ? @{$msg_hash->{'loaded_modules'}} : qw();
- my $sql = "UPDATE $main::known_server_tn SET status='$header', hostkey='$key' WHERE hostname='$source'";
+ my $new_update_time = &calc_timestamp(&get_time(), 'plus', $main::foreign_servers_register_delay);
+ my $sql = "UPDATE $main::known_server_tn".
+ " SET status='$header', hostkey='$key', loaded_modules='".join(",",@loaded_modules)."', macaddress='$mac', update_time='$new_update_time'".
+ " WHERE hostname='$source'";
my $res = $main::known_server_db->update_dbentry($sql);
# add clients of foreign server to known_foreign_clients_db
push(@sql_list, $del_sql);
my $sql = "INSERT INTO $main::foreign_clients_tn VALUES ("
- ."'".$client_details[0]."'," # hostname
- ."'".$client_details[1]."'," # macaddress
- ."'".$source."'," # regserver
- ."'".&get_time()."')"; # timestamp
+ ."'".$client_details[0]."'," # hostname
+ ."'".$client_details[1]."'," # macaddress
+ ."'".$source."'," # regserver
+ ."'".&get_time()."')"; # timestamp
push(@sql_list, $sql);
}
if (@sql_list) {
sub trigger_wake {
my ($msg, $msg_hash, $session_id) = @_ ;
- foreach (@{$msg_hash->{macAddress}}){
+ foreach (@{$msg_hash->{'macaddress'}}){
&main::daemon_log("$session_id INFO: trigger wake for $_", 5);
my $host = $_;
my $ipaddr = '255.255.255.255';
}
+sub confirm_usr_msg {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ &clMessages::confirm_usr_msg($msg, $msg_hash, $session_id);
+ return;
+}
+
+
1;