From: rettenbe Date: Wed, 2 Jan 2008 13:03:17 +0000 (+0000) Subject: gosa-si-server ver. 2.0 (unstable) X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6286ed4aab97aa07d977d56f53d84cd6dfc6ce79;p=gosa.git gosa-si-server ver. 2.0 (unstable) git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8174 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/DBsqlite.pm b/gosa-si/DBsqlite.pm new file mode 100644 index 000000000..f82a0d973 --- /dev/null +++ b/gosa-si/DBsqlite.pm @@ -0,0 +1,243 @@ +package DBsqlite; + + +use strict; +use warnings; +use DBI; +use Data::Dumper; + + + +sub new { + my $object = shift; + my $db_name = shift; + + my $obj_ref = {}; + bless($obj_ref,$object); + my $dbh = DBI->connect("dbi:SQLite:dbname=$db_name"); + $obj_ref->{dbh} = $dbh; + + return($obj_ref); +} + + +sub create_table { + my $object = shift; + my $table_name = shift; + my $col_names_ref = shift; + my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name (".join(', ', @{$col_names_ref}).")"; + $object->{dbh}->do($sql_statement); + return 0; +} + + + +sub add_dbentry { + + my $obj = shift; + my $arg = shift; + + # if dbh not specified, return errorflag 1 + my $table = $arg->{table}; + if (not defined $table) { + return 1; + } + + # incrementing running id + if (not exists $arg->{id}) { + my $max_id = @{@{$obj->{dbh}->selectall_arrayref("SELECT MAX(id) FROM $table")}[0]}[0]; + if (not defined $max_id) { + $max_id = 0; + } + $arg->{id} = $max_id + 1; + } + + + # 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}) { + if (exists $arg->{$col_name}) { + push(@add_list, $arg->{$col_name}); + } else { + my $default_val = "none"; + if ($col_name eq "timestamp") { + $default_val = "19700101000000"; + } + push(@add_list, $default_val); + } + + } + + # check wether id does not exists in table, otherwise return errorflag 2 + my $res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE id='$arg->{id}'")}; + if ($res != 0) { + return 2; + } + + my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."') "; + print " INSERT INTO $table VALUES ('".join("', '", @add_list)."')\n"; + $obj->{dbh}->do($sql_statement); + + return 0; + +} + +sub change_dbentry { + my $obj = shift; + my $arg = shift; + + # check completeness of function parameter + # extract table statement from arg hash + my $table = $arg->{table}; + if (not defined $table) { + return 1; + } else { + delete $arg->{table}; + } + # extract where parameter from arg hash + my $restric_pram = $arg->{where}; + if (not defined $restric_pram) { + return 2; + } else { + delete $arg->{'where'}; + } + # extrac where value from arg hash + my $restric_val = $arg->{$restric_pram}; + if (not defined $restric_val) { + return 3; + } else { + delete $arg->{$restric_pram}; + } + + # check wether table has all specified columns + my $columns = {}; + my @res = @{$obj->{dbh}->selectall_arrayref("pragma table_info('$table')")}; + foreach my $column (@res) { + $columns->{@$column[1]} = ""; + } + my @pram_list = keys %$arg; + foreach my $pram (@pram_list) { + if (not exists $columns->{$pram}) { + return 4; + } + } + + + # select all changes + my @change_list; + my $sql_part; + + while (my($pram, $val) = each(%{$arg})) { + push(@change_list, "$pram='$val'"); + } + + if (not@change_list) { + return 5; + } + + $obj->{dbh}->do("UPDATE $table SET ".join(', ',@change_list)." WHERE $restric_pram='$restric_val'"); + return 0; +} + + +sub del_dbentry { + my $obj = shift; + my $arg = shift; + + # check completeness of function parameter + # extract table statement from arg hash + my $table = $arg->{table}; + if (not defined $table) { + return 1; + } else { + delete $arg->{table}; + } + # extract where parameter from arg hash + my $restric_pram = $arg->{where}; + if (not defined $restric_pram) { + return 2; + } else { + delete $arg->{'where'}; + } + # extrac where value from arg hash + my $restric_val = $arg->{$restric_pram}; + if (not defined $restric_val) { + return 3; + } else { + delete $arg->{$restric_pram}; + } + + # check wether entry exists + my $res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE $restric_pram='$restric_val'")}; + if ($res == 0) { + return 4; + } + + $obj->{dbh}->do("DELETE FROM $table WHERE $restric_pram='$restric_val'"); + + return 0; +} + + +sub get_table_columns { + my $obj = shift; + my $table = shift; + + my @columns; + my @res = @{$obj->{dbh}->selectall_arrayref("pragma table_info('$table')")}; + foreach my $column (@res) { + push(@columns, @$column[1]); + } + + return \@columns; +} + +sub select_dbentry { + my $obj = shift; + my $arg = shift; + + # check completeness of function parameter + # extract table statement from arg hash + my $table = $arg->{table}; + if (not defined $table) { + return 1; + } else { + delete $arg->{table}; + } + + # collect select statements + my @select_list; + my $sql_part; + while (my ($pram, $val) = each %{$arg}) { + push(@select_list, "$pram = '$val'"); + } + + my $sql_statement = "SELECT * FROM 'jobs' WHERE ".join(' AND ', @select_list); + my $answer = $obj->{dbh}->selectall_arrayref($sql_statement); + return $answer; +} + + +sub show_table { + my $obj = shift; + my $table_name = shift; + my @res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table_name")}; + my @answer; + foreach my $hit (@res) { + push(@answer, "hit: ".join(', ', @{$hit})); + } + return join("\n", @answer); +} + + +sub exec_statement { + my $obj = shift; + my $sql_statement = shift; + my @res = @{$obj->{dbh}->selectall_arrayref($sql_statement)}; + return \@res; +} + +1; diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus index 6022c37c5..90de439b5 100755 --- a/gosa-si/gosa-si-bus +++ b/gosa-si/gosa-si-bus @@ -662,7 +662,7 @@ sub create_xml_hash { sub create_xml_string { my ($xml_hash) = @_ ; my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml'); - $xml_string =~ s/[\n]+//g; + #$xml_string =~ s/[\n]+//g; return $xml_string; } diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index b7c64d956..d45e64bc3 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -338,7 +338,7 @@ sub register_at_server { # create msg hash my $register_hash = &create_xml_hash("here_i_am", $client_address, $server); &add_content2xml_hash($register_hash, "new_passwd", $new_server_passwd); - &add_content2xml_hash($register_hash, "client_mac_address", $client_mac_address); + &add_content2xml_hash($register_hash, "mac_address", $client_mac_address); &add_content2xml_hash($register_hash, "events", $events); # send xml hash to server with general server passwd @@ -820,12 +820,13 @@ sub process_incoming_msg { return; } - my $header = &get_content_from_xml_hash($msg_hash, "header"); + my $header = @{$msg_hash->{header}}[0]; - daemon_log("header from msg:", 1); - daemon_log("\t$header", 1); - daemon_log("msg to process:", 7); - daemon_log("\t$msg", 7); + daemon_log("recieve '$header' from $host", 1); +# daemon_log("header from msg:", 1); +# daemon_log("\t$header", 1); +# daemon_log("msg to process:", 7); +# daemon_log("\t$msg", 7); #check whether msg to process is a event opendir(DIR, $event_dir) diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index 027814b80..afa087216 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -38,19 +38,20 @@ use Cwd; use File::Spec; use IPC::Shareable qw( :lock); IPC::Shareable->clean_up_all; +use GosaSupportDaemon; use lib "/etc/gosa-si/modules"; my $modules_path = "/etc/gosa-si/modules"; -my ($cfg_file, %cfg_defaults, $foreground, $verbose, $ping_timeout, $no_bus); +my (%cfg_defaults, $foreground, $verbose, $ping_timeout); my ($bus, $msg_to_bus, $bus_cipher); my ($server, $server_mac_address, $server_events); -my ($gosa_server); +my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name); my ($known_daemons, $shmda, $known_clients, $shmcl, $known_modules); my ($max_clients); my ($pid_file, $procid, $pid, $log_file); my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout); -my ($arp_activ, $arp_fifo, $arp_fifo_path, $no_arp); +my ($arp_activ, $arp_fifo, $arp_fifo_path); # variables declared in config file are always set to 'our' our (%cfg_defaults, $log_file, $pid_file, @@ -65,6 +66,11 @@ our $xml; our $server_address; our $bus_address; our $gosa_address; +our $no_bus; +our $no_arp; +our $verbose; +our $forground; +our $cfg_file; # specifies the verbosity of the daemon_log $verbose = 0 ; @@ -79,6 +85,9 @@ $no_bus = 0; $no_arp = 0; +# name of table for storing gosa jobs +$job_queue_table_name = 'jobs'; + # holds all other gosa-sd as well as the gosa-sd-bus our $known_daemons = {}; our $shmda = tie($known_daemons, 'IPC::Shareable', undef, {create => 1, @@ -102,6 +111,8 @@ our $shmcl = tie($known_clients, 'IPC::Shareable', undef, {create => 1, "child_max" => [\$child_max, 10], "child_min" => [\$child_min, 3], "child_timeout" => [\$child_timeout, 180], + "job_queue_timeout" => [\$job_queue_timeout, undef], + "job_queue_file_name" => [\$job_queue_file_name, '/tmp/jobs.db'], }, "bus" => {"bus_activ" => [\$bus_activ, "on"], @@ -143,6 +154,9 @@ usage: $0 [-hvf] [-c config] -c : config file -f : foreground, process will not be forked to background -v : be verbose (multiple to increase verbosity) + -no-bus : starts $0 without connection to bus + -no-arp : starts $0 without connection to arp module + EOF print "\n" ; } @@ -183,7 +197,7 @@ sub read_configfile { # DESCRIPTION: function for logging #=============================================================================== sub daemon_log { -# log into log_file + # log into log_file my( $msg, $level ) = @_; if(not defined $msg) { return } if(not defined $level) { $level = 1 } @@ -198,7 +212,7 @@ sub daemon_log { if(defined $foreground) { print $msg."\n" } } } - close( LOG_HANDLE ); +# close( LOG_HANDLE ); #log into syslog # my ($msg, $level, $facility) = @_; # if(not defined $msg) {return} @@ -314,9 +328,11 @@ sub get_ip_and_mac { #=== FUNCTION ================================================================ # NAME: import_modules -# PARAMETERS: module_path - string - abs. path to the directory the modules are stored +# PARAMETERS: module_path - string - abs. path to the directory the modules +# are stored # RETURNS: nothing -# DESCRIPTION: each file in module_path which ends with '.pm' is imported by "require 'file';" +# DESCRIPTION: each file in module_path which ends with '.pm' is imported by +# "require 'file';" #=============================================================================== sub import_modules { daemon_log(" ", 1); @@ -337,10 +353,13 @@ sub import_modules { next; } my $mod_name = $1; - my $module_tag_hash = eval( $mod_name.'::get_module_tags()' ); - $known_modules->{$mod_name} = $module_tag_hash; + #my $module_tag_hash = eval( $mod_name.'::get_module_tags()' ); + + my $info = eval($mod_name.'::get_module_info()'); + my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info}; + $known_modules->{$mod_name} = $info; - daemon_log("load module $mod_name", 1); + daemon_log("module $mod_name loaded", 1); } # for debugging @@ -352,30 +371,6 @@ sub import_modules { } -#=== FUNCTION ================================================================ -# NAME: register_at_bus -# PARAMETERS: nothing -# RETURNS: nothing -# DESCRIPTION: creates an entry in known_daemons and send a 'here_i_am' msg to bus -#=============================================================================== -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); - - my $msg_hash = &create_xml_hash("here_i_am", "$server_ip:$server_port", $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; -} - - #=== FUNCTION ================================================================ # NAME: sig_int_handler # PARAMETERS: signal - string - signal arose from system @@ -419,6 +414,7 @@ sub activating_child { my $pipe_wr = $$child{'pipe_wr'}; my $pipe_rd = $$child{'pipe_rd'}; $$child{client_ref} = $client; + daemon_log("activating: childpid:$$child{'pid'}", 5); print $pipe_wr $msg.".".$host."\n"; @@ -515,23 +511,22 @@ sub get_processing_child { # forward msg to all imported modules no strict "refs"; my $answer; - while( my ($module, $tag_hash) = each(%$known_modules)) { - #if(exists $known_modules->{$module}->{server_packages}) { + my %act_modules = %$known_modules; + while( my ($module, $info) = each(%act_modules)) { my $tmp = &{ $module."::process_incoming_msg" }($msg); if (defined $tmp) { $answer = $tmp; } - #} } #&print_known_daemons(); #&print_known_clients(); daemon_log("processing of msg finished", 5); - - if (defined $answer) { + + if (defined $answer) { print $PARENT_wr $answer."\n"; - daemon_log("\t$answer", 5); + daemon_log("with answer: $answer", 5); daemon_log(" ", 5); } else { print $PARENT_wr "done"."\n"; @@ -566,203 +561,6 @@ sub get_processing_child { } -#=== FUNCTION ================================================================ -# NAME: process_incoming_msg -# PARAMETERS: crypted_msg - string - incoming crypted message -# RETURNS: nothing -# DESCRIPTION: handels the proceeded distribution to the appropriated functions -#=============================================================================== -sub process_incoming_msg { - my ($crypted_msg) = @_; - if(not defined $crypted_msg) { - daemon_log("function 'process_incoming_msg': got no msg", 7); - } - $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); - daemon_log("msg from host:", 1); - daemon_log("\t$host", 1); - #daemon_log("crypted msg:", 7); - #daemon_log("\t$crypted_msg", 7); - - # collect addresses from possible incoming clients - my @valid_keys; - my @host_keys = keys %$known_daemons; - foreach my $host_key (@host_keys) { - if($host_key =~ "^$host") { - push(@valid_keys, $host_key); - } - } - my @client_keys = keys %$known_clients; - foreach my $client_key (@client_keys) { - if($client_key =~ "^$host"){ - push(@valid_keys, $client_key); - } - } - push(@valid_keys, $server_address); - - my $l = @valid_keys; - my ($msg, $msg_hash); - my $msg_flag = 0; - - # determine the correct passwd for deciphering of the incoming msgs - foreach my $host_key (@valid_keys) { - eval{ - daemon_log( "key: $host_key", 7); - my $key_passwd; - if (exists $known_daemons->{$host_key}) { - $key_passwd = $known_daemons->{$host_key}->{passwd}; - } elsif (exists $known_clients->{$host_key}) { - $key_passwd = $known_clients->{$host_key}->{passwd}; - } elsif ($host_key eq $server_address) { - $key_passwd = $server_passwd; - } - daemon_log("key_passwd: $key_passwd", 7); - my $key_cipher = &create_ciphering($key_passwd); - $msg = &decrypt_msg($crypted_msg, $key_cipher); - $msg_hash = $xml->XMLin($msg, ForceArray=>1); - }; - if($@) { - daemon_log("key raise error", 7); - $msg_flag += 1; - } else { - last; - } - } - - if($msg_flag >= $l) { - daemon_log("ERROR: do not understand the message:", 1); - daemon_log("\t$msg", 1); - return; - } - - # process incoming msg - my $header = &get_content_from_xml_hash($msg_hash, "header"); - my $source = @{$msg_hash->{source}}[0]; - - daemon_log("header from msg:", 1); - daemon_log("\t$header", 1); - daemon_log("msg to process:", 5); - daemon_log("\t$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:", 7); - daemon_log("\t$target", 7); - - if ($target eq $server_address) { - # msg is for server - if ($header eq 'new_passwd'){ &new_passwd($msg_hash)} - elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)} - 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 'get_load') { &execute_actions($msg_hash)} - else { daemon_log("ERROR: no function assigned to this msg", 5) } - - - } elsif ($target eq "*") { - # msg is for all clients - - my @target_addresses = keys(%$known_clients); - foreach my $target_address (@target_addresses) { - if ($target_address eq $source) { next; } - $msg_hash->{target} = [$target_address]; - &send_msg_hash2address($msg_hash, $target_address); - } - } else { - # msg is for one client - - if (exists $known_clients->{$target}) { - # target is known - - &send_msg_hash2address($msg_hash, $target); - } else { - # target is not known - - daemon_log("ERROR: target $target is not known in known_clients", 1); - } - } - } else { - # we have multiple target symbols - - my $target_string = join(", ", @targets); - daemon_log("msg is for:", 7); - daemon_log("\t$target_string", 7); - - my $target_address; - foreach $target_address (@targets) { - if (exists $known_clients->{$target_address}) { - # target_address is known - - &send_msg_hash2address($msg_hash, $target_address); - daemon_log("server forwards msg $header to client $target_address", 3); - } else { - # target is not known - - daemon_log("ERROR: target $target_address is not known in known_clients", 1); - } - } - - - } - - return; -} - - -#=== 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; -} - - -#=== FUNCTION ================================================================ -# NAME: open_fifo -# PARAMETERS: $fifo_path -# RETURNS: 0: FIFO couldn"t be setup, 1: FIFO setup correctly -# DESCRIPTION: creates a FIFO at $fifo_path -#=============================================================================== -sub open_fifo { - my ($fifo_path) = @_ ; - if( -p $fifo_path ) { - daemon_log("FIFO at $fifo_path already exists! Is being deleted!", 1); - unlink($fifo_path); - } - POSIX::mkfifo($fifo_path, 0666) or die "can't mkfifo $fifo_path: $!"; - daemon_log( "FIFO started at $fifo_path", 1) ; - return 1; -} - - #=== FUNCTION ================================================================ # NAME: read_from_socket # PARAMETERS: socket fh - @@ -786,598 +584,6 @@ sub read_from_socket { } -#=== 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 -} - - -#=== 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: 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: 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 = $xml_ref->{$element}; - if( $element eq "header" || $element eq "target" || $element eq "source") { - return @$result[0]; - } - return @$result; -} - - -#=== 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: 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 = &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 - if(not defined $passwd) { - if(exists $known_daemons->{$address}) { - $passwd = $known_daemons->{$address}->{passwd}; - } elsif(exists $known_clients->{$address}) { - $passwd = $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 $known_clients->{$address}) { - if ($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 $known_daemons->{$address}) { - #&update_known_daemons(); - } elsif(exists $known_clients->{$address}) { - &update_known_clients(hostname=>$address, status=>$header); - } - - return 0; -} - - -#=== FUNCTION ================================================================ -# NAME: send_msg_hash2bus -# PARAMETERS: msg_hash - hash - xml_hash created with function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: ???? -#=============================================================================== -sub send_msg_hash2bus { - 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); - - # encrypt xml msg - my $crypted_msg = &encrypt_msg($msg_xml, $bus_cipher); - - # open socket - my $socket = &open_socket($bus_address); - if(not defined $socket){ - daemon_log( "cannot send '$header'-msg to $bus_address , bus not reachable", 5); - return; - } - - # send xml msg - print $socket $crypted_msg."\n"; - - close $socket; - - - daemon_log("send '$header'-msg to bus", 1); - daemon_log("$msg_xml", 5); - #daemon_log("crypted msg:",7); - #daemon_log("\t$crypted_msg", 7); - - return; -} - - - - - - - -##=== FUNCTION ================================================================ -## NAME: new_passwd -## PARAMETERS: msg_hash - ref - hash from function create_xml_hash -## RETURNS: nothing -## DESCRIPTION: process this incoming message -##=============================================================================== -#sub new_passwd { -# my ($msg_hash) = @_; -# -# my $source = &get_content_from_xml_hash($msg_hash, "source"); -# my $passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; -# -# if (exists $known_daemons->{$source}) { -# &add_content2known_daemons(hostname=>$source, status=>"new_passwd", passwd=>$passwd); -# $bus_cipher = &create_ciphering($passwd); -# my $hash = &create_xml_hash("confirm_new_passwd", "$server_ip:$server_port", "$source"); -# &send_msg_hash2address($hash, $source); -# -# } elsif (exists $known_clients->{$source}) { -# &add_content2known_clients(hostname=>$source, status=>"new_passwd", passwd=>$passwd); -# -# } else { -# daemon_log("ERROR: $source not known, neither in known_daemons nor in known_clients", 1) -# } -# -# return; -#} - - -##=== FUNCTION ================================================================ -## NAME: make ping -## PARAMETERS: address - string - address which should be pinged -## RETURNS: nothing -## DESCRIPTION: send ping message to address -##=============================================================================== -#sub make_ping { -# my ($msg_hash) = @_; -# -# my $source = &get_content_from_xml_hash($msg_hash, "source"); -# my $target = &get_content_from_xml_hash($msg_hash, "target"); -# -# print "make_ping:$source\n"; -# my $out_hash = &create_xml_hash("ping", $target, $source); -# &send_msg_hash2address($out_hash, $source); -# return; -#} - - -##=== FUNCTION ================================================================ -## NAME: got_ping -## PARAMETERS: msg_hash - hash - hash from function create_xml_hash -## RETURNS: nothing -## DESCRIPTION: process this incoming message -##=============================================================================== -#sub got_ping { -# my ($msg_hash) = @_; -# -# my $source = &get_content_from_xml_hash($msg_hash, 'source'); -# my $target = &get_content_from_xml_hash($msg_hash, 'target'); -# my $header = &get_content_from_xml_hash($msg_hash, 'header'); -# -# if(exists $known_daemons->{$source}) { -# &add_content2known_daemons(hostname=>$source, status=>$header); -# } else { -# &add_content2known_clients(hostname=>$source, status=>$header); -# } -# -# return; -#} - - -##=== FUNCTION ================================================================ -## NAME: here_i_am -## PARAMETERS: msg_hash - hash - hash from function create_xml_hash -## RETURNS: nothing -## DESCRIPTION: process this incoming message -##=============================================================================== -#sub here_i_am { -# my ($msg_hash) = @_; -# -# my $source = &get_content_from_xml_hash($msg_hash, "source"); -# my $mac_address = (&get_content_from_xml_hash($msg_hash, "mac_address"))[0]; -# my $out_hash; -# -# # number of known clients -# my $nu_clients = keys %$known_clients; -# -# # check wether client address or mac address is already known -# if (exists $known_clients->{$source}) { -# daemon_log("WARNING: $source is already known as a client", 1); -# daemon_log("WARNING: values for $source are being overwritten", 1); -# $nu_clients --; -# } -# -# # number of actual activ clients -# my $act_nu_clients = $nu_clients; -# -# daemon_log("number of actual activ clients: $act_nu_clients", 5); -# daemon_log("number of maximal allowed clients: $max_clients", 5); -# -# if($max_clients <= $act_nu_clients) { -# my $out_hash = &create_xml_hash("denied", $server_address, $source); -# &add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!"); -# my $passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; -# &send_msg_hash2address($out_hash, $source, $passwd); -# return; -# } -# -# # new client accepted -# my $new_passwd = (&get_content_from_xml_hash($msg_hash, "new_passwd"))[0]; -# -# # create known_daemons entry -# my $events = (&get_content_from_xml_hash($msg_hash, "events"))[0]; -# &create_known_client($source); -# &add_content2known_clients(hostname=>$source, events=>$events, mac_address=>$mac_address, -# status=>"registered", passwd=>$new_passwd); -# -# # return acknowledgement to client -# $out_hash = &create_xml_hash("registered", $server_address, $source); -# &send_msg_hash2address($out_hash, $source); -# -# # notify registered client to bus -# $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); -# &send_msg_hash2bus($out_hash); -# -# # give the new client his ldap config -# &new_ldap_config($source); -# -# return; -#} - - -#=== FUNCTION ================================================================ -# NAME: who_has -# PARAMETERS: msg_hash - hash - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: process this incoming message -#=============================================================================== -#sub who_has { -# my ($msg_hash) = @_ ; -# -# # what is your search pattern -# my $search_pattern = (&get_content_from_xml_hash($msg_hash, "who_has"))[0]; -# my $search_element = (&get_content_from_xml_hash($msg_hash, $search_pattern))[0]; -# daemon_log("who_has-msg looking for $search_pattern $search_element", 7); -# -# # scanning known_clients for search_pattern -# my @host_addresses = keys %$known_clients; -# my $known_clients_entries = length @host_addresses; -# my $host_address; -# foreach my $host (@host_addresses) { -# my $client_element = $known_clients->{$host}->{$search_pattern}; -# if ($search_element eq $client_element) { -# $host_address = $host; -# last; -# } -# } -# -# # search was successful -# if (defined $host_address) { -# my $source = @{$msg_hash->{source}}[0]; -# my $out_msg = &create_xml_hash("who_has_i_do", $server_address, $source, "mac_address"); -# &add_content2xml_hash($out_msg, "mac_address", $search_element); -# &send_msg_hash2address($out_msg, $bus_address); -# } -# return; -#} - - -#sub who_has_i_do { -# my ($msg_hash) = @_ ; -# my $header = &get_content_from_xml_hash($msg_hash, "header"); -# my $source = &get_content_from_xml_hash($msg_hash, "source"); -# my $search_param = (&get_content_from_xml_hash($msg_hash, $header))[0]; -# my $search_value = (&get_content_from_xml_hash($msg_hash, $search_param))[0]; -# print "\ngot msg $header:\nserver $source has client with $search_param $search_value\n"; -#} - - -#=== FUNCTION ================================================================ -# NAME: update_status -# PARAMETERS: msg_hash - hash - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: process this incoming message -#=============================================================================== -#sub update_status { -# my ($msg_hash) = @_; -# my $header = &get_content_from_xml_hash($msg_hash, "header"); -# my $source = &get_content_from_xml_hash($msg_hash, "source"); -# my $new_status = (&get_content_from_xml_hash($msg_hash, "update_status"))[0]; -# -# # find the source -# my $act_known_hash; -# if (exists $known_daemons->{$source}) { -# -# &add_content2known_daemons(hostname=>$source, status=>$new_status); -# } elsif (exists $known_clients->{$source}) { -# &update_known_clients(hostname=>$source, status=>$new_status); -# #&add_content2known_clients(hostname=>$source, status=>$new_status); -# } else { -# daemon_log("ERROR: got $header-msg, but cannot find $source in my hashes, unable to update status", 1); -# return; -# } -# -# return; -#} - - -##=== FUNCTION ================================================================ -## NAME: new_ldap_config -## PARAMETERS: address - string - ip address and port of a host -## RETURNS: nothing -## DESCRIPTION: send to address the ldap configuration found for dn gotoLdapServer -##=============================================================================== -#sub new_ldap_config { -# my ($address) = @_ ; -# -# if (not exists $known_clients->{$address}) { -# daemon_log("ERROR: $address does not exist in known_clients, cannot send him his ldap config", 1); -# return; -# } -# -# my $mac_address = $known_clients->{$address}->{"mac_address"}; -# if (not defined $mac_address) { -# daemon_log("ERROR: no mac address found for client $address", 1); -# return; -# } -# -# # fetch dn -# my $goHard_cmd = "ldapsearch -x '(&(objectClass=goHard)(macAddress=00:11:22:33:44:57))' dn gotoLdapServer"; -# my $dn; -# my @gotoLdapServer; -# open (PIPE, "$goHard_cmd 2>&1 |"); -# while() { -# chomp $_; -# # If it's a comment, goto next -# if ($_ =~ m/^[#]/) { next;} -# if ($_ =~ m/^dn: ([\S]+?)$/) { -# $dn = $1; -# } elsif ($_ =~ m/^gotoLdapServer: ([\S]+?)$/) { -# push(@gotoLdapServer, $1); -# } -# } -# close(PIPE); -# -# # no dn found -# if (not defined $dn) { -# daemon_log("ERROR: no dn arose from command: $goHard_cmd", 1); -# return; -# } -# -# # no gotoLdapServer found -# my $gosaGroupOfNames_cmd = "ldapsearch -x '(&(objectClass=gosaGroupOfNames)(member=$dn))' gotoLdapServer"; -# if (@gotoLdapServer == 0) { -# open (PIPE, "$gosaGroupOfNames_cmd 2>&1 |"); -# while() { -# chomp $_; -# if ($_ =~ m/^[#]/) { next; } -# if ($_ =~ m/^gotoLdapServer: ([\S]+?)$/) { -# push(@gotoLdapServer, $1); -# } -# } -# close(PIPE); -# } -# -# # still no gotoLdapServer found -# if (@gotoLdapServer == 0) { -# daemon_log("ERROR: cannot find gotoLdapServer entry in command: $gosaGroupOfNames_cmd", 1); -# return; -# } -# -# # sort @gotoLdapServer and then split of ranking -# my @sorted_gotoLdapServer = sort(@gotoLdapServer); -# @gotoLdapServer = reverse(@sorted_gotoLdapServer); -# foreach (@gotoLdapServer) { -# $_ =~ s/^\d://; -# } -# -# my $t = join(" ", @gotoLdapServer); -# -# my $out_hash = &create_xml_hash("new_ldap_config", $server_address, $address); -# map(&add_content2xml_hash($out_hash, "new_ldap_config", $_), @gotoLdapServer); -# &send_msg_hash2address($out_hash, $address); -# -# return; -#} - - -##=== FUNCTION ================================================================ -## NAME: execute_actions -## PARAMETERS: msg_hash - hash - hash from function create_xml_hash -## RETURNS: nothing -## DESCRIPTION: invokes the script specified in msg_hash which is located under -## /etc/gosad/actions -##=============================================================================== -#sub execute_actions { -# my ($msg_hash) = @_ ; -# my $configdir= '/etc/gosad/actions/'; -# my $result; -# -# my $header = &get_content_from_xml_hash($msg_hash, 'header'); -# my $source = &get_content_from_xml_hash($msg_hash, 'source'); -# my $target = &get_content_from_xml_hash($msg_hash, 'target'); -# -# -# if((not defined $source) -# && (not defined $target) -# && (not defined $header)) { -# daemon_log("ERROR: Entries missing in XML msg for gosad actions under /etc/gosad/actions"); -# } else { -# my $parameters=""; -# my @params = &get_content_from_xml_hash($msg_hash, $header); -# my $params = join(", ", @params); -# daemon_log("execute_actions: got parameters: $params", 5); -# -# if (@params) { -# foreach my $param (@params) { -# my $param_value = (&get_content_from_xml_hash($msg_hash, $param))[0]; -# daemon_log("execute_actions: parameter -> value: $param -> $param_value", 7); -# $parameters.= " ".$param_value; -# } -# } -# -# my $cmd= $configdir.$header."$parameters"; -# daemon_log("execute_actions: executing cmd: $cmd", 7); -# $result= ""; -# open(PIPE, "$cmd 2>&1 |"); -# while() { -# $result.=$_; -# } -# close(PIPE); -# } -# -# # process the event result -# -# -# return; -#} - - #=== FUNCTION ================================================================ # NAME: print_known_daemons # PARAMETERS: nothing @@ -1583,7 +789,8 @@ sub create_known_client { # status - string - (optional) # passwd - string - (optional) # mac_address - string - (optional) -# events - string - event of client, executable skripts under /etc/gosac/events +# events - string - event of client, executable skripts +# under /etc/gosac/events # RETURNS: nothing # DESCRIPTION: nome est omen and updates each time the timestamp of hostname #=============================================================================== @@ -1734,14 +941,13 @@ GetOptions("h|help" => \&usage, &check_cmdline_param ; &read_configfile; &check_pid; -&import_modules; $SIG{CHLD} = 'IGNORE'; # restart daemon log file if(-e $log_file ) { unlink $log_file } daemon_log(" ", 1); -daemon_log("gosa-si-server started!", 1); +daemon_log("$0 started!", 1); # Just fork, if we"re not in foreground mode if( ! $foreground ) { $pid = fork(); } @@ -1755,88 +961,44 @@ close( LOCK_FILE ); if( !$foreground ) { exit( 0 ) }; } -# detect own ip and mac address -($server_ip, $server_mac_address) = &get_ip_and_mac(); -if (not defined $server_ip) { - die "EXIT: ip address of $0 could not be detected"; -} -daemon_log("server ip address detected: $server_ip", 1); -daemon_log("server mac address detected: $server_mac_address", 1); +# import all modules +&import_modules; -# setup xml parser -$xml = new XML::Simple(); +# check wether all modules are gosa-si valid passwd check -# create cipher object -$bus_cipher = &create_ciphering($bus_passwd); -$bus_address = "$bus_ip:$bus_port"; +# connect to gosa-si job queue +my $job_db = DBsqlite->new($job_queue_file_name); # create reading and writing vectors my $rbits = my $wbits = my $ebits = ""; -# open server socket -$server_address = "$server_ip:$server_port"; -if($server_activ eq "on"){ - daemon_log(" ", 1); - $server = IO::Socket::INET->new(LocalPort => $server_port, - Type => SOCK_STREAM, - Reuse => 1, - Listen => 20, - ); - if(not defined $server){ - daemon_log("cannot be a tcp server at $server_port : $@"); - } else { - daemon_log("start server: $server_address", 1); - vec($rbits, fileno $server, 1) = 1; - vec($wbits, fileno $server, 1) = 1; - } -} +# add all module inputs to listening vector +while( my ($mod_name, $info) = each %$known_modules ) { + my ($input_address, $input_key, $input, $input_activ, $input_type) = @{$info}; + vec($rbits, fileno $input, 1) = 1; -# register at bus -if ($no_bus > 0) { - $bus_activ = "off" -} -if($bus_activ eq "on") { - daemon_log(" ", 1); - ®ister_at_bus(); } -# 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: $!" ; - - vec($rbits, fileno $arp_fifo, 1) = 1; -} - -$gosa_address = "$gosa_ip:$gosa_port"; -# start gosa inferface fifos -if ($gosa_activ eq "on") { - daemon_log(" ",1); - $gosa_server = IO::Socket::INET->new(LocalPort => $gosa_port, - Type => SOCK_STREAM, - Reuse => 1, - Listen => 1, - ); - 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: $gosa_address", 1); - vec($rbits, fileno $gosa_server, 1) = 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: $!" ; +# +# vec($rbits, fileno $arp_fifo, 1) = 1; +#} +# -################################### +################################## #everything ready, okay, lets start -################################### +################################## while(1) { # add all handles from the childs @@ -1855,33 +1017,12 @@ while(1) { } my ($rout, $wout); - my $nf = select($rout=$rbits, $wout=$wbits, undef, undef); + my $nf = select($rout=$rbits, $wout=$wbits, undef, $job_queue_timeout); # error handling if($nf < 0 ) { } - # something is coming in - if($server_activ eq "on" && vec($rout, fileno $server, 1)) { - daemon_log(" ", 1); - my $client = $server->accept(); - my $other_end = getpeername($client); - if(not defined $other_end) { - daemon_log("client cannot be identified: $!"); - } else { - my ($port, $iaddr) = unpack_sockaddr_in($other_end); - my $actual_ip = inet_ntoa($iaddr); - daemon_log("accept client at daemon socket from $actual_ip", 5); - my $in_msg = &read_from_socket($client); - if(defined $in_msg){ - chomp($in_msg); - &activating_child($in_msg, $actual_ip); - } else { - daemon_log("cannot read from $actual_ip", 5); - } - } - close($client); - } if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) { my $in_msg = <$arp_fifo>; @@ -1906,27 +1047,32 @@ while(1) { print "\n"; } - if($gosa_activ eq "on" && vec($rout, fileno $gosa_server, 1)) { - daemon_log(" ", 1); - my $client = $gosa_server->accept(); - my $other_end = getpeername($client); - if(not defined $other_end) { - daemon_log("client cannot be identified: $!"); - } else { - my ($port, $iaddr) = unpack_sockaddr_in($other_end); - my $actual_ip = inet_ntoa($iaddr); - daemon_log("accept client at gosa socket from $actual_ip", 5); - my $in_msg = <$client>; - #my $in_msg = &read_from_socket($client); - - if(defined $in_msg){ - chomp($in_msg); - &activating_child($in_msg, $actual_ip, $client); + + # check input fhd of all modules + while ( my ($mod_name, $info) = each %$known_modules) { + my $input_fhd = @{$info}[2]; + my $input_activ = @{$info}[3]; + if (vec($rout, fileno $input_fhd, 1) && $input_activ eq 'on') { + daemon_log(" ", 1); + my $client = $input_fhd->accept(); + my $other_end = getpeername($client); + if(not defined $other_end) { + daemon_log("client cannot be identified: $!"); } else { - daemon_log("cannot read from $actual_ip", 5); + my ($port, $iaddr) = unpack_sockaddr_in($other_end); + my $actual_ip = inet_ntoa($iaddr); + daemon_log("accept client at daemon socket from $actual_ip", 5); + my $in_msg = &read_from_socket($client); + if(defined $in_msg){ + chomp($in_msg); + &activating_child($in_msg, $actual_ip, $client); + } else { + daemon_log("cannot read from $actual_ip", 5); + } } + #close($client); + } - #close($client); } # check all processing childs whether they are finished ('done') or @@ -1956,9 +1102,11 @@ while(1) { $free_child{$pid} = $child_hash; } else { + # send computed answer back to connected client my $act_client = $busy_child{$pid}{client_ref}; print $act_client $in_msg."\n"; - my $act_pipe = $busy_child{$pid}{pipe_rd}; + + #my $act_pipe = $busy_child{$pid}{pipe_rd}; sleep(10); close ($act_client); delete $busy_child{$pid}; @@ -1968,5 +1116,73 @@ while(1) { } } + # check gosa job queue for jobs with executable timestamp + print ">>>>>>>>>>>check gosa job queue "; + 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 $timestamp = "$year$month$monthday$hours$minutes$seconds"; + print "$timestamp\n"; + + + my $sql = "SELECT * FROM '$job_queue_table_name' WHERE status='waiting' AND timestamp<'$timestamp'"; + my $res = $job_db->exec_statement($sql); + foreach my $msg (@{$res}) { + + my $jobdb_id = @{$msg}[0]; + my $job_msg_hash = &transform_msg2hash(@{$msg}[6]); + my $out_msg_hash = $job_msg_hash; + + # hole mac address und suche die entsprechende ip addresse + my $target; + my @hostnames = keys %{$known_clients}; + foreach my $hostname (@hostnames) { + if ($known_clients->{$hostname}->{mac_address} eq $job_msg_hash->{mac}[0]) { + $target = $hostname; + last; + } + } + + if (not defined $target) { + &daemon_log("ERROR: no host found for mac address: $job_msg_hash->{mac}[0]", 1); + next; + } + + # add target + print "select: target: $target\n"; + &add_content2xml_hash($out_msg_hash, "target", $target); + + # add new header + my $out_header = $job_msg_hash->{header}[0]; + $out_header =~ s/job_/gosa_/; + print "select: header: $out_header\n"; + delete $out_msg_hash->{header}; + &add_content2xml_hash($out_msg_hash, "header", $out_header); + + # add sqlite_id + &add_content2xml_hash($out_msg_hash, "jobdb_id", $jobdb_id); + +# my $out_msg = &create_xml_string($out_msg_hash); +# +# # encrypt msg as a GosaPackage module +# my $cipher = &create_ciphering($gosa_passwd); +# my $crypted_out_msg = &encrypt_msg($out_msg, $cipher); + + my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $gosa_passwd); + + if ($error == 0) { + my $sql = "UPDATE '$job_queue_table_name' SET status='processing', target='$target' WHERE id='$jobdb_id'"; + my $res = $job_db->exec_statement($sql); + } + + + } + } diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index ab5938dc6..664c10081 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -3,64 +3,223 @@ package GosaPackages; use Exporter; @ISA = ("Exporter"); -# Each module has to have a function 'process_incoming_msg'. This function works as a interface to gosa-sd and recieves the msg hash from gosa-sd. 'process_incoming_function checks, wether it has a function to process the incoming msg and forward the msg to it. - - use strict; use warnings; use GosaSupportDaemon; +use IO::Socket::INET; +use XML::Simple; +use File::Spec; +use DBsqlite; BEGIN{} - END{} +my ($server_activ, $server_port, $server_passwd, $max_clients); +my ($bus_activ, $bus_passwd, $bus_ip, $bus_port); +my ($gosa_activ, $gosa_ip, $gosa_port, $gosa_passwd); +my ($job_queue_timeout, $job_queue_file_name); + +my $gosa_server; +my $event_dir = "/home/rettenbe/gonicus/projekte/gosa-trunk/gosa-si/server/events"; + +# name of table for storing gosa jobs +my $job_queue_table_name = 'jobs'; + +my %cfg_defaults = +("general" => + {"job_queue_file_name" => [\$job_queue_file_name, '/tmp/jobs.db'], + }, +"server" => + {"server_activ" => [\$server_activ, "on"], + "server_port" => [\$server_port, "20081"], + "server_passwd" => [\$server_passwd, ""], + "max_clients" => [\$max_clients, 100], + }, +"bus" => + {"bus_activ" => [\$bus_activ, "on"], + "bus_passwd" => [\$bus_passwd, ""], + "bus_ip" => [\$bus_ip, ""], + "bus_port" => [\$bus_port, "20080"], + }, +"gosa" => + {"gosa_activ" => [\$gosa_activ, "on"], + "gosa_ip" => [\$gosa_ip, ""], + "gosa_port" => [\$gosa_port, "20082"], + "gosa_passwd" => [\$gosa_passwd, "none"], + }, +); + ### START ########################## +# read configfile and import variables +&read_configfile(); + +# detect own ip and mac address +my ($server_ip, $server_mac_address) = &get_ip_and_mac(); + +# complete addresses +my $server_address = "$server_ip:$server_port"; +my $bus_address = "$bus_ip:$bus_port"; +my $gosa_address = "$gosa_ip:$gosa_port"; + # create general settings for this module -my $gosa_cipher = &create_ciphering($main::gosa_passwd); +my $gosa_cipher = &create_ciphering($gosa_passwd); +my $xml = new XML::Simple(); -sub get_module_tags { - - # dort stehen drei packettypen, für die sich das modul anmelden kann, gosa-admin-packages, - # server-packages, client-packages - my %tag_hash = (gosa_admin_packages => "yes", - server_packages => "no", - client_packages => "no"); - return \%tag_hash; +# open gosa socket +if ($gosa_activ eq "on") { + &main::daemon_log(" ",1); + $gosa_server = IO::Socket::INET->new(LocalPort => $gosa_port, + Type => SOCK_STREAM, + Reuse => 1, + Listen => 1, + ); + if (not defined $gosa_server) { + &main::daemon_log("cannot start tcp server at $gosa_port for communication to gosa: $@", 1); + } else { + &main::daemon_log("start server for communication to gosa: $gosa_address", 1); + + } +} + +# create gosa job queue as a SQLite DB +my @col_names = ("id", "timestamp", "status", "result", "header", + "target", "xml", "mac"); +my $table_name = "jobs"; +my $sqlite = DBsqlite->new($job_queue_file_name); +$sqlite->create_table($table_name, \@col_names); + + + + +### FUNCTIONS ################################################################# + +sub get_module_info { + my @info = ($gosa_address, + $gosa_passwd, + $gosa_server, + $gosa_activ, + "socket", + ); + return \@info; +} + + +#=== FUNCTION ================================================================ +# NAME: read_configfile +# PARAMETERS: cfg_file - string - +# RETURNS: nothing +# DESCRIPTION: read cfg_file and set variables +#=============================================================================== +sub read_configfile { + my $cfg; + if( defined( $main::cfg_file) && ( length($main::cfg_file) > 0 )) { + if( -r $main::cfg_file ) { + $cfg = Config::IniFiles->new( -file => $main::cfg_file ); + } else { + print STDERR "Couldn't read config file!"; + } + } else { + $cfg = Config::IniFiles->new() ; + } + foreach my $section (keys %cfg_defaults) { + foreach my $param (keys %{$cfg_defaults{ $section }}) { + my $pinfo = $cfg_defaults{ $section }{ $param }; + ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] ); + } + } +} + + +#=== FUNCTION ================================================================ +# NAME: get_ip_and_mac +# PARAMETERS: nothing +# RETURNS: (ip, mac) +# DESCRIPTION: executes /sbin/ifconfig and parses the output, the first occurence +# of a inet address is returned as well as the mac address in the line +# above the inet address +#=============================================================================== +sub get_ip_and_mac { + my $ip = "0.0.0.0.0"; # Defualt-IP + my $mac = "00:00:00:00:00:00"; # Default-MAC + my @ifconfig = qx(/sbin/ifconfig); + foreach(@ifconfig) { + if (/Hardware Adresse (\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/) { + $mac = "$1:$2:$3:$4:$5:$6"; + next; + } + if (/inet Adresse:(\d+).(\d+).(\d+).(\d+)/) { + $ip = "$1.$2.$3.$4"; + last; + } + } + return ($ip, $mac); +} + + +#=== 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; + } + &main::daemon_log("open_socket to: $PeerAddr", 7); + return $socket; } +#=== FUNCTION ================================================================ +# NAME: process_incoming_msg +# PARAMETERS: crypted_msg - string - incoming crypted message +# RETURNS: nothing +# DESCRIPTION: handels the proceeded distribution to the appropriated functions +#=============================================================================== 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("GosaPackages: crypted_msg:$crypted_msg", 7); - &main::daemon_log("GosaPackages: crypted_msg len:".length($crypted_msg), 7); +# &main::daemon_log("GosaPackages: crypted_msg:$crypted_msg", 7); +# &main::daemon_log("GosaPackages: crypted_msg len:".length($crypted_msg), 7); $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); &main::daemon_log("GosaPackages: crypted_msg:$crypted_msg", 7); - &main::daemon_log("GosaPackages: crypted_msg len:".length($crypted_msg), 7); +# &main::daemon_log("GosaPackages: crypted_msg len:".length($crypted_msg), 7); # collect addresses from possible incoming clients # only gosa is allowd as incoming client &main::daemon_log("GosaPackages: host_key: $host", 7); - &main::daemon_log("GosaPackages: key_passwd: $main::gosa_passwd", 7); + &main::daemon_log("GosaPackages: key_passwd: $gosa_passwd", 7); - $gosa_cipher = &main::create_ciphering($main::gosa_passwd); + $gosa_cipher = &create_ciphering($gosa_passwd); # determine the correct passwd for deciphering of the incoming msgs my $msg = ""; my $msg_hash; eval{ - $msg = &main::decrypt_msg($crypted_msg, $gosa_cipher); + $msg = &decrypt_msg($crypted_msg, $gosa_cipher); &main::daemon_log("GosaPackages: decrypted_msg: $msg", 7); - $msg_hash = $main::xml->XMLin($msg, ForceArray=>1); + $msg_hash = $xml->XMLin($msg, ForceArray=>1); }; if($@) { &main::daemon_log("WARNING: GosaPackages do not understand the message:", 5); @@ -68,41 +227,107 @@ sub process_incoming_msg { return; } - &main::daemon_log("GosaPackages: msg for daemon from host:", 1); - &main::daemon_log("\t$host", 1); - &main::daemon_log("GosaPackages: msg to process:", 5); - &main::daemon_log("\t$msg", 5); + my $header = @{$msg_hash->{header}}[0]; - $msg = "gosaPackages hat was bekommen"; + &main::daemon_log("recieve '$header' at GosaPackages from $host", 1); + &main::daemon_log("$msg", 7); - my $out_cipher = &main::create_ciphering($main::gosa_passwd); - my $out_msg = &main::encrypt_msg($msg, $out_cipher); - return $out_msg; + my $out_msg; + if ($header =~ /^job_/) { + $out_msg = &process_job_msg($msg, $msg_hash); + } elsif ($header =~ /^gosa_/) { + $out_msg = &process_gosa_msg($msg, $header); + } else { + &main::daemon_log("ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix"); + } + + + if (not defined $out_msg) { + return; + } + + if ($out_msg =~ /(\d*?)<\/jobdb_id>/) { + my $job_id = $1; + my $sql = "UPDATE '$job_queue_table_name' SET status='done', result='$out_msg' WHERE id='$job_id'"; + my $res = $sqlite->exec_statement($sql); + return; + + } else { + my $out_cipher = &create_ciphering($gosa_passwd); + $out_msg = &encrypt_msg($out_msg, $out_cipher); + return $out_msg; + } } +sub process_gosa_msg { + my ($msg, $header) = @_ ; + my $out_msg; + $header =~ s/gosa_//; + &main::daemon_log("GosaPackages: got a gosa msg $header", 5); -#=== FUNCTION ================================================================ -# NAME: got_ping -# PARAMETERS: msg_hash - hash - hash from function create_xml_hash -# RETURNS: nothing -# DESCRIPTION: process this incoming message -#=============================================================================== -sub got_ping { - my ($msg_hash) = @_; + # fetch all available eventhandler under $event_dir + opendir (DIR, $event_dir) or &main::daemon_log("ERROR cannot open $event_dir: $!\n", 1) and return; + while (defined (my $file = readdir (DIR))) { + if (not $file eq $header) { + next; + } + # try to deliver incoming msg to eventhandler + + my $cmd = File::Spec->join($event_dir, $header)." '$msg'"; + &main::daemon_log("GosaPackages: execute event_handler $header", 3); + &main::daemon_log("GosaPackages: cmd: $cmd", 7); + + $out_msg = ""; + open(PIPE, "$cmd 2>&1 |"); + while() { + $out_msg.=$_; + } + close(PIPE); + &main::daemon_log("GosaPackages: answer of cmd: $out_msg", 5); + last; + } + + # if delivery not possible raise error and return + if (not defined $out_msg) { + &main::daemon_log("ERROR: GosaPackages: no event_handler defined for $header", 1); + } elsif ($out_msg eq "") { + &main::daemon_log("ERROR: GosaPackages got not answer from event_handler $header", 1); + } + return $out_msg; - my $source = @{$msg_hash->{source}}[0]; - my $target = @{$msg_hash->{target}}[0]; +} + + +sub process_job_msg { + my ($msg, $msg_hash)= @_ ; + my $header = @{$msg_hash->{header}}[0]; + $header =~ s/job_//; + &main::daemon_log("GosaPackages: got a job msg $header", 5); - if(exists $main::known_daemons->{$source}) { - &main::add_content2known_daemons(hostname=>$source, status=>$header); - } else { - &main::add_content2known_clients(hostname=>$source, status=>$header); + # check wether mac address is already known in known_daemons or known_clients + my $target = 'not known until now'; + + # add job to job queue + my $func_dic = {table=>$table_name, + timestamp=>@{$msg_hash->{timestamp}}[0], + status=>'waiting', + result=>'none', + header=>$header, + target=>$target, + xml=>$msg, + mac=>@{$msg_hash->{mac}}[0], + }; + my $res = $sqlite->add_dbentry($func_dic); + if (not $res == 0) { + &main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1); } + &main::daemon_log("GosaPackages: $header job successfully added to job queue", 3); return; -} +} 1; + diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index a92ef00a1..37da24aa9 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -13,6 +13,7 @@ use MIME::Base64; use XML::Simple; + BEGIN {} END {} @@ -233,7 +234,7 @@ sub add_content2xml_hash { sub create_xml_string { my ($xml_hash) = @_ ; my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml'); - $xml_string =~ s/[\n]+//g; + #$xml_string =~ s/[\n]+//g; #daemon_log("create_xml_string:",7); #daemon_log("$xml_string\n", 7); return $xml_string; @@ -319,4 +320,15 @@ sub open_socket { } +1; + + + + + + + + + + diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index c2fc7eea9..874aaa472 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -9,34 +9,216 @@ use Exporter; use strict; use warnings; use GosaSupportDaemon; +use IO::Socket::INET; +use XML::Simple; BEGIN{} - END {} -### START ########## +my ($server_activ, $server_port, $server_passwd, $max_clients); +my ($bus_activ, $bus_passwd, $bus_ip, $bus_port); +my $server; +my $no_bus; + +my %cfg_defaults = +("server" => + {"server_activ" => [\$server_activ, "on"], + "server_port" => [\$server_port, "20081"], + "server_passwd" => [\$server_passwd, ""], + "max_clients" => [\$max_clients, 100], + }, +"bus" => + {"bus_activ" => [\$bus_activ, "on"], + "bus_passwd" => [\$bus_passwd, ""], + "bus_ip" => [\$bus_ip, ""], + "bus_port" => [\$bus_port, "20080"], + }, +); + +### START ##################################################################### + + +# read configfile and import variables +&read_configfile(); + +# detect own ip and mac address +my ($server_ip, $server_mac_address) = &get_ip_and_mac(); +if (not defined $server_ip) { + die "EXIT: ip address of $0 could not be detected"; +} +&main::daemon_log("server ip address detected: $server_ip", 1); +&main::daemon_log("server mac address detected: $server_mac_address", 1); + +# complete addresses +my $server_address = "$server_ip:$server_port"; +my $bus_address = "$bus_ip:$bus_port"; + +# create general settings for this module +my $xml = new XML::Simple(); + +# open server socket +if($server_activ eq "on"){ + &main::daemon_log(" ", 1); + $server = IO::Socket::INET->new(LocalPort => $server_port, + Type => SOCK_STREAM, + Reuse => 1, + Listen => 20, + ); + if(not defined $server){ + &main::daemon_log("cannot be a tcp server at $server_port : $@"); + } else { + &main::daemon_log("start server: $server_address", 1); + } +} +# register at bus +if ($main::no_bus > 0) { + $bus_activ = "off" +} +if($bus_activ eq "on") { + &main::daemon_log(" ", 1); + ®ister_at_bus(); +} +### functions ################################################################# + +#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 get_module_info { + my @info = ($server_address, + $server_passwd, + $server, + $server_activ, + "socket", + ); + return \@info; +} -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; + +#=== FUNCTION ================================================================ +# NAME: read_configfile +# PARAMETERS: cfg_file - string - +# RETURNS: nothing +# DESCRIPTION: read cfg_file and set variables +#=============================================================================== +sub read_configfile { + my $cfg; + if( defined( $main::cfg_file) && ( length($main::cfg_file) > 0 )) { + if( -r $main::cfg_file ) { + $cfg = Config::IniFiles->new( -file => $main::cfg_file ); + } else { + print STDERR "Couldn't read config file!"; + } + } else { + $cfg = Config::IniFiles->new() ; + } + foreach my $section (keys %cfg_defaults) { + foreach my $param (keys %{$cfg_defaults{ $section }}) { + my $pinfo = $cfg_defaults{ $section }{ $param }; + ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] ); + } + } +} + + +#=== FUNCTION ================================================================ +# NAME: get_ip_and_mac +# PARAMETERS: nothing +# RETURNS: (ip, mac) +# DESCRIPTION: executes /sbin/ifconfig and parses the output, the first occurence +# of a inet address is returned as well as the mac address in the line +# above the inet address +#=============================================================================== +sub get_ip_and_mac { + my $ip = "0.0.0.0.0"; # Defualt-IP + my $mac = "00:00:00:00:00:00"; # Default-MAC + my @ifconfig = qx(/sbin/ifconfig); + foreach(@ifconfig) { + if (/Hardware Adresse (\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/) { + $mac = "$1:$2:$3:$4:$5:$6"; + next; + } + if (/inet Adresse:(\d+).(\d+).(\d+).(\d+)/) { + $ip = "$1.$2.$3.$4"; + last; + } + } + return ($ip, $mac); } +#=== 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; + } + &main::daemon_log("open_socket to: $PeerAddr", 7); + return $socket; +} + +#=== FUNCTION ================================================================ +# NAME: register_at_bus +# PARAMETERS: nothing +# RETURNS: nothing +# DESCRIPTION: creates an entry in known_daemons and send a 'here_i_am' msg to bus +#=============================================================================== +sub register_at_bus { + + # create known_daemons entry + &main::create_known_daemon($bus_address); + &main::add_content2known_daemons(hostname=>$bus_address, status=>"register_at_bus", passwd=>$bus_passwd); + + my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address); + my $answer = ""; + $answer = &send_msg_hash2address($msg_hash, $bus_address); + if ($answer == 0) { + &main::daemon_log("register at bus: $bus_address", 1); + } else { + &main::daemon_log("unable to send 'register'-msg to bus: $bus_address", 1); + } + return; +} + +#=== FUNCTION ================================================================ +# NAME: process_incoming_msg +# PARAMETERS: crypted_msg - string - incoming crypted message +# RETURNS: nothing +# DESCRIPTION: handels the proceeded distribution to the appropriated functions +#=============================================================================== sub process_incoming_msg { my ($crypted_msg) = @_ ; if(not defined $crypted_msg) { &main::daemon_log("function 'process_incoming_msg': got no msg", 7); } + $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); @@ -55,7 +237,7 @@ sub process_incoming_msg { push(@valid_keys, $client_key); } } - push(@valid_keys, $main::server_address); + push(@valid_keys, $server_address); my $l = @valid_keys; my $msg_hash; @@ -71,14 +253,14 @@ sub process_incoming_msg { $key_passwd = $main::known_daemons->{$host_key}->{passwd}; } elsif (exists $main::known_clients->{$host_key}) { $key_passwd = $main::known_clients->{$host_key}->{passwd}; - } elsif ($host_key eq $main::server_address) { - $key_passwd = $main::server_passwd; + } elsif ($host_key eq $server_address) { + $key_passwd = $server_passwd; } &main::daemon_log("ServerPackage: key_passwd: $key_passwd", 7); my $key_cipher = &create_ciphering($key_passwd); $msg = &decrypt_msg($crypted_msg, $key_cipher); &main::daemon_log("ServerPackages: decrypted msg: $msg", 7); - $msg_hash = $main::xml->XMLin($msg, ForceArray=>1); + $msg_hash = $xml->XMLin($msg, ForceArray=>1); #my $tmp = printf Dumper $msg_hash; #&main::daemon_log("DEBUG: ServerPackages: xml hash: $tmp", 7); }; @@ -100,10 +282,11 @@ sub process_incoming_msg { my $header = @{$msg_hash->{header}}[0]; my $source = @{$msg_hash->{source}}[0]; - &main::daemon_log("ServerPackages: msg from host:", 5); - &main::daemon_log("\t$host", 5); - &main::daemon_log("ServerPackages: header from msg:", 5); - &main::daemon_log("\t$header", 5); + &main::daemon_log("recieve '$header' at ServerPackages from $host", 1); +# &main::daemon_log("ServerPackages: msg from host:", 5); +# &main::daemon_log("\t$host", 5); +# &main::daemon_log("ServerPackages: header from msg:", 5); +# &main::daemon_log("\t$header", 5); &main::daemon_log("ServerPackages: msg to process:", 5); &main::daemon_log("\t$msg", 5); @@ -119,7 +302,7 @@ sub process_incoming_msg { &main::daemon_log("SeverPackages: msg is for:", 7); &main::daemon_log("\t$target", 7); - if ($target eq $main::server_address) { + if ($target eq $server_address) { # msg is for server if ($header eq 'new_passwd'){ &new_passwd($msg_hash)} elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)} @@ -196,7 +379,7 @@ sub new_passwd { if (exists $main::known_daemons->{$source}) { &main::add_content2known_daemons(hostname=>$source, status=>"new_passwd", passwd=>$passwd); - my $hash = &create_xml_hash("confirm_new_passwd", $main::server_address, $source); + my $hash = &create_xml_hash("confirm_new_passwd", $server_address, $source); &send_msg_hash2address($hash, $source); } elsif (exists $main::known_clients->{$source}) { @@ -237,10 +420,10 @@ sub here_i_am { my $act_nu_clients = $nu_clients; &main::daemon_log("number of actual activ clients: $act_nu_clients", 5); - &main::daemon_log("number of maximal allowed clients: $main::max_clients", 5); + &main::daemon_log("number of maximal allowed clients: $max_clients", 5); - if($main::max_clients <= $act_nu_clients) { - my $out_hash = &create_xml_hash("denied", $main::server_address, $source); + if($max_clients <= $act_nu_clients) { + my $out_hash = &create_xml_hash("denied", $server_address, $source); &add_content2xml_hash($out_hash, "denied", "I_cannot_take_any_more_clients!"); my $passwd = @{$msg_hash->{new_passwd}}[0]; &send_msg_hash2address($out_hash, $source, $passwd); @@ -257,12 +440,13 @@ sub here_i_am { status=>"registered", passwd=>$new_passwd); # return acknowledgement to client - $out_hash = &create_xml_hash("registered", $main::server_address, $source); + $out_hash = &create_xml_hash("registered", $server_address, $source); &send_msg_hash2address($out_hash, $source); # notify registered client to bus - $out_hash = &main::create_xml_hash("new_client", $main::server_address, $main::bus_address, $source); - &main::send_msg_hash2bus($out_hash); + $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source); + #&main::send_msg_hash2bus($out_hash); + &send_msg_hash2address($out_hash, $bus_address); # give the new client his ldap config &new_ldap_config($source); @@ -300,9 +484,9 @@ sub who_has { # search was successful if (defined $host_address) { my $source = @{$msg_hash->{source}}[0]; - my $out_msg = &main::create_xml_hash("who_has_i_do", $main::server_address, $source, "mac_address"); - &main::add_content2xml_hash($out_msg, "mac_address", $search_element); - &main::send_msg_hash2address($out_msg, $main::bus_address); + my $out_msg = &create_xml_hash("who_has_i_do", $server_address, $source, "mac_address"); + &add_content2xml_hash($out_msg, "mac_address", $search_element); + &send_msg_hash2address($out_msg, $bus_address); } return; } @@ -394,9 +578,9 @@ sub new_ldap_config { my $t = join(" ", @gotoLdapServer); - my $out_hash = &main::create_xml_hash("new_ldap_config", $main::server_address, $address); - map(&main::add_content2xml_hash($out_hash, "new_ldap_config", $_), @gotoLdapServer); - &main::send_msg_hash2address($out_hash, $address); + my $out_hash = &create_xml_hash("new_ldap_config", $server_address, $address); + map(&add_content2xml_hash($out_hash, "new_ldap_config", $_), @gotoLdapServer); + &send_msg_hash2address($out_hash, $address); return; } @@ -452,4 +636,5 @@ sub execute_actions { return; } + 1; diff --git a/gosa-si/server.conf b/gosa-si/server.conf index 352bc5667..97047ce41 100644 --- a/gosa-si/server.conf +++ b/gosa-si/server.conf @@ -4,6 +4,7 @@ pid_file = /var/run/gosa-si-server.pid child_max = 10 child_min = 2 child_timeout = 10 +job_queue_timeout = 5 [bus] bus_activ = on diff --git a/gosa-si/server/events/ping b/gosa-si/server/events/ping new file mode 100755 index 000000000..f8ae99606 --- /dev/null +++ b/gosa-si/server/events/ping @@ -0,0 +1,26 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use GosaSupportDaemon; + + +# transform msg to hash +my $hash = &transform_msg2hash($ARGV[0]); + +# extract from hash all what you need +my $header = @{$hash->{header}}[0]; +my $source = @{$hash->{source}}[0]; +my $target = @{$hash->{target}}[0]; +my $jobdb_id = @{$hash->{jobdb_id}}[0]; + +# and do what ever you want + + +my $out_hash = &create_xml_hash("got_ping", "10.89.1.155:10001", "10.89.1.155:10000"); +if (defined $jobdb_id) { + &add_content2xml_hash($out_hash, 'jobdb_id', $jobdb_id); +} +my $out_xml = &create_xml_string($out_hash); +print $out_xml; + diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php new file mode 100755 index 000000000..12f33c642 --- /dev/null +++ b/gosa-si/tests/client.php @@ -0,0 +1,27 @@ +#!/usr/bin/php5 -q +setEncryptionKey("secret-gosa-password"); + +if($sock->connected()){ + /* Prepare a hunge bunch of data to be send */ + #$data = "
gosa_ping
10.89.1.155:2008211:22:33:44:55
"; + #$data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 19700101000000
"; + $data = "
job_ping
10.89.1.155:2008300:1B:77:04:8A:6C 20080102133900
"; + $sock->write($data); + + #$sock->setEncryptionKey("ferdinand_frost"); + + $answer = $sock->read(); + echo "$answer\n"; + $sock->close(); +}else{ + echo "... FAILED!\n"; +} + +?>