From: rettenbe Date: Fri, 14 Dec 2007 10:21:04 +0000 (+0000) Subject: add missing modules to repository X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7a175f7355bbc2dfb1b4165a5f684b4f833286c4;p=gosa.git add missing modules to repository clean up at gosa-si git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8127 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus index ed5601ba4..6022c37c5 100755 --- a/gosa-si/gosa-si-bus +++ b/gosa-si/gosa-si-bus @@ -435,8 +435,8 @@ sub process_incoming_msg { $crypted_msg = $1; my $host = sprintf("%s.%s.%s.%s", $2, $3, $4, $5); - daemon_log("msg from host:\n\t$host", 1); - daemon_log("crypted_msg:\n\t$crypted_msg", 7); + daemon_log("msg from host: $host", 1); + daemon_log("crypted_msg: $crypted_msg", 7); my @valid_keys; my @daemon_keys = keys %$known_daemons; @@ -447,7 +447,7 @@ sub process_incoming_msg { } my $l = @valid_keys; - daemon_log("number of valid daemons: $l\n", 7); + daemon_log("number of valid daemons: $l", 7); my ($msg, $msg_hash); my $msg_flag = 0; @@ -455,7 +455,7 @@ sub process_incoming_msg { # collect addresses from possible incoming clients foreach my $host_key (@valid_keys) { eval{ - daemon_log( "daemon: $host_key\n", 7); + daemon_log( "daemon: $host_key", 7); my $key_passwd = $known_daemons->{$host_key}->{passwd}; daemon_log("daemon_passwd: $key_passwd\n", 7); my $key_cipher = &create_ciphering($key_passwd); @@ -480,9 +480,9 @@ sub process_incoming_msg { my $header = &get_content_from_xml_hash($msg_hash, "header"); my $target = &get_content_from_xml_hash($msg_hash, "target"); - daemon_log("header from msg:\n\t$header", 1); - daemon_log("msg to process:\n\t$msg", 5); - daemon_log("msg is for: \n\t$target", 7); + daemon_log("header from msg: $header", 1); + daemon_log("msg to process: $msg", 5); + daemon_log("msg is for: $target", 7); if($target eq $bus_address) { # msg is for bus @@ -1101,7 +1101,8 @@ $SIG{CHLD} = 'IGNORE'; # restart daemon log file if(-e $log_file ) { unlink $log_file } -daemon_log("$0 started!"); +daemon_log(" ", 1); +daemon_log("$0 started!", 1); # Just fork, if we"re not in foreground mode if( ! $foreground ) { $pid = fork(); } @@ -1136,6 +1137,7 @@ my $rbits = my $wbits = my $ebits = ""; # open the bus socket if($bus_activ eq "on") { + daemon_log(" ", 1); $bus = IO::Socket::INET->new(LocalPort => $bus_port, Type => SOCK_STREAM, Reuse => 1, @@ -1143,7 +1145,7 @@ if($bus_activ eq "on") { ) or die "kann kein TCP-Server an Port $bus_port sein: $@\n"; vec($rbits, fileno $bus, 1) = 1; vec($wbits, fileno $bus, 1) = 1; - print "start bus at $bus_ip:$bus_port\n"; + daemon_log ("start bus at $bus_ip:$bus_port", 1); } # add bus to known_daemons diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index 2dcb06781..b7c64d956 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -343,10 +343,9 @@ sub register_at_server { # send xml hash to server with general server passwd my $answer = &send_msg_hash2address($register_hash, $server, $server_passwd); - - # sending fails, no sens to wait for response - if ($answer ne "done") { next; } - + + if ($answer != 0) { next; } + # waiting for response daemon_log("waiting for response...\n", 5); my $nf = select($rout=$rbits, $wout=$wbits, undef, $server_timeout); @@ -384,7 +383,7 @@ sub register_at_server { daemon_log("ERROR: do not understand the incoming message:" , 5); daemon_log("$@", 7); } else { - my $header = &get_content_from_xml_hash($msg_hash, "header"); + my $header = @{$msg_hash->{header}}[0]; if($header eq "registered") { $reg_server = $server; last; @@ -396,7 +395,7 @@ sub register_at_server { } } } - # kommt antwort nicht, dann probiere es mit dem nächsten in der liste + # if no answer arrive, try next server in list } @@ -422,19 +421,19 @@ sub register_at_server { # RETURNS: # DESCRIPTION: #=============================================================================== -sub create_xml_hash { - my ($header, $source, $target, $header_value) = @_; - my $hash = { - header => [$header], - source => [$source], - target => [$target], - $header => [$header_value], - }; - daemon_log("create_xml_hash:", 7), - chomp(my $tmp = Dumper $hash); - daemon_log("\t$tmp\n", 7); - return $hash -} +#sub create_xml_hash { +# my ($header, $source, $target, $header_value) = @_; +# my $hash = { +# header => [$header], +# source => [$source], +# target => [$target], +# $header => [$header_value], +# }; +# daemon_log("create_xml_hash:", 7), +# chomp(my $tmp = Dumper $hash); +# daemon_log("\t$tmp\n", 7); +# return $hash +#} #=== FUNCTION ================================================================ @@ -443,13 +442,13 @@ sub create_xml_hash { # RETURNS: # DESCRIPTION: #=============================================================================== -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:\n\t$xml_string\n", 7); - return $xml_string; -} +#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:\n\t$xml_string\n", 7); +# return $xml_string; +#} #=== FUNCTION ================================================================ @@ -458,15 +457,15 @@ sub create_xml_string { # RETURNS: # DESCRIPTION: #=============================================================================== -sub add_content2xml_hash { - my ($xml_ref, $element, $content) = @_; - if(not exists $$xml_ref{$element} ) { - $$xml_ref{$element} = []; - } - my $tmp = $$xml_ref{$element}; - push(@$tmp, $content); - return; -} +#sub add_content2xml_hash { +# my ($xml_ref, $element, $content) = @_; +# if(not exists $$xml_ref{$element} ) { +# $$xml_ref{$element} = []; +# } +# my $tmp = $$xml_ref{$element}; +# push(@$tmp, $content); +# return; +#} #=== FUNCTION ================================================================ @@ -478,14 +477,14 @@ sub add_content2xml_hash { # function returns a string cause it is expected that these keys # do just have one value, all other keys returns an array!!! #=============================================================================== -sub get_content_from_xml_hash { - my ($xml_ref, $element) = @_; - my $result = $xml_ref->{$element}; - if( $element eq "header" || $element eq "target" || $element eq "source") { - return @$result[0]; - } - return @$result; -} +#sub get_content_from_xml_hash { +# my ($xml_ref, $element) = @_; +# my $result = $xml_ref->{$element}; +# if( $element eq "header" || $element eq "target" || $element eq "source") { +# return @$result[0]; +# } +# return @$result; +#} # my ($xml_ref, $element) = @_; # if (exists $xml_ref->{$element}) { @@ -509,14 +508,14 @@ sub get_content_from_xml_hash { # RETURNS: # DESCRIPTION: #=============================================================================== -sub encrypt_msg { - my ($msg, $my_cipher) = @_; - if(not defined $my_cipher) { print "no cipher object\n"; } - $msg = "\0"x(16-length($msg)%16).$msg; - my $crypted_msg = $my_cipher->encrypt($msg); - chomp($crypted_msg = &encode_base64($crypted_msg)); - return $crypted_msg; -} +#sub encrypt_msg { +# my ($msg, $my_cipher) = @_; +# if(not defined $my_cipher) { print "no cipher object\n"; } +# $msg = "\0"x(16-length($msg)%16).$msg; +# my $crypted_msg = $my_cipher->encrypt($msg); +# chomp($crypted_msg = &encode_base64($crypted_msg)); +# return $crypted_msg; +#} #=== FUNCTION ================================================================ @@ -525,13 +524,13 @@ sub encrypt_msg { # RETURNS: # DESCRIPTION: #=============================================================================== -sub decrypt_msg { - my ($crypted_msg, $my_cipher) = @_ ; - $crypted_msg = &decode_base64($crypted_msg); - my $msg = $my_cipher->decrypt($crypted_msg); - $msg =~ s/\0*//g; - return $msg; -} +#sub decrypt_msg { +# my ($crypted_msg, $my_cipher) = @_ ; +# $crypted_msg = &decode_base64($crypted_msg); +# my $msg = $my_cipher->decrypt($crypted_msg); +# $msg =~ s/\0*//g; +# return $msg; +#} #=== FUNCTION ================================================================ @@ -540,17 +539,17 @@ sub decrypt_msg { # RETURNS: cipher object # DESCRIPTION: #=============================================================================== -sub create_ciphering { - my ($passwd) = @_; - $passwd = substr(md5_hex("$passwd") x 32, 0, 32); - my $iv = substr(md5_hex('GONICUS GmbH'),0, 16); - - #daemon_log("iv: $iv", 7); - #daemon_log("key: $passwd", 7); - my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC()); - $my_cipher->set_iv($iv); - return $my_cipher; -} +#sub create_ciphering { +# my ($passwd) = @_; +# $passwd = substr(md5_hex("$passwd") x 32, 0, 32); +# my $iv = substr(md5_hex('GONICUS GmbH'),0, 16); +# +# #daemon_log("iv: $iv", 7); +# #daemon_log("key: $passwd", 7); +# my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC()); +# $my_cipher->set_iv($iv); +# return $my_cipher; +#} #=== FUNCTION ================================================================ @@ -577,52 +576,52 @@ sub create_passwd { # RETURNS: nothing # DESCRIPTION: ???? #=============================================================================== -sub send_msg_hash2address { - my ($msg_hash, $address, $passwd) = @_ ; - - # fetch header for logging - my $header = @{$msg_hash->{header}}[0]; - - # generiere xml string - my $msg_xml = &create_xml_string($msg_hash); - - # hole das entsprechende passwd aus dem hash - if(not defined $passwd) { - if(exists $known_hosts->{$address}) { - $passwd = $known_hosts->{$address}->{passwd}; - } elsif ($address eq $server_address) { - $passwd = $server_passwd; - } else { - daemon_log("$address not known, neither as server nor as client", 1); - return "failed"; - } - } - - # erzeuge ein ciphering object - my $act_cipher = &create_ciphering($passwd); - - # encrypt xml msg - my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher); - - # öffne socket - my $socket = &open_socket($address); - if(not defined $socket){ - daemon_log("cannot open socket to $address, server not reachable", 1); - daemon_log("cannot send '$header'-msg", 1); - return "failed"; - } - - # versende xml msg - print $socket $crypted_msg."\n"; - - # schließe socket - close $socket; - - daemon_log("send '$header'-msg to $address", 5); - daemon_log("crypted_msg:\n\t$crypted_msg", 7); - - return "done"; -} +#sub send_msg_hash2address { +# my ($msg_hash, $address, $passwd) = @_ ; +# +# # fetch header for logging +# my $header = @{$msg_hash->{header}}[0]; +# +# # generiere xml string +# my $msg_xml = &create_xml_string($msg_hash); +# +# # hole das entsprechende passwd aus dem hash +# if(not defined $passwd) { +# if(exists $known_hosts->{$address}) { +# $passwd = $known_hosts->{$address}->{passwd}; +# } elsif ($address eq $server_address) { +# $passwd = $server_passwd; +# } else { +# daemon_log("$address not known, neither as server nor as client", 1); +# return "failed"; +# } +# } +# +# # erzeuge ein ciphering object +# my $act_cipher = &create_ciphering($passwd); +# +# # encrypt xml msg +# my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher); +# +# # öffne socket +# my $socket = &open_socket($address); +# if(not defined $socket){ +# daemon_log("cannot open socket to $address, server not reachable", 1); +# daemon_log("cannot send '$header'-msg", 1); +# return "failed"; +# } +# +# # versende xml msg +# print $socket $crypted_msg."\n"; +# +# # schließe socket +# close $socket; +# +# daemon_log("send '$header'-msg to $address", 5); +# daemon_log("crypted_msg:\n\t$crypted_msg", 7); +# +# return "done"; +#} #=== FUNCTION ================================================================ @@ -1015,7 +1014,8 @@ GetOptions("h|help" => \&usage, # restart daemon log file if(-e $log_file ) { unlink $log_file } -daemon_log("started!"); +daemon_log(" ", 1); +daemon_log("$0 started!", 1); # Just fork, if we"re not in foreground mode if( ! $foreground ) { $pid = fork(); } @@ -1047,6 +1047,7 @@ $client_address = $client_ip.":".$client_port; $xml = new XML::Simple(); # create input socket +daemon_log(" ", 1); $rbits = $wbits = $ebits = ""; $input_socket = IO::Socket::INET->new(LocalPort => $client_port, Type => SOCK_STREAM, @@ -1056,12 +1057,13 @@ $input_socket = IO::Socket::INET->new(LocalPort => $client_port, if(not defined $input_socket){ daemon_log("cannot be a tcp server at $client_port : $@\n"); } else { - daemon_log("start server:\n\t$server_ip:$client_port",1) ; + daemon_log("start client at $client_address",1) ; vec($rbits, fileno $input_socket, 1) = 1; vec($wbits, fileno $input_socket, 1) = 1; } # register at server +daemon_log(" ", 1); ®ister_at_server(); diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 485ccba37..027814b80 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -363,10 +363,15 @@ sub register_at_bus { # create known_daemons entry &create_known_daemon($bus_address); &add_content2known_daemons(hostname=>$bus_address, status=>"register_at_bus", passwd=>$bus_passwd); - daemon_log("register at bus: $bus_address", 1); my $msg_hash = &create_xml_hash("here_i_am", "$server_ip:$server_port", $bus_address); - &send_msg_hash2address($msg_hash, $bus_address); + my $answer = ""; + $answer = &send_msg_hash2address($msg_hash, $bus_address); + if ($answer == 0) { + daemon_log("register at bus: $bus_address", 1); + } else { + daemon_log("unable to send 'register'-msg to bus: $bus_address", 1); + } return; } @@ -418,16 +423,6 @@ sub activating_child { print $pipe_wr $msg.".".$host."\n"; -# if (defined $client) { -# my $rbits = ""; -# vec($rbits, fileno $client, 1) = 1; -# -# my ($rout); -# my $nf = select($rout=$rbits, undef, undef, $gosa_timeout); -# if($gosa_activ eq "on" && vec($rout, fileno $gosa_server, 1)) { -# -# } -# } return; } @@ -441,27 +436,6 @@ sub activating_child { #=============================================================================== sub get_processing_child { my $child; - # checking %busy_child{pipe_wr} if msg is 'done', then set child from busy to free -# while(my ($key, $val) = each(%busy_child)) { -# # test ob prozess noch existiert -# my $exitus_pid = waitpid($key, WNOHANG); -# if($exitus_pid != 0) { -# delete $busy_child{$key}; -# print "prozess:$key wurde aus busy_child entfernt\n"; -# next; -# } -# -# # check wether process sitll works -# my $fh = $$val{'pipe_rd'}; -# $fh->blocking(0); -# my $child_answer; -# if(not $child_answer = <$fh>) { next } -# chomp($child_answer); -# if($child_answer eq "done") { -# delete $busy_child{$key}; -# $free_child{$key} = $val; -# } -# } while(my ($key, $val) = each(%free_child)) { my $exitus_pid = waitpid($key, WNOHANG); @@ -690,7 +664,6 @@ sub process_incoming_msg { elsif ($header eq 'who_has') { &who_has($msg_hash) } elsif ($header eq 'who_has_i_do') { &who_has_i_do($msg_hash)} elsif ($header eq 'update_status') { &update_status($msg_hash) } - #elsif ($header eq 'got_ping') { &got_ping($msg_hash)} elsif ($header eq 'get_load') { &execute_actions($msg_hash)} else { daemon_log("ERROR: no function assigned to this msg", 5) } @@ -809,13 +782,6 @@ sub read_from_socket { $result .= $char; } -# my $len = 16; -# while($len == 16){ -# my $char; -# $len = sysread($socket, $char, 16); -# if($len != 16) { last } -# $result .= $char; -# } return $result; } @@ -975,7 +941,7 @@ sub send_msg_hash2address { } else { daemon_log("$address not known, neither as server nor as client", 1); - return; + return 1; } } @@ -1001,7 +967,7 @@ sub send_msg_hash2address { } } - return; + return 1; } # send xml msg @@ -1023,7 +989,7 @@ sub send_msg_hash2address { &update_known_clients(hostname=>$address, status=>$header); } - return; + return 0; } @@ -1591,9 +1557,6 @@ sub print_known_clients { } - - - #=== FUNCTION ================================================================ # NAME: create_known_client # PARAMETERS: hostname - string - key for the hash known_clients @@ -1614,8 +1577,6 @@ sub create_known_client { } - - #=== FUNCTION ================================================================ # NAME: add_content2known_clients # PARAMETERS: hostname - string - ip address and port of host (required) @@ -1780,7 +1741,7 @@ $SIG{CHLD} = 'IGNORE'; # restart daemon log file if(-e $log_file ) { unlink $log_file } daemon_log(" ", 1); -daemon_log("gosad started!", 1); +daemon_log("gosa-si-server started!", 1); # Just fork, if we"re not in foreground mode if( ! $foreground ) { $pid = fork(); } @@ -1824,8 +1785,7 @@ if($server_activ eq "on"){ if(not defined $server){ daemon_log("cannot be a tcp server at $server_port : $@"); } else { - daemon_log("start server:", 1); - daemon_log("\t$server_ip:$server_port",1) ; + daemon_log("start server: $server_address", 1); vec($rbits, fileno $server, 1) = 1; vec($wbits, fileno $server, 1) = 1; } @@ -1841,14 +1801,13 @@ if($bus_activ eq "on") { } -daemon_log(" ", 1); - # start arp fifo if ($no_arp > 0) { $arp_activ = "off"; } my $my_fifo; if($arp_activ eq "on") { + daemon_log(" ", 1); $my_fifo = &open_fifo($arp_fifo_path); if($my_fifo == 0) { die "fifo file disappeared\n" } sysopen($arp_fifo, $arp_fifo_path, O_RDWR) or die "can't read from $arp_fifo: $!" ; @@ -1868,20 +1827,10 @@ if ($gosa_activ eq "on") { if (not defined $gosa_server) { daemon_log("cannot start tcp server at $gosa_port for communication to gosa: $@", 1); } else { - daemon_log("start server at for communication to gosa", 1); - daemon_log("\t$server_ip:$gosa_port"); + daemon_log("start server at for communication to gosa: $gosa_address", 1); vec($rbits, fileno $gosa_server, 1) = 1; } - - - #&open_fifo($gosa_fifo_in); - #sysopen(GOSA_FIFO_IN, $gosa_fifo_in, O_RDWR) or die "can't read from GOSA_FIFO_IN: $!" ; - #vec($rbits, fileno GOSA_FIFO_IN, 1) = 1; - - #&open_fifo($gosa_fifo_out); - #sysopen(GOSA_FIFO_OUT, $gosa_fifo_out, O_RDWR) or die "can't read from GOSA_FIFO_IN: $!" ; - } @@ -1970,7 +1919,6 @@ while(1) { my $in_msg = <$client>; #my $in_msg = &read_from_socket($client); - daemon_log(">>>>>>>>>>> frisch vom socket gelesen\n!$in_msg!\n",1); if(defined $in_msg){ chomp($in_msg); &activating_child($in_msg, $actual_ip, $client); diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm new file mode 100644 index 000000000..a92ef00a1 --- /dev/null +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -0,0 +1,322 @@ +package GosaSupportDaemon; + +use Exporter; +@ISA = qw(Exporter); +@EXPORT = qw(create_xml_hash send_msg_hash2address get_content_from_xml_hash add_content2xml_hash create_xml_string encrypt_msg decrypt_msg create_ciphering transform_msg2hash); + +use strict; +use warnings; +use IO::Socket::INET; +use Crypt::Rijndael; +use Digest::MD5 qw(md5 md5_hex md5_base64); +use MIME::Base64; +use XML::Simple; + + +BEGIN {} + +END {} + +### Start ###################################################################### + +my $xml = new XML::Simple(); + + +sub process_incoming_msg { + return; +} + +sub daemon_log { + my ($msg, $level) = @_ ; + &main::daemon_log($msg, $level); + return; +} + + +##=== FUNCTION ================================================================ +## NAME: logging +## PARAMETERS: level - string - default 'info' +## msg - string - +## facility - string - default 'LOG_DAEMON' +## RETURNS: nothing +## DESCRIPTION: function for logging +##=============================================================================== +#my $log_file = $main::log_file; +#my $verbose = $main::verbose; +#my $foreground = $main::forground; +#sub daemon_log { +# # log into log_file +# my( $msg, $level ) = @_; +# if(not defined $msg) { return } +# if(not defined $level) { $level = 1 } +# if(defined $log_file){ +# open(LOG_HANDLE, ">>$log_file"); +# if(not defined open( LOG_HANDLE, ">>$log_file" )) { +# print STDERR "cannot open $log_file: $!"; +# return } +# chomp($msg); +# if($level <= $verbose){ +# print LOG_HANDLE "$level $msg\n"; +# if(defined $foreground) { print $msg."\n" } +# } +# } +# close( LOG_HANDLE ); +##log into syslog +## my ($msg, $level, $facility) = @_; +## if(not defined $msg) {return} +## if(not defined $level) {$level = "info"} +## if(not defined $facility) {$facility = "LOG_DAEMON"} +## openlog($0, "pid,cons,", $facility); +## syslog($level, $msg); +## closelog; +## return; +#} + + +#=== FUNCTION ================================================================ +# NAME: create_xml_hash +# PARAMETERS: header - string - message header (required) +# source - string - where the message come from (required) +# target - string - where the message should go to (required) +# [header_value] - string - something usefull (optional) +# RETURNS: hash - hash - nomen est omen +# DESCRIPTION: creates a key-value hash, all values are stored in a array +#=============================================================================== +sub create_xml_hash { + my ($header, $source, $target, $header_value) = @_; + my $hash = { + header => [$header], + source => [$source], + target => [$target], + $header => [$header_value], + }; + #daemon_log("create_xml_hash:", 7), + #chomp(my $tmp = Dumper $hash); + #daemon_log("\t$tmp", 7); + return $hash +} + + +sub transform_msg2hash { + my ($msg) = @_ ; + + my $hash = $xml->XMLin($msg, ForceArray=>1); + return $hash; +} + + +#=== 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); + + # fetch the appropriated passwd from hash + if(not defined $passwd) { + if(exists $main::known_daemons->{$address}) { + $passwd = $main::known_daemons->{$address}->{passwd}; + } elsif(exists $main::known_clients->{$address}) { + $passwd = $main::known_clients->{$address}->{passwd}; + + } else { + daemon_log("$address not known, neither as server nor as client", 1); + return 1; + } + } + + # 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); + + if (exists $main::known_clients->{$address}) { + if ($main::known_clients->{$address}->{status} eq "down") { + # if status of not reachable client is already 'down', + # then delete client from known_clients + &clean_up_known_clients($address); + + } else { + # update status to 'down' + &update_known_clients(hostname=>$address, status=>"down"); + + } + } + return 1; + } + + # send xml msg + print $socket $crypted_msg."\n"; + + close $socket; + + daemon_log("send '$header'-msg to $address", 1); + + daemon_log("$msg_xml", 5); + + #daemon_log("crypted message:",7); + #daemon_log("\t$crypted_msg", 7); + + # update status of client in known_clients with last send msg + if(exists $main::known_daemons->{$address}) { + #&update_known_daemons(); + } elsif(exists $main::known_clients->{$address}) { + &main::update_known_clients(hostname=>$address, status=>$header); + } + + 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 +# element - string - key for the hash +# content - string - value for the hash +# RETURNS: nothing +# DESCRIPTION: add key-value pair to xml_ref, if key alread exists, +# then append value to list +#=============================================================================== +sub add_content2xml_hash { + my ($xml_ref, $element, $content) = @_; + if(not exists $$xml_ref{$element} ) { + $$xml_ref{$element} = []; + } + my $tmp = $$xml_ref{$element}; + push(@$tmp, $content); + return; +} + + +#=== 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 +# my_cipher - ref - reference to a Crypt::Rijndael object +# RETURNS: crypted_msg - string - crypted message +# DESCRIPTION: crypts the incoming message with the Crypt::Rijndael module +#=============================================================================== +sub encrypt_msg { + my ($msg, $my_cipher) = @_; + if(not defined $my_cipher) { print "no cipher object\n"; } + $msg = "\0"x(16-length($msg)%16).$msg; + my $crypted_msg = $my_cipher->encrypt($msg); + chomp($crypted_msg = &encode_base64($crypted_msg)); + return $crypted_msg; +} + + +#=== FUNCTION ================================================================ +# NAME: decrypt_msg +# PARAMETERS: crypted_msg - string - message to decrypt +# my_cipher - ref - reference to a Crypt::Rijndael object +# RETURNS: msg - string - decrypted message +# DESCRIPTION: decrypts the incoming message with the Crypt::Rijndael module +#=============================================================================== +sub decrypt_msg { + my ($crypted_msg, $my_cipher) = @_ ; + $crypted_msg = &decode_base64($crypted_msg); + my $msg = $my_cipher->decrypt($crypted_msg); + $msg =~ s/\0*//g; + return $msg; +} + + +#=== FUNCTION ================================================================ +# NAME: create_ciphering +# PARAMETERS: passwd - string - used to create ciphering +# RETURNS: cipher - object +# DESCRIPTION: creates a Crypt::Rijndael::MODE_CBC object with passwd as key +#=============================================================================== +sub create_ciphering { + my ($passwd) = @_; + $passwd = substr(md5_hex("$passwd") x 32, 0, 32); + my $iv = substr(md5_hex('GONICUS GmbH'),0, 16); + + #daemon_log("iv: $iv", 7); + #daemon_log("key: $passwd", 7); + my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC()); + $my_cipher->set_iv($iv); + return $my_cipher; +} + + +#=== FUNCTION ================================================================ +# NAME: open_socket +# PARAMETERS: PeerAddr string something like 192.168.1.1 or 192.168.1.1:10000 +# [PeerPort] string necessary if port not appended by PeerAddr +# RETURNS: socket IO::Socket::INET +# DESCRIPTION: open a socket to PeerAddr +#=============================================================================== +sub open_socket { + my ($PeerAddr, $PeerPort) = @_ ; + if(defined($PeerPort)){ + $PeerAddr = $PeerAddr.":".$PeerPort; + } + my $socket; + $socket = new IO::Socket::INET(PeerAddr => $PeerAddr, + Porto => "tcp", + Type => SOCK_STREAM, + Timeout => 5, + ); + if(not defined $socket) { + return; + } + &daemon_log("open_socket:", 7); + &daemon_log("\t$PeerAddr", 7); + return $socket; +} + + + diff --git a/gosa-si/modules/TestModule.pm b/gosa-si/modules/TestModule.pm new file mode 100644 index 000000000..90c8d6abb --- /dev/null +++ b/gosa-si/modules/TestModule.pm @@ -0,0 +1,76 @@ +package TestModule; + +use Exporter; +@ISA = ("Exporter"); + +use strict; +use warnings; +use GosaSupportDaemon; + +BEGIN{ +} + +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 + my %tag_hash = (gosa_admin_packages => "yes", + server_packages => "yes", + client_packages => "yes", + ); + return \%tag_hash; +} + + +sub process_incoming_msg { + my ($crypted_msg) = @_ ; + if(not defined $crypted_msg) { + &main::daemon_log("function 'process_incoming_msg': got no msg", 7); + } + &main::daemon_log("TestModule: crypted_msg:$crypted_msg", 7); + &main::daemon_log("TestModule: crypted_msg len:".length($crypted_msg), 7); + + + # chomp address from host who send the message + $crypted_msg =~ /^([\s\S]*?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)$/; + $crypted_msg = $1; + my $host = sprintf("%s.%s.%s.%s", $2, $3, $4, $5); + + my $gosa_passwd = $main::gosa_passwd; + my $gosa_cipher = &create_ciphering($gosa_passwd); + + my $in_msg; + my $in_hash; + eval{ + $in_msg = &decrypt_msg($crypted_msg, $gosa_cipher); + $in_hash = &transform_msg2hash($in_msg); + }; + if ($@) { + &main::daemon_log("TestModul konnte msg nicht entschlüsseln:", 5); + &main::daemon_log("$@", 7); + return; + } + + my $header = @{$in_hash->{header}}[0]; + my $ip_address = @{$in_hash->{target}}[0]; + + + # hier kommt die logik suche den entsprechenden daemon, der den client target hat + + my $out_hash = &create_xml_hash("halt", $main::server_address, $ip_address); + + &send_msg_hash2address($out_hash, $ip_address); + + &main::daemon_log("TestModul: ip $ip_address bekommt $header "); + return ; +} + + + +