index 6f6a5e0b775381a4726a69ba92ee35404d1379d1..f03074b18c8fe398cf610294445317ab981cd73c 100644 (file)
use Data::Dumper;
use GOSA::DBsqlite;
use MIME::Base64;
-use utf8;
my $event_dir = "/usr/lib/gosa-si/server/events";
use lib "/usr/lib/gosa-si/server/events";
BEGIN{}
END{}
-my ($server_ip, $server_mac_address, $server_port, $server_passwd, $max_clients);
+my ($server_ip, $server_port, $server_passwd, $max_clients);
my ($gosa_ip, $gosa_mac_address, $gosa_port, $gosa_passwd, $network_interface);
my ($job_queue_timeout, $job_queue_file_name);
#===============================================================================
sub read_configfile {
my $cfg;
- if( defined( $main::cfg_file) && ( length($main::cfg_file) > 0 )) {
+ if( defined( $main::cfg_file) && ( (-s $main::cfg_file) > 0 )) {
if( -r $main::cfg_file ) {
$cfg = Config::IniFiles->new( -file => $main::cfg_file );
} else {
sub import_events {
if (not -e $event_dir) {
- &main::daemon_log("ERROR: cannot find directory or directory is not readable: $event_dir", 1);
+ &main::daemon_log("G ERROR: cannot find directory or directory is not readable: $event_dir", 1);
}
opendir (DIR, $event_dir) or die "ERROR while loading gosa-si-events from directory $event_dir : $!\n";
while (defined (my $event = readdir (DIR))) {
if( $event eq "." || $event eq ".." ) { next; }
- if( $event eq "siTriggered.pm" ) { next; } # SI specific events not needed in GosaPackages.pm
- if( $event eq "clMessages.pm" ) { next; } # SI specific events not needed in GosaPackages.pm
+ if( $event eq "siTriggered.pm" ) { next; } # SI specific events not needed in GosaPackages.pm
+ if( $event eq "clMessages.pm" ) { next; } # SI specific events not needed in GosaPackages.pm
eval{ require $event; };
if( $@ ) {
- &main::daemon_log("ERROR: import of event module '$event' failed", 1);
+ &main::daemon_log("G ERROR: import of event module '$event' failed", 1);
&main::daemon_log("$@", 1);
next;
}
$event_hash->{$event_name} = $event_module;
}
my $events_string = join( ", ", @{$events_l});
- &main::daemon_log("INFO: GosaPackages imported events $events_string", 5);
+ &main::daemon_log("G DEBUG: GosaPackages from '$1' imported events $events_string", 8);
}
}
my @msg_l;
my @out_msg_l;
- &main::daemon_log("DEBUG: GosaPackages: receive '$header'", 8);
+ &main::daemon_log("$session_id DEBUG: GosaPackages: msg to process '$header'", 7);
if ($header =~ /^job_/) {
@msg_l = &process_job_msg($msg, $msg_hash, $session_id);
@msg_l = &process_gosa_msg($msg, $msg_hash, $session_id);
}
else {
- &main::daemon_log("ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix", 1);
+ &main::daemon_log("$session_id ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix", 1);
}
foreach my $out_msg ( @msg_l ) {
-
- # keep job queue up-to-date and save result and status
- if (defined ($out_msg) && $out_msg =~ /<jobdb_id>(\d+)<\/jobdb_id>/) {
- my $job_id = $1;
- my $sql = "UPDATE '".$main::job_queue_tn."'".
- " SET status='processing'".
- " WHERE id='$job_id'";
- my $res = $main::job_db->exec_statement($sql);
- }
-
# substitute in all outgoing msg <source>GOSA</source> of <source>$server_address</source>
$out_msg =~ s/<source>GOSA<\/source>/<source>$server_address<\/source>/g;
-
+ $out_msg =~ s/<\/xml>/<session_id>$session_id<\/session_id><\/xml>/;
if (defined $out_msg){
push(@out_msg_l, $out_msg);
}
if( exists $event_hash->{$header} ) {
# a event exists with the header as name
- &main::daemon_log("INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5);
+ &main::daemon_log("$session_id INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5);
no strict 'refs';
@out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id);
}
# if delivery not possible raise error and return
if( not defined $out_msg_l[0] ) {
- &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3);
+# &main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3);
@out_msg_l = ();
} elsif( $out_msg_l[0] eq 'nohandler') {
- &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for '$header'", 1);
+ &main::daemon_log("$session_id ERROR: GosaPackages: no event handler or core function defined for '$header'", 1);
@out_msg_l = ();
}
my $header = @{$msg_hash->{'header'}}[0];
$header =~ s/job_//;
+ my $target = @{$msg_hash->{'target'}}[0];
# if no timestamp is specified, use 19700101000000
my $timestamp = "19700101000000";
"</xml>";
}
- # check wether mac address is already known in known_daemons or known_clients
- my $target = 'none';
+ # if mac address is already known in ldap, set plain_name to 'cn'
+ my $plain_name;
+ my $ldap_handle = &main::get_ldap_handle($session_id);
+ if( not defined $ldap_handle ) {
+ &main::daemon_log("$session_id ERROR: cannot connect to ldap", 1);
+ $plain_name = "none";
+
+ # try to fetch a 'real name'
+ } else {
+ my $mesg = $ldap_handle->search(
+ base => $main::ldap_base,
+ scope => 'sub',
+ attrs => ['cn'],
+ filter => "(macAddress=$macaddress)");
+ if($mesg->code) {
+ &main::daemon_log($mesg->error, 1);
+ $plain_name = "none";
+ } else {
+ my $entry= $mesg->entry(0);
+ $plain_name = $entry->get_value("cn");
+ }
+ }
if( $error == 0 ) {
# add job to job queue
my $func_dic = {table=>$main::job_queue_tn,
- primkey=>['id'],
+ primkey=>[],
timestamp=>$timestamp,
status=>'waiting',
result=>'none',
targettag=>$target,
xmlmessage=>$msg,
macaddress=>$macaddress,
+ plainname=>$plain_name,
};
-
my $res = $main::job_db->add_dbentry($func_dic);
if (not $res == 0) {
- &main::daemon_log("ERROR: GosaPackages: process_job_msg: $res", 1);
+ &main::daemon_log("$session_id ERROR: GosaPackages: process_job_msg: $res", 1);
} else {
- &main::daemon_log("INFO: GosaPackages: $header job successfully added to job queue", 5);
+ &main::daemon_log("$session_id INFO: GosaPackages: $header job successfully added to job queue", 5);
}
$out_msg = "<xml><header>answer</header><source>$server_address</source><target>GOSA</target><answer1>$res</answer1></xml>";
}