index 70e998bfb4832919825e70317d350f8d592038ed..f03074b18c8fe398cf610294445317ab981cd73c 100644 (file)
use warnings;
use GOSA::GosaSupportDaemon;
use IO::Socket::INET;
+use Socket;
use XML::Simple;
use File::Spec;
use Data::Dumper;
use GOSA::DBsqlite;
use MIME::Base64;
+my $event_dir = "/usr/lib/gosa-si/server/events";
+use lib "/usr/lib/gosa-si/server/events";
+
BEGIN{}
END{}
-my ($server_activ, $server_port, $server_passwd, $max_clients, $server_event_dir);
-my ($bus_activ, $bus_passwd, $bus_ip, $bus_port);
-my ($gosa_activ, $gosa_ip, $gosa_port, $gosa_passwd);
+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);
my $gosa_server;
-
-my %cfg_defaults =
-("general" =>
- {"job_queue_file_name" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
- },
-"server" =>
- {"server_activ" => [\$server_activ, "on"],
- "server_port" => [\$server_port, "20081"],
- "server_passwd" => [\$server_passwd, ""],
- "max_clients" => [\$max_clients, 100],
- "server_event_dir" => [\$server_event_dir, '/usr/lib/gosa-si/server/events'],
- },
-"bus" =>
- {"bus_activ" => [\$bus_activ, "on"],
- "bus_passwd" => [\$bus_passwd, ""],
- "bus_ip" => [\$bus_ip, ""],
- "bus_port" => [\$bus_port, "20080"],
+my $event_hash;
+
+my %cfg_defaults = (
+"server" => {
+ "ip" => [\$server_ip, "0.0.0.0"],
+ "port" => [\$server_port, "20081"],
+ "key" => [\$server_passwd, ""],
+ "max-clients" => [\$max_clients, 100],
},
-"gosa" =>
- {"gosa_activ" => [\$gosa_activ, "on"],
- "gosa_ip" => [\$gosa_ip, ""],
- "gosa_port" => [\$gosa_port, "20082"],
- "gosa_passwd" => [\$gosa_passwd, "none"],
+"GOsaPackages" => {
+ "ip" => [\$gosa_ip, "0.0.0.0"],
+ "port" => [\$gosa_port, "20082"],
+ "key" => [\$gosa_passwd, "none"],
+ "job-queue" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
},
);
# read configfile and import variables
&read_configfile();
-
-# detect own ip and mac address
-my ($server_ip, $server_mac_address) = &get_ip_and_mac();
+$network_interface= &get_interface_for_ip($server_ip);
+$gosa_mac_address= &get_mac($network_interface);
# complete addresses
-my $server_address = "$server_ip:$server_port";
-my $bus_address = "$bus_ip:$bus_port";
+if( inet_aton($server_ip) ){ $server_ip = inet_ntoa(inet_aton($server_ip)); }
+our $server_address = "$server_ip:$server_port";
+if( inet_aton($gosa_ip) ){ $gosa_ip = inet_ntoa(inet_aton($gosa_ip)); }
my $gosa_address = "$gosa_ip:$gosa_port";
# create general settings for this module
-my $gosa_cipher = &create_ciphering($gosa_passwd);
+#y $gosa_cipher = &create_ciphering($gosa_passwd);
my $xml = new XML::Simple();
-# 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 $table_name = "jobs";
-my $sqlite = GOSA::DBsqlite->new($job_queue_file_name);
-
-
+# import events
+&import_events();
## FUNCTIONS #################################################################
sub get_module_info {
my @info = ($gosa_address,
$gosa_passwd,
- $gosa_server,
- $gosa_activ,
- "socket",
);
return \@info;
}
#===============================================================================
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 {
}
}
-
#=== 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
+# NAME: get_interface_for_ip
+# PARAMETERS: ip address (i.e. 192.168.0.1)
+# RETURNS: array: list of interfaces if ip=0.0.0.0, matching interface if found, undef else
+# DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
#===============================================================================
-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);
+sub get_interface_for_ip {
+ my $result;
+ my $ip= shift;
+ if ($ip && length($ip) > 0) {
+ my @ifs= &get_interfaces();
+ if($ip eq "0.0.0.0") {
+ $result = "all";
+ } else {
+ foreach (@ifs) {
+ my $if=$_;
+ if(get_ip($if) eq $ip) {
+ $result = $if;
+ }
+ }
+ }
+ }
+ return $result;
}
-
#=== 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
+# NAME: get_interfaces
+# PARAMETERS: none
+# RETURNS: (list of interfaces)
+# DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
#===============================================================================
-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;
-}
+sub get_interfaces {
+ my @result;
+ my $PROC_NET_DEV= ('/proc/net/dev');
+ open(PROC_NET_DEV, "<$PROC_NET_DEV")
+ or die "Could not open $PROC_NET_DEV";
-#=== 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: incoming msg: \n$crypted_msg", 7);
+ my @ifs = <PROC_NET_DEV>;
- $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);
-
- # 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: $gosa_passwd", 7);
-
- $gosa_cipher = &create_ciphering($gosa_passwd);
-
- # determine the correct passwd for deciphering of the incoming msgs
- my $msg = "";
- my $msg_hash;
- eval{
- $msg = &decrypt_msg($crypted_msg, $gosa_cipher);
- &main::daemon_log("GosaPackages: decrypted_msg: \n$msg", 7);
-
- $msg_hash = $xml->XMLin($msg, ForceArray=>1);
- };
- if($@) {
- &main::daemon_log("WARNING: GosaPackages do not understand the message:", 5);
- &main::daemon_log("$@", 7);
- return;
- }
+ close(PROC_NET_DEV);
- my $header = @{$msg_hash->{header}}[0];
-
- &main::daemon_log("recieve '$header' at GosaPackages from $host", 1);
- &main::daemon_log("$msg", 7);
-
- 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;
- }
+ # Eat first two line
+ shift @ifs;
+ shift @ifs;
- if ($out_msg =~ /<jobdb_id>(\d*?)<\/jobdb_id>/) {
- my $job_id = $1;
- my $sql = "UPDATE '$main::job_queue_table_name' SET status='done', result='$out_msg' WHERE id='$job_id'";
- my $res = $main::job_db->exec_statement($sql);
- return;
-
- } else {
- my $out_cipher = &create_ciphering($gosa_passwd);
- $out_msg = &encrypt_msg($out_msg, $out_cipher);
- return $out_msg;
- }
+ chomp @ifs;
+ foreach my $line(@ifs) {
+ my $if= (split /:/, $line)[0];
+ $if =~ s/^\s+//;
+ push @result, $if;
+ }
+ return @result;
}
-sub process_gosa_msg {
- my ($msg, $header) = @_ ;
- my $out_msg;
- $header =~ s/gosa_//;
- &main::daemon_log("GosaPackages: got a gosa msg $header", 5);
-
- # decide wether msg is a core function or a event handler
- if ( $header eq 'query_jobdb') { $out_msg = &query_jobdb }
- elsif ($header eq 'delete_jobdb_entry') { $out_msg = &delete_jobdb_entry }
- elsif ($header eq 'clear_jobdb') { $out_msg = &clear_jobdb }
- elsif ($header eq 'update_status_jobdb_entry' ) { $out_msg = &update_status_jobdb_entry }
- elsif ($header eq 'update_timestamp_jobdb_entry' ) { $out_msg = &update_timestamp_jobdb_entry }
- else {
- # msg could not be assigned to core function
- # fetch all available eventhandler under $server_event_dir
- opendir (DIR, $server_event_dir) or &main::daemon_log("ERROR cannot open $server_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($server_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(<PIPE>) {
- $out_msg.=$_;
- }
- close(PIPE);
- &main::daemon_log("GosaPackages: answer of cmd: $out_msg", 5);
- last;
+#=== FUNCTION ================================================================
+# NAME: get_mac
+# PARAMETERS: interface name (i.e. eth0)
+# RETURNS: (mac address)
+# DESCRIPTION: Uses ioctl to get mac address directly from system.
+#===============================================================================
+sub get_mac {
+ my $ifreq= shift;
+ my $result;
+ if ($ifreq && length($ifreq) > 0) {
+ if($ifreq eq "all") {
+ $result = "00:00:00:00:00:00";
+ } else {
+ my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list
+
+ # A configured MAC Address should always override a guessed value
+ if ($gosa_mac_address and length($gosa_mac_address) > 0) {
+ $result= $gosa_mac_address;
+ }
+
+ socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')
+ or die "socket: $!";
+
+ if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) {
+ my ($if, $mac)= unpack 'h36 H12', $ifreq;
+
+ if (length($mac) > 0) {
+ $mac=~ m/^([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/;
+ $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6);
+ $result = $mac;
+ }
+ }
+ }
}
- }
-
- # if delivery not possible raise error and return
- if (not defined $out_msg) {
- &main::daemon_log("ERROR: GosaPackages: no event handler or core function defined for $header", 1);
- } elsif ($out_msg eq "") {
- &main::daemon_log("ERROR: GosaPackages got not answer from event_handler $header", 1);
- }
- return $out_msg;
-
+ return $result;
}
+#=== FUNCTION ================================================================
+# NAME: get_ip
+# PARAMETERS: interface name (i.e. eth0)
+# RETURNS: (ip address)
+# DESCRIPTION: Uses ioctl to get ip address directly from system.
+#===============================================================================
+sub get_ip {
+ my $ifreq= shift;
+ my $result= "";
+ my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list
+ my $proto= getprotobyname('ip');
+
+ socket SOCKET, PF_INET, SOCK_DGRAM, $proto
+ or die "socket: $!";
+
+ if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) {
+ my ($if, $sin) = unpack 'a16 a16', $ifreq;
+ my ($port, $addr) = sockaddr_in $sin;
+ my $ip = inet_ntoa $addr;
+
+ if ($ip && length($ip) > 0) {
+ $result = $ip;
+ }
+ }
-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);
-
- # 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=>$main::job_queue_table_name,
- timestamp=>@{$msg_hash->{timestamp}}[0],
- status=>'waiting',
- result=>'none',
- headertag=>$header,
- targettag=>$target,
- xmlmessage=>$msg,
- macaddress=>@{$msg_hash->{mac}}[0],
- };
- 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("GosaPackages: $header job successfully added to job queue", 3);
- return "<xml><1>$res</1></xml>";
-
+ return $result;
}
-sub db_res_2_xml {
- my ($db_res) = @_ ;
- my $xml = "<xml>";
+sub import_events {
+ if (not -e $event_dir) {
+ &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 ( my ($hit, $hash) = each %{ $db_res } ) {
- $xml .= "<answer$hit>";
+ 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
- while ( my ($column_name, $column_value) = each %{$hash} ) {
- $xml .= "<$column_name>";
- my $xml_content = $column_value;
- if( $column_name eq "xml" ) {
- $xml_content = &encode_base64($column_value);
- }
- $xml .= $xml_content;
- $xml .= "</$column_name>";
+ eval{ require $event; };
+ if( $@ ) {
+ &main::daemon_log("G ERROR: import of event module '$event' failed", 1);
+ &main::daemon_log("$@", 1);
+ next;
}
- $xml .= "</answer$hit>";
+ $event =~ /(\S*?).pm$/;
+ my $event_module = $1;
+ my $events_l = eval( $1."::get_events()") ;
+ foreach my $event_name (@{$events_l}) {
+ $event_hash->{$event_name} = $event_module;
+ }
+ my $events_string = join( ", ", @{$events_l});
+ &main::daemon_log("G DEBUG: GosaPackages from '$1' imported events $events_string", 8);
}
-
- $xml .= "</xml>";
- return $xml;
}
-## CORE FUNCTIONS ############################################################
-
-sub query_jobdb {
- my ($msg) = @_;
- my $msg_hash = &transform_msg2hash($msg);
+#=== 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 ($msg, $msg_hash, $session_id) = @_ ;
+ my $header = @{$msg_hash->{header}}[0];
+ my @msg_l;
+ my @out_msg_l;
- # prepare query sql statement
- my @where = @{$msg_hash->{where}};
- my $where_hash = {table=>$main::job_queue_table_name };
- foreach my $where_pram (@where) {
- my $where_val = @{$msg_hash->{$where_pram}}[0];
- if (defined $where_val) {
- $where_hash->{$where_pram} = $where_val;
- }
+ &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);
+ }
+ elsif ($header =~ /^gosa_/) {
+ @msg_l = &process_gosa_msg($msg, $msg_hash, $session_id);
+ }
+ else {
+ &main::daemon_log("$session_id ERROR: $header is not a valid GosaPackage-header, need a 'job_' or a 'gosa_' prefix", 1);
}
-
- # execute db query
- my $res_hash = $main::job_db->select_dbentry($where_hash);
-
- my $out_xml = &db_res_2_xml($res_hash);
- return $out_xml;
-}
-sub delete_jobdb_entry {
- my ($msg) = @_ ;
- my $msg_hash = &transform_msg2hash($msg);
-
- # prepare query sql statement
- my @where = @{$msg_hash->{where}};
- my $where_hash = {table=>$main::job_queue_table_name };
- foreach my $where_pram (@where) {
- my $where_val = @{$msg_hash->{$where_pram}}[0];
- if (defined $where_val) {
- $where_hash->{$where_pram} = $where_val;
+ foreach my $out_msg ( @msg_l ) {
+ # 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);
}
- }
-
- # execute db query
- my $db_res = $main::job_db->del_dbentry($where_hash);
- my $res;
- if( $db_res > 0 ) {
- $res = 0 ;
- } else {
- $res = 1;
}
- # prepare xml answer
- my $out_xml = "<xml><answer1>$res</answer1></xml>";
- return $out_xml;
-
+ return \@out_msg_l;
}
-sub clear_jobdb {
- my ($msg) = @_ ;
- my $msg_hash = &transform_msg2hash($msg);
-
- my $where_hash = {table=>$main::job_queue_table_name };
-
- # execute db query
- my $db_res = $main::job_db->del_dbentry($where_hash);
- print STDERR "db_res=$db_res\n";
- my $res;
- if( $db_res eq '0E0' ) {
- $res = 0 ;
- } else {
- $res = 1;
- }
-
- # prepare xml answer
- my $out_xml = "<xml><answer1>$res</answer1></xml>";
- return $out_xml;
-}
-sub update_status_jobdb_entry {
- my ($msg) = @_ ;
- my $msg_hash = &transform_msg2hash($msg);
+sub process_gosa_msg {
+ my ($msg, $msg_hash, $session_id) = @_ ;
+ my $out_msg;
+ my @out_msg_l = ('nohandler');
- # prepare query sql statement
- my $update_hash = {table=>$main::job_queue_table_name };
- if( exists $msg_hash->{where} ) {
- $update_hash->{where} = $msg_hash->{where};
- } else {
- $update_hash->{where} = [];
- }
+ my $header = @{$msg_hash->{'header'}}[0];
+ $header =~ s/gosa_//;
- if( not exists $msg_hash->{update}[0]->{status} ) {
- return "<xml><answer1>1</answer1></xml>";
+ if( exists $event_hash->{$header} ) {
+ # a event exists with the header as name
+ &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);
}
- $update_hash->{update} = [ { status=>$msg_hash->{update}[0]->{status} } ];
- # execute db query
- my $db_res = $main::job_db->update_dbentry($update_hash);
+ # 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);
+ @out_msg_l = ();
+ } elsif( $out_msg_l[0] eq 'nohandler') {
+ &main::daemon_log("$session_id ERROR: GosaPackages: no event handler or core function defined for '$header'", 1);
+ @out_msg_l = ();
+ }
+
+ return @out_msg_l;
+}
- # transform db answer to error returnment
- my $res;
- if( $db_res > 0 ) {
- $res = 0 ;
- } else {
- $res = 1;
- }
- # prepare xml answer
- my $out_xml = "<xml><answer1>$res</answer1></xml>";
- return $out_xml;
-}
+sub process_job_msg {
+ my ($msg, $msg_hash, $session_id)= @_ ;
+ my $out_msg;
+ my $error = 0;
-sub update_timestamp_jobdb_entry {
- my ($msg) = @_ ;
- my $msg_hash = &transform_msg2hash($msg);
+ my $header = @{$msg_hash->{'header'}}[0];
+ $header =~ s/job_//;
+ my $target = @{$msg_hash->{'target'}}[0];
- # prepare query sql statement
- my $update_hash = {table=>$main::job_queue_table_name };
- if( exists $msg_hash->{where} ) {
- $update_hash->{where} = $msg_hash->{where};
- } else {
- $update_hash->{where} = [];
- }
-
- if( not exists $msg_hash->{update}[0]->{timestamp} ) {
- return "<xml><answer1>1</answer1></xml>";
+ # if no timestamp is specified, use 19700101000000
+ my $timestamp = "19700101000000";
+ if( exists $msg_hash->{'timestamp'} ) {
+ $timestamp = @{$msg_hash->{'timestamp'}}[0];
}
- $update_hash->{update} = [ { timestamp=>$msg_hash->{update}[0]->{timestamp} } ];
-
- # execute db query
- my $db_res = $main::job_db->update_dbentry($update_hash);
-
- # transform db answer to error returnment
- my $res;
- if( $db_res > 0 ) {
- $res = 0 ;
+ #if no macaddress is specified, raise error
+ my $macaddress;
+ if( exists $msg_hash->{'macaddress'} ) {
+ $macaddress = @{$msg_hash->{'macaddress'}}[0];
+ } elsif (@{$msg_hash->{'target'}}[0] =~ /^([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 ) {
+ $macaddress = $1;
} else {
- $res = 1;
+ $error ++;
+ $out_msg = "<xml>".
+ "<header>answer</header>".
+ "<source>$server_address</source>".
+ "<target>GOSA</target>".
+ "<answer1>1</answer1>".
+ "<error_string>no mac address specified, neither in target-tag nor in macaddres-tag</error_string>".
+ "</xml>";
}
-
- # prepare xml answer
- my $out_xml = "<xml><answer1>$res</answer1></xml>";
- return $out_xml;
-
+
+ # 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=>[],
+ timestamp=>$timestamp,
+ status=>'waiting',
+ result=>'none',
+ progress=>'none',
+ headertag=>$header,
+ 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("$session_id ERROR: GosaPackages: process_job_msg: $res", 1);
+ } else {
+ &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>";
+ }
+
+ my @out_msg_l = ( $out_msg );
+ return @out_msg_l;
}
-
1;