Code

bugfix: wrong changelog file for deb packages
[gosa.git] / gosa-si / gosa-si-server
index 262d1afd1ec962e081b6a4ed155ffdecd60d5c73..9d0f7ad9935303f3d141d8cb1486d9942fe25890 100755 (executable)
@@ -84,8 +84,11 @@ my %repo_dirs=();
 our (%cfg_defaults, $log_file, $pid_file, 
     $server_ip, $server_port, $ClientPackages_key, 
     $arp_activ, $gosa_unit_tag,
-    $GosaPackages_key, $gosa_ip, $gosa_port, $gosa_timeout,
+    $GosaPackages_key, $gosa_timeout,
     $foreign_server_string, $server_domain, $ServerPackages_key, $foreign_servers_register_delay,
+    $wake_on_lan_passwd, $job_synchronization, $modified_jobs_loop_delay,
+    $arp_enabled, $arp_interface,
+    $opsi_enabled, $opsi_server, $opsi_admin, $opsi_password,
 );
 
 # additional variable which should be globaly accessable
@@ -98,12 +101,6 @@ our $forground;
 our $cfg_file;
 our ($ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $ldap_server_dn);
 
-# dak variables
-our $dak_base_directory;
-our $dak_signing_keys_directory;
-our $dak_queue_directory;
-our $dak_user;
-
 # specifies the verbosity of the daemon_log
 $verbose = 0 ;
 
@@ -145,6 +142,8 @@ my @job_queue_col_names = ("id INTEGER PRIMARY KEY",
                "xmlmessage DEFAULT 'none'", 
                "macaddress DEFAULT 'none'",
                "plainname DEFAULT 'none'",
+        "siserver DEFAULT 'none'",
+        "modified DEFAULT '0'",
                );
 
 # holds all other gosa-si-server
@@ -206,12 +205,20 @@ my @msgs_to_decrypt = qw();
 my $max_children = 2;
 
 
+# loop delay for job queue to look for opsi jobs
+my $job_queue_opsi_delay = 10;
+our $opsi_client;
+our $opsi_url;
+
+
 %cfg_defaults = (
 "general" => {
     "log-file" => [\$log_file, "/var/run/".$prg.".log"],
     "pid-file" => [\$pid_file, "/var/run/".$prg.".pid"],
     },
 "server" => {
+    "ip" => [\$server_ip, "0.0.0.0"],
     "port" => [\$server_port, "20081"],
     "known-clients"        => [\$known_clients_file_name, '/var/lib/gosa-si/clients.db' ],
     "known-servers"        => [\$known_server_file_name, '/var/lib/gosa-si/servers.db'],
@@ -230,18 +237,13 @@ my $max_children = 2;
     "ldap-admin-password"  => [\$ldap_admin_password, ""],
     "gosa-unit-tag"        => [\$gosa_unit_tag, ""],
     "max-clients"          => [\$max_clients, 10],
+    "wol-password"           => [\$wake_on_lan_passwd, ""],
     },
 "GOsaPackages" => {
-    "ip" => [\$gosa_ip, "0.0.0.0"],
-    "port" => [\$gosa_port, "20082"],
     "job-queue" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
     "job-queue-loop-delay" => [\$job_queue_loop_delay, 3],
     "messaging-db-loop-delay" => [\$messaging_db_loop_delay, 3],
     "key" => [\$GosaPackages_key, "none"],
-       "dak-base" => [\$dak_base_directory, "/srv/archive"],
-       "dak-keyring" => [\$dak_signing_keys_directory, "/srv/archive/keyrings"],
-       "dak-queue" => [\$dak_queue_directory, "/srv/archive/queue"],
-       "dak-user" => [\$dak_user, "deb-dak"],
     },
 "ClientPackages" => {
     "key" => [\$ClientPackages_key, "none"],
@@ -251,7 +253,20 @@ my $max_children = 2;
     "domain"  => [\$server_domain, ""],
     "key"     => [\$ServerPackages_key, "none"],
     "key-lifetime" => [\$foreign_servers_register_delay, 120],
-}
+    "job-synchronization-enabled" => [\$job_synchronization, "true"],
+    "synchronization-loop" => [\$modified_jobs_loop_delay, 5],
+    },
+"ArpHandler" => {
+    "enabled"   => [\$arp_enabled, "true"],
+    "interface" => [\$arp_interface, "all"],
+       },
+"Opsi" => {
+    "enabled"  => [\$opsi_enabled, "false"], 
+    "server"   => [\$opsi_server, "localhost"],
+    "admin"    => [\$opsi_admin, "opsi-admin"],
+    "password" => [\$opsi_password, "secret"],
+   },
+
 );
 
 
@@ -276,32 +291,6 @@ EOF
 }
 
 
-#===  FUNCTION  ================================================================
-#         NAME:  read_configfile
-#   PARAMETERS:  cfg_file - string -
-#      RETURNS:  nothing
-#  DESCRIPTION:  read cfg_file and set variables
-#===============================================================================
-sub read_configfile {
-    my $cfg;
-    if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
-        if( -r $cfg_file ) {
-            $cfg = Config::IniFiles->new( -file => $cfg_file );
-        } else {
-            print STDERR "Couldn't read config file!\n";
-        }
-    } else {
-        $cfg = Config::IniFiles->new() ;
-    }
-    foreach my $section (keys %cfg_defaults) {
-        foreach my $param (keys %{$cfg_defaults{ $section }}) {
-            my $pinfo = $cfg_defaults{ $section }{ $param };
-            ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] );
-        }
-    }
-}
-
-
 #===  FUNCTION  ================================================================
 #         NAME:  logging
 #   PARAMETERS:  level - string - default 'info'
@@ -323,7 +312,7 @@ sub daemon_log {
             return 
         }
         chomp($msg);
-        $msg =~s/\n//g;   # no newlines are allowed in log messages, this is important for later log parsing
+        #$msg =~s/\n//g;   # no newlines are allowed in log messages, this is important for later log parsing
         if($level <= $verbose){
             my ($seconds, $minutes, $hours, $monthday, $month,
                     $year, $weekday, $yearday, $sommertime) = localtime(time);
@@ -443,10 +432,9 @@ sub import_modules {
         }
                my $mod_name = $1;
 
+        # ArpHandler switch
         if( $file =~ /ArpHandler.pm/ ) {
-            if( $no_arp > 0 ) {
-                next;
-            }
+            if( $arp_enabled eq "false" ) { next; }
         }
         
         eval { require $file; };
@@ -463,14 +451,40 @@ sub import_modules {
                        }
                }
     }   
+
     close (DIR);
 }
 
+#===  FUNCTION  ================================================================
+#         NAME:  password_check
+#   PARAMETERS:  nothing
+#      RETURNS:  nothing
+#  DESCRIPTION:  escalates an critical error if two modules exist which are avaialable by 
+#                the same password
+#===============================================================================
+sub password_check {
+    my $passwd_hash = {};
+    while (my ($mod_name, $mod_info) = each %$known_modules) {
+        my $mod_passwd = @$mod_info[1];
+        if (not defined $mod_passwd) { next; }
+        if (not exists $passwd_hash->{$mod_passwd}) {
+            $passwd_hash->{$mod_passwd} = $mod_name;
+
+        # escalates critical error
+        } else {
+            &daemon_log("0 ERROR: two loaded modules do have the same password. Please modify the 'key'-parameter in config file");
+            &daemon_log("0 ERROR: module='$mod_name' and module='".$passwd_hash->{$mod_passwd}."'");
+            exit( -1 );
+        }
+    }
+
+}
+
 
 #===  FUNCTION  ================================================================
 #         NAME:  sig_int_handler
 #   PARAMETERS:  signal - string - signal arose from system
-#      RETURNS:  noting
+#      RETURNS:  nothing
 #  DESCRIPTION:  handels tasks to be done befor signal becomes active
 #===============================================================================
 sub sig_int_handler {
@@ -527,7 +541,7 @@ sub check_key_and_xml_validity {
         }
     };
     if($@) {
-        daemon_log("$session_id DEBUG: do not understand the message: $@", 7);
+        daemon_log("$session_id ERROR: do not understand the message: $@", 1);
         $msg = undef;
         $msg_hash = undef;
     }
@@ -537,7 +551,7 @@ sub check_key_and_xml_validity {
 
 
 sub check_outgoing_xml_validity {
-    my ($msg) = @_;
+    my ($msg, $session_id) = @_;
 
     my $msg_hash;
     eval{
@@ -590,8 +604,8 @@ sub check_outgoing_xml_validity {
         }
     };
     if($@) {
-        daemon_log("WARNING: outgoing msg is not gosa-si envelope conform", 5);
-        daemon_log("$@ ".(defined($msg) && length($msg)>0)?$msg:"Empty Message", 8);
+        daemon_log("$session_id ERROR: outgoing msg is not gosa-si envelope conform: $@", 1);
+        daemon_log("$@ ".(defined($msg) && length($msg)>0)?$msg:"Empty Message", 1);
         $msg_hash = undef;
     }
 
@@ -819,36 +833,6 @@ sub open_socket {
 }
 
 
-# moved to GosaSupportDaemon: 03-06-2008: rettenbe
-#===  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;
-#              }
-#      }
-#
-#      return $result;
-#}
-
-
 sub get_local_ip_for_remote_ip {
        my $remote_ip= shift;
        my $result="0.0.0.0";
@@ -885,7 +869,7 @@ sub get_local_ip_for_remote_ip {
                        }
                }
        } else {
-               daemon_log("get_local_ip_for_remote_ip was called with a non-ip parameter: $remote_ip", 1);
+               daemon_log("0 WARNING: get_local_ip_for_remote_ip() was called with a non-ip parameter: '$remote_ip'", 1);
        }
        return $result;
 }
@@ -918,7 +902,7 @@ sub send_msg_to_target {
     # opensocket
     my $socket = &open_socket($address);
     if( !$socket ) {
-        daemon_log("$session_id ERROR: cannot send ".$header."msg to $address , host not reachable", 1);
+        daemon_log("$session_id WARNING: cannot send ".$header."msg to $address , host not reachable", 3);
         $error++;
     }
     
@@ -1042,8 +1026,8 @@ sub msg_to_decrypt {
     if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
         # if an incoming msg could not be decrypted (maybe a wrong key), send client a ping. If the client
         # could not understand a msg from its server the client cause a re-registering process
-        daemon_log("$session_id INFO cannot understand incoming msg, send 'ping'-msg to all host with ip '".$heap->{remote_ip}.
-                "' to cause a re-registering of the client if necessary", 5);
+        daemon_log("$session_id WARNING cannot understand incoming msg, send 'ping'-msg to all host with ip '".$heap->{remote_ip}.
+                "' to cause a re-registering of the client if necessary", 3);
         my $sql_statement = "SELECT * FROM $main::known_clients_tn WHERE (hostname LIKE '".$heap->{'remote_ip'}."%')";
         my $query_res = $known_clients_db->select_dbentry( $sql_statement ); 
         while( my ($hit_num, $hit) = each %{ $query_res } ) {    
@@ -1107,6 +1091,11 @@ sub msg_to_decrypt {
                                                my $hostname = $res->{1}->{'hostname'};
                                                $msg =~ s/<target>$target<\/target>/<target>$hostname<\/target>/;
                                                #print STDERR "target is a client address in known_clients -> process here\n";
+                        my $local_address = &get_local_ip_for_remote_ip($target_ip).":$server_port";
+                        if ($source eq "GOSA") {
+                            $msg =~ s/<\/xml>/<forward_to_gosa>$local_address,$session_id<\/forward_to_gosa><\/xml>/;
+                        }
+
                                } else {
                                                $not_found_in_known_clients_db = 1;
                                }
@@ -1130,7 +1119,7 @@ sub msg_to_decrypt {
                if ($done) {
                                # if a job or a gosa message comes from a foreign server, fake module to GosaPackages
                                # so gosa-si-server knows how to process this kind of messages
-                               if ($header =~ /^gosa_/ || $header =~ /job_/) {
+                               if ($header =~ /^gosa_/ || $header =~ /^job_/) {
                                                $module = "GosaPackages";
                                }
 
@@ -1160,6 +1149,7 @@ sub msg_to_decrypt {
                     if(exists $heap->{'client'}) {
                         $msg = &encrypt_msg($msg, $GosaPackages_key);
                         $heap->{'client'}->put($msg);
+                        &daemon_log("$session_id INFO: incoming '$header' message forwarded to GOsa", 5); 
                     }
                     $done = 1;
                     #print STDERR "target is own address with forward_to_gosa-tag pointing at myself -> forward to gosa\n";
@@ -1173,7 +1163,9 @@ sub msg_to_decrypt {
             $sql = "SELECT * FROM $foreign_clients_tn WHERE (hostname='$target' OR macaddress LIKE '$target')";
             $res = $foreign_clients_db->select_dbentry($sql);
             if (keys(%$res) > 0) {
-                my $hostname = $res->{1}->{'hostname'};
+                   my $hostname = $res->{1}->{'hostname'};
+                   my ($host_ip, $host_port) = split(/:/, $hostname);
+                   my $local_address =  &get_local_ip_for_remote_ip($host_ip).":$server_port";
                 my $regserver = $res->{1}->{'regserver'};
                 my $sql = "SELECT * FROM $known_server_tn WHERE hostname='$regserver'"; 
                 my $res = $known_server_db->select_dbentry($sql);
@@ -1298,6 +1290,7 @@ sub handle_task_done {
 
 sub process_task {
     no strict "refs";
+    #CHECK: Not @_[...]?
     my ($session, $heap, $task) = @_;
     my $error = 0;
     my $answer_l;
@@ -1346,7 +1339,7 @@ sub process_task {
 
         foreach my $answer ( @{$answer_l} ) {
             # check outgoing msg to xml validity
-            my $answer_hash = &check_outgoing_xml_validity($answer);
+            my $answer_hash = &check_outgoing_xml_validity($answer, $session_id);
             if( not defined $answer_hash ) { next; }
             
             $answer_header = @{$answer_hash->{'header'}}[0];
@@ -1404,9 +1397,9 @@ sub process_task {
                     &update_jobdb_status_for_send_msgs($answer, $error);
                 }
 
-                # target of msg is a mac address
+                # Target of msg is a mac address
                 elsif( $answer_target =~ /^([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 ) {
-                    daemon_log("$session_id INFO: target is mac address '$answer_target', looking for host in known_clients", 5);
+                    daemon_log("$session_id INFO: target is mac address '$answer_target', looking for host in known_clients and foreign_clients", 5);
                     my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$answer_target'";
                     my $query_res = $known_clients_db->select_dbentry( $sql_statement );
                     my $found_ip_flag = 0;
@@ -1419,11 +1412,40 @@ sub process_task {
                         &update_jobdb_status_for_send_msgs($answer, $error);
                         $found_ip_flag++ ;
                     }   
+                    if ($found_ip_flag == 0) {
+                        my $sql = "SELECT * FROM $foreign_clients_tn WHERE macaddress LIKE '$answer_target'";
+                        my $res = $foreign_clients_db->select_dbentry($sql);
+                        while( my ($hit_num, $hit) = each %{ $res } ) {
+                            my $host_name = $hit->{hostname};
+                            my $reg_server = $hit->{regserver};
+                            daemon_log("$session_id INFO: found host '$host_name' with mac '$answer_target', registered at '$reg_server'", 5);
+                            
+                            # Fetch key for reg_server
+                            my $reg_server_key;
+                            my $sql = "SELECT * FROM $known_server_tn WHERE hostname='$reg_server'";
+                            my $res = $known_server_db->select_dbentry($sql);
+                            if (exists $res->{1}) {
+                                $reg_server_key = $res->{1}->{'hostkey'}; 
+                            } else {
+                                daemon_log("$session_id ERROR: cannot find hostkey for '$host_name' in '$known_server_tn'", 1); 
+                                daemon_log("$session_id ERROR: unable to forward answer to correct registration server, processing is aborted!", 1); 
+                                $reg_server_key = undef;
+                            }
+
+                            # Send answer to server where client is registered
+                            if (defined $reg_server_key) {
+                                $answer =~ s/$answer_target/$host_name/g;
+                                my $error = &send_msg_to_target($answer, $reg_server, $reg_server_key, $answer_header, $session_id);
+                                &update_jobdb_status_for_send_msgs($answer, $error);
+                                $found_ip_flag++ ;
+                            }
+                        }
+                    }
                     if( $found_ip_flag == 0) {
                         daemon_log("$session_id WARNING: no host found in known_clients with mac address '$answer_target'", 3);
                     }
 
-                #  answer is for one specific host   
+                # Answer is for one specific host   
                 } else {
                     # get encrypt_key
                     my $encrypt_key = &get_encrypt_key($answer_target);
@@ -1459,21 +1481,28 @@ sub session_start {
        $kernel->yield('create_fai_release_db', $fai_release_tn );
     $kernel->yield('watch_for_next_tasks');
        $kernel->sig(USR1 => "sig_handler");
-       $kernel->sig(USR2 => "create_packages_list_db");
+       $kernel->sig(USR2 => "recreate_packages_db");
        $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
        $kernel->delay_set('watch_for_done_jobs', $job_queue_loop_delay); 
+    $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay); 
        $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
     $kernel->delay_set('watch_for_delivery_messages', $messaging_db_loop_delay);
        $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay);
     $kernel->delay_set('watch_for_old_known_clients', $job_queue_loop_delay);
 
+    # Start opsi check
+    if ($opsi_enabled eq "true") {
+        $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay); 
+    }
+
 }
 
 
 sub watch_for_done_jobs {
+    #CHECK: $heap for what?
     my ($kernel,$heap) = @_[KERNEL, HEAP];
 
-    my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE status='done'";
+    my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((status='done') AND (modified='0'))";
        my $res = $job_db->select_dbentry( $sql_statement );
 
     while( my ($id, $hit) = each %{$res} ) {
@@ -1486,12 +1515,142 @@ sub watch_for_done_jobs {
 }
 
 
+sub watch_for_opsi_jobs {
+    my ($kernel) = $_[KERNEL];
+
+    # This is not very nice to look for opsi install jobs, but headertag has to be trigger_action_reinstall. The only way to identify a 
+    # opsi install job is to parse the xml message. There is still the correct header.
+    my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((xmlmessage LIKE '%opsi_install_client</header>%') AND (status='processing') AND (siserver='localhost'))";
+       my $res = $job_db->select_dbentry( $sql_statement );
+
+    # Ask OPSI for an update of the running jobs
+    while (my ($id, $hit) = each %$res ) {
+        # Determine current parameters of the job
+        my $hostId = $hit->{'plainname'};
+        my $macaddress = $hit->{'macaddress'};
+        my $progress = $hit->{'progress'};
+
+        my $result= {};
+        
+        # For hosts, only return the products that are or get installed
+        my $callobj;
+        $callobj = {
+            method  => 'getProductStates_hash',
+            params  => [ $hostId ],
+            id  => 1,
+        };
+        
+        my $hres = $opsi_client->call($opsi_url, $callobj);
+        #my ($hres_err, $hres_err_string) = &check_opsi_res($hres);
+        if (not &check_opsi_res($hres)) {
+            my $htmp= $hres->result->{$hostId};
+        
+            # Check state != not_installed or action == setup -> load and add
+            my $products= 0;
+            my $installed= 0;
+            my $installing = 0;
+            my $error= 0;  
+            my @installed_list;
+            my @error_list;
+            my $act_status = "none";
+            foreach my $product (@{$htmp}){
+
+                if ($product->{'installationStatus'} ne "not_installed" or
+                        $product->{'actionRequest'} eq "setup"){
+
+                    # Increase number of products for this host
+                    $products++;
+        
+                    if ($product->{'installationStatus'} eq "failed"){
+                        $result->{$product->{'productId'}}= "error";
+                        unshift(@error_list, $product->{'productId'});
+                        $error++;
+                    }
+                    if ($product->{'installationStatus'} eq "installed" && $product->{'actionRequest'}  eq "none"){
+                        $result->{$product->{'productId'}}= "installed";
+                        unshift(@installed_list, $product->{'productId'});
+                        $installed++;
+                    }
+                    if ($product->{'installationStatus'} eq "installing"){
+                        $result->{$product->{'productId'}}= "installing";
+                        $installing++;
+                        $act_status = "installing - ".$product->{'productId'};
+                    }
+                }
+            }
+        
+            # Estimate "rough" progress, avoid division by zero
+            if ($products == 0) {
+                $result->{'progress'}= 0;
+            } else {
+                $result->{'progress'}= int($installed * 100 / $products);
+            }
+
+            # Set updates in job queue
+            if ((not $error) && (not $installing) && ($installed)) {
+                $act_status = "installed - ".join(", ", @installed_list);
+            }
+            if ($error) {
+                $act_status = "error - ".join(", ", @error_list);
+            }
+            if ($progress ne $result->{'progress'} ) {
+                # Updating progress and result 
+                my $update_statement = "UPDATE $job_queue_tn SET modified='1', progress='".$result->{'progress'}."', result='$act_status' WHERE macaddress='$macaddress' AND siserver='localhost'";
+                my $update_res = $job_db->update_dbentry($update_statement);
+            }
+            if ($progress eq 100) { 
+                # Updateing status
+                my $done_statement = "UPDATE $job_queue_tn SET modified='1', ";
+                if ($error) {
+                    $done_statement .= "status='error'";
+                } else {
+                    $done_statement .= "status='done'";
+                }
+                $done_statement .= " WHERE macaddress='$macaddress' AND siserver='localhost'";
+                my $done_res = $job_db->update_dbentry($done_statement);
+            }
+
+
+        }
+    }
+
+    $kernel->delay_set('watch_for_opsi_jobs', $job_queue_opsi_delay);
+}
+
+
+# If a job got an update or was modified anyway, send to all other si-server an update message of this jobs.
+sub watch_for_modified_jobs {
+    my ($kernel,$heap) = @_[KERNEL, HEAP];
+
+    my $sql_statement = "SELECT * FROM $job_queue_tn WHERE ((siserver='localhost') AND (modified='1'))"; 
+    my $res = $job_db->select_dbentry( $sql_statement );
+    
+    # if db contains no jobs which should be update, do nothing
+    if (keys %$res != 0) {
+
+        if ($job_synchronization  eq "true") {
+            # make out of the db result a gosa-si message   
+            my $update_msg = &db_res2si_msg ($res, "foreign_job_updates", "KNOWN_SERVER", "MY_LOCAL_ADDRESS");
+            # update all other SI-server
+            &inform_all_other_si_server($update_msg);
+        }
+
+        # set jobs all jobs to modified = 0, wait until the next modification for updates of other si-server
+        $sql_statement = "UPDATE $job_queue_tn SET modified='0' ";
+        $res = $job_db->update_dbentry($sql_statement);
+    }
+
+    $kernel->delay_set('watch_for_modified_jobs', $modified_jobs_loop_delay);
+}
+
+
 sub watch_for_new_jobs {
        if($watch_for_new_jobs_in_progress == 0) {
                $watch_for_new_jobs_in_progress = 1;
                my ($kernel,$heap) = @_[KERNEL, HEAP];
 
-               # check gosa job queue for jobs with executable timestamp
+               # check gosa job quaeue for jobs with executable timestamp
                my $timestamp = &get_time();
                my $sql_statement = "SELECT * FROM $job_queue_tn WHERE status='waiting' AND (CAST (timestamp AS INTEGER)) < $timestamp ORDER BY timestamp";
                my $res = $job_db->exec_statement( $sql_statement );
@@ -1776,7 +1935,7 @@ sub watch_for_old_known_clients {
                 );
 
         $dt->add( seconds => 2 * int($hit->{'keylifetime'}) );
-        $expired_timestamp = $dt->ymd('').$dt->hms('')."\n";
+        $expired_timestamp = $dt->ymd('').$dt->hms('');
         if ($act_time > $expired_timestamp) {
             my $hostname = $hit->{'hostname'};
             my $del_sql = "DELETE FROM $known_clients_tn WHERE hostname='$hostname'"; 
@@ -2002,6 +2161,16 @@ sub change_goto_state {
 }
 
 
+sub run_recreate_packages_db {
+    my ($kernel, $session, $heap) = @_[KERNEL, SESSION, HEAP];
+    my $session_id = $session->ID;
+       &main::daemon_log("$session_id INFO: Recreating FAI Packages DB ('$fai_release_tn', '$fai_server_tn', '$packages_list_tn')", 5);
+       $kernel->yield('create_fai_release_db', $fai_release_tn);
+       $kernel->yield('create_fai_server_db', $fai_server_tn);
+       return;
+}
+
+
 sub run_create_fai_server_db {
     my ($kernel, $session, $heap, $table_name) = @_[KERNEL, SESSION, HEAP, ARG0];
     my $session_id = $session->ID;
@@ -2511,6 +2680,7 @@ sub create_packages_list_db {
 
        close (CONFIG);
 
+
        find(\&cleanup_and_extract, keys( %repo_dirs ));
        &main::strip_packages_list_statements();
        unshift @packages_list_statements, "VACUUM";
@@ -2759,7 +2929,7 @@ sub cleanup_and_extract {
 
                if( -f "$dir/DEBIAN/templates" ) {
 
-                       daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 5);
+                       daemon_log("DEBUG: Found debconf templates in '$package' - $newver", 7);
 
                        my $tmpl= "";
                        {
@@ -2827,7 +2997,7 @@ GetOptions("h|help" => \&usage,
 
 #  read and set config parameters
 &check_cmdline_param ;
-&read_configfile;
+&read_configfile($cfg_file, %cfg_defaults);
 &check_pid;
 
 $SIG{CHLD} = 'IGNORE';
@@ -2944,9 +3114,9 @@ if ( !$server_domain) {
     # Try our DNS Searchlist
     for my $domain(get_dns_domains()) {
         chomp($domain);
-        my @tmp_domains= &get_server_addresses($domain);
-        if(@tmp_domains) {
-            for my $tmp_server(@tmp_domains) {
+        my ($tmp_domains, $error_string) = &get_server_addresses($domain);
+        if(@$tmp_domains) {
+            for my $tmp_server(@$tmp_domains) {
                 push @tmp_servers, $tmp_server;
             }
         }
@@ -2972,11 +3142,8 @@ daemon_log("0 INFO: found foreign server in config file and DNS: $all_foreign_se
 my $act_timestamp = &get_time();
 foreach my $foreign_server (@foreign_server_list) {
 
-       #######################################
-       # TODO for jan
        # do not add myself to known_server_db
-       # work around!!!
-       if ($foreign_server eq '172.16.2.89:20081') { next; }
+       if (&is_local($foreign_server)) { next; }
        ######################################
 
     my $res = $known_server_db->add_dbentry( {table=>$known_server_tn, 
@@ -2989,6 +3156,21 @@ foreach my $foreign_server (@foreign_server_list) {
 }
 
 
+# Import all modules
+&import_modules;
+
+# Check wether all modules are gosa-si valid passwd check
+&password_check;
+
+# Prepare for using Opsi 
+if ($opsi_enabled eq "true") {
+    use JSON::RPC::Client;
+    use XML::Quote qw(:all);
+    $opsi_url= "https://".$opsi_admin.":".$opsi_password."@".$opsi_server.":4447/rpc";
+    $opsi_client = new JSON::RPC::Client;
+}
+
+
 POE::Component::Server::TCP->new(
     Alias => "TCP_SERVER",
        Port => $server_port,
@@ -3025,11 +3207,14 @@ POE::Session->create(
         watch_for_delivery_messages => \&watch_for_delivery_messages,
         watch_for_done_messages => \&watch_for_done_messages,
                watch_for_new_jobs => \&watch_for_new_jobs,
+        watch_for_modified_jobs => \&watch_for_modified_jobs,
         watch_for_done_jobs => \&watch_for_done_jobs,
+        watch_for_opsi_jobs => \&watch_for_opsi_jobs,
         watch_for_old_known_clients => \&watch_for_old_known_clients,
         create_packages_list_db => \&run_create_packages_list_db,
         create_fai_server_db => \&run_create_fai_server_db,
         create_fai_release_db => \&run_create_fai_release_db,
+               recreate_packages_db => \&run_recreate_packages_db,
         session_run_result => \&session_run_result,
         session_run_debug => \&session_run_debug,
         session_run_done => \&session_run_done,
@@ -3038,14 +3223,6 @@ POE::Session->create(
 );
 
 
-# import all modules
-&import_modules;
-
-# TODO
-# check wether all modules are gosa-si valid passwd check
-
-
-
 POE::Kernel->run();
 exit;