From 0f55a9267edafebca4e67943ab48b8a418d510b1 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Fri, 1 Feb 2008 15:02:55 +0000 Subject: [PATCH] GosaPackages answers are now gosa-si envelope conform git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8731 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client.conf | 3 +- gosa-si/gosa-si-bus | 2 +- gosa-si/gosa-si-server | 8 +- gosa-si/modules/GosaPackages.pm | 49 ++------- gosa-si/modules/GosaSupportDaemon.pm | 153 +++++++++++++++------------ gosa-si/tests/client.php | 7 +- 6 files changed, 99 insertions(+), 123 deletions(-) diff --git a/gosa-si/client.conf b/gosa-si/client.conf index 0c65e2cad..6827a7c8d 100644 --- a/gosa-si/client.conf +++ b/gosa-si/client.conf @@ -3,11 +3,12 @@ log_file = /var/log/gosa-si-client.log pid_file = /var/run/gosa-si-client.pid [client] +client_ip = 10.89.1.31 client_port = 20083 [server] server_ip = 127.0.0.1 server_port = 20081 -server_passwd = secret-server-password +server_key = secret-server-password server_timeout = 5 server_domain = intranet.gonicus.de diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus index dd848c182..2c7be1ac5 100755 --- a/gosa-si/gosa-si-bus +++ b/gosa-si/gosa-si-bus @@ -53,7 +53,7 @@ $foreground = 0 ; "child_max" => [\$child_max, 10], "child_min" => [\$child_min, 3], "child_timeout" => [\$child_timeout, 180], - "bus_known_server_file_name" => [\$bus_known_server_file_name, "/var/lib/gosa-si/bus_known_server.db"] + "bus_known_server_file_name" => [\$bus_known_server_file_name, "/var/lib/gosa-si/gosa-si-bus_known_server.db"] }, "bus" => {"bus_activ" => [\$bus_activ, "on"], diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 461c15498..16beffc07 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -669,7 +669,6 @@ sub send_msg_to_target { } if( $error == 0 ) { - # send xml msg print $socket $crypted_msg."\n"; @@ -786,13 +785,10 @@ sub client_input { my $query_res = $known_server_db->select_dbentry( $sql_statement ); while( my ($hit_num, $hit) = each %{ $query_res } ) { my $host_name = $hit->{hostname}; - my $host_key = $hit->{hostkey}; - $answer =~ s/KNOWN_SERVER/$host_name/g; + my $host_key = $hit->{hostkey}; + $answer =~ s/KNOWN_SERVER/$host_name/g; &send_msg_to_target($answer, $host_name, $host_key); } - - print STDERR $answer_target."\n"; - } else { # answer is for one specific host diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index e54da9aa0..b58fe246a 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -349,7 +349,7 @@ sub process_job_msg { } &main::daemon_log("GosaPackages: $header job successfully added to job queue", 3); - return "$res"; + return "
answer
$server_addressGOSA$res
"; } @@ -357,7 +357,7 @@ sub process_job_msg { sub db_res_2_xml { my ($db_res) = @_ ; - my $xml = ""; + my $xml = "
answer
$server_addressGOSA"; my $len_db_res= keys %{$db_res}; @@ -418,7 +418,7 @@ sub count_jobdb { my $res_hash = $main::job_db->select_dbentry($sql_statement); my $count = keys(%{$res_hash}); - $out_xml= "$count"; + $out_xml= "
answer
$server_addressGOSA$count
"; return $out_xml; } @@ -444,7 +444,7 @@ sub delete_jobdb_entry { } # prepare xml answer - my $out_xml = "$res"; + my $out_xml = "
answer
$server_addressGOSA$res
"; return $out_xml; } @@ -463,7 +463,7 @@ sub clear_jobdb { if( not $db_res > 0 ) { $error++; }; if( $error == 0 ) { - $out_xml = "0"; + $out_xml = "
answer
$server_addressGOSA0
"; } return $out_xml; @@ -474,7 +474,7 @@ sub update_status_jobdb_entry { my ($msg) = @_ ; my $msg_hash = &transform_msg2hash($msg); my $error= 0; - my $out_xml= "1"; + my $out_xml= "
answer
$server_addressGOSA1
"; my @len_hash = keys %{$msg_hash}; if( 0 == @len_hash) { $error++; }; @@ -495,47 +495,12 @@ sub update_status_jobdb_entry { } if( $error == 0) { - $out_xml = "0"; + $out_xml = "
answer
$server_addressGOSA0
"; } return $out_xml; } -#sub update_timestamp_jobdb_entry { -# my ($msg) = @_ ; -# my $msg_hash = &transform_msg2hash($msg); -# -# # prepare query sql statement -# my $update_hash = {table=>$main::job_queue_table_name }; -# if( exists $msg_hash->{where} ) { -# $update_hash->{where} = $msg_hash->{where}; -# } else { -# $update_hash->{where} = []; -# } -# -# if( not exists $msg_hash->{update}[0]->{timestamp} ) { -# return "1"; -# } -# -# $update_hash->{update} = [ { timestamp=>$msg_hash->{update}[0]->{timestamp} } ]; -# -# # execute db query -# my $db_res = $main::job_db->update_dbentry($update_hash); -# -# # transform db answer to error returnment -# my $res; -# if( $db_res > 0 ) { -# $res = 0 ; -# } else { -# $res = 1; -# } -# -# # prepare xml answer -# my $out_xml = "$res"; -# return $out_xml; -# -#} - 1; diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index de952229e..93ff49d7a 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -30,10 +30,6 @@ END {} my $xml = new XML::Simple(); -sub process_incoming_msg { - return; -} - sub daemon_log { my ($msg, $level) = @_ ; &main::daemon_log($msg, $level); @@ -101,37 +97,37 @@ sub transform_msg2hash { # 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; -} +#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 ================================================================ @@ -142,15 +138,15 @@ sub send_msg_hash2address ($$$){ # 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; -} +#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 ================================================================ @@ -197,19 +193,31 @@ sub create_xml_string { # 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"; } +# my ($msg, $my_cipher) = @_; +# if(not defined $my_cipher) { print "no cipher object\n"; } +# { +# use bytes; +# $msg = "\0"x(16-length($msg)%16).$msg; +# } +# $msg = $my_cipher->encrypt($msg); +# chomp($msg = &encode_base64($msg)); +# +# # there are no newlines allowed inside msg +# $msg=~ s/\n//g; +# +# return $msg; + my ($msg, $key) = @_; + my $my_cipher = &create_ciphering($key); { use bytes; $msg = "\0"x(16-length($msg)%16).$msg; } $msg = $my_cipher->encrypt($msg); chomp($msg = &encode_base64($msg)); - # there are no newlines allowed inside msg $msg=~ s/\n//g; - return $msg; + } @@ -221,10 +229,17 @@ sub encrypt_msg { # DESCRIPTION: decrypts the incoming message with the Crypt::Rijndael module #=============================================================================== sub decrypt_msg { - my ($msg, $my_cipher) = @_ ; - if(defined $msg && defined $my_cipher) { - $msg = &decode_base64($msg); - } +# my ($msg, $my_cipher) = @_ ; +# +# if(defined $msg && defined $my_cipher) { +# $msg = &decode_base64($msg); +# } +# $msg = $my_cipher->decrypt($msg); +# $msg =~ s/\0*//g; +# return $msg; + my ($msg, $key) = @_ ; + $msg = &decode_base64($msg); + my $my_cipher = &create_ciphering($key); $msg = $my_cipher->decrypt($msg); $msg =~ s/\0*//g; return $msg; @@ -257,23 +272,23 @@ sub create_ciphering { # 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: $PeerAddr", 7); - return $socket; -} +#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: $PeerAddr", 7); +# return $socket; +#} sub get_time { diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 867101e0f..cbfc25cd3 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -10,7 +10,6 @@ for($count = 1; $count <= $zahl; $count++) { $sock = new Socket_Client("127.0.0.1","20081",TRUE,1); -#$sock = new Socket_Client("169.254.2.248","9999",TRUE,1); $sock->setEncryptionKey("secret-gosa-password"); if($sock->connected()){ @@ -19,7 +18,7 @@ if($sock->connected()){ # add #$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 19700101000001
"; #$data = "
job_sayHello
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; -#$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 20130102133900
"; +#$data = "
job_ping
10.89.1.155:20083 10.89.1.155:2008100:1B:77:04:8A:6C 20130102133900
"; # delete #$data = "
gosa_delete_jobdb_entry
3
"; @@ -37,10 +36,10 @@ if($sock->connected()){ #$data = "
gosa_count_jobdb
"; # clear -#$data = "
gosa_clear_jobdb
"; +$data = "
gosa_clear_jobdb
"; # set gosa-si-client to 'activated' -$data = "
gosa_set_activated_for_installation
127.0.0.1:20083 127.0.0.1:20081
"; +#$data = "
gosa_set_activated_for_installation
127.0.0.1:20083 127.0.0.1:20081
"; $sock->write($data); -- 2.30.2