Code

fix bug: update known_clients at gosa-si/gosa-si-server
authorrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 9 Jan 2008 17:56:19 +0000 (17:56 +0000)
committerrettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8>
Wed, 9 Jan 2008 17:56:19 +0000 (17:56 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8278 594d385d-05f5-0310-b6e9-bd551577e9d8

gosa-si/gosa-si-server
gosa-si/modules/DBsqlite.pm
gosa-si/modules/GosaPackages.pm
gosa-si/modules/ServerPackages.pm
gosa-si/tests/client.php

index 3993ca464557399385db4e0e6682a69bda32388e..2d4b84d484fd688d59c0346a4bad91f4469077cc 100755 (executable)
@@ -218,7 +218,7 @@ sub daemon_log {
             chomp($msg);
             if($level <= $verbose){
                 print LOG_HANDLE "$level $msg\n";
-                if(defined $foreground) { print $msg."\n" }
+                if($foreground) { print $msg."\n" }
             }
     }
 #    close( LOG_HANDLE );
@@ -601,25 +601,25 @@ sub read_from_socket {
 #      RETURNS:  nothing
 #  DESCRIPTION:  nomen est omen
 #===============================================================================
-sub print_known_daemons {
-    my ($tmp) = @_ ;
-    print "####################################\n";
-    print "# status of known_daemons\n";
-    $shmda->shlock(LOCK_EX);
-    my @hosts = keys %$known_daemons;
-    foreach my $host (@hosts) {
-        my $status = $known_daemons->{$host}->{status} ;
-        my $passwd = $known_daemons->{$host}->{passwd};
-        my $timestamp = $known_daemons->{$host}->{timestamp};
-        print "$host\n";
-        print "\tstatus:    $status\n";
-        print "\tpasswd:    $passwd\n";
-        print "\ttimestamp: $timestamp\n";
-    }
-    $shmda->shunlock(LOCK_EX);
-    print "####################################\n";
-    return;
-}
+#sub print_known_daemons {
+#    my ($tmp) = @_ ;
+#    print "####################################\n";
+#    print "# status of known_daemons\n";
+#    $shmda->shlock(LOCK_EX);
+#    my @hosts = keys %$known_daemons;
+#    foreach my $host (@hosts) {
+#        my $status = $known_daemons->{$host}->{status} ;
+#        my $passwd = $known_daemons->{$host}->{passwd};
+#        my $timestamp = $known_daemons->{$host}->{timestamp};
+#        print "$host\n";
+#        print "\tstatus:    $status\n";
+#        print "\tpasswd:    $passwd\n";
+#        print "\ttimestamp: $timestamp\n";
+#    }
+#    $shmda->shunlock(LOCK_EX);
+#    print "####################################\n";
+#    return;
+#}
 
 
 #===  FUNCTION  ================================================================
@@ -979,15 +979,20 @@ daemon_log(" ", 1);
 daemon_log("$0 started!", 1);
 
 # Just fork, if we"re not in foreground mode
-if( ! $foreground ) { $pid = fork(); }
-else { $pid = $$; }
+if( ! $foreground ) { 
+    $pid = fork();  
+} else { 
+    $pid = $$; 
+}
 
 # Do something useful - put our PID into the pid_file
 if( 0 != $pid ) {
     open( LOCK_FILE, ">$pid_file" );
     print LOCK_FILE "$pid\n";
-close( LOCK_FILE );
-    if( !$foreground ) { exit( 0 ) };
+    close( LOCK_FILE );
+    if( !$foreground ) { 
+        exit( 0 ) 
+    };
 }
 
 # connect to gosa-si job queue
@@ -1063,28 +1068,28 @@ while(1) {
     }
 
 
-    if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) {
-        my $in_msg = <$arp_fifo>;
-        chomp($in_msg);
-        print "arp_activ: msg: $in_msg\n";
-        my $act_passwd = $known_daemons->{$bus_address}->{passwd};
-        print "arp_activ: arp_passwd: $act_passwd\n";
-
-        my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1);
-
-        my $target = &get_content_from_xml_hash($in_msg_hash, 'target');
-
-        if ($target eq $server_address) { 
-             print "arp_activ: forward to server\n";
-            my $arp_cipher = &create_ciphering($act_passwd);
-            my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher);
-            &activating_child($crypted_msg, $server_ip);
-        } else {
-            print "arp_activ: send to bus\n";
-            &send_msg_hash2address($in_msg_hash, $bus_address);
-        }
-        print "\n";
-    }
+#    if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) {
+#        my $in_msg = <$arp_fifo>;
+#        chomp($in_msg);
+#        print "arp_activ: msg: $in_msg\n";
+#        my $act_passwd = $known_daemons->{$bus_address}->{passwd};
+#        print "arp_activ: arp_passwd: $act_passwd\n";
+#
+#        my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1);
+#
+#        my $target = &get_content_from_xml_hash($in_msg_hash, 'target');
+#
+#        if ($target eq $server_address) { 
+#             print "arp_activ: forward to server\n";
+#            my $arp_cipher = &create_ciphering($act_passwd);
+#            my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher);
+#            &activating_child($crypted_msg, $server_ip);
+#        } else {
+#            print "arp_activ: send to bus\n";
+#            &send_msg_hash2address($in_msg_hash, $bus_address);
+#        }
+#        print "\n";
+#    }
 
 
     # check input fhd of all modules 
@@ -1109,8 +1114,6 @@ while(1) {
                     daemon_log("cannot read from $actual_ip", 5);
                 }
             }
-            #close($client);
-
         }
     }
 
@@ -1194,13 +1197,11 @@ while(1) {
         }
 
         # add target
-        print "select: target: $target\n";
         &add_content2xml_hash($out_msg_hash, "target", $target);
 
         # add new header
         my $out_header = $job_msg_hash->{header}[0];
         $out_header =~ s/job_/gosa_/;
-        print "select: header: $out_header\n";
         delete $out_msg_hash->{header};
         &add_content2xml_hash($out_msg_hash, "header", $out_header);
         
index 9f341ec5e132ab1eb83f06fb8da75227d6bb1649..db717fa7d4baabe4b79e20c67b1aeb5ea356d074 100644 (file)
@@ -71,20 +71,10 @@ sub add_dbentry {
         if (exists $arg->{$col_name}) {
             push(@add_list, $arg->{$col_name});
         }
-        # use default values for column values
-#        } else {
-#            my $default_val = "none";
-#            if ($col_name eq "timestamp") {
-#                $default_val = "19700101000000";
-#            }             
-#            push(@add_list, $default_val);
-#        }
     }    
 
     my $sql_statement = " INSERT INTO $table VALUES ('".join("', '", @add_list)."')";
-    print " INSERT INTO $table VALUES ('".join("', '", @add_list)."')\n";
     my $db_res = $obj->{dbh}->do($sql_statement);
-    print " DB result: $db_res\n";
     return 0;
 
 }
index eea707322b1140f74b22f5d9ca1cd3b0c4d928cc..255022e3d9262f09f3d39f16fd5bfa9e5576642e 100644 (file)
@@ -444,7 +444,6 @@ sub update_status_jobdb_entry {
         return "<xml><1>1</1></xml>";
     }
     $update_hash->{update} = [ { status=>$msg_hash->{update}[0]->{status} } ];
-    #$update_hash->{update} = $msg_hash->{update};
 
     # execute db query
     my $db_res = $main::job_db->update_dbentry($update_hash);
index 7797dc404d0d23d05ded81969dc896aab4534448..e3bee1793155dd72a64d39f11c4f1de303720e15 100644 (file)
@@ -487,17 +487,17 @@ sub here_i_am {
                                                 timestamp=>&get_time,
                                                 } );
     if ($res == 3) {
-        $res = $main::known_clients_db->update_dbentry( {table=>'known_clients', 
-                                                where=>'hostname',
-                                                hostname=>$source,
-                                                events=>$events,
-                                                macaddress=>$mac_address,
-                                                status=>'registered',
-                                                hostkey=>$new_passwd,
-                                                timestamp=>&get_time,
-                                                } );
+        my $update_hash = { table=>'known_clients' };
+        $update_hash->{where} = [ { hostname=>[$source] } ],
+        $update_hash->{update} = [ { events=>[$events],
+                                     macaddress=>[$mac_address],
+                                     status=>['registered'],
+                                     hostkey=>[$new_passwd],
+                                     timestamp=>[&get_time],
+                                    } ];
+        $res = $main::known_clients_db->update_dbentry( $update_hash );
     } 
-    if ($res > 0)  {
+    if ($res != 1)  {
         &main::daemon_log("ERROR: cannot add entry to known_clients: $res");
         return;
     }
@@ -507,8 +507,11 @@ sub here_i_am {
     &send_msg_hash2address($out_hash, $source, $new_passwd);
 
     # notify registered client to bus
-    $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
-    &send_msg_hash2address($out_hash, $bus_address);
+    if( $bus_activ eq "on") {
+        &main::daemon_log("send bus msg that client '$source' has registerd at server '$server_address'", 3);
+        $out_hash = &create_xml_hash("new_client", $server_address, $bus_address, $source);
+        &send_msg_hash2address($out_hash, $bus_address);
+    }
 
     # give the new client his ldap config
     &new_ldap_config($source);
@@ -606,7 +609,11 @@ sub new_ldap_config {
 
     # Sanity check
     if ($mesg->count != 1) {
-           &main::daemon_log("WARNING: client mac address $macaddress not found/not unique", 1);
+           &main::daemon_log("WARNING: client mac address $macaddress not found/not unique in ldap search", 1);
+        &main::daemon_log("\tbase: $ldap_base", 1);
+        &main::daemon_log("\tscope: sub", 1);
+        &main::daemon_log("\tattrs: dn, gotoLdapServer", 1);
+        &main::daemon_log("\tfilter: (&(objectClass=GOhard)(macaddress=$macaddress))", 1);
            return;
     }
 
index b52a4d8f3581e198671e2d74d04faac70fd284a4..0384e9535d004910b95fc7518fdeed07ad6b5724 100755 (executable)
@@ -15,7 +15,7 @@ if($sock->connected()){
        #$data = "<xml><header>gosa_ping</header><source>10.89.1.155:20082</source><target></target><mac>11:22:33:44:55</mac></xml>";
        #$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>19700101000000</timestamp> </xml>";
        #$data = "<xml> <header>job_sayHello</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
-       $data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
+       #$data = "<xml> <header>job_ping</header> <source>10.89.1.155:20083</source><mac>00:1B:77:04:8A:6C</mac> <timestamp>20130102133900</timestamp> </xml>";
 
 # delete
        #$data = "<xml> <header>gosa_delete_jobdb_entry</header> <where>headertag</where> <headertag>sayHello</headertag> </xml>";
@@ -29,7 +29,7 @@ if($sock->connected()){
        #$data = "<xml><header>gosa_query_jobdb</header><where>status</where><status>waiting</status></xml>";
        
 # clear
-       #$data = "<xml> <header>gosa_clear_jobdb</header> </xml>";
+       $data = "<xml> <header>gosa_clear_jobdb</header> </xml>";
 
   $sock->write($data);