From: rettenbe Date: Tue, 11 Dec 2007 14:33:06 +0000 (+0000) Subject: event handling established X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0d87ea3d6666150360e56249c6dee75d4f5a4b20;p=gosa.git event handling established git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8080 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/contrib/daemon/gosa-sc b/contrib/daemon/gosa-sc index 9f5113427..ef9e6618b 100755 --- a/contrib/daemon/gosa-sc +++ b/contrib/daemon/gosa-sc @@ -35,15 +35,17 @@ use Data::Dumper; use Sys::Syslog qw( :DEFAULT setlogsock); use File::Spec; use Cwd; - +use GosaSupportDaemon; my ($cfg_file, %cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file); my ($server_address, $server_ip, $server_port, $server_domain, $server_passwd, $server_cipher, $server_timeout); my ($client_address, $client_ip, $client_port, $client_mac_address); my ($input_socket, $rbits, $wbits, $ebits, $xml, $known_hosts); +my (@events); # default variables +my $event_dir = "/etc/gosac/events"; $known_hosts = {}; $foreground = 0 ; %cfg_defaults = @@ -303,10 +305,10 @@ sub register_at_server { my $new_server_cipher; # detect all client accepted events - opendir(DIR, "/etc/gosac/events") - or daemon_log("cannot find directory /etc/gosac/events!\ngosac starts without any accepting events!", 1); + opendir(DIR, $event_dir) + or daemon_log("cannot find directory $event_dir!\ngosac starts without any accepting events!", 1); my $file_name; - my @events = (); + @events = (); while(defined($file_name = readdir(DIR))){ if ($file_name eq "." || $file_name eq "..") { next; @@ -579,7 +581,7 @@ sub send_msg_hash2address { my ($msg_hash, $address, $passwd) = @_ ; # fetch header for logging - my $header = &get_content_from_xml_hash($msg_hash, "header"); + my $header = @{$msg_hash->{header}}[0]; # generiere xml string my $msg_xml = &create_xml_string($msg_hash); @@ -826,6 +828,35 @@ sub process_incoming_msg { daemon_log("msg to process:", 7); daemon_log("\t$msg", 7); + #check whether msg to process is a event + opendir(DIR, $event_dir) + or daemon_log("cannot find directory $event_dir, no events specified", 5); + my $file_name; + while(defined($file_name = readdir(DIR))){ + if ($file_name eq "." || $file_name eq "..") { + next; + } + if ($file_name eq $header) { + my $cmd = "$event_dir/$file_name '$msg'"; + my $result_xml = ""; + open(PIPE, "$cmd 2>&1 |"); + while() { + $result_xml.=$_; + last; + } + close(PIPE); + my $res_hash = &transform_msg2hash($result_xml); + my $res_target = @{$res_hash->{target}}[0]; + &send_msg_hash2address($res_hash, $server_address); + + return; + } + } + close(DIR); + daemon_log("could not assign the msg $header to an event", 5); + + + if ($header eq 'new_ldap_config') { &new_ldap_config($msg_hash)} elsif ($header eq 'ping') { &got_ping($msg_hash) } elsif ($header eq 'wake_up') { &execute_event($msg_hash)} diff --git a/contrib/daemon/gosa-sd b/contrib/daemon/gosa-sd index 1b161528e..989a82385 100755 --- a/contrib/daemon/gosa-sd +++ b/contrib/daemon/gosa-sd @@ -39,11 +39,10 @@ use File::Spec; use IPC::Shareable qw( :lock); IPC::Shareable->clean_up_all; - use lib "/etc/gosad/modules"; my $modules_path = "/etc/gosad/modules"; -my ($cfg_file, %cfg_defaults, $foreground, $verbose, $ping_timeout); +my ($cfg_file, %cfg_defaults, $foreground, $verbose, $ping_timeout, $no_bus); my ($bus, $msg_to_bus, $bus_cipher); my ($server, $server_mac_address, $server_events); my ($gosa_server); @@ -76,9 +75,7 @@ $foreground = 0 ; # specifies the timeout seconds while checking the online status of a registrating client $ping_timeout = 5; -# specifies the listening port while checking the online status of a registrating client -# this port HAS to be different to server_port! -my $ping_port = "12345"; +$no_bus = 0; # holds all other gosa-sd as well as the gosa-sd-bus our $known_daemons = {}; @@ -333,7 +330,12 @@ sub import_modules { if (not $file =~ /(\S*?).pm$/) { next; } - require $file; + eval { require $file; }; + if ($@) { + daemon_log("ERROR: gosa-sd could not load module $file", 1); + daemon_log("$@", 5); + next; + } my $mod_name = $1; my $module_tag_hash = eval( $mod_name.'::get_module_tags()' ); $known_modules->{$mod_name} = $module_tag_hash; @@ -1760,9 +1762,10 @@ sub update_known_clients { # parse commandline options Getopt::Long::Configure( "bundling" ); GetOptions("h|help" => \&usage, - "c|config=s" => \$cfg_file, - "f|foreground" => \$foreground, - "v|verbose+" => \$verbose, + "c|config=s" => \$cfg_file, + "f|foreground" => \$foreground, + "v|verbose+" => \$verbose, + "no-bus+" => \$no_bus, ); # read and set config parameters @@ -1828,6 +1831,9 @@ if($server_activ eq "on"){ } # register at bus +if ($no_bus > 0) { + $bus_activ = "off" +} if($bus_activ eq "on") { daemon_log(" ", 1); ®ister_at_bus(); diff --git a/contrib/daemon/gosa-sd-bus b/contrib/daemon/gosa-sd-bus index 7b6dbe3ef..c096d933d 100755 --- a/contrib/daemon/gosa-sd-bus +++ b/contrib/daemon/gosa-sd-bus @@ -463,7 +463,6 @@ sub process_incoming_msg { $msg = &decrypt_msg($crypted_msg, $key_cipher); daemon_log("daemon decrypted msg:$msg", 7); $msg_hash = $xml->XMLin($msg, ForceArray=>1); - print Dumper $msg_hash; }; if($@) { daemon_log("msg processing raise error", 7); diff --git a/contrib/daemon/modules/GosaPackages.pm b/contrib/daemon/modules/GosaPackages.pm index fbce4bf9a..ab5938dc6 100644 --- a/contrib/daemon/modules/GosaPackages.pm +++ b/contrib/daemon/modules/GosaPackages.pm @@ -8,14 +8,9 @@ use Exporter; use strict; use warnings; -use Crypt::CBC; +use GosaSupportDaemon; - -BEGIN{ - # prepare module for working - # print "Module Gosa started!\n"; - -} +BEGIN{} END{} @@ -23,11 +18,12 @@ END{} ### START ########################## # create general settings for this module -my $gosa_cipher = &main::create_ciphering($main::gosa_passwd); +my $gosa_cipher = &create_ciphering($main::gosa_passwd); sub get_module_tags { - # dort stehen drei packettypen, für die sich das modul anmelden kann, gosa-admin-packages, server-packages, client-packages + # dort stehen drei packettypen, für die sich das modul anmelden kann, gosa-admin-packages, + # server-packages, client-packages my %tag_hash = (gosa_admin_packages => "yes", server_packages => "no", client_packages => "no"); @@ -67,7 +63,8 @@ sub process_incoming_msg { $msg_hash = $main::xml->XMLin($msg, ForceArray=>1); }; if($@) { - &main::daemon_log("ERROR: GosaPackages do not understand the message: $@", 1); + &main::daemon_log("WARNING: GosaPackages do not understand the message:", 5); + &main::daemon_log("$@", 7); return; } diff --git a/contrib/daemon/modules/ServerPackages.pm b/contrib/daemon/modules/ServerPackages.pm index 78093aa53..c2fc7eea9 100644 --- a/contrib/daemon/modules/ServerPackages.pm +++ b/contrib/daemon/modules/ServerPackages.pm @@ -8,16 +8,9 @@ use Exporter; use strict; use warnings; -use Data::Dumper; - - -BEGIN{ - # prepare module for working - #print "ServerPackages loaded!\n"; - -} - +use GosaSupportDaemon; +BEGIN{} END {} @@ -25,10 +18,12 @@ END {} ### START ########## + sub get_module_tags { # lese config file aus dort gibt es eine section Basic - # dort stehen drei packettypen, für die sich das modul anmelden kann, gosa-admin-packages, server-packages, client-packages + # dort stehen drei packettypen, für die sich das modul anmelden kann, gosa-admin-packages, + # server-packages, client-packages my %tag_hash = (gosa_admin_packages => "yes", server_packages => "yes", client_packages => "yes", @@ -37,32 +32,6 @@ sub get_module_tags { } -#=== FUNCTION ================================================================ -# NAME: read_configfile -# PARAMETERS: cfg_file - string - -# RETURNS: nothing -# DESCRIPTION: read cfg_file and set variables -#=============================================================================== -#sub read_configfile { -# my $cfg; -# if( defined( $cfg_file) && ( length($cfg_file) > 0 )) { -# if( -r $cfg_file ) { -# $cfg = Config::IniFiles->new( -file => $cfg_file ); -# } else { -# print STDERR "Couldn't read config file!"; -# } -# } else { -# $cfg = Config::IniFiles->new() ; -# } -# foreach my $section (keys %cfg_defaults) { -# foreach my $param (keys %{$cfg_defaults{ $section }}) { -# my $pinfo = $cfg_defaults{ $section }{ $param }; -# ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] ); -# } -# } -#} - - sub process_incoming_msg { my ($crypted_msg) = @_ ; if(not defined $crypted_msg) { @@ -106,8 +75,8 @@ sub process_incoming_msg { $key_passwd = $main::server_passwd; } &main::daemon_log("ServerPackage: key_passwd: $key_passwd", 7); - my $key_cipher = &main::create_ciphering($key_passwd); - $msg = &main::decrypt_msg($crypted_msg, $key_cipher); + my $key_cipher = &create_ciphering($key_passwd); + $msg = &decrypt_msg($crypted_msg, $key_cipher); &main::daemon_log("ServerPackages: decrypted msg: $msg", 7); $msg_hash = $main::xml->XMLin($msg, ForceArray=>1); #my $tmp = printf Dumper $msg_hash; @@ -122,8 +91,8 @@ sub process_incoming_msg { } if($msg_flag >= $l) { - &main::daemon_log("ERROR: ServerPackage do not understand the message:", 1); - &main::daemon_log("\t$msg", 7); + &main::daemon_log("WARNING: ServerPackage do not understand the message:", 5); + &main::daemon_log("$@", 7); return; } @@ -131,10 +100,10 @@ sub process_incoming_msg { my $header = @{$msg_hash->{header}}[0]; my $source = @{$msg_hash->{source}}[0]; - &main::daemon_log("ServerPackages: msg from host:", 1); - &main::daemon_log("\t$host", 1); - &main::daemon_log("ServerPackages: header from msg:", 1); - &main::daemon_log("\t$header", 1); + &main::daemon_log("ServerPackages: msg from host:", 5); + &main::daemon_log("\t$host", 5); + &main::daemon_log("ServerPackages: header from msg:", 5); + &main::daemon_log("\t$header", 5); &main::daemon_log("ServerPackages: msg to process:", 5); &main::daemon_log("\t$msg", 5); @@ -172,16 +141,16 @@ sub process_incoming_msg { &send_msg_hash2address($msg_hash, $target_address); } } else { - # msg is for one client + # msg is for one host if (exists $main::known_clients->{$target}) { + &send_msg_hash2address($msg_hash, $target); + } elsif (exists $main::known_daemons->{$target}) { # target is known - &send_msg_hash2address($msg_hash, $target); } else { # target is not known - - &main::daemon_log("ERROR: ServerPackages. target $target is not known in known_clients", 1); + &main::daemon_log("ERROR: ServerPackages: target $target is not known neither in known_clients nor in known_daemons", 1); } } } @@ -227,8 +196,8 @@ sub new_passwd { if (exists $main::known_daemons->{$source}) { &main::add_content2known_daemons(hostname=>$source, status=>"new_passwd", passwd=>$passwd); - my $hash = &main::create_xml_hash("confirm_new_passwd", $main::server_address, $source); - &main::send_msg_hash2address($hash, $source); + my $hash = &create_xml_hash("confirm_new_passwd", $main::server_address, $source); + &send_msg_hash2address($hash, $source); } elsif (exists $main::known_clients->{$source}) { &main::add_content2known_clients(hostname=>$source, status=>"new_passwd", passwd=>$passwd); @@ -271,10 +240,10 @@ sub here_i_am { &main::daemon_log("number of maximal allowed clients: $main::max_clients", 5); if($main::max_clients <= $act_nu_clients) { - my $out_hash = &main::create_xml_hash("denied", $main::server_address, $source); - &main::add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!"); + my $out_hash = &create_xml_hash("denied", $main::server_address, $source); + &add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!"); my $passwd = @{$msg_hash->{new_passwd}}[0]; - &main::send_msg_hash2address($out_hash, $source, $passwd); + &send_msg_hash2address($out_hash, $source, $passwd); return; } @@ -288,8 +257,8 @@ sub here_i_am { status=>"registered", passwd=>$new_passwd); # return acknowledgement to client - $out_hash = &main::create_xml_hash("registered", $main::server_address, $source); - &main::send_msg_hash2address($out_hash, $source); + $out_hash = &create_xml_hash("registered", $main::server_address, $source); + &send_msg_hash2address($out_hash, $source); # notify registered client to bus $out_hash = &main::create_xml_hash("new_client", $main::server_address, $main::bus_address, $source); @@ -374,6 +343,10 @@ sub new_ldap_config { my $dn; my @gotoLdapServer; open (PIPE, "$goHard_cmd 2>&1 |"); +# my $rbits = ""; +# vec($rbits, fileno PIPE, 1) = 1; +# my $rout; +# my $nf = select($rout=$rbits, undef, undef, $ldap_timeout); while() { chomp $_; # If it's a comment, goto next