Code

Updated to generate autonetwork conf
[gosa.git] / gosa-si / modules / SIPackages.pm
index ef5081e34f4a4c41c9bb964761201feb56be6dc5..8f052d07c7db414b6aa2761ecb114d1537f7ae65 100644 (file)
@@ -65,6 +65,7 @@ if((not defined($gosa_unit_tag)) || length($gosa_unit_tag) == 0) {
        # Read gosaUnitTag from LDAP
        my $tmp_ldap= Net::LDAP->new($ldap_uri);
        if(defined($tmp_ldap)) {
+               &main::daemon_log("Searching for servers gosaUnitTag with mac address $server_mac_address",6);
                my $mesg= $tmp_ldap->bind($ldap_admin_dn, password => $ldap_admin_password);
                # Perform search for Unit Tag
                $mesg = $tmp_ldap->search(
@@ -81,13 +82,49 @@ if((not defined($gosa_unit_tag)) || length($gosa_unit_tag) == 0) {
                                &main::daemon_log("Detected gosaUnitTag $unit_tag for creating entries", 4);
                                $gosa_unit_tag= $unit_tag;
                        }
-                       $mesg = $tmp_ldap->unbind;
                } else {
-                       &main::daemon_log("Not using gosaUnitTag",8);
+                       # Perform another search for Unit Tag
+                       my $hostname= `hostname -f`;
+                       &main::daemon_log("Searching for servers gosaUnitTag with hostname $hostname",6);
+                       $mesg = $tmp_ldap->search(
+                               base   => $ldap_base,
+                               scope  => 'sub',
+                               attrs  => ['gosaUnitTag'],
+                               filter => "(&(cn=$hostname)(objectClass=goServer))"
+                       );
+                       if ($mesg->count == 1) {
+                               my $entry= $mesg->entry(0);
+                               my $unit_tag= $entry->get_value("gosaUnitTag");
+                               if(defined($unit_tag) && length($unit_tag) > 0) {
+                                       &main::daemon_log("Detected gosaUnitTag $unit_tag for creating entries", 4);
+                                       $gosa_unit_tag= $unit_tag;
+                               }
+                       } else {
+                               # Perform another search for Unit Tag
+                               $hostname= `hostname -s`;
+                               &main::daemon_log("Searching for servers gosaUnitTag with hostname $hostname",6);
+                               $mesg = $tmp_ldap->search(
+                                       base   => $ldap_base,
+                                       scope  => 'sub',
+                                       attrs  => ['gosaUnitTag'],
+                                       filter => "(&(cn=$hostname)(objectClass=goServer))"
+                               );
+                               if ($mesg->count == 1) {
+                                       my $entry= $mesg->entry(0);
+                                       my $unit_tag= $entry->get_value("gosaUnitTag");
+                                       if(defined($unit_tag) && length($unit_tag) > 0) {
+                                               &main::daemon_log("Detected gosaUnitTag $unit_tag for creating entries", 4);
+                                               $gosa_unit_tag= $unit_tag;
+                                       }
+                               } else {
+                                       &main::daemon_log("Not using gosaUnitTag", 6);
+                               }
+                       }
                }
+       } else {
+               &main::daemon_log("Using gosaUnitTag from config-file: $gosa_unit_tag",6);
        }
-} else {
-       &main::daemon_log("Using gosaUnitTag from config-file: $gosa_unit_tag",6);
+       $tmp_ldap->unbind;
 }
 
 # complete addresses
@@ -396,24 +433,16 @@ sub process_incoming_msg {
                     &main::daemon_log("SIPackages: trigger wake for $_", 1);
                     do_wake($_);
                 }
-
             } else {
                 &main::daemon_log("ERROR: $header is an unknown core function", 1);
                 $error++;
             }
-        }
-               else {
-                       &main::daemon_log("msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5);
-                       push(@out_msg_l, $msg);
-               }
+        } else {
+               &main::daemon_log("msg is not for gosa-si-server '$server_address', deliver it to target '$target'", 5);
+               push(@out_msg_l, $msg);
+       }
     }
 
-#    if( $error == 0) {
-#        if( 0 == @out_msg_l ) {
-#                      push(@out_msg_l, $msg);
-#        }
-#    }
-    
     return \@out_msg_l;
 }
 
@@ -426,21 +455,44 @@ sub process_incoming_msg {
 #===============================================================================
 sub got_ping {
     my ($msg_hash) = @_;
-    
+
     my $source = @{$msg_hash->{source}}[0];
     my $target = @{$msg_hash->{target}}[0];
     my $header = @{$msg_hash->{header}}[0];
+    my $session_id = @{$msg_hash->{'session_id'}}[0];
+    my $act_time = &get_time;
+    my @out_msg_l;
+    my $out_msg;
+
+    # check known_clients_db
+    my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'";
+    my $query_res = $main::known_clients_db->select_dbentry( $sql_statement );
+    if( 1 == keys %{$query_res} ) {
+         my $sql_statement= "UPDATE known_clients ".
+            "SET status='$header', timestamp='$act_time' ".
+            "WHERE hostname='$source'";
+         my $res = $main::known_clients_db->update_dbentry( $sql_statement );
+    } 
     
-    if(exists $main::known_daemons->{$source}) {
-        &main::add_content2known_daemons(hostname=>$source, status=>$header);
-    } else {
-        &main::add_content2known_clients(hostname=>$source, status=>$header);
-    }
+    # check known_server_db
+    $sql_statement = "SELECT * FROM known_server WHERE hostname='$source'";
+    $query_res = $main::known_server_db->select_dbentry( $sql_statement );
+    if( 1 == keys %{$query_res} ) {
+         my $sql_statement= "UPDATE known_server ".
+            "SET status='$header', timestamp='$act_time' ".
+            "WHERE hostname='$source'";
+         my $res = $main::known_server_db->update_dbentry( $sql_statement );
+    } 
+
+    # create out_msg
+    my $out_hash = &create_xml_hash($header, $source, "GOSA");
+    &add_content2xml_hash($out_hash, "session_id", $session_id);
+    $out_msg = &create_xml_string($out_hash);
+    push(@out_msg_l, $out_msg);
     
-    return;
+    return @out_msg_l;
 }
 
-
 #===  FUNCTION  ================================================================
 #         NAME:  new_passwd
 #   PARAMETERS:  msg_hash - ref - hash from function create_xml_hash
@@ -734,12 +786,12 @@ sub new_ldap_config {
        @servers= sort (@servers);
 
        foreach $server (@servers){
-                # Conversation for backward compatibility
-                if ($server !=~ /^ldap[^:]+:\/\// ) {
-                        if ($server =~ /^([^:]+):(.*)$/ ) {
-                                $server= "1:dummy:ldap://$1/$2";
-                        }
-                }
+        # Conversation for backward compatibility
+        if ($server !=~ /^ldap[^:]+:\/\// ) {
+            if ($server =~ /^([^:]+):(.*)$/ ) {
+                $server= "1:dummy:ldap://$1/$2";
+            }
+        }
 
                $base= $server;
                $server =~ s%^[^:]+:[^:]+:(ldap.*://[^/]+)/.*$%$1%;
@@ -796,7 +848,7 @@ sub new_ldap_config {
        $mesg = $ldap->unbind;
 
        # Send information
-       return send_msg("new_ldap_config", $server_address, $address, \%data);
+       return &build_msg("new_ldap_config", $server_address, $address, \%data);
 }
 
 sub process_detected_hardware {
@@ -860,17 +912,20 @@ sub process_detected_hardware {
                        $entry->add("objectClass" => "gosaAdministrativeUnit");
                        $entry->add("gosaUnitTag" => $gosa_unit_tag);
                }
-               if(my $res=$entry->update($ldap)) {
+               my $res=$entry->update($ldap);
+               if(defined($res->{'errorMessage'}) &&
+                       length($res->{'errorMessage'}) >0) {
+                       &main::daemon_log("There was a problem adding the entries to LDAP:", 1);
+                       &main::daemon_log($res->{'errorMessage'}, 1);
+                       return;
+               } else {
                        # Fill $mesg again
                        $mesg = $ldap->search(
                                base   => $ldap_base,
                                scope  => 'sub',
                                filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
                        );
-               } else {
-                       &main::daemon_log("ERROR: There was a problem adding the entry", 1);
                }
-
        }
        
        if($mesg->count == 1) {
@@ -880,7 +935,8 @@ sub process_detected_hardware {
                        "gotoSndModule", "ghNetNic", "gotoXResolution", "ghSoundAdapter", "ghCpuType", "gotoXkbModel", 
                        "ghGfxAdapter", "gotoXMousePort", "ghMemSize", "gotoXMouseType", "ghUsbSupport", "gotoXHsync", 
                        "gotoXDriver", "gotoXVsync", "gotoXMonitor", "gotoHardwareChecksum") {
-                       if(defined($msg_hash->{detected_hardware}[0]->{$attribute})) {
+                       if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
+                               length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
                                if(defined($entry->get_value($attribute))) {
                                        $entry->delete($attribute);
                                }
@@ -890,7 +946,8 @@ sub process_detected_hardware {
                }
                foreach my $attribute (
                        "gotoModules", "ghScsiDev", "ghIdeDev") {
-                       if(defined($msg_hash->{detected_hardware}[0]->{$attribute})) {
+                       if(defined($msg_hash->{detected_hardware}[0]->{$attribute}) &&
+                               length($msg_hash->{detected_hardware}[0]->{$attribute}) >0 ) {
                                if(defined($entry->get_value($attribute))) {
                                        $entry->delete($attribute);
                                }
@@ -898,10 +955,14 @@ sub process_detected_hardware {
                                        $entry->add($attribute => $array_entry);
                                }
                        }
-
                }
 
-               if($entry->update($ldap)) {
+               my $res=$entry->update($ldap);
+               if(defined($res->{'errorMessage'}) &&
+                       length($res->{'errorMessage'}) >0) {
+                       &main::daemon_log("There was a problem adding the entries to LDAP:", 1);
+                       &main::daemon_log($res->{'errorMessage'}, 1);
+               } else {
                        &main::daemon_log("Added Hardware configuration to LDAP", 4);
                }
 
@@ -1032,7 +1093,7 @@ sub hardware_config {
        &main::daemon_log("Send detect_hardware message to $address", 4);
 
        # Send information
-       return send_msg("detect_hardware", $server_address, $address, \%data);
+       return &build_msg("detect_hardware", $server_address, $address, \%data);
 }
 
 sub server_matches {
@@ -1132,4 +1193,5 @@ sub execute_actions {
 }
 
 
+#vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 1;