From: rettenbe Date: Mon, 19 May 2008 15:09:02 +0000 (+0000) Subject: * gosa-si-server-nobus X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fb33980834bf79d0118553a9f8e87681a3e1178b;p=gosa.git * gosa-si-server-nobus * under construction git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10957 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-server-nobus b/gosa-si/gosa-si-server-nobus index 25a091cb8..a9f612b32 100755 --- a/gosa-si/gosa-si-server-nobus +++ b/gosa-si/gosa-si-server-nobus @@ -85,7 +85,7 @@ our (%cfg_defaults, $log_file, $pid_file, $server_ip, $server_port, $ClientPackages_key, $arp_activ, $gosa_unit_tag, $GosaPackages_key, $gosa_ip, $gosa_port, $gosa_timeout, - $foreign_server_string, $server_domain, $foreign_server_key + $foreign_server_string, $server_domain, $ServerPackages_key, $foreign_servers_register_delay, ); # additional variable which should be globaly accessable @@ -239,7 +239,8 @@ my $max_children = 2; "ServerPackages"=> { "address" => [\$foreign_server_string, ""], "domain" => [\$server_domain, ""], - "key" => [\$foreign_server_key, "none"], + "key" => [\$ServerPackages_key, "none"], + "key-lifetime" => [\$foreign_servers_register_delay, 600], } ); @@ -670,8 +671,8 @@ sub input_from_unknown_host { my $error_string; my %act_modules = %$known_modules; - - while( my ($mod, $info) = each(%act_modules)) { + + while( my ($mod, $info) = each(%act_modules)) { # check a key exists for this module my $module_key = ${$mod."_key"}; @@ -954,7 +955,7 @@ sub send_msg_to_target { if( $act_status eq "down" ) { $sql_statement = "DELETE FROM known_server WHERE hostname='$address'"; $res = $known_server_db->del_dbentry($sql_statement); - daemon_log("$session_id WARNING: failed 2x to a send msg to host '$address', delete host from known_server", 3); + daemon_log("$session_id WARNING: failed 2x to send a message to host '$address', delete host from known_server", 3); } else { $sql_statement = "UPDATE known_server SET status='$new_status' WHERE hostname='$address'"; @@ -999,6 +1000,7 @@ sub _start { my ($kernel) = $_[KERNEL]; &trigger_db_loop($kernel); $global_kernel = $kernel; + $kernel->yield('register_at_foreign_servers'); $kernel->yield('create_fai_server_db', $fai_server_tn ); $kernel->yield('create_fai_release_db', $fai_release_tn ); $kernel->sig(USR1 => "sig_handler"); @@ -2575,6 +2577,36 @@ sub cleanup_and_extract { } +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); + + # no entries in known_server_db + if (not ref(@$res[0]) eq "ARRAY") { + # TODO + } + + foreach my $hit (@$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); + + + } + + $kernel->delay_set("register_at_foreign_servers", $foreign_servers_register_delay); + return; +} + + #==== MAIN = main ============================================================== # parse commandline options Getopt::Long::Configure( "bundling" ); @@ -2656,6 +2688,7 @@ $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name); $known_clients_db->create_table($known_clients_tn, \@known_clients_col_names); # connect to known_server_db +unlink($known_server_file_name); $known_server_db = GOSA::DBsqlite->new($known_server_file_name); $known_server_db->create_table($known_server_tn, \@known_server_col_names); @@ -2686,7 +2719,60 @@ $messaging_db->create_table($messaging_tn, \@messaging_col_names); # create xml object used for en/decrypting $xml = new XML::Simple(); -# create socket for incoming xml messages + +# foreign servers +my @foreign_server_list; + +# add foreign server from cfg file +if ($foreign_server_string ne "") { + my @cfg_foreign_server_list = split(",", $foreign_server_string); + foreach my $foreign_server (@cfg_foreign_server_list) { + push(@foreign_server_list, $foreign_server); + } +} + +# add foreign server from dns +my @tmp_servers; +if ( !$server_domain) { + # Try our DNS Searchlist + for my $domain(get_dns_domains()) { + chomp($domain); + my @tmp_domains= &get_server_addresses($domain); + if(@tmp_domains) { + for my $tmp_server(@tmp_domains) { + push @tmp_servers, $tmp_server; + } + } + } + if(@tmp_servers && length(@tmp_servers)==0) { + daemon_log("0 WARNING: no foreign gosa-si-server found in DNS for domain '$server_domain'", 3); + } +} else { + @tmp_servers = &get_server_addresses($server_domain); + if( 0 == @tmp_servers ) { + daemon_log("0 WARNING: no foreign gosa-si-server found in DNS for domain '$server_domain'", 3); + } +} +foreach my $server (@tmp_servers) { + unshift(@foreign_server_list, $server); +} +# eliminate duplicate entries +@foreign_server_list = &del_doubles(@foreign_server_list); +my $all_foreign_server = join(", ", @foreign_server_list); +daemon_log("0 INFO: found foreign server in config file and DNS: $all_foreign_server", 5); + +# add all found foreign servers to known_server +my $act_timestamp = &get_time(); +foreach my $foreign_server (@foreign_server_list) { + my $res = $known_server_db->add_dbentry( {table=>$known_server_tn, + primkey=>['hostname'], + hostname=>$foreign_server, + status=>'not_jet_registered', + hostkey=>"none", + timestamp=>$act_timestamp, + } ); +} + POE::Component::Server::TCP->new( Port => $server_port, @@ -2713,6 +2799,7 @@ daemon_log("start socket for incoming xml messages at port '$server_port' ", 1); POE::Session->create( inline_states => { _start => \&_start, + register_at_foreign_servers => \®ister_at_foreign_servers, sig_handler => \&sig_handler, watch_for_new_messages => \&watch_for_new_messages, watch_for_delivery_messages => \&watch_for_delivery_messages, @@ -2736,63 +2823,6 @@ POE::Session->create( # TODO # check wether all modules are gosa-si valid passwd check -############################################# -# send registration message to foreign server -my @foreign_server_list; -# add foreign server from cfg file -if ($foreign_server_string ne "") { - my @cfg_foreign_server_list = split(",", $foreign_server_string); - foreach my $foreign_server (@cfg_foreign_server_list) { - push(@foreign_server_list, $foreign_server); - } -} - -# add foreign server from dns -my @tmp_servers; -if ( !$server_domain) { - # Try our DNS Searchlist - for my $domain(get_dns_domains()) { - chomp($domain); - my @tmp_domains= &get_server_addresses($domain); - if(@tmp_domains) { - for my $tmp_server(@tmp_domains) { - push @tmp_servers, $tmp_server; - } - } - } - if(@tmp_servers && length(@tmp_servers)==0) { - daemon_log("0 WARNING: no foreign gosa-si-server found in DNS for domain '$server_domain'", 3); - } -} else { - @tmp_servers = &get_server_addresses($server_domain); - if( 0 == @tmp_servers ) { - daemon_log("0 WARNING: no foreign gosa-si-server found in DNS for domain '$server_domain'", 3); - } -} -foreach my $server (@tmp_servers) { - unshift(@foreign_server_list, $server); -} -# eliminate duplicate entries -@foreign_server_list = &del_doubles(@foreign_server_list); - -my $all_foreign_server = join(", ", @foreign_server_list); -daemon_log("0 INFO: found foreign server in config file and DNS: $all_foreign_server", 5); - -# build messages -foreach my $foreign_server (@foreign_server_list) { - # do not send myself a 'new_server' registration!!! - if ($foreign_server eq $server_address) { next;} - - print STDERR "foreign_server: $foreign_server\n"; - my %data= ('known_clients' => "", - 'key' => "", - ); - my $foreign_server_msg = &build_msg('new_server', $server_address, $foreign_server, \%data); - my $error = &send_msg_to_target($foreign_server_msg, $foreign_server, $foreign_server_key, "new_server", 0); - if ($error != 0 ) { - daemon_log("0 WARNING: sending of 'new_server'-message to $foreign_server failed!", 3); - } -} POE::Kernel->run(); diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index b3430e89d..d2296f050 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -3,6 +3,7 @@ package GOSA::GosaSupportDaemon; use Exporter; @ISA = qw(Exporter); my @functions = ( + "create_passwd", "create_xml_hash", "get_content_from_xml_hash", "add_content2xml_hash", @@ -492,14 +493,14 @@ sub import_events { my $DIR; if ($error == 0) { - opendir (DIR, $event_dir) or sub { + opendir ($DIR, $event_dir) or do { $error++; push(@result, "cannot open directory '$event_dir' for reading: $!\n"); } } if ($error == 0) { - while (defined (my $event = readdir (DIR))) { + while (defined (my $event = readdir ($DIR))) { if( $event eq "." || $event eq ".." ) { next; } # try to import event module @@ -520,6 +521,8 @@ sub import_events { my $events_string = join( ", ", @{$events_l}); push(@result, "import of event module '$event' succeed: $events_string"); } + + close $DIR; } return ($error, \@result, $event_hash); diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index 9e45163ab..d70afd40e 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -42,9 +42,30 @@ if ($error == 0) { sub get_module_info { my @info = ($main::server_address, + $main::foreign_server_key, ); return \@info; } +sub process_incoming_msg { + my ($msg, $msg_hash, $session_id) = @_ ; + my $header = @{$msg_hash->{header}}[0]; + my $source = @{$msg_hash->{source}}[0]; + my @target_l = @{$msg_hash->{target}}; + + my @msg_l; + my @out_msg_l; + + &main::daemon_log("$session_id DEBUG: ServerPackages: msg to process '$header'", 7); + 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); + } else { + } + + return @out_msg_l; +} 1; diff --git a/gosa-si/server/events/server_server_com.pm b/gosa-si/server/events/server_server_com.pm index e146e2dd4..2df9c7c2e 100644 --- a/gosa-si/server/events/server_server_com.pm +++ b/gosa-si/server/events/server_server_com.pm @@ -24,7 +24,7 @@ sub get_events { sub new_server { - +print STDERR "hier kommt die logik von new_server\n"; } 1; diff --git a/gosa-si/tests/sqlite-check-server.pl b/gosa-si/tests/sqlite-check-server.pl index d4d51a9f8..18f59d7b5 100755 --- a/gosa-si/tests/sqlite-check-server.pl +++ b/gosa-si/tests/sqlite-check-server.pl @@ -28,36 +28,6 @@ my $res; my $db_name; -$db_name = "/var/lib/gosa-si/jobs.db"; -if (-e $db_name) { - print "\n############################################################\n"; - my $table_name = "jobs"; - 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"; -} - - -$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"; -} - - $db_name = "/var/lib/gosa-si/servers.db"; if (-e $db_name) { print "\n############################################################\n"; @@ -72,20 +42,4 @@ if (-e $db_name) { print $answer."\n"; } - -$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";