diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index 3bf04aff50ef16c21daf159e1a6f88c1e799e602..848f237cc7e040830c3085f845b8c84e25b987f8 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
use Getopt::Long;
use Config::IniFiles;
use POSIX;
use Getopt::Long;
use Config::IniFiles;
use POSIX;
+use utf8;
use Fcntl;
use IO::Socket::INET;
use Fcntl;
use IO::Socket::INET;
$no_arp = 0;
$no_arp = 0;
-# name of table for storing gosa jobs
-our $job_queue_table_name = 'jobs';
+# holds all gosa jobs
our $job_db;
our $job_db;
+our $job_queue_table_name = 'jobs';
# holds all other gosa-sd as well as the gosa-sd-bus
our $known_server_db;
# holds all other gosa-sd as well as the gosa-sd-bus
our $known_server_db;
"activ" => [\$bus_activ, "true"],
},
"server" => {
"activ" => [\$bus_activ, "true"],
},
"server" => {
-# "ip" => [\$server_ip, "0.0.0.0"],
+# "ip" => [\$server_ip, "0.0.0.0"],
"port" => [\$server_port, "20081"],
"known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ],
"known-servers" => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'],
"port" => [\$server_port, "20081"],
"known-clients" => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ],
"known-servers" => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'],
if( $info ) {
my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info};
$known_modules->{$mod_name} = $info;
if( $info ) {
my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info};
$known_modules->{$mod_name} = $info;
- daemon_log("module $mod_name loaded", 1);
+ daemon_log("INFO: module $mod_name loaded", 5);
}
}
}
}
}
}
sub check_key_and_xml_validity {
my ($crypted_msg, $module_key) = @_;
sub check_key_and_xml_validity {
my ($crypted_msg, $module_key) = @_;
-
my $msg;
my $msg_hash;
my $msg;
my $msg_hash;
+ my $error_string;
eval{
$msg = &decrypt_msg($crypted_msg, $module_key);
eval{
$msg = &decrypt_msg($crypted_msg, $module_key);
&main::daemon_log("decrypted_msg: \n$msg", 8);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
&main::daemon_log("decrypted_msg: \n$msg", 8);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
+ ##############
# check header
# check header
+ if( not exists $msg_hash->{'header'} ) { die "no header specified"; }
my $header_l = $msg_hash->{'header'};
my $header_l = $msg_hash->{'header'};
- if( 1 != @{$header_l} ) {
- die 'header error';
- }
+ if( 1 > @{$header_l} ) { die 'empty header tag'; }
+ if( 1 < @{$header_l} ) { die 'more than one header specified'; }
my $header = @{$header_l}[0];
my $header = @{$header_l}[0];
- if( 0 == length $header) {
- die 'header error';
- }
+ if( 0 == length $header) { die 'empty string in header tag'; }
+ ##############
# check source
# check source
+ if( not exists $msg_hash->{'source'} ) { die "no source specified"; }
my $source_l = $msg_hash->{'source'};
my $source_l = $msg_hash->{'source'};
- if( not defined @{$source_l} or 1 != @{$source_l} ) {
- die 'source error';
- }
+ if( 1 > @{$source_l} ) { die 'empty source tag'; }
+ if( 1 < @{$source_l} ) { die 'more than one source specified'; }
my $source = @{$source_l}[0];
my $source = @{$source_l}[0];
- if( 0 == length $source) {
- die 'source error';
- }
+ if( 0 == length $source) { die 'source error'; }
+ ##############
# check target
# check target
+ if( not exists $msg_hash->{'target'} ) { die "no target specified"; }
my $target_l = $msg_hash->{'target'};
my $target_l = $msg_hash->{'target'};
- if( 1 != @{$target_l} ) {
- die'target error';
- }
- my $target = @{$target_l}[0];
- if( 0 == length $target) {
- die 'target error';
- }
+ if( 1 > @{$target_l} ) { die 'empty target tag'; }
}
};
if($@) {
&main::daemon_log("WARNING: do not understand the message", 5);
&main::daemon_log("$@", 8);
}
};
if($@) {
&main::daemon_log("WARNING: do not understand the message", 5);
&main::daemon_log("$@", 8);
+ $msg = undef;
+ $msg_hash = undef;
}
return ($msg, $msg_hash);
}
return ($msg, $msg_hash);
$target =~ /^GOSA$/i ||
$target =~ /^\*$/ ||
$target =~ /KNOWN_SERVER/i ||
$target =~ /^GOSA$/i ||
$target =~ /^\*$/ ||
$target =~ /KNOWN_SERVER/i ||
+ $target =~ /JOBDB/i ||
$target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ){
die "target '$target' is not a complete ip-address with port or a valid target name or a mac-address";
}
$target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ){
die "target '$target' is not a complete ip-address with port or a valid target name or a mac-address";
}
next;
}
my $host_key = $hit->{hostkey};
next;
}
my $host_key = $hit->{hostkey};
- daemon_log("SIPackages: known_server host_name: $host_name", 7);
- daemon_log("SIPackages: known_server host_key: $host_key", 7);
+ daemon_log("DEBUG: input_from_known_server: host_name: $host_name", 7);
+ daemon_log("DEBUG: input_from_known_server: host_key: $host_key", 7);
# check if module can open msg envelope with module key
my ($tmp_msg, $tmp_msg_hash) = &check_key_and_xml_validity($input, $host_key);
if( (!$tmp_msg) || (!$tmp_msg_hash) ) {
# check if module can open msg envelope with module key
my ($tmp_msg, $tmp_msg_hash) = &check_key_and_xml_validity($input, $host_key);
if( (!$tmp_msg) || (!$tmp_msg_hash) ) {
- daemon_log("SIPackages: deciphering raise error", 7);
+ daemon_log("DEBUG: input_from_known_server: deciphering raise error", 7);
daemon_log("$@", 8);
next;
}
daemon_log("$@", 8);
next;
}
}
if( (!$msg) || (!$msg_hash) || (!$module) ) {
}
if( (!$msg) || (!$msg_hash) || (!$module) ) {
- daemon_log("Incoming message is not from a known server", 3);
+ daemon_log("INFO: Incoming message is not from a known server", 5);
}
return ($msg, $msg_hash, $module);
}
return ($msg, $msg_hash, $module);
while( my ($hit_num, $hit) = each %{ $query_res } ) {
my $host_name = $hit->{hostname};
if( not $host_name =~ /^$remote_ip:\d*$/) {
while( my ($hit_num, $hit) = each %{ $query_res } ) {
my $host_name = $hit->{hostname};
if( not $host_name =~ /^$remote_ip:\d*$/) {
- next;
+ next;
}
my $host_key = $hit->{hostkey};
}
my $host_key = $hit->{hostkey};
- &daemon_log("SIPackages: known_client host_name: $host_name", 7);
- &daemon_log("SIPackages: known_client host_key: $host_key", 7);
+ &daemon_log("DEBUG: input_from_known_client: host_name: $host_name", 7);
+ &daemon_log("DEBUG: input_from_known_client: host_key: $host_key", 7);
# check if module can open msg envelope with module key
($msg, $msg_hash) = &check_key_and_xml_validity($input, $host_key);
if( (!$msg) || (!$msg_hash) ) {
# check if module can open msg envelope with module key
($msg, $msg_hash) = &check_key_and_xml_validity($input, $host_key);
if( (!$msg) || (!$msg_hash) ) {
- &daemon_log("SIPackages: deciphering raise error", 7);
+ &daemon_log("DEGUG: input_from_known_client: deciphering raise error", 7);
&daemon_log("$@", 8);
next;
}
&daemon_log("$@", 8);
next;
}
}
if( (!$msg) || (!$msg_hash) || (!$module) ) {
}
if( (!$msg) || (!$msg_hash) || (!$module) ) {
- &daemon_log("Incoming message is not from a known client", 3);
+ &daemon_log("INFO: Incoming message is not from a known client", 5);
}
return ($msg, $msg_hash, $module);
}
return ($msg, $msg_hash, $module);
no strict "refs";
my ($input) = @_ ;
my ($msg, $msg_hash, $module);
no strict "refs";
my ($input) = @_ ;
my ($msg, $msg_hash, $module);
+ my $error_string;
my %act_modules = %$known_modules;
my %act_modules = %$known_modules;
# check a key exists for this module
my $module_key = ${$mod."_key"};
# check a key exists for this module
my $module_key = ${$mod."_key"};
- if( ! $module_key ) {
+ if( not defined $module_key ) {
if( $mod eq 'ArpHandler' ) {
next;
}
daemon_log("ERROR: no key specified in config file for $mod", 1);
next;
}
if( $mod eq 'ArpHandler' ) {
next;
}
daemon_log("ERROR: no key specified in config file for $mod", 1);
next;
}
- daemon_log("$mod: $module_key", 5);
+ daemon_log("DEBUG: $mod: $module_key", 7);
# check if module can open msg envelope with module key
($msg, $msg_hash) = &check_key_and_xml_validity($input, $module_key);
# check if module can open msg envelope with module key
($msg, $msg_hash) = &check_key_and_xml_validity($input, $module_key);
- if( (!$msg) || (!$msg_hash) ) {
- #daemon_log("$mod: deciphering failed", 5);
+ if( (not defined $msg) || (not defined $msg_hash) ) {
next;
}
else {
next;
}
else {
}
if( (!$msg) || (!$msg_hash) || (!$module)) {
}
if( (!$msg) || (!$msg_hash) || (!$module)) {
- daemon_log("Incoming message is not from a unknown host", 5);
+ daemon_log("INFO: Incoming message is not from an unknown host", 5);
}
return ($msg, $msg_hash, $module);
}
return ($msg, $msg_hash, $module);
if(not defined $socket) {
return;
}
if(not defined $socket) {
return;
}
- &daemon_log("open_socket: $PeerAddr", 7);
+# &daemon_log("DEBUG: open_socket: $PeerAddr", 7);
return $socket;
}
return $socket;
}
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
- daemon_log("cannot send ".$header."msg to $address , host not reachable", 1);
+ daemon_log("ERROR: cannot send ".$header."msg to $address , host not reachable", 1);
$error++;
}
$error++;
}
# send xml msg
print $socket $crypted_msg."\n";
# send xml msg
print $socket $crypted_msg."\n";
- daemon_log("send ".$header."msg to $address", 1);
+ daemon_log("INFO: send ".$header."msg to $address", 5);
daemon_log("message:\n$msg", 8);
}
daemon_log("message:\n$msg", 8);
}
}
}
}
}
}
}
-
- return;
+ return $error;
}
}
my ($answer_header, @answer_target_l, $answer_source);
my $client_answer;
my ($answer_header, @answer_target_l, $answer_source);
my $client_answer;
- daemon_log("Incoming msg from '".$heap->{'remote_ip'}."'", 7);
- daemon_log("message:\n$input", 8);
+ daemon_log("INFO: Incoming msg from '".$heap->{'remote_ip'}."'", 5);
+ daemon_log("DEBUG: Incoming message:\n$input", 8);
####################
# check incoming msg
####################
# check incoming msg
######################
# process incoming msg
if( $error == 0) {
######################
# process incoming msg
if( $error == 0) {
- daemon_log("Processing module ".$module, 5);
+ daemon_log("DEBUG: Processing module ".$module, 7);
$answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id);
if ( 0 > @{$answer_l} ) {
my $answer_str = join("\n", @{$answer_l});
$answer_l = &{ $module."::process_incoming_msg" }($msg, $msg_hash, $session_id);
if ( 0 > @{$answer_l} ) {
my $answer_str = join("\n", @{$answer_l});
- daemon_log("$module: Got answer from module: \n".$answer_str,8);
+ daemon_log("DEGUB: $module: Got answer from module: \n".$answer_str,8);
}
}
if( !$answer_l ) { $error++ };
}
}
if( !$answer_l ) { $error++ };
# deliver msg to all targets
foreach my $answer_target ( @answer_target_l ) {
# deliver msg to all targets
foreach my $answer_target ( @answer_target_l ) {
+
+ # targets of msg are all gosa-si-clients in known_clients_db
if( $answer_target eq "*" ) {
# answer is for all clients
my $sql_statement= "SELECT * FROM known_clients";
if( $answer_target eq "*" ) {
# answer is for all clients
my $sql_statement= "SELECT * FROM known_clients";
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
}
}
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
}
}
- elsif( $answer_target eq "GOSA" ) {
- $answer =~ /<session_id>(\d+)<\/session_id>/;
- my $session_id = $1;
- my $add_on = "";
- if( defined $session_id ) {
- $add_on = ".session_id=$session_id";
- }
-
- # answer is for GOSA and has to returned to connected client
- my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
- $client_answer = $gosa_answer.$add_on;
- }
+ # targets of msg are all gosa-si-server in known_server_db
elsif( $answer_target eq "KNOWN_SERVER" ) {
# answer is for all server in known_server
my $sql_statement= "SELECT * FROM known_server";
elsif( $answer_target eq "KNOWN_SERVER" ) {
# answer is for all server in known_server
my $sql_statement= "SELECT * FROM known_server";
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
}
}
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
}
}
+
+ # target of msg is GOsa
+ elsif( $answer_target eq "GOSA" ) {
+ $answer =~ /<session_id>(\d+)<\/session_id>/;
+ my $session_id = $1;
+ my $add_on = "";
+ if( defined $session_id ) {
+ $add_on = ".session_id=$session_id";
+ }
+ # answer is for GOSA and has to returned to connected client
+ my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
+ $client_answer = $gosa_answer.$add_on;
+ }
+
+ # target of msg is job queue at this host
+ elsif( $answer_target eq "JOBDB") {
+ $answer =~ /<header>(\S+)<\/header>/;
+ my $header;
+ if( defined $1 ) { $header = $1; }
+ &send_msg_to_target($answer, $server_address, $GosaPackages_key, $header);
+ }
+
+ # target of msg is a mac address
elsif( $answer_target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) {
daemon_log("target is mac address '$answer_target', looking for host in known_clients", 3);
my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$answer_target'";
elsif( $answer_target =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i ) {
daemon_log("target is mac address '$answer_target', looking for host in known_clients", 3);
my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$answer_target'";
my $host_name = $hit->{hostname};
my $host_key = $hit->{hostkey};
$answer =~ s/$answer_target/$host_name/g;
my $host_name = $hit->{hostname};
my $host_key = $hit->{hostkey};
$answer =~ s/$answer_target/$host_name/g;
- daemon_log("found host '$host_name', assoziated to '$answer_target'", 3);
+ daemon_log("found host '$host_name', associated to '$answer_target'", 3);
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
$found_ip_flag++ ;
}
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
$found_ip_flag++ ;
}
}
}
}
}
- } else {
- # ... answer is for one specific host
+ # answer is for one specific host
+ } else {
# get encrypt_key
my $encrypt_key = &get_encrypt_key($answer_target);
if( not defined $encrypt_key ) {
# get encrypt_key
my $encrypt_key = &get_encrypt_key($answer_target);
if( not defined $encrypt_key ) {
# check gosa job queue for jobs with executable timestamp
my $timestamp = &get_time();
# check gosa job queue for jobs with executable timestamp
my $timestamp = &get_time();
-
my $sql_statement = "SELECT * FROM ".$job_queue_table_name.
" WHERE status='waiting' AND timestamp<'$timestamp'";
my $sql_statement = "SELECT * FROM ".$job_queue_table_name.
" WHERE status='waiting' AND timestamp<'$timestamp'";
-
my $res = $job_db->select_dbentry( $sql_statement );
while( my ($id, $hit) = each %{$res} ) {
my $res = $job_db->select_dbentry( $sql_statement );
while( my ($id, $hit) = each %{$res} ) {
-
my $jobdb_id = $hit->{id};
my $jobdb_id = $hit->{id};
- my $macaddress = $hit->{macaddress};
- my $job_msg_hash = &transform_msg2hash($hit->{xmlmessage});
- my $out_msg_hash = $job_msg_hash;
+ my $macaddress = $hit->{'macaddress'};
+ my $job_msg = $hit->{'xmlmessage'};
+ my $header = $hit->{'headertag'};
my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$macaddress'";
my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
# expect macaddress is unique!!!!!!
my $target = $res_hash->{1}->{hostname};
if (not defined $target) {
my $sql_statement = "SELECT * FROM known_clients WHERE macaddress='$macaddress'";
my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
# expect macaddress is unique!!!!!!
my $target = $res_hash->{1}->{hostname};
if (not defined $target) {
- &daemon_log("ERROR: no host found for mac address: $job_msg_hash->{mac}[0]", 1);
- &daemon_log("xml message: $hit->{xmlmessage}", 5);
+ &daemon_log("ERROR: no host found for mac address: $macaddress", 1);
+ &daemon_log("$hit->{xmlmessage}", 8);
my $sql_statement = "UPDATE $job_queue_table_name ".
"SET status='error', result='no host found for mac address' ".
"WHERE id='$jobdb_id'";
my $sql_statement = "UPDATE $job_queue_table_name ".
"SET status='error', result='no host found for mac address' ".
"WHERE id='$jobdb_id'";
next;
}
next;
}
- # add target
- &add_content2xml_hash($out_msg_hash, "target", $target);
-
- # add new header
- my $out_header = $job_msg_hash->{header}[0];
- $out_header =~ s/job_/gosa_/;
- delete $out_msg_hash->{header};
- &add_content2xml_hash($out_msg_hash, "header", $out_header);
+ # change header
+ $job_msg =~ s/<header>job_/<header>gosa_/;
# add sqlite_id
# add sqlite_id
- &add_content2xml_hash($out_msg_hash, "jobdb_id", $jobdb_id);
-
- my $out_msg = &create_xml_string($out_msg_hash);
+ $job_msg =~ s/<\/xml>$/<jobdb_id>$jobdb_id<\/jobdb_id><\/xml>/;
- # encrypt msg as a GosaPackage module
- my $cipher = &create_ciphering($GosaPackages_key);
- my $crypted_out_msg = &encrypt_msg($out_msg, $cipher);
-
- my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $GosaPackages_key);
-
- if ($error == 0) {
- my $sql_statement = "UPDATE $job_queue_table_name ".
- "SET status='processing', targettag='$target' ".
- "WHERE id='$jobdb_id'";
- my $res = $job_db->update_dbentry($sql_statement);
- } else {
- my $sql_statement = "UPDATE $job_queue_table_name ".
- "SET status='error' ".
- "WHERE id='$jobdb_id'";
- my $res = $job_db->update_dbentry($sql_statement);
- }
- }
+ my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header);
+ }
$kernel->delay_set('watch_for_new_jobs',3);
}
$kernel->delay_set('watch_for_new_jobs',3);
}
#unlink('/tmp/gosa_si_lock*');
# connect to gosa-si job queue
#unlink('/tmp/gosa_si_lock*');
# connect to gosa-si job queue
-my @job_col_names = ("id INTEGER", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
+my @job_col_names = ("id INTEGER", "timestamp", "status", "result", "progress", "headertag", "targettag", "xmlmessage", "macaddress");
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table('jobs', \@job_col_names);
# connect to known_clients_db
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table('jobs', \@job_col_names);
# connect to known_clients_db
-my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events');
+my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events', 'login');
$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
$known_clients_db->create_table('known_clients', \@clients_col_names);
$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
$known_clients_db->create_table('known_clients', \@clients_col_names);