summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4fa1f57)
raw | patch | inline | side by side (parent: 4fa1f57)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 10 Jan 2008 16:59:06 +0000 (16:59 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Thu, 10 Jan 2008 16:59:06 +0000 (16:59 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8302 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus
index 90de439b50d246c3803699098d2af58fbf346489..bec214a3f4520948ba25842d081c6e8cf5fe494d 100755 (executable)
--- a/gosa-si/gosa-si-bus
+++ b/gosa-si/gosa-si-bus
use Sys::Syslog qw( :DEFAULT setlogsock);
use Cwd;
use File::Spec;
-use IPC::Shareable qw( :lock);
-IPC::Shareable->clean_up_all;
+use GOSA::GosaSupportDaemon;
+use GOSA::DBsqlite;
+#use IPC::Shareable qw( :lock);
+#IPC::Shareable->clean_up_all;
my ($cfg_file, $default_cfg_file, %cfg_defaults, $foreground, $verbose);
my ($bus_activ, $bus_passwd, $bus_ip, $bus_port, $bus_address, $bus, $bus_mac_address);
my ($pid_file, $procid, $pid, $log_file, $my_own_address);
my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout);
-my ($xml, $bus_cipher, $known_daemons, $shmkh);
+my ($bus_known_server_db, $bus_known_server_file_name);
+my ($xml, $bus_cipher);
$foreground = 0 ;
-$known_daemons = {};
-$shmkh = tie($known_daemons, 'IPC::Shareable', undef, {create => 1,
- exclusive => 1,
- mode => 0666,
- destroy => 1,
- });
+
%cfg_defaults =
("general" =>
{"log_file" => [\$log_file, "/var/run/".$0.".log"],
"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" =>
{"bus_activ" => [\$bus_activ, "on"],
print "$bus closed\n";
}
print "$signal\n";
- IPC::Shareable->clean_up;
exit(1);
}
$SIG{INT} = \&sig_int_handler;
$crypted_msg = $1;
my $host = sprintf("%s.%s.%s.%s", $2, $3, $4, $5);
- daemon_log("msg from host: $host", 1);
- daemon_log("crypted_msg: $crypted_msg", 7);
+ my $msg;
+ my $msg_hash;
+ my $host_name;
+ my $host_key;
+
+ # check wether incoming msg is a new msg
+ $host_name = $bus_address;
+ $host_key = $bus_passwd;
+ daemon_log("process_incoming_msg: host_name: $host_name", 7);
+ daemon_log("process_incoming_msg: host_key: $host_key", 7);
+ eval{
+ my $key_cipher = &create_ciphering($host_key);
+ $msg = &decrypt_msg($crypted_msg, $key_cipher);
+ $msg_hash = &transform_msg2hash($msg);
+ };
+ if($@) {
+ daemon_log("process_incoming_msg: deciphering raise error", 7);
+ daemon_log("$@", 8);
+ $msg = undef;
+ $msg_hash = undef;
+ $host_name = undef;
+ $host_key = undef;
+ }
- my @valid_keys;
- my @daemon_keys = keys %$known_daemons;
- foreach my $daemon_key (@daemon_keys) {
- if($daemon_key =~ "^$daemon_key") {
- push(@valid_keys, $daemon_key);
+ # check wether incoming msg is from a bus_known_server
+ if( not defined $msg ) {
+ my $query_res = $bus_known_server_db->select_dbentry( {table=>'bus_known_server'} );
+ while( my ($hit_num, $hit) = each %{ $query_res } ) {
+ $host_name = $hit->{hostname};
+ if( not $host_name =~ "^$host") {
+ next;
+ }
+ $host_key = $hit->{hostkey};
+ daemon_log("process_incoming_msg: host_name: $host_name", 7);
+ daemon_log("process_incoming_msg: host_key: $host_key", 7);
+ eval{
+ my $key_cipher = &create_ciphering($host_key);
+ $msg = &decrypt_msg($crypted_msg, $key_cipher);
+ $msg_hash = &transform_msg2hash($msg);
+ };
+ if($@) {
+ daemon_log("process_incoming_msg: deciphering raise error", 7);
+ daemon_log("$@", 8);
+ $msg = undef;
+ $msg_hash = undef;
+ $host_name = undef;
+ $host_key = undef;
+ } else {
+ last;
+ }
}
}
- my $l = @valid_keys;
- daemon_log("number of valid daemons: $l", 7);
-
- my ($msg, $msg_hash);
- my $msg_flag = 0;
-
- # collect addresses from possible incoming clients
- foreach my $host_key (@valid_keys) {
- eval{
- 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);
- $msg = &decrypt_msg($crypted_msg, $key_cipher);
- daemon_log("daemon decrypted msg:$msg", 7);
- $msg_hash = $xml->XMLin($msg, ForceArray=>1);
- };
- if($@) {
- daemon_log("msg processing raise error", 7);
- daemon_log("error string: $@", 7);
- $msg_flag += 1;
- } else {
- last;
- }
- }
-
- if($msg_flag >= $l) {
- daemon_log("\nERROR: do not understand the message:\n$msg" , 1);
+ if( not defined $msg ) {
+ daemon_log("WARNING: bus does not understand the message:", 5);
return;
}
- my $header = &get_content_from_xml_hash($msg_hash, "header");
- my $target = &get_content_from_xml_hash($msg_hash, "target");
+ # process incoming msg
+ my $header = @{$msg_hash->{header}}[0];
+ my $source = @{$msg_hash->{source}}[0];
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
- if($header eq 'here_i_am'){ &here_i_am($msg_hash)}
- elsif($header eq 'confirm_new_passwd'){ &confirm_new_passwd($msg_hash)}
- elsif($header eq 'got_ping') { &got_ping($msg_hash)}
- elsif($header eq 'ping') { &ping($msg_hash)}
- elsif($header eq 'who_has') { &who_has($msg_hash)}
- elsif($header eq 'new_client') { &new_client($msg_hash)}
- elsif($header eq 'delete_client') { &delete_client($msg_hash)}
- } else {
- # msg is for any other server
- my @targets = @{$msg_hash->{target}};
- my $len_targets = @targets;
-
- if ($len_targets == 0){
- # no targets specified
-
- daemon_log("ERROR: no target specified for msg $header", 1);
-
- } elsif ($targets[0] eq "*"){
- # all deamons in known_daemons are targets
-
- my $target = $targets[0];
- my $source = @{$msg_hash->{source}}[0];
- my @target_addresses = keys(%$known_daemons);
- foreach my $target_address (@target_addresses) {
- if ($target_address eq $source) { next; }
- if ($target_address eq $bus_address) { next ; }
- $msg_hash->{target} = [$target_address];
- &send_msg_hash2address($msg_hash, $target_address);
+ daemon_log("msg to process:", 5);
+ daemon_log($msg, 5);
+
+ my @targets = @{$msg_hash->{target}};
+ my $len_targets = @targets;
+
+ if ($len_targets == 0){
+ daemon_log("ERROR: no target specified for msg $header", 1);
+
+ } elsif ($len_targets == 1){
+ # we have only one target symbol
+ my $target = $targets[0];
+ daemon_log("msg is for: $target", 7);
+
+ if($target eq $bus_address) {
+ # msg is for bus
+ if($header eq 'here_i_am'){ &here_i_am($msg_hash)}
+ elsif($header eq 'confirm_new_passwd'){ &confirm_new_passwd($msg_hash)}
+ elsif($header eq 'got_ping') { &got_ping($msg_hash)}
+ elsif($header eq 'ping') { &ping($msg_hash)}
+ elsif($header eq 'who_has') { &who_has($msg_hash)}
+ elsif($header eq 'new_client') { &new_client($msg_hash)}
+ elsif($header eq 'delete_client') { &delete_client($msg_hash)}
+
+ } elsif ($target eq "*"){
+ # msg is for all server
+ my $query_res = $bus_known_server_db->select_dbentry( {table=>'known_server'} );
+ while( my ($hit_num, $hit) = each %{ $query_res } ) {
+ $host_name = $hit->{hostname};
+ $host_key = $hit->{hostkey};
+ $msg_hash->{target} = [$host_name];
+ &send_msg_hash2address($msg_hash, $host_name, $host_key);
}
+ return;
+ }
- } else {
- # a list of targets is specified
-
- my $target_address;
- foreach $target_address (@targets) {
- if (exists $known_daemons->{$target_address}) {
- &send_msg_hash2address($msg_hash, $target_address);
- } else {
- my @daemon_addresses = keys %$known_daemons;
- my $daemon_address;
- foreach $daemon_address (@daemon_addresses) {
- if (exists $known_daemons->{$daemon_address}->{clients}->{$target_address}) {
- my $header = &get_content_from_xml_hash($msg_hash, "header");
- &send_msg_hash2address($msg_hash, $daemon_address);
- daemon_log("bus forwards msg $header for client $target_address to server $daemon_address", 3);
- last;
+ } else {
+ # a list of targets is specified
+ my $target_address;
+ foreach $target_address (@targets) {
+
+ my $query_res = $bus_known_server_db->select_dbentry( {table=>'known_server', hostname=>$target_address} );
+ if( 1 == keys %{$query_res} ) {
+ $host_key = $query_res->{1}->{hostkey};
+ &send_msg_hash2address($msg_hash, $target_address, $host_key);
+ next;
+
+ } else {
+ $query_res = $bus_known_server_db->select_dbentry( {table=>'known_server'} );
+ while( my ($hit_num, $hit) = each %{$query_res} ) {
+ my $host_name = $hit->{hostname};
+ my $host_key = $hit->{hostkey};
+ my $clients = $hit->{clients};
+ my @clients = split(/,/, $clients);
+ foreach my $client (@clients) {
+ if( not $client eq $target_address ) {
+ next;
}
+ $msg_hash->{target} = [ $target_address ];
+ &send_msg_hash2address($msg_hash, $host_name, $host_key);
+ daemon_log("bus forwards msg $header for client $target_address to server $host_name", 3);
+ last;
}
-
}
}
}
}
- #&print_known_daemons_hash();
return;
}
# 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;
-}
+#sub create_ciphering {
+# my ($passwd) = @_;
+# $passwd = substr(md5_hex("$passwd") x 32, 0, 32);
+# my $iv = substr(md5_hex('GONICUS GmbH'),0, 16);
+#
+# my $my_cipher = Crypt::Rijndael->new($passwd , Crypt::Rijndael::MODE_CBC());
+# $my_cipher->set_iv($iv);
+# return $my_cipher;
+#}
#=== FUNCTION ================================================================
# 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;
-}
+#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 ================================================================
# 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;
-}
+#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 ================================================================
# 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) = @_ ;
-
- if (not defined $header || not defined $source || not defined $target) {
- daemon_log("ERROR: create_xml_hash function is invoked with uncompleted parameters", 7);
- }
-
- 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) = @_ ;
+#
+# if (not defined $header || not defined $source || not defined $target) {
+# daemon_log("ERROR: create_xml_hash function is invoked with uncompleted parameters", 7);
+# }
+#
+# 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 ================================================================
# 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;
- return $xml_string;
-}
+#sub create_xml_string {
+# my ($xml_hash) = @_ ;
+# my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml');
+# #$xml_string =~ s/[\n]+//g;
+# return $xml_string;
+#}
#=== FUNCTION ================================================================
# 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;
-}
+#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 ================================================================
# value - list - for all other keys in xml hash
# DESCRIPTION:
#===============================================================================
-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;
+#}
#=== FUNCTION ================================================================
# 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,
- Reuse => 1,
- Timeout => 5,
- );
- if(not defined $socket) {
- return;
- }
- 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,
+# Reuse => 1,
+# Timeout => 5,
+# );
+# if(not defined $socket) {
+# return;
+# }
+# return $socket;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: ????
#===============================================================================
-sub send_msg_hash2address {
- my ($msg_hash, $address) = @_ ;
-
- # fetch header for logging
- my $header = &get_content_from_xml_hash($msg_hash, "header");
-
- # generate xml string
- my $msg_xml = &create_xml_string($msg_hash);
-
- # fetch the appropriated passwd from hash
- my $passwd = $known_daemons->{$address}->{passwd};
-
- # create a ciphering object
- my $act_cipher = &create_ciphering($passwd);
-
- # encrypt xml msg
- my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher);
-
- # open socket
- my $socket = &open_socket($address);
- if(not defined $socket){
- daemon_log("ERROR: cannot send '$header'-msg to $address , server not reachable", 1);
- return;
- }
-
- # send xml msg
- print $socket $crypted_msg."\n";
-
- close $socket;
- daemon_log("send '$header'-msg to $address", 5);
- daemon_log("crypted_msg:\n\t$crypted_msg", 7);
- return;
-}
+#sub send_msg_hash2address {
+# my ($msg_hash, $address) = @_ ;
+#
+# # fetch header for logging
+# my $header = &get_content_from_xml_hash($msg_hash, "header");
+#
+# # generate xml string
+# my $msg_xml = &create_xml_string($msg_hash);
+#
+# # fetch the appropriated passwd from hash
+# my $passwd = $known_daemons->{$address}->{passwd};
+#
+# # create a ciphering object
+# my $act_cipher = &create_ciphering($passwd);
+#
+# # encrypt xml msg
+# my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher);
+#
+# # open socket
+# my $socket = &open_socket($address);
+# if(not defined $socket){
+# daemon_log("ERROR: cannot send '$header'-msg to $address , server not reachable", 1);
+# return;
+# }
+#
+# # send xml msg
+# print $socket $crypted_msg."\n";
+#
+# close $socket;
+# daemon_log("send '$header'-msg to $address", 5);
+# daemon_log("crypted_msg:\n\t$crypted_msg", 7);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: send msg_hash to all registered daemons
#===============================================================================
-sub send_msg_hash2all {
- my ($msg_hash) = @_;
-
- # fetch header for logging
- my $header = &get_content_from_xml_hash($msg_hash, "header");
-
- # generate xml string
- my $msg_xml = &create_xml_string($msg_hash);
-
- # fetch a list of all target addresses
- my @targets = keys(%$known_daemons);
-
- # itterates through the list an send each the msg
- foreach my $target (@targets) {
- if($target eq $bus_address) {next}; # do not send msg to bus
-
- # fetch the appropriated passwd
- my $passwd = $known_daemons->{$target}->{passwd};
-
- # create ciphering object
- my $act_cipher = &create_ciphering($passwd);
-
- # encrypt xml msg
- my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher);
-
- # open socket
- my $socket = &open_socket($target);
- if(not defined $socket){
- daemon_log("ERROR: cannot open socket to $target , server not reachable", 1);
- &update_known_daemons_entry(hostname=>$target, status=>"down");
- next;
- }
-
- # send xml msg
- print $socket $crypted_msg."\n";
-
- close $socket;
- daemon_log("send '$header'-msg to $target", 5);
- daemon_log("crypted_msg:\n\t$crypted_msg", 7);
- }
- return;
-}
+#sub send_msg_hash2all {
+# my ($msg_hash) = @_;
+#
+# # fetch header for logging
+# my $header = &get_content_from_xml_hash($msg_hash, "header");
+#
+# # generate xml string
+# my $msg_xml = &create_xml_string($msg_hash);
+#
+# # fetch a list of all target addresses
+# my @targets = keys(%$known_daemons);
+#
+# # itterates through the list an send each the msg
+# foreach my $target (@targets) {
+# if($target eq $bus_address) {next}; # do not send msg to bus
+#
+# # fetch the appropriated passwd
+# my $passwd = $known_daemons->{$target}->{passwd};
+#
+# # create ciphering object
+# my $act_cipher = &create_ciphering($passwd);
+#
+# # encrypt xml msg
+# my $crypted_msg = &encrypt_msg($msg_xml, $act_cipher);
+#
+# # open socket
+# my $socket = &open_socket($target);
+# if(not defined $socket){
+# daemon_log("ERROR: cannot open socket to $target , server not reachable", 1);
+# &update_known_daemons_entry(hostname=>$target, status=>"down");
+# next;
+# }
+#
+# # send xml msg
+# print $socket $crypted_msg."\n";
+#
+# close $socket;
+# daemon_log("send '$header'-msg to $target", 5);
+# daemon_log("crypted_msg:\n\t$crypted_msg", 7);
+# }
+# return;
+#}
#=== FUNCTION ================================================================
#===============================================================================
sub here_i_am {
my ($msg_hash) = @_ ;
- my $source = &get_content_from_xml_hash($msg_hash, "source");
-
- my $new_passwd = &create_passwd();
-
- # create known_daemons entry
- &create_known_daemons_entry($source);
- &update_known_daemons_entry(hostname=>$source, status=>"registered", passwd=>$bus_passwd);
+ my $source = @{$msg_hash->{source}}[0];;
+
+ my $new_key = &create_passwd();
+
+ # create bus_known_server entry
+ my $add_hash = {
+ table=>"bus_known_server",
+ primkey=>"hostname",
+ hostname=>$source,
+ status=>"registered",
+ hostkey=>$bus_passwd,
+ clients=>"",
+ };
+ $bus_known_server_db->add_dbentry($add_hash);
# create outgoing msg
- my $out_hash = &create_xml_hash("new_passwd", "$bus_ip:$bus_port", $source, $new_passwd);
- &send_msg_hash2address($out_hash, $source);
+ my $out_hash = &create_xml_hash("new_passwd", $bus_address, $source, $new_key);
+ &send_msg_hash2address($out_hash, $source, $bus_passwd);
- # change passwd, reason
- # &send_msg_hash2address takes $known_daemons->{"$source"}->{passwd} to cipher msg
- &update_known_daemons_entry(hostname=>$source, status=>"new_passwd", passwd=>$new_passwd);
+ # change hostkey, reason
+ my $update_hash = { table=>'bus_known_server' };
+ $update_hash->{where} = [ { hostname=>[$source] } ];
+ $update_hash->{update} = [ { hostkey=>[$new_key] } ];
+ $bus_known_server_db->update_dbentry($update_hash);
return;
}
#===============================================================================
sub confirm_new_passwd {
my ($msg_hash) = @_ ;
- my $source = &get_content_from_xml_hash($msg_hash, "source");
- &update_known_daemons_entry(hostname=>$source, status=>"confirmed_new_passwd");
+ my $source = @{$msg_hash->{source}}[0];
+
+ my $update_hash = { table=>'bus_known_server' };
+ $update_hash->{where} = [ { hostname=>[$source] } ];
+ $update_hash->{update} = [ { status=>['key_confirmed'] } ];
+ $bus_known_server_db->update_dbentry($update_hash);
+
return;
}
#===============================================================================
sub ping {
my ($msg_hash) = @_ ;
- my $source = &get_content_from_xml_hash($msg_hash, "source");
- &update_known_daemons_entry(hostname=>$source, status=>"ping");
+ my $header = @{$msg_hash->{header}}[0];
+ my $source = @{$msg_hash->{source}}[0];
+
+ my $update_hash = { table=>'bus_known_server',
+ where=> [ { hostname=>[$source] } ],
+ update=> [ { status=>$header } ],
+ };
+ $bus_known_server_db->update_dbentry($update_hash);
+
my $out_hash = &create_xml_hash("got_ping", $bus_address, $source);
- &send_msg_hash2address($out_hash, $source);
+
+ my $res = $bus_known_server_db->select_dbentry( { table=>'bus_known_server', hostname=>$source } );
+ my $hostkey = $res->{1}->{hostkey};
+ &send_msg_hash2address($out_hash, $source, $hostkey);
+
return;
}
# RETURNS: nothing
# DESCRIPTION: send ping message to address
#===============================================================================
-sub make_ping {
- my ($address) = @_;
- daemon_log("ping:$address\n", 1);
- my $out_hash = &create_xml_hash("ping", "$bus_ip:$bus_port", $address);
- &send_msg_hash2address($out_hash, $address);
- return;
-}
+#sub make_ping {
+# my ($address) = @_;
+# daemon_log("ping:$address\n", 1);
+# my $out_hash = &create_xml_hash("ping", "$bus_ip:$bus_port", $address);
+# &send_msg_hash2address($out_hash, $address);
+# return;
+#}
#=== FUNCTION ================================================================
#===============================================================================
sub got_ping {
my ($msg_hash) = @_;
- my $source = &get_content_from_xml_hash($msg_hash, "source");
- &update_known_daemons_entry(hostname=>$source, status=>"got_ping");
+ my $source = @{$msg_hash->{source}}[0];
+
+ my $update_hash = { table=>'bus_known_server',
+ where=> [ { hostname=>[$source] } ],
+ update=> [ { status=>'got_ping' } ],
+ };
+ $bus_known_server_db->update_dbentry($update_hash);
+
return;
}
#===============================================================================
sub new_client {
my ($msg_hash) = @_ ;
- my $source = &get_content_from_xml_hash($msg_hash, "source");
- my $header = &get_content_from_xml_hash($msg_hash, "header");
- my $new_client = (&get_content_from_xml_hash($msg_hash, $header))[0];
+ my $source = @{$msg_hash->{source}}[0];
+ my $header = @{$msg_hash->{header}}[0];
+ my $new_client = @{$msg_hash->{$header}}[0];
- &update_known_daemons_entry(hostname=>$source, client=>$new_client);
+ my $res = $bus_known_server_db->select_dbentry( { table=>'bus_known_server', hostname=>$source } );
+ my $clients = $res->{1}->{clients};
+
+ # if host has alread more clients, than just append
+ if( length($clients) != 0 ) {
+ $clients .= ",$new_client";
+ } else {
+ $clients = $new_client;
+ }
+
+ my $update_hash = { table=>'bus_known_server',
+ where=>[ {hostname=>[$source] } ],
+ update=>[ {clients=>[$clients] } ],
+ };
+
+ $bus_known_server_db->update_dbentry( $update_hash );
return;
}
# RETURNS: nothing
# DESCRIPTION: process this incoming message
#===============================================================================
-sub delete_client {
- my ($msg_hash) = @_ ;
- my $source = &get_content_from_xml_hash($msg_hash, "source");
- my $header = &get_content_from_xml_hash($msg_hash, "header");
- my $del_client = (&get_content_from_xml_hash($msg_hash, $header))[0];
-
- if (not exists $known_daemons->{$source}->{$del_client}) {
- daemon_log
- }
- delete $known_daemons->{$source}->{$del_client};
-
- return;
-}
+#sub delete_client {
+# my ($msg_hash) = @_ ;
+# my $source = &get_content_from_xml_hash($msg_hash, "source");
+# my $header = &get_content_from_xml_hash($msg_hash, "header");
+# my $del_client = (&get_content_from_xml_hash($msg_hash, $header))[0];
+#
+# if (not exists $known_daemons->{$source}->{$del_client}) {
+# daemon_log
+# }
+# delete $known_daemons->{$source}->{$del_client};
+#
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: nome est omen
#===============================================================================
-sub print_known_daemons_hash {
- my ($tmp) = @_;
- print "####################################\n";
- print "# status of known_daemons\n";
- my $hosts;
- my $host_hash;
- $shmkh->shlock(LOCK_EX);
- my @hosts = keys %$known_daemons;
- foreach my $host (@hosts) {
- my $status = $known_daemons->{$host}->{status} ;
- my $passwd = $known_daemons->{$host}->{passwd};
- my $timestamp = $known_daemons->{$host}->{timestamp};
- my @clients = keys %{$known_daemons->{$host}->{clients}};
- my $client_string = join(", ", @clients);
- print "$host\n";
- print "\tstatus: $status\n";
- print "\tpasswd: $passwd\n";
- print "\ttimestamp: $timestamp\n";
- print "\tclients: $client_string\n";
-
- }
- $shmkh->shunlock(LOCK_EX);
- print "####################################\n\n";
- return;
-}
+#sub print_known_daemons_hash {
+# my ($tmp) = @_;
+# print "####################################\n";
+# print "# status of known_daemons\n";
+# my $hosts;
+# my $host_hash;
+# $shmkh->shlock(LOCK_EX);
+# my @hosts = keys %$known_daemons;
+# foreach my $host (@hosts) {
+# my $status = $known_daemons->{$host}->{status} ;
+# my $passwd = $known_daemons->{$host}->{passwd};
+# my $timestamp = $known_daemons->{$host}->{timestamp};
+# my @clients = keys %{$known_daemons->{$host}->{clients}};
+# my $client_string = join(", ", @clients);
+# print "$host\n";
+# print "\tstatus: $status\n";
+# print "\tpasswd: $passwd\n";
+# print "\ttimestamp: $timestamp\n";
+# print "\tclients: $client_string\n";
+#
+# }
+# $shmkh->shunlock(LOCK_EX);
+# print "####################################\n\n";
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: nome est omen
#===============================================================================
-sub create_known_daemons_entry {
- my ($hostname) = @_;
- $shmkh->shlock(LOCK_EX);
- $known_daemons->{$hostname} = {};
- $known_daemons->{$hostname}->{status} = "none";
- $known_daemons->{$hostname}->{passwd} = "none";
- $known_daemons->{$hostname}->{timestamp} = "none";
- $known_daemons->{$hostname}->{clients} = {};
- $shmkh->shunlock(LOCK_EX);
- return;
-}
+#sub create_known_daemons_entry {
+# my ($hostname) = @_;
+# $shmkh->shlock(LOCK_EX);
+# $known_daemons->{$hostname} = {};
+# $known_daemons->{$hostname}->{status} = "none";
+# $known_daemons->{$hostname}->{passwd} = "none";
+# $known_daemons->{$hostname}->{timestamp} = "none";
+# $known_daemons->{$hostname}->{clients} = {};
+# $shmkh->shunlock(LOCK_EX);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub update_known_daemons_entry {
- my $arg = {
- hostname => undef, status => undef, passwd => undef,
- client => undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- my $passwd = $arg->{passwd};
- my $client = $arg->{client};
-
- if (not defined $hostname) {
- daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
- return;
- }
-
- my ($seconds, $minutes, $hours, $monthday, $month,
- $year, $weekday, $yearday, $sommertime) = localtime(time);
- $hours = $hours < 10 ? $hours = "0".$hours : $hours;
- $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
- $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
- $month+=1;
- $month = $month < 10 ? $month = "0".$month : $month;
- $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
- $year+=1900;
- my $t = "$year$month$monthday$hours$minutes$seconds";
-
- $shmkh->shlock(LOCK_EX);
- if (defined $status) {
- $known_daemons->{$hostname}->{status} = $status;
- }
- if (defined $passwd) {
- $known_daemons->{$hostname}->{passwd} = $passwd;
- }
- if (defined $client) {
- $known_daemons->{$hostname}->{clients}->{$client} = "";
- }
- $known_daemons->{$hostname}->{timestamp} = $t;
- $shmkh->shunlock(LOCK_EX);
- return;
-}
+#sub update_known_daemons_entry {
+# my $arg = {
+# hostname => undef, status => undef, passwd => undef,
+# client => undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# my $passwd = $arg->{passwd};
+# my $client = $arg->{client};
+#
+# if (not defined $hostname) {
+# daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
+# return;
+# }
+#
+# my ($seconds, $minutes, $hours, $monthday, $month,
+# $year, $weekday, $yearday, $sommertime) = localtime(time);
+# $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+# $month+=1;
+# $month = $month < 10 ? $month = "0".$month : $month;
+# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+# $year+=1900;
+# my $t = "$year$month$monthday$hours$minutes$seconds";
+#
+# $shmkh->shlock(LOCK_EX);
+# if (defined $status) {
+# $known_daemons->{$hostname}->{status} = $status;
+# }
+# if (defined $passwd) {
+# $known_daemons->{$hostname}->{passwd} = $passwd;
+# }
+# if (defined $client) {
+# $known_daemons->{$hostname}->{clients}->{$client} = "";
+# }
+# $known_daemons->{$hostname}->{timestamp} = $t;
+# $shmkh->shunlock(LOCK_EX);
+# return;
+#}
#==== MAIN = main ==============================================================
if( !$foreground ) { exit( 0 ) };
}
+# connect to bus_known_server_db
+my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'clients' );
+$bus_known_server_db = GOSA::DBsqlite->new($bus_known_server_file_name);
+$bus_known_server_db->create_table('bus_known_server', \@server_col_names);
+
+
# detect own ip and mac address
($bus_ip, $bus_mac_address) = &get_ip_and_mac();
if (not defined $bus_ip) {
daemon_log("bus ip address detected: $bus_ip", 1);
daemon_log("bus mac address detected: $bus_mac_address", 1);
+# complete addresses
+$bus_address = "$bus_ip:$bus_port";
# setup xml parser
$xml = new XML::Simple();
}
# add bus to known_daemons
-&create_known_daemons_entry($bus_address);
-&update_known_daemons_entry(hostname=>$bus_address, status=>"bus", passwd=>$bus_passwd);
+
+#&create_known_daemons_entry($bus_address);
+#&update_known_daemons_entry(hostname=>$bus_address, status=>"bus", passwd=>$bus_passwd);
while(1) {
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 6f54d2d0688a69924b25486506862c47388e871b..520ba5e0003086dd3b38dc7766e4e5b375de78d6 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
my ($bus, $msg_to_bus, $bus_cipher);
my ($server, $server_mac_address, $server_events);
my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name);
-my ($known_daemons, $shmda, $known_clients, $shmcl, $known_modules, $known_clients_file_name, $known_server_file_name, $known_clients_db, $known_server_db);
+my ($known_modules, $known_clients_file_name, $known_server_file_name);
my ($max_clients);
my ($pid_file, $procid, $pid, $log_file);
my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout);
# holds all other gosa-sd as well as the gosa-sd-bus
our $known_server_db;
-#our $known_daemons = {};
-#our $shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1,
-# exclusive => 1,
-# mode => 0666,
-# destroy => 1,
-# });
# holds all registrated clients
our $known_clients_db;
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub add_content2known_daemons {
- my $arg = {
- hostname => undef, status => undef, passwd => undef,
- mac_address => undef, events => undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- my $passwd = $arg->{passwd};
- my $mac_address = $arg->{mac_address};
- my $events = $arg->{events};
-
- if (not defined $hostname) {
- daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
- return;
- }
-
- my ($seconds, $minutes, $hours, $monthday, $month,
- $year, $weekday, $yearday, $sommertime) = localtime(time);
- $hours = $hours < 10 ? $hours = "0".$hours : $hours;
- $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
- $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
- $month+=1;
- $month = $month < 10 ? $month = "0".$month : $month;
- $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
- $year+=1900;
- my $t = "$year$month$monthday$hours$minutes$seconds";
-
- $shmda->shlock(LOCK_EX);
- if (defined $status) {
- $known_daemons->{$hostname}->{status} = $status;
- }
- if (defined $passwd) {
- $known_daemons->{$hostname}->{passwd} = $passwd;
- }
- if (defined $mac_address) {
- $known_daemons->{$hostname}->{mac_address} = $mac_address;
- }
- if (defined $events) {
- $known_daemons->{$hostname}->{events} = $events;
- }
- $known_daemons->{$hostname}->{timestamp} = $t;
- $shmda->shlock(LOCK_EX);
- return;
-}
+#sub add_content2known_daemons {
+# my $arg = {
+# hostname => undef, status => undef, passwd => undef,
+# mac_address => undef, events => undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# my $passwd = $arg->{passwd};
+# my $mac_address = $arg->{mac_address};
+# my $events = $arg->{events};
+#
+# if (not defined $hostname) {
+# daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
+# return;
+# }
+#
+# my ($seconds, $minutes, $hours, $monthday, $month,
+# $year, $weekday, $yearday, $sommertime) = localtime(time);
+# $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+# $month+=1;
+# $month = $month < 10 ? $month = "0".$month : $month;
+# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+# $year+=1900;
+# my $t = "$year$month$monthday$hours$minutes$seconds";
+#
+# $shmda->shlock(LOCK_EX);
+# if (defined $status) {
+# $known_daemons->{$hostname}->{status} = $status;
+# }
+# if (defined $passwd) {
+# $known_daemons->{$hostname}->{passwd} = $passwd;
+# }
+# if (defined $mac_address) {
+# $known_daemons->{$hostname}->{mac_address} = $mac_address;
+# }
+# if (defined $events) {
+# $known_daemons->{$hostname}->{events} = $events;
+# }
+# $known_daemons->{$hostname}->{timestamp} = $t;
+# $shmda->shlock(LOCK_EX);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub update_known_daemons {
- my $arg = {
- hostname => undef, status => undef, passwd => undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- my $passwd = $arg->{passwd};
-
- if (not defined $hostname) {
- daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
- return;
- }
-
- my ($seconds, $minutes, $hours, $monthday, $month,
- $year, $weekday, $yearday, $sommertime) = localtime(time);
- $hours = $hours < 10 ? $hours = "0".$hours : $hours;
- $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
- $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
- $month+=1;
- $month = $month < 10 ? $month = "0".$month : $month;
- $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
- $year+=1900;
- my $t = "$year$month$monthday$hours$minutes$seconds";
-
- $shmda->shlock(LOCK_EX);
- if (defined $status) {
- $known_daemons->{$hostname}->{status} = $status;
- }
- if (defined $passwd) {
- $known_daemons->{$hostname}->{passwd} = $passwd;
- }
- $known_daemons->{$hostname}->{timestamp} = $t;
- $shmda->shunlock(LOCK_EX);
- return;
-}
+#sub update_known_daemons {
+# my $arg = {
+# hostname => undef, status => undef, passwd => undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# my $passwd = $arg->{passwd};
+#
+# if (not defined $hostname) {
+# daemon_log("ERROR: function add_content2known_daemons is not invoked with requiered parameter 'hostname'", 1);
+# return;
+# }
+#
+# my ($seconds, $minutes, $hours, $monthday, $month,
+# $year, $weekday, $yearday, $sommertime) = localtime(time);
+# $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+# $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+# $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+# $month+=1;
+# $month = $month < 10 ? $month = "0".$month : $month;
+# $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+# $year+=1900;
+# my $t = "$year$month$monthday$hours$minutes$seconds";
+#
+# $shmda->shlock(LOCK_EX);
+# if (defined $status) {
+# $known_daemons->{$hostname}->{status} = $status;
+# }
+# if (defined $passwd) {
+# $known_daemons->{$hostname}->{passwd} = $passwd;
+# }
+# $known_daemons->{$hostname}->{timestamp} = $t;
+# $shmda->shunlock(LOCK_EX);
+# return;
+#}
#=== FUNCTION ================================================================
daemon_log("ERROR: cannot add entry to known_clients.db: $res", 1);
}
-# $shmcl->shlock(LOCK_EX);
-# $known_clients->{$hostname} = {};
-# $known_clients->{$hostname}->{status} = "none";
-# $known_clients->{$hostname}->{passwd} = "none";
-# $known_clients->{$hostname}->{timestamp} = "none";
-# $known_clients->{$hostname}->{mac_address} = "none";
-# $known_clients->{$hostname}->{events} = "none";
-# $shmcl->shunlock(LOCK_EX);
return;
}
# RETURNS: nothing
# DESCRIPTION: nome est omen and updates each time the timestamp of hostname
#===============================================================================
-sub update_known_clients {
- my $arg = {
- hostname => undef, status => undef, hostkey => undef,
- macaddress => undef, events => undef, timestamp=>undef,
- @_ };
- my $hostname = $arg->{hostname};
- my $status = $arg->{status};
- my $hostkey = $arg->{hostkey};
- my $macaddress = $arg->{macaddress};
- my $events = $arg->{events};
- my $timestamp = $arg->{timestamp};
-
- if (not defined $hostname) {
- daemon_log("ERROR: function add_content2known_clients is not invoked with requiered parameter 'hostname'", 1);
- return;
- }
-
- my ($seconds, $minutes, $hours, $monthday, $month,
- $year, $weekday, $yearday, $sommertime) = localtime(time);
- $hours = $hours < 10 ? $hours = "0".$hours : $hours;
- $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
- $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
- $month+=1;
- $month = $month < 10 ? $month = "0".$month : $month;
- $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
- $year+=1900;
- my $t = "$year$month$monthday$hours$minutes$seconds";
-
- my $change_entry = { table=>'known_clients',
- where=>'hostname',
- timestamp=>$t,
- };
-
-
- if (defined $status) {
- $change_entry->{status} = $status;
- }
- if (defined $hostkey) {
- $change_entry->{hostkey} = $hostkey;
- }
- if (defined $macaddress) {
- $change_entry->{macaddress} = $macaddress;
- }
- if (defined $events) {
- $change_entry->{events} = $events;
- }
-
- $known_clients->change_dbentry($change_entry);
- return;
-}
+#sub update_known_clients {
+# my $arg = {
+# hostname => undef, status => undef, hostkey => undef,
+# macaddress => undef, events => undef, timestamp=>undef,
+# @_ };
+# my $hostname = $arg->{hostname};
+# my $status = $arg->{status};
+# my $hostkey = $arg->{hostkey};
+# my $macaddress = $arg->{macaddress};
+# my $events = $arg->{events};
+# my $timestamp = $arg->{timestamp};
+#
+# if (not defined $hostname) {
+# daemon_log("ERROR: function add_content2known_clients is not invoked with requiered parameter 'hostname'", 1);
+# return;
+# }
+#
+# my $change_entry = { table=>'known_clients',
+# where=>'hostname',
+# timestamp=>&get_time,
+# };
+#
+#
+# if (defined $status) {
+# $change_entry->{status} = $status;
+# }
+# if (defined $hostkey) {
+# $change_entry->{hostkey} = $hostkey;
+# }
+# if (defined $macaddress) {
+# $change_entry->{macaddress} = $macaddress;
+# }
+# if (defined $events) {
+# $change_entry->{events} = $events;
+# }
+#
+# $known_clients->change_dbentry($change_entry);
+# return;
+#}
#=== FUNCTION ================================================================
# RETURNS:
# DESCRIPTION:
#===============================================================================
-sub clean_up_known_clients {
- my ($address) = @_ ;
-
- if (not exists $known_clients->{$address}) {
- daemon_log("cannot prune known_clients from $address, client not known", 5);
- return;
- }
-
- delete $known_clients->{$address};
-
- # send bus a msg that address was deleted from known_clients
- my $out_hash = &create_xml_hash('delete_client', $server_address, $bus_address, $address);
- &send_msg_hash2bus($out_hash);
-
- daemon_log("client $address deleted from known_clients because of multiple down time", 3);
- return;
-}
+#sub clean_up_known_clients {
+# my ($address) = @_ ;
+#
+# if (not exists $known_clients->{$address}) {
+# daemon_log("cannot prune known_clients from $address, client not known", 5);
+# return;
+# }
+#
+# delete $known_clients->{$address};
+#
+# # send bus a msg that address was deleted from known_clients
+# my $out_hash = &create_xml_hash('delete_client', $server_address, $bus_address, $address);
+# &send_msg_hash2bus($out_hash);
+#
+# daemon_log("client $address deleted from known_clients because of multiple down time", 3);
+# return;
+#}
#=== FUNCTION ================================================================
index 840bce0d6fb7d67abd90f4ea0b28ce5a0a2ecb7a..5bee915c414a74b42152acc92d4beaf4bd8dd92b 100644 (file)
if ( ( defined $primkey ) && ( not $arg->{ $primkey } ) ) {
return 2;
}
+
+ # if timestamp is not provided, add timestamp
+ if( not exists $arg->{timestamp} ) {
+ $arg->{timestamp} = &get_time;
+ }
# check wether primkey is unique in table, otherwise return errorflag 3
my $res = @{ $obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'") };
}
}
-# # check wether primkey is unique in table, otherwise return errorflag 3
-# if ( defined $primkey ) {
-# my $res = @{ $obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'") };
-# if ($res != 0) {
-# return 3;
-# }
-# }
-#
-# # fetch column names of table
-# my $col_names = $obj->get_table_columns($table);
-#
-# # assign values to column name variables
-# my @add_list;
-# foreach my $col_name (@{$col_names}) {
-# # use function parameter for column values
-# if (exists $arg->{$col_name}) {
-# push(@add_list, $arg->{$col_name});
-# }
-# }
-#
-# my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."')";
-# my $db_res = $obj->{dbh}->do($sql_statement);
-# return 0;
-
}
return \@res;
}
+sub get_time {
+ my ($seconds, $minutes, $hours, $monthday, $month,
+ $year, $weekday, $yearday, $sommertime) = localtime(time);
+ $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+ $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+ $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+ $month+=1;
+ $month = $month < 10 ? $month = "0".$month : $month;
+ $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+ $year+=1900;
+ return "$year$month$monthday$hours$minutes$seconds";
+}
+
+
1;
index bb3a305811ab71224ff3ba417d3f8b8ad193e405..0238769913dfe669ea87a9b5f4411323561f7ec7 100644 (file)
# RETURNS: nothing
# DESCRIPTION: ????
#===============================================================================
-sub send_msg_hash2address {
+sub send_msg_hash2address ($$$){
my ($msg_hash, $address, $passwd) = @_ ;
# fetch header for logging
index ea9632d1e11d9d9951e8d5f9c4efd95f73b01604..803a95614b59ab74404383046d85e4c1207a67eb 100644 (file)
} else {
# msg is for one host
- my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} );
+ my $query_res;
+ $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} );
if( 1 == keys %{$query_res} ) {
$host_key = $query_res->{1}->{host_key};
&send_msg_hash2address($msg_hash, $target, $host_key);
return;
}
- my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} );
+ $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} );
if( 1 == keys %{$query_res} ) {
$host_key = $query_res->{1}->{host_key};
&send_msg_hash2address($msg_hash, $target, $host_key);
hostkey=>$new_passwd,
timestamp=>&get_time,
} );
-# if ($res == 3) {
-# my $update_hash = { table=>'known_clients' };
-# $update_hash->{where} = [ { hostname=>[$source] } ];
-# $update_hash->{update} = [ { events=>[$events],
-# macaddress=>[$mac_address],
-# status=>['registered'],
-# hostkey=>[$new_passwd],
-# timestamp=>[&get_time],
-# } ];
-# $res = $main::known_clients_db->update_dbentry( $update_hash );
-# }
- if ($res != 1) {
+
+ if ($res != 0) {
&main::daemon_log("ERROR: cannot add entry to known_clients: $res");
return;
}
# notify registered client to bus
if( $bus_activ eq "on") {
- &main::daemon_log("send bus msg that client '$source' has registerd at server '$server_address'", 3);
+ # fetch actual bus key
+ my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server'} );
+ my $hostkey = $query_res->{1}->{hostkey};
+
+ # send update msg to bus
$out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
- &send_msg_hash2address($out_hash, $bus_address);
+ &send_msg_hash2address($out_hash, $bus_address, $hostkey);
+
+ &main::daemon_log("send bus msg that client '$source' has registerd at server '$server_address'", 3);
}
# give the new client his ldap config
my $hit_counter = keys %{$res};
if( not $hit_counter == 1 ) {
&main::daemon_log("ERROR: more or no hit found in known_clients_db by query by '$address'", 1);
- my $tmp = print Dumer $res;
}
my $macaddress = $res->{1}->{macaddress};
index 0384e9535d004910b95fc7518fdeed07ad6b5724..03509692c2d9d62ca9ee3e2b0e80063bbfe10114 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
/* Prepare a hunge bunch of data to be send */
# add
- #$data = "<xml><header>gosa_ping</header><source>10.89.1.155:20082</source><target></target><mac>11:22:33:44:55</mac></xml>";
+ $data = "<xml><header>gosa_ping</header><source>10.89.1.155:20082</source><target>10.89.1.155:20080</target></xml>";
#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>19700101000000</timestamp> </xml>";
#$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
#$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
#$data = "<xml><header>gosa_query_jobdb</header><where>status</where><status>waiting</status></xml>";
# clear
- $data = "<xml> <header>gosa_clear_jobdb</header> </xml>";
+ #$data = "<xml> <header>gosa_clear_jobdb</header> </xml>";
$sock->write($data);