From b2cdf619b7566bce0a8b164fd7470d4084082aaa Mon Sep 17 00:00:00 2001 From: rettenbe Date: Tue, 20 May 2008 16:03:50 +0000 Subject: [PATCH] * gosa-si-server-nobus * under construction git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10968 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-server-nobus | 38 +++++++++----- gosa-si/modules/ClientPackages.pm | 49 ++++++++++--------- gosa-si/server/events/server_server_com.pm | 28 +++++++++-- gosa-si/tests/sqlite-check-clients.pl | 46 +++++++++++++++++ gosa-si/tests/sqlite-check-foreign-clients.pl | 46 +++++++++++++++++ gosa-si/tests/sqlite-check-incoming.pl | 46 +++++++++++++++++ gosa-si/tests/sqlite-check-users.pl | 48 ++++++++++++++++++ 7 files changed, 263 insertions(+), 38 deletions(-) create mode 100755 gosa-si/tests/sqlite-check-clients.pl create mode 100755 gosa-si/tests/sqlite-check-foreign-clients.pl create mode 100755 gosa-si/tests/sqlite-check-incoming.pl create mode 100755 gosa-si/tests/sqlite-check-users.pl diff --git a/gosa-si/gosa-si-server-nobus b/gosa-si/gosa-si-server-nobus index f1c762966..0e177473e 100755 --- a/gosa-si/gosa-si-server-nobus +++ b/gosa-si/gosa-si-server-nobus @@ -157,6 +157,12 @@ our $known_clients_tn = "known_clients"; my $known_clients_file_name; my @known_clients_col_names = ("hostname", "status", "hostkey", "timestamp", "macaddress", "events"); +# holds all registered clients at a foreign server +our $foreign_clients_db; +our $foreign_clients_tn = "foreign_clients"; +my $foreign_clients_file_name; +my @foreign_clients_col_names = ("hostname", "macaddress", "regserver", "timestamp"); + # holds all logged in user at each client our $login_users_db; our $login_users_tn = "login_users"; @@ -216,6 +222,7 @@ my $max_children = 2; "fai-release" => [\$fai_release_file_name, '/var/lib/gosa-si/fai_release.db'], "packages-list" => [\$packages_list_file_name, '/var/lib/gosa-si/packages.db'], "messaging" => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'], + "foreign-clients" => [\$foreign_clients_file_name, '/var/lib/gosa-si/foreign_clients.db'], "source-list" => [\$sources_list, '/etc/apt/sources.list'], "repo-path" => [\$repo_path, '/srv/www/repository'], "ldap-uri" => [\$ldap_uri, ""], @@ -950,7 +957,6 @@ sub send_msg_to_target { # known_server $sql_statement = "SELECT * FROM $known_server_tn WHERE hostname='$address'"; $res = $known_server_db->select_dbentry($sql_statement); -print STDERR Dumper($res); if( keys(%$res) > 0 ) { $act_status = $res->{1}->{'status'}; if ($act_status eq "down" && $new_status eq "down") { @@ -2582,25 +2588,31 @@ sub register_at_foreign_servers { my ($kernel) = $_[KERNEL]; # hole alle bekannten server aus known_server_db - my $sql = "SELECT * FROM $known_server_tn"; - my $res = $known_server_db->exec_statement($sql); + my $server_sql = "SELECT * FROM $known_server_tn"; + my $server_res = $known_server_db->exec_statement($server_sql); # no entries in known_server_db - if (not ref(@$res[0]) eq "ARRAY") { + if (not ref(@$server_res[0]) eq "ARRAY") { # TODO } - foreach my $hit (@$res) { + # detect already connected clients + my $client_sql = "SELECT * FROM $known_clients_tn"; + my $client_res = $known_clients_db->exec_statement($client_sql); + + # send my server details to all other gosa-si-server within the network + foreach my $hit (@$server_res) { my $hostname = @$hit[0]; my $hostkey = &create_passwd; - my %data= ('known_clients' => "", - 'key' => $hostkey, - ); - my $foreign_server_msg = &build_msg('new_server', $server_address, $hostname, \%data); - my $error = &send_msg_to_target($foreign_server_msg, $hostname, $ServerPackages_key, "new_server", 0); - + # add already connected clients to registration message + my $myhash = &create_xml_hash('new_server', $server_address, $hostname); + &add_content2xml_hash($myhash, 'key', $hostkey); + map(&add_content2xml_hash($myhash, 'client', @{$_}[0].",".@{$_}[4]), @$client_res); + # build registration message and send it + my $foreign_server_msg = &create_xml_string($myhash); + my $error = &send_msg_to_target($foreign_server_msg, $hostname, $ServerPackages_key, "new_server", 0); } $kernel->delay_set("register_at_foreign_servers", $foreign_servers_register_delay); @@ -2688,6 +2700,10 @@ $job_db->create_table($job_queue_tn, \@job_queue_col_names); $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); $known_clients_db->create_table($known_clients_tn, \@known_clients_col_names); +# connect to foreign_clients_db +$foreign_clients_db = GOSA::DBsqlite->new($foreign_clients_file_name); +$foreign_clients_db->create_table($foreign_clients_tn, \@foreign_clients_col_names); + # connect to known_server_db unlink($known_server_file_name); $known_server_db = GOSA::DBsqlite->new($known_server_file_name); diff --git a/gosa-si/modules/ClientPackages.pm b/gosa-si/modules/ClientPackages.pm index ec549253d..b25c44d95 100644 --- a/gosa-si/modules/ClientPackages.pm +++ b/gosa-si/modules/ClientPackages.pm @@ -431,11 +431,13 @@ sub process_incoming_msg { } elsif ($header eq 'here_i_am') { @out_msg_l = &here_i_am($msg, $msg_hash, $session_id) } else { + # a event exists with the header as name if( exists $event_hash->{$header} ) { - # a event exists with the header as name &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5); no strict 'refs'; @out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id); + + # if no event handler is implemented } else { $sql_events = "SELECT * FROM $main::known_clients_tn WHERE ( (macaddress LIKE '$source') OR (hostname='$source') )"; my $res = $main::known_clients_db->select_dbentry( $sql_events ); @@ -557,7 +559,6 @@ sub here_i_am { my ($msg, $msg_hash, $session_id) = @_; my @out_msg_l; my $out_hash; - my $source = @{$msg_hash->{source}}[0]; my $mac_address = @{$msg_hash->{mac_address}}[0]; my $gotoHardwareChecksum = @{$msg_hash->{gotoHardwareChecksum}}[0]; @@ -594,11 +595,8 @@ sub here_i_am { # new client accepted my $new_passwd = @{$msg_hash->{new_passwd}}[0]; - # create entry in known_clients - my $events = @{$msg_hash->{events}}[0]; - - # add entry to known_clients_db + my $events = @{$msg_hash->{events}}[0]; my $act_timestamp = &get_time; my $res = $main::known_clients_db->add_dbentry( {table=>'known_clients', primkey=>['hostname'], @@ -618,21 +616,24 @@ sub here_i_am { # return acknowledgement to client $out_hash = &create_xml_hash("registered", $server_address, $source); - # notify registered client to bus - if( $bus_activ eq "on") { - # fetch actual bus key - my $sql_statement= "SELECT * FROM known_server WHERE status='bus'"; - my $query_res = $main::known_server_db->select_dbentry( $sql_statement ); - my $hostkey = $query_res->{1}->{'hostkey'}; - - # send update msg to bus - $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); - &add_content2xml_hash($out_hash, "macaddress", $mac_address); - &add_content2xml_hash($out_hash, "timestamp", $act_timestamp); - my $new_client_out = &create_xml_string($out_hash); - push(@out_msg_l, $new_client_out); - &main::daemon_log("$session_id INFO: send bus msg that client '$source' has registered at server '$server_address'", 5); - } + + + +# # notify registered client to all other server +# if( $bus_activ eq "on") { +# # fetch actual bus key +# my $sql_statement= "SELECT * FROM known_server WHERE status='bus'"; +# my $query_res = $main::known_server_db->select_dbentry( $sql_statement ); +# my $hostkey = $query_res->{1}->{'hostkey'}; +# +# # send update msg to bus +# $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); +# &add_content2xml_hash($out_hash, "macaddress", $mac_address); +# &add_content2xml_hash($out_hash, "timestamp", $act_timestamp); +# my $new_client_out = &create_xml_string($out_hash); +# push(@out_msg_l, $new_client_out); +# &main::daemon_log("$session_id INFO: send bus msg that client '$source' has registered at server '$server_address'", 5); +# } # give the new client his ldap config # Workaround: Send within the registration response, if the client will get an ldap config later @@ -661,9 +662,13 @@ sub here_i_am { push(@out_msg_l, $hardware_config_out); } + # notify registered client to all other server + my %mydata = ( 'client' => $source, 'macaddress' => $mac_address); + my $mymsg = &build_msg('new_foreign_client', $main::server_address, "KNOWN_SERVER", \%mydata); + push(@out_msg_l, $mymsg); + &main::daemon_log("$session_id INFO: register client $source ($mac_address)", 5); &main::daemon_log("$session_id INFO: client version: $client_status - $client_revision", 5); - return @out_msg_l; } diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm index 56b7f2a13..bc1027c8b 100644 --- a/gosa-si/server/events/server_server_com.pm +++ b/gosa-si/server/events/server_server_com.pm @@ -30,12 +30,12 @@ sub new_server { my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $key = @{$msg_hash->{'key'}}[0]; - my $clients = @{$msg_hash->{'clients'}}[0]; - + my @clients = @{$msg_hash->{'client'}}; + # sanity check if (ref $key eq 'HASH') { &main::daemon_log("$session_id ERROR: 'new_server'-message from host '$source' contains no key!", 1); - #return; + return; } # add foreign server to known_server_db @@ -53,8 +53,26 @@ sub new_server { } # add clients of foreign server to known_foreign_clients_db - - + my @sql_list; + foreach my $client (@clients) { + my @client_details = split(/,/, $client); + + # workaround to avoid double entries in foreign_clients_db + my $del_sql = "DELTE FROM $main::foreign_clients_tn WHERE hostname='".$client_details[0]."'"; + 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 + push(@sql_list, $sql); + } + if (@sql_list) { + &main::daemon_log("$session_id DEBUG: Inserting ".scalar @sql_list." entries to foreign_clients_db", 8); + my $res = $main::foreign_clients_db->exec_statementlist(\@sql_list); + } + # build confirm_new_server message my %data = ( key=>$key ); my $out_msg = &build_msg('confirm_new_server', $main::server_address, $source, \%data); diff --git a/gosa-si/tests/sqlite-check-clients.pl b/gosa-si/tests/sqlite-check-clients.pl new file mode 100755 index 000000000..1b197ba14 --- /dev/null +++ b/gosa-si/tests/sqlite-check-clients.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: DBD-SQlite.pl +# +# USAGE: ./DBD-SQlite.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: (), <> +# COMPANY: +# VERSION: 1.0 +# CREATED: 20.12.2007 08:54:52 CET +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use GOSA::DBsqlite; +use Data::Dumper; + +print "START\n"; +my $res; +my $db_name; + + +$db_name = "/var/lib/gosa-si/clients.db"; +if (-e $db_name) { + print "\n############################################################\n"; + my $table_name = "known_clients"; + print "$db_name\n"; + print "$table_name\n"; + + my $sqlite = GOSA::DBsqlite->new($db_name); + my $col_names = $sqlite->get_table_columns($table_name); + print join(', ', @{ $col_names } )."\n" ; + my $answer = $sqlite->show_table($table_name); + print $answer."\n"; +} + + +print "\nFINISH\n"; diff --git a/gosa-si/tests/sqlite-check-foreign-clients.pl b/gosa-si/tests/sqlite-check-foreign-clients.pl new file mode 100755 index 000000000..e3ebba80e --- /dev/null +++ b/gosa-si/tests/sqlite-check-foreign-clients.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: DBD-SQlite.pl +# +# USAGE: ./DBD-SQlite.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: (), <> +# COMPANY: +# VERSION: 1.0 +# CREATED: 20.12.2007 08:54:52 CET +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use GOSA::DBsqlite; +use Data::Dumper; + +print "START\n"; +my $res; +my $db_name; + + +$db_name = "/var/lib/gosa-si/foreign_clients.db"; +if (-e $db_name) { + print "\n############################################################\n"; + my $table_name = "foreign_clients"; + print "$db_name\n"; + print "$table_name\n"; + + my $sqlite = GOSA::DBsqlite->new($db_name); + my $col_names = $sqlite->get_table_columns($table_name); + print join(', ', @{ $col_names } )."\n" ; + my $answer = $sqlite->show_table($table_name); + print $answer."\n"; +} + + +print "\nFINISH\n"; diff --git a/gosa-si/tests/sqlite-check-incoming.pl b/gosa-si/tests/sqlite-check-incoming.pl new file mode 100755 index 000000000..03a40e12d --- /dev/null +++ b/gosa-si/tests/sqlite-check-incoming.pl @@ -0,0 +1,46 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: DBD-SQlite.pl +# +# USAGE: ./DBD-SQlite.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: (), <> +# COMPANY: +# VERSION: 1.0 +# CREATED: 20.12.2007 08:54:52 CET +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use GOSA::DBsqlite; +use Data::Dumper; + +print "START\n"; +my $res; +my $db_name; + + +$db_name = "/var/lib/gosa-si/incoming.db"; +if (-e $db_name) { + print "\n############################################################\n"; + my $table_name = "incoming"; + print "$db_name\n"; + print "$table_name\n"; + my $sqlite = GOSA::DBsqlite->new($db_name); + my $col_names = $sqlite->get_table_columns($table_name); + + print join(', ', @{ $col_names } )."\n" ; + my $answer = $sqlite->show_table($table_name); + print $answer."\n"; +} + + +print "\nFINISH\n"; diff --git a/gosa-si/tests/sqlite-check-users.pl b/gosa-si/tests/sqlite-check-users.pl new file mode 100755 index 000000000..1f49f8cc5 --- /dev/null +++ b/gosa-si/tests/sqlite-check-users.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: DBD-SQlite.pl +# +# USAGE: ./DBD-SQlite.pl +# +# DESCRIPTION: +# +# OPTIONS: --- +# REQUIREMENTS: --- +# BUGS: --- +# NOTES: --- +# AUTHOR: (), <> +# COMPANY: +# VERSION: 1.0 +# CREATED: 20.12.2007 08:54:52 CET +# REVISION: --- +#=============================================================================== + +use strict; +use warnings; +use GOSA::DBsqlite; +use Data::Dumper; + +print "START\n"; +my $res; +my $db_name; + + + + +$db_name = "/var/lib/gosa-si/users.db"; +if (-e $db_name) { + print "\n############################################################\n"; + my $table_name = "login_users"; + print "$db_name\n"; + print "$table_name\n"; + + my $sqlite = GOSA::DBsqlite->new($db_name); + my $col_names = $sqlite->get_table_columns($table_name); + print join(', ', @{ $col_names } )."\n" ; + my $answer = $sqlite->show_table($table_name); + print $answer."\n"; +} + + +print "\nFINISH\n"; -- 2.30.2