From b9bf255a8cdde98c3f66a1b46ca5afd016089a5c Mon Sep 17 00:00:00 2001 From: rettenbe Date: Mon, 19 May 2008 08:54:16 +0000 Subject: [PATCH] new package module and some function moves git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10946 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/debian/gosa-si-server.install | 9 ++- gosa-si/gosa-si-client | 77 ++++++++++---------- gosa-si/gosa-si-server-nobus | 101 +++++++++++++++++++++----- gosa-si/modules/GosaSupportDaemon.pm | 97 +++++++++++++++++++++++++ gosa-si/modules/ServerPackages.pm | 40 ++++++++++ gosa-si/server.conf | 2 + 6 files changed, 265 insertions(+), 61 deletions(-) create mode 100644 gosa-si/modules/ServerPackages.pm diff --git a/gosa-si/debian/gosa-si-server.install b/gosa-si/debian/gosa-si-server.install index d858ee01e..843f0d7cb 100644 --- a/gosa-si/debian/gosa-si-server.install +++ b/gosa-si/debian/gosa-si-server.install @@ -2,10 +2,11 @@ gosa-si-server usr/sbin gosa-si-bus usr/sbin server.conf etc/gosa-si bus.conf etc/gosa-si -modules/SIPackages.pm usr/lib/gosa-si/modules -modules/GosaPackages.pm usr/lib/gosa-si/modules -modules/ArpHandler.pm usr/lib/gosa-si/modules -modules/oui.txt usr/lib/gosa-si/modules +modules/SIPackages.pm usr/lib/gosa-si/modules +modules/GosaPackages.pm usr/lib/gosa-si/modules +modules/ArpHandler.pm usr/lib/gosa-si/modules +modules/oui.txt usr/lib/gosa-si/modules +modules/ServerPackages.pm usr/lib/gosa-si/modules server/events/gosaTriggered.pm usr/lib/gosa-si/server/events server/events/siTriggered.pm usr/lib/gosa-si/server/events server/events/clMessages.pm usr/lib/gosa-si/server/events diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 7330d128d..a966c1a81 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -34,7 +34,7 @@ use GOSA::GosaSupportDaemon; use Digest::MD5 qw(md5_hex md5 md5_base64); use MIME::Base64; use XML::Simple; -use Net::DNS; +#use Net::DNS; # no longer used because function moved to GosaSupportDaemon.pm : rettenbe : 16.05.2008 use File::Basename; use File::Spec; @@ -551,42 +551,43 @@ sub decrypt_msg { } -sub get_server_addresses { - my $domain= shift; - my @result; - - my $error = 0; - my $res = Net::DNS::Resolver->new; - my $query = $res->send("_gosa-si._tcp.".$domain, "SRV"); - my @hits; - - if ($query) { - foreach my $rr ($query->answer) { - push(@hits, $rr->target.":".$rr->port); - } - } - else { - #warn "query failed: ", $res->errorstring, "\n"; - $error++; - } - - if( $error == 0 ) { - foreach my $hit (@hits) { - my ($hit_name, $hit_port) = split(/:/, $hit); - chomp($hit_name); - chomp($hit_port); - - my $address_query = $res->send($hit_name); - if( 1 == length($address_query->answer) ) { - foreach my $rr ($address_query->answer) { - push(@result, $rr->address.":".$hit_port); - } - } - } - } - - return @result; -} +# moved to GosaSupportDaemon: rettenbe: 16.05.2008 +#sub get_server_addresses { +# my $domain= shift; +# my @result; +# +# my $error = 0; +# my $res = Net::DNS::Resolver->new; +# my $query = $res->send("_gosa-si._tcp.".$domain, "SRV"); +# my @hits; +# +# if ($query) { +# foreach my $rr ($query->answer) { +# push(@hits, $rr->target.":".$rr->port); +# } +# } +# else { +# #warn "query failed: ", $res->errorstring, "\n"; +# $error++; +# } +# +# if( $error == 0 ) { +# foreach my $hit (@hits) { +# my ($hit_name, $hit_port) = split(/:/, $hit); +# chomp($hit_name); +# chomp($hit_port); +# +# my $address_query = $res->send($hit_name); +# if( 1 == length($address_query->answer) ) { +# foreach my $rr ($address_query->answer) { +# push(@result, $rr->address.":".$hit_port); +# } +# } +# } +# } +# +# return @result; +#} #=== FUNCTION ================================================================ @@ -1276,7 +1277,7 @@ daemon_log("start socket for incoming xml messages at port '$client_port' ", 1); if( inet_aton($server_ip) ){ $server_ip = inet_ntoa(inet_aton($server_ip)); } ############################################################ # to change -if( $server_ip eq "127.0.1.1" ) { $server_ip = "127.0.0.1" } +#if( $server_ip eq "127.0.1.1" ) { $server_ip = "127.0.0.1" } ############################################################ if (defined $server_ip && defined $server_port) { $server_address = $server_ip.":".$server_port; diff --git a/gosa-si/gosa-si-server-nobus b/gosa-si/gosa-si-server-nobus index 886d908a1..3e96edf46 100755 --- a/gosa-si/gosa-si-server-nobus +++ b/gosa-si/gosa-si-server-nobus @@ -85,6 +85,7 @@ our (%cfg_defaults, $log_file, $pid_file, $server_ip, $server_port, $SIPackages_key, $arp_activ, $gosa_unit_tag, $GosaPackages_key, $gosa_ip, $gosa_port, $gosa_timeout, + $foreign_server_string, $server_domain, $foreign_server_key ); # additional variable which should be globaly accessable @@ -207,22 +208,22 @@ my $max_children = 2; }, "server" => { "port" => [\$server_port, "20081"], - "known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ], - "known-servers" => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'], - "incoming" => [\$incoming_file_name, '/var/lib/gosa-si/incoming.db'], - "login-users" => [\$login_users_file_name, '/var/lib/gosa-si/users.db'], - "fai-server" => [\$fai_server_file_name, '/var/lib/gosa-si/fai_server.db'], - "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'], - "source-list" => [\$sources_list, '/etc/apt/sources.list'], - "repo-path" => [\$repo_path, '/srv/www/repository'], - "ldap-uri" => [\$ldap_uri, ""], - "ldap-base" => [\$ldap_base, ""], - "ldap-admin-dn" => [\$ldap_admin_dn, ""], - "ldap-admin-password" => [\$ldap_admin_password, ""], - "gosa-unit-tag" => [\$gosa_unit_tag, ""], - "max-clients" => [\$max_clients, 10], + "known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ], + "known-servers" => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'], + "incoming" => [\$incoming_file_name, '/var/lib/gosa-si/incoming.db'], + "login-users" => [\$login_users_file_name, '/var/lib/gosa-si/users.db'], + "fai-server" => [\$fai_server_file_name, '/var/lib/gosa-si/fai_server.db'], + "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'], + "source-list" => [\$sources_list, '/etc/apt/sources.list'], + "repo-path" => [\$repo_path, '/srv/www/repository'], + "ldap-uri" => [\$ldap_uri, ""], + "ldap-base" => [\$ldap_base, ""], + "ldap-admin-dn" => [\$ldap_admin_dn, ""], + "ldap-admin-password" => [\$ldap_admin_password, ""], + "gosa-unit-tag" => [\$gosa_unit_tag, ""], + "max-clients" => [\$max_clients, 10], }, "GOsaPackages" => { "ip" => [\$gosa_ip, "0.0.0.0"], @@ -235,6 +236,11 @@ my $max_children = 2; "SIPackages" => { "key" => [\$SIPackages_key, "none"], }, +"foreign-server"=> { + "address" => [\$foreign_server_string, ""], + "domain" => [\$server_domain, ""], + "key" => [\$foreign_server_key, "none"], +} ); @@ -415,7 +421,7 @@ sub import_modules { daemon_log(" ", 1); if (not -e $modules_path) { - daemon_log("ERROR: cannot find directory or directory is not readable: $modules_path", 1); + daemon_log("0 ERROR: cannot find directory or directory is not readable: $modules_path", 1); } opendir (DIR, $modules_path) or die "ERROR while loading modules from directory $modules_path : $!\n"; @@ -433,7 +439,7 @@ sub import_modules { eval { require $file; }; if ($@) { - daemon_log("ERROR: gosa-si-server could not load module $file", 1); + daemon_log("0 ERROR: gosa-si-server could not load module $file", 1); daemon_log("$@", 5); } else { my $info = eval($mod_name.'::get_module_info()'); @@ -441,7 +447,7 @@ sub import_modules { if( $info ) { my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info}; $known_modules->{$mod_name} = $info; - daemon_log("INFO: module $mod_name loaded", 5); + daemon_log("0 INFO: module $mod_name loaded", 5); } } } @@ -2727,8 +2733,65 @@ POE::Session->create( # import all modules &import_modules; +# 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); +} +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(); exit; diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index a14d5def0..c9b6f865e 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -18,7 +18,9 @@ my @functions = ( "get_limit_statement", "get_orderby_statement", "get_dns_domains", + "get_server_addresses", "get_logged_in_users", + "import_events", ); @EXPORT = @functions; use strict; @@ -29,6 +31,8 @@ use Digest::MD5 qw(md5 md5_hex md5_base64); use MIME::Base64; use XML::Simple; use Data::Dumper; +use Net::DNS; + my $op_hash = { 'eq' => '=', @@ -174,6 +178,9 @@ sub get_time { sub build_msg ($$$$) { my ($header, $from, $to, $data) = @_; + # data is of form, i.e. + # %data= ('ip' => $address, 'mac' => $mac); + my $out_hash = &create_xml_hash($header, $from, $to); while ( my ($key, $value) = each(%$data) ) { @@ -395,6 +402,47 @@ sub get_dns_domains() { } +############################################# +# moved from gosa-si-client: rettenbe, 16.05.2008 +# outcommented at gosa-si-client +sub get_server_addresses { + my $domain= shift; + my @result; + + my $error = 0; + my $res = Net::DNS::Resolver->new; + my $query = $res->send("_gosa-si._tcp.".$domain, "SRV"); + my @hits; + + if ($query) { + foreach my $rr ($query->answer) { + push(@hits, $rr->target.":".$rr->port); + } + } + else { + #warn "query failed: ", $res->errorstring, "\n"; + $error++; + } + + if( $error == 0 ) { + foreach my $hit (@hits) { + my ($hit_name, $hit_port) = split(/:/, $hit); + chomp($hit_name); + chomp($hit_port); + + my $address_query = $res->send($hit_name); + if( 1 == length($address_query->answer) ) { + foreach my $rr ($address_query->answer) { + push(@result, $rr->address.":".$hit_port); + } + } + } + } + + return @result; +} + + sub get_logged_in_users { my $result = qx(/usr/bin/w -hs); my @res_lines; @@ -415,4 +463,53 @@ sub get_logged_in_users { } + +sub import_events { + my ($event_dir)= @_; + my $error = 0; + my @result = (); + + if (not -e $event_dir) { + $error++; + push(@result, "cannot find directory or directory is not readable: $event_dir"); + } + + my $DIR; + if ($error == 0) { + opendir (DIR, $event_dir) or sub { + $error++; + push(@result, "cannot open directory '$event_dir' for reading: $!\n"); + } + } + + if ($error == 0) { + while (defined (my $event = readdir (DIR))) { + if( $event eq "." || $event eq ".." ) { next; } + if ($event ne "server_server_com.pm") { next; } + + # try to import event module + eval{ require $event; }; + if( $@ ) { + $error++; + push(@result, "import of event module '$event' failed: $@"); + next; + } + + # fetch all single events + $event =~ /(\S*?).pm$/; + my $event_module = $1; + my $events_l = eval( $1."::get_events()") ; + foreach my $event_name (@{$events_l}) { + $event_hash->{$event_name} = $event_module; + } + my $events_string = join( ", ", @{$events_l}); + push(@result, "import of event module '$event' succeed: $events_string"); + } + } + + return ($error, \@result); + +} + + 1; diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm new file mode 100644 index 000000000..6c4f27583 --- /dev/null +++ b/gosa-si/modules/ServerPackages.pm @@ -0,0 +1,40 @@ +package ServerPackages; + +use Exporter; +@ISA = ("Exporter"); + +# Each module has to have a function 'process_incoming_msg'. This function works as a interface to gosa-sd and receives the msg hash from gosa-sd. 'process_incoming_function checks, wether it has a function to process the incoming msg and forward the msg to it. + +use strict; +use warnings; +use GOSA::GosaSupportDaemon; + +#use IO::Socket::INET; +#use XML::Simple; +#use Data::Dumper; +#use NetAddr::IP; +#use Net::LDAP; +#use Socket; +#use Net::hostent; + +my $event_dir = "/usr/lib/gosa-si/server/events"; +use lib "/usr/lib/gosa-si/server/events"; + +BEGIN{} +END {} + + +### START ##################################################################### + +# read configfile and import variables +#&read_configfile(); + +sub get_module_info { + my @info = ($server_address, + $SIPackages_key, + ); + return \@info; +} + + +1; diff --git a/gosa-si/server.conf b/gosa-si/server.conf index 8225c4fcf..00a54a2f5 100644 --- a/gosa-si/server.conf +++ b/gosa-si/server.conf @@ -23,3 +23,5 @@ enabled = false enabled = true key = secret-gosa-password +[foreign-server] +key = secret-foreign-key -- 2.30.2