Code

removed images.
[gosa.git] / gosa-si / modules / GosaPackages.pm
index 8976fa1138ff97de6e860e468b7ecd7de39e8de6..5791a318eb9fd1d4392f6e43b2da8793fc700782 100644 (file)
@@ -51,20 +51,17 @@ $gosa_mac_address= &get_mac($network_interface);
 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";
+$main::gosa_address = "$gosa_ip:$gosa_port";
 
-# create general settings for this module
-#y $gosa_cipher = &create_ciphering($gosa_passwd);
 my $xml = new XML::Simple();
 
 # import local events
 my ($error, $result, $event_hash) = &import_events($event_dir);
-if ($error == 0) {
-    foreach my $log_line (@$result) {
+
+foreach my $log_line (@$result) {
+    if ($log_line =~ / succeed: /) {
         &main::daemon_log("0 DEBUG: GosaPackages - $log_line", 7);
-    }
-} else {
-    foreach my $log_line (@$result) {
+    } else {
         &main::daemon_log("0 ERROR: GosaPackages - $log_line", 1);
     }
 }
@@ -73,7 +70,7 @@ if ($error == 0) {
 ## FUNCTIONS #################################################################
 
 sub get_module_info {
-    my @info = ($gosa_address,
+    my @info = ($main::gosa_address,
                 $gosa_passwd,
                 );
     return \@info;
@@ -105,61 +102,6 @@ sub read_configfile {
     }
 }
 
-#===  FUNCTION  ================================================================
-#         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_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:  get_interfaces 
-#   PARAMETERS:  none
-#      RETURNS:  (list of interfaces) 
-#  DESCRIPTION:  Uses proc fs (/proc/net/dev) to get list of interfaces.
-#===============================================================================
-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";
-
-        my @ifs = <PROC_NET_DEV>;
-
-        close(PROC_NET_DEV);
-
-        # Eat first two line
-        shift @ifs;
-        shift @ifs;
-
-        chomp @ifs;
-        foreach my $line(@ifs) {
-                my $if= (split /:/, $line)[0];
-                $if =~ s/^\s+//;
-                push @result, $if;
-        }
-
-        return @result;
-}
 
 #===  FUNCTION  ================================================================
 #         NAME:  get_mac 
@@ -168,95 +110,37 @@ sub get_interfaces {
 #  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;
-                                }
-                        }
-                }
-        }
-        return $result;
-}
+    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
 
-#===  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');
+                # 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, $proto
+            socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')
                 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(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) {
+                my ($if, $mac)= unpack 'h36 H12', $ifreq;
 
-                if ($ip && length($ip) > 0) {
-                        $result = $ip;
+                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;
                 }
+            }
         }
-
-        return $result;
+    }
+    return $result;
 }
 
 
-#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 (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
-#
-#        eval{ require $event; };
-#        if( $@ ) {
-#            &main::daemon_log("G ERROR: import of event module '$event' failed", 1);
-#            &main::daemon_log("$@", 1);
-#            next;
-#        }
-#
-#        $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);
-#    }
-#}
-
-
 #===  FUNCTION  ================================================================
 #         NAME:  process_incoming_msg
 #   PARAMETERS:  crypted_msg - string - incoming crypted message
@@ -345,11 +229,12 @@ sub process_gosa_msg {
         &main::daemon_log("$session_id ERROR: GosaPackages: no event handler or core function defined for '$header'", 1);
         @out_msg_l = ();
     } elsif ($out_msg_l[0] eq 'knownclienterror') {
+        &main::daemon_log("$session_id ERROR: no event handler found for '$header', check client registration events!", 1);
         &main::daemon_log("$session_id ERROR: no or more than 1 hits are found at known_clients_db with sql query: '$sql_events'", 1);
-        &main::daemon_log("$session_id WARNING: processing is aborted and message will not be forwarded");
+        &main::daemon_log("$session_id ERROR: processing is aborted and message will not be forwarded", 1);
         @out_msg_l = ();
     } elsif ($out_msg_l[0] eq 'noeventerror') {
-        &main::daemon_log("$session_id WARNING: client '$target' is not registered for event '$header', processing is aborted", 1); 
+        &main::daemon_log("$session_id ERROR: client '$target' is not registered for event '$header', processing is aborted", 1); 
         @out_msg_l = ();
     }
 
@@ -415,7 +300,7 @@ sub process_job_msg {
     if( $error == 0 ) {
         # add job to job queue
         my $func_dic = {table=>$main::job_queue_tn, 
-            primkey=>[],
+            primkey=>['macaddress', 'headertag'],
             timestamp=>$timestamp,
             status=>'waiting', 
             result=>'none',
@@ -425,6 +310,8 @@ sub process_job_msg {
             xmlmessage=>$msg,
             macaddress=>$macaddress,
                        plainname=>$plain_name,
+            siserver=>"localhost",
+            modified=>"1",
         };
         my $res = $main::job_db->add_dbentry($func_dic);
         if (not $res == 0) {
@@ -439,14 +326,5 @@ sub process_job_msg {
     return @out_msg_l;
 }
 
+# vim:ts=4:shiftwidth:expandtab
 1;
-
-
-
-
-
-
-
-
-
-