From 1fcd03dd879a2af5d292f3ccb9a58b0f8b28a468 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Fri, 15 Feb 2008 09:23:37 +0000 Subject: [PATCH] new fifo at gosa-si-client, all input is wrapped in a gosa-si valid envelope and forwarded to server git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8924 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/gosa-si-client | 65 +++++++++++++++- gosa-si/modules/GosaSupportDaemon.pm | 92 ++++------------------ gosa-si/tests/sqlite-check.pl | 109 --------------------------- 3 files changed, 79 insertions(+), 187 deletions(-) delete mode 100755 gosa-si/tests/sqlite-check.pl diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 9b0374de2..27de3ab34 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -25,7 +25,7 @@ use Config::IniFiles; use POSIX; use Time::HiRes qw( gettimeofday ); -use POE qw(Component::Server::TCP); +use POE qw(Component::Server::TCP Wheel::FollowTail); use IO::Socket::INET; use NetAddr::IP; use Data::Dumper; @@ -48,6 +48,8 @@ my $default_server_key; my $event_hash; my @servers; my $gotoHardwareChecksum; +my $gosa_si_client_fifo; +my %files_to_watch; $verbose= 1; # globalise variables which are used in imported events @@ -59,6 +61,10 @@ our $server_key; # default variables our $REGISTERED = 0; +# path to fifo for non-gosa-si-client messages to gosa-si-server +$gosa_si_client_fifo = "/tmp/gosa-si-client-fifo"; +%files_to_watch = (fifo => $gosa_si_client_fifo); + # in function register_at_gosa_si_server, after which period of seconds a new registration should be tried if a registration was # not successful until now my $delay_set_time = 5; @@ -1103,10 +1109,56 @@ sub trigger_new_key { } +sub generic_file_reset { + my ( $heap, $wheel_id ) = @_[ HEAP, ARG0 ]; + + my $service = $heap->{services}->{$wheel_id}; + daemon_log("INFO: '$service' watching reset", 5); + return; +} + +sub generic_file_error { + my ( $heap, $operation, $errno, $error_string, $wheel_id ) = + @_[ HEAP, ARG0, ARG1, ARG2, ARG3 ]; + + my $service = $heap->{services}->{$wheel_id}; + daemon_log("ERROR: '$service' watcher $operation error $errno: $error_string", 1); + daemon_log("ERROR: shutting down '$service' file watcher", 1); + + delete $heap->{services}->{$wheel_id}; + delete $heap->{watchers}->{$wheel_id}; + return; +} + +sub fifo_got_record { + my $file_record = $_[ARG0]; + print STDERR "$file_record\n"; + + my $clmsg_hash = &create_xml_hash("CLMSG_$file_record", $client_address, $server_address); + my $clmsg = &create_xml_string($clmsg_hash); + &send_msg_to_target($clmsg, $server_address, $server_key); + return; +} + + sub _start { - my ($kernel) = $_[KERNEL]; + my ($kernel, $heap) = @_[KERNEL, HEAP]; $kernel->alias_set('client_session'); + + # force a registration at a gosa-si-server $kernel->yield('register_at_gosa_si_server'); + + # install all file watcher defined + while( my($file_name, $file) = each %files_to_watch ) { + my $file_watcher = POE::Wheel::FollowTail->new( + Filename => $file, + InputEvent => $file_name."_record", + ResetEvent => "file_reset", + ErrorEvent => "file_error", + ); + $heap->{services}->{ $file_watcher->ID } = $file_name; + $heap->{watchers}->{ $file_watcher->ID } = $file_watcher; + } } @@ -1277,6 +1329,8 @@ else { } +# open fifo for non-gosa-si-client-msgs to gosa-si-server +POSIX::mkfifo("$gosa_si_client_fifo", "0600"); POE::Session->create( @@ -1284,6 +1338,13 @@ POE::Session->create( _start => \&_start, register_at_gosa_si_server => \®ister_at_gosa_si_server, trigger_new_key => \&trigger_new_key, + + # handle records from each defined file differently + fifo_record => \&fifo_got_record, + + # handle file resets and errors the same way for each file + file_reset => \&generic_file_reset, + file_error => \&generic_file_error, } ); diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 1a40c23a0..ccdcea151 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -58,6 +58,22 @@ sub create_xml_hash { } +#=== FUNCTION ================================================================ +# NAME: create_xml_string +# PARAMETERS: xml_hash - hash - hash from function create_xml_hash +# RETURNS: xml_string - string - xml string representation of the hash +# DESCRIPTION: transform the hash to a string using XML::Simple module +#=============================================================================== +sub create_xml_string { + my ($xml_hash) = @_ ; + my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml'); + #$xml_string =~ s/[\n]+//g; + #daemon_log("create_xml_string:",7); + #daemon_log("$xml_string\n", 7); + return $xml_string; +} + + sub transform_msg2hash { my ($msg) = @_ ; my $hash = $xml->XMLin($msg, ForceArray=>1); @@ -89,66 +105,6 @@ sub transform_msg2hash { } -#=== FUNCTION ================================================================ -# NAME: send_msg_hash2address -# PARAMETERS: msg_hash - hash - xml_hash created with function create_xml_hash -# PeerAddr string - socket address to send msg -# PeerPort string - socket port, if not included in socket address -# RETURNS: nothing -# DESCRIPTION: ???? -#=============================================================================== -#sub send_msg_hash2address ($$$){ -# my ($msg_hash, $address, $passwd) = @_ ; -# -# # fetch header for logging -# my $header = @{$msg_hash->{header}}[0]; -# -# # generate xml string -# my $msg_xml = &create_xml_string($msg_hash); -# -# # create ciphering object -# my $act_cipher = &create_ciphering($passwd); -# -# # encrypt xml msg -# my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher); -# -# # opensocket -# my $socket = &open_socket($address); -# if(not defined $socket){ -# daemon_log("cannot send '$header'-msg to $address , server not reachable", 5); -# return 1; -# } -# -# # send xml msg -# print $socket $crypted_msg."\n"; -# -# close $socket; -# -# daemon_log("send '$header'-msg to $address", 1); -# daemon_log("message:\n$msg_xml", 8); -# return 0; -#} - - -#=== FUNCTION ================================================================ -# NAME: get_content_from_xml_hash -# PARAMETERS: xml_ref - ref - reference of the xml hash -# element - string - key of the value you want -# RETURNS: value - string - if key is either header, target or source -# value - list - for all other keys in xml hash -# DESCRIPTION: -#=============================================================================== -#sub get_content_from_xml_hash { -# my ($xml_ref, $element) = @_ ; -# #my $result = $main::xml_ref->{$element}; -# #if( $element eq "header" || $element eq "target" || $element eq "source") { -# # return @$result[0]; -# #} -# my @result = $xml_ref->{$element}; -# return \@result; -#} - - #=== FUNCTION ================================================================ # NAME: add_content2xml_hash # PARAMETERS: xml_ref - ref - reference to a hash from function create_xml_hash @@ -169,22 +125,6 @@ sub add_content2xml_hash { } -#=== FUNCTION ================================================================ -# NAME: create_xml_string -# PARAMETERS: xml_hash - hash - hash from function create_xml_hash -# RETURNS: xml_string - string - xml string representation of the hash -# DESCRIPTION: transform the hash to a string using XML::Simple module -#=============================================================================== -sub create_xml_string { - my ($xml_hash) = @_ ; - my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml'); - #$xml_string =~ s/[\n]+//g; - #daemon_log("create_xml_string:",7); - #daemon_log("$xml_string\n", 7); - return $xml_string; -} - - #=== FUNCTION ================================================================ # NAME: encrypt_msg # PARAMETERS: msg - string - message to encrypt diff --git a/gosa-si/tests/sqlite-check.pl b/gosa-si/tests/sqlite-check.pl deleted file mode 100755 index b9752be25..000000000 --- a/gosa-si/tests/sqlite-check.pl +++ /dev/null @@ -1,109 +0,0 @@ -#!/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; - - -print "START\n"; -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"; -# $db_name =~ /\/([^\/]*?)\.db$/; -# my $table_name = $1; - 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"; -# $db_name =~ /\/([^\/]*?)\.db$/; -# my $table_name = $1; - my $table_name = "known_server"; - 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/bus-server.db"; -if (-e $db_name) { - print "\n############################################################\n"; -# $db_name =~ /\/([^\/]*?)\.db$/; -# my $table_name = $1; - my $table_name = "bus_known_server"; - 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/bus-clients.db"; -if (-e $db_name) { - print "\n############################################################\n"; -# $db_name =~ /\/([^\/]*?)\.db$/; -# my $table_name = $1; - my $table_name = "bus_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"; -- 2.30.2