bc1027c8bbd340f96a2e9e33e090bde1db763fd0
1 package server_server_com;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 'new_server',
6 'confirm_new_server',
7 );
8 @EXPORT = @events;
10 use strict;
11 use warnings;
12 use Data::Dumper;
13 use GOSA::GosaSupportDaemon;
16 BEGIN {}
18 END {}
20 ### Start ######################################################################
22 sub get_events {
23 return \@events;
24 }
27 sub new_server {
28 my ($msg, $msg_hash, $session_id) = @_ ;
29 my $header = @{$msg_hash->{'header'}}[0];
30 my $source = @{$msg_hash->{'source'}}[0];
31 my $target = @{$msg_hash->{'target'}}[0];
32 my $key = @{$msg_hash->{'key'}}[0];
33 my @clients = @{$msg_hash->{'client'}};
35 # sanity check
36 if (ref $key eq 'HASH') {
37 &main::daemon_log("$session_id ERROR: 'new_server'-message from host '$source' contains no key!", 1);
38 return;
39 }
41 # add foreign server to known_server_db
42 my $func_dic = {table=>$main::known_server_tn,
43 primkey=>['hostname'],
44 hostname => $source,
45 hostkey => $key,
46 timestamp=>&get_time(),
47 };
48 my $res = $main::known_server_db->add_dbentry($func_dic);
49 if (not $res == 0) {
50 &main::daemon_log("$session_id ERROR: server_server_com.pm: cannot add server to known_server_db: $res", 1);
51 } else {
52 &main::daemon_log("$session_id INFO: server_server_com.pm: server '$source' successfully added to known_server_db", 5);
53 }
55 # add clients of foreign server to known_foreign_clients_db
56 my @sql_list;
57 foreach my $client (@clients) {
58 my @client_details = split(/,/, $client);
60 # workaround to avoid double entries in foreign_clients_db
61 my $del_sql = "DELTE FROM $main::foreign_clients_tn WHERE hostname='".$client_details[0]."'";
62 push(@sql_list, $del_sql);
64 my $sql = "INSERT INTO $main::foreign_clients_tn VALUES ("
65 ."'".$client_details[0]."'," # hostname
66 ."'".$client_details[1]."'," # macaddress
67 ."'".$source."'," # regserver
68 ."'".&get_time()."')"; # timestamp
69 push(@sql_list, $sql);
70 }
71 if (@sql_list) {
72 &main::daemon_log("$session_id DEBUG: Inserting ".scalar @sql_list." entries to foreign_clients_db", 8);
73 my $res = $main::foreign_clients_db->exec_statementlist(\@sql_list);
74 }
76 # build confirm_new_server message
77 my %data = ( key=>$key );
78 my $out_msg = &build_msg('confirm_new_server', $main::server_address, $source, \%data);
79 my $error = &main::send_msg_to_target($out_msg, $source, $main::ServerPackages_key, 'confirm_new_server', $session_id);
82 }
85 sub confirm_new_server {
86 my ($msg, $msg_hash, $session_id) = @_ ;
87 my $header = @{$msg_hash->{'header'}}[0];
88 my $source = @{$msg_hash->{'source'}}[0];
89 my $key = @{$msg_hash->{'key'}}[0];
91 my $sql = "UPDATE $main::known_server_tn SET status='$header', hostkey='$key' WHERE hostname='$source'";
92 my $res = $main::known_server_db->update_dbentry($sql);
95 }
97 1;