Code

* gosa-si-server
[gosa.git] / gosa-si / gosa-si-client
index c4a59936190aeb6695299ead8ac54528c25d3e91..df75a81e132eb39d4bac2be1406c9428cf0a1f02 100755 (executable)
@@ -52,8 +52,8 @@ my (%cfg_defaults, $foreground, $verbose, $pid_file, $procid, $pid, $log_file, $
 my ($server_ip, $server_port, $server_timeout, $server_domain, $server_key_lifetime);
 my ($client_port, $ldap_enabled, $ldap_config, $pam_config, $nss_config);
 my $xml;
-my $default_server_key;
 my $event_hash;
+my $default_server_key;
 my @servers;
 my $gotoHardwareChecksum;
 my $gosa_si_client_fifo;
@@ -240,7 +240,7 @@ $SIG{INT} = \&sig_int_handler;
 #  DESCRIPTION: 
 #===============================================================================
 sub daemon_log {
-    # log into log_file
+# log into log_file
     my( $msg, $level ) = @_;
     if(not defined $msg) { return }
     if(not defined $level) { $level = 1 }
@@ -249,25 +249,26 @@ sub daemon_log {
         chmod 0600, $log_file;
         if(not defined open( LOG_HANDLE, ">>$log_file" )) {
             print STDERR "cannot open $log_file: $!";
-            return }
-            chomp($msg);
-            if($level <= $verbose){
-                my ($seconds, $minutes, $hours, $monthday, $month,
-                        $year, $weekday, $yearday, $sommertime) = localtime(time);
-                $hours = $hours < 10 ? $hours = "0".$hours : $hours;
-                $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
-                $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
-                my @monthnames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
-                $month = $monthnames[$month];
-                $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
-                $year+=1900;
-
-                my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n";
-                print LOG_HANDLE $log_msg;
-                if( $foreground ) { 
-                    print STDERR $log_msg;
-                }
+            return 
+        }
+        chomp($msg);
+        if($level <= $verbose){
+            my ($seconds, $minutes, $hours, $monthday, $month,
+                    $year, $weekday, $yearday, $sommertime) = localtime(time);
+            $hours = $hours < 10 ? $hours = "0".$hours : $hours;
+            $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
+            $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
+            my @monthnames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
+            $month = $monthnames[$month];
+            $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+            $year+=1900;
+
+            my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n";
+            print LOG_HANDLE $log_msg;
+            if( $foreground ) { 
+                print STDERR $log_msg;
             }
+        }
         close( LOG_HANDLE );
     }
 }
@@ -621,16 +622,16 @@ sub send_msg_to_target {
     # encrypt xml msg
     my $crypted_msg = &encrypt_msg($msg, $encrypt_key);
 
-       # xxxxxxxxxxxxxx
-
-       
-
     # opensocket
     my $socket = &open_socket($address);
     if( !$socket ) {
         daemon_log("ERROR: cannot send ".$msg_header."msg to $address , host not reachable", 1);
-        $REGISTERED = 0;        # if server is not available, cause reregistering
-        #$global_kernel->yield('register_at_gosa_si_server');
+        if ($REGISTERED == 1) {
+            $REGISTERED = 0;        # if server is not available, cause reregistering
+            daemon_log("INFO: cause reregistering at gosa-si-server", 5); 
+            $global_kernel->yield('register_at_gosa_si_server');
+
+        }
         $error++;
     }
     
@@ -638,7 +639,7 @@ sub send_msg_to_target {
     if( $error == 0 ) {
         print $socket $crypted_msg."\n";
         daemon_log("INFO: send ".$msg_header."msg to $address", 5);
-        daemon_log("DEBUG: message:\n$msg", 8);
+        daemon_log("DEBUG: message:\n$msg", 9);
     }
 
     # close socket in any case
@@ -691,7 +692,7 @@ sub open_socket {
     if(not defined $socket) {
         return;
     }
-    &daemon_log("open_socket: $PeerAddr", 7);
+    &daemon_log("DEBUG: open_socket: $PeerAddr", 7);
     return $socket;
 }
 
@@ -818,7 +819,7 @@ sub check_key_and_xml_validity {
     my $msg_hash;
     eval{
         $msg = &decrypt_msg($crypted_msg, $module_key);
-        &main::daemon_log("decrypted_msg: \n$msg", 8);
+        &main::daemon_log("decrypted_msg: \n$msg", 9);
 
         $msg_hash = $xml->XMLin($msg, ForceArray=>1);
 
@@ -1117,7 +1118,7 @@ sub server_input {
     
 
     daemon_log("INFO: Incoming msg from '$remote_ip'", 5);
-    daemon_log("DEBUG: Incoming msg:\n$input\n", 8);
+    daemon_log("DEBUG: Incoming msg:\n$input\n", 9);
 
     my ($msg, $msg_hash) = &check_key_and_xml_validity($input, $server_key);
     if( (!$msg) || (!$msg_hash) ) {
@@ -1149,12 +1150,12 @@ sub server_input {
         if( exists $event_hash->{$header} ) {
 
             # a event exists with the header as name
-            daemon_log("DEBUG: found event '$header' at event-module '".$event_hash->{$header}."'", 7);
+            daemon_log("INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5);
             no strict 'refs';
             $answer = &{$event_hash->{$header}."::$header"}($msg, $msg_hash);
         }
         else {
-            daemon_log("WARNING: no event '$header' found in event modules under $event_dir", 1);
+            daemon_log("WARNING: no event '$header' found in event modules under $event_dir", 3);
         }
     }
 
@@ -1249,8 +1250,8 @@ if ($client_headURL =~ /\/tag\// ||
 
 daemon_log(" ", 1);
 daemon_log("$prg started!", 1);
-daemon_log("status: $client_status", 1);
-daemon_log($client_status_hash->{$client_status}.": $client_revision", 1); 
+daemon_log("INFO: status: $client_status", 1);
+daemon_log("INFO: ".$client_status_hash->{$client_status}.": $client_revision", 1); 
 
 # delete old DBsqlite lock files
 system('rm -f /tmp/gosa_si_lock*gosa-si-client*');
@@ -1259,17 +1260,27 @@ system('rm -f /tmp/gosa_si_lock*gosa-si-client*');
 $client_address = $client_ip.":".$client_port;
 my $network_interface= &get_interface_for_ip($client_ip);
 $client_mac_address= &get_mac($network_interface);
-daemon_log("gosa-si-client ip address detected: $client_ip", 1);
-daemon_log("gosa-si-client mac address detected: $client_mac_address", 1);
+daemon_log("INFO: ip address detected: $client_ip", 1);
+daemon_log("INFO: gosa-si-client mac address detected: $client_mac_address", 1);
 
 
 # import events
-&import_events($event_dir);
+my ($error, $result, $tmp_hash) = &import_events($event_dir);
+$event_hash = $tmp_hash;
+if ($error == 0) {
+    foreach my $log_line (@$result) {
+        daemon_log("DEBUG: $log_line", 7);
+    }
+} else {
+    foreach my $log_line (@$result) {
+        daemon_log("ERROR: $log_line", 1);
+    }
+}
 
 
 # compute hardware checksum
 $gotoHardwareChecksum= &generate_hw_digest();
-daemon_log("gosa-si-client gotoHardwareChecksum detected: $gotoHardwareChecksum", 1);
+daemon_log("INFO: gotoHardwareChecksum detected: $gotoHardwareChecksum", 1);
 
 
 # create socket for incoming xml messages
@@ -1278,7 +1289,7 @@ POE::Component::Server::TCP->new(
        Port => $client_port,
        ClientInput => \&server_input,
 );
-daemon_log("start socket for incoming xml messages at port '$client_port' ", 1);
+daemon_log("INFO: start socket for incoming xml messages at port '$client_port' ", 1);
 
 
 # prepare variables