Code

Added raid image
[gosa.git] / gosa-si / gosa-si-server
index 374343c92e69fe4cc0caf33267601a7ce0b0c32c..283eb1d664d671a2fb9ea4a09302f52353e38e45 100755 (executable)
@@ -151,6 +151,7 @@ my @job_queue_col_names = ("id INTEGER PRIMARY KEY",
        "plainname VARCHAR(255) DEFAULT 'none'",
        "siserver VARCHAR(255) DEFAULT 'none'",
        "modified INTEGER DEFAULT '0'",
+       "periodic VARCHAR(6) DEFAULT 'none'",
 );
 
 # holds all other gosa-si-server
@@ -225,6 +226,10 @@ our $logged_in_user_date_of_expiry = 600;
 # List of month names, used in function daemon_log
 my @monthnames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 
+# List of accepted periodical xml tags related to cpan modul DateTime
+our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minutes"=>''};
+
+
 %cfg_defaults = (
 "general" => {
     "log-file" => [\$log_file, "/var/run/".$prg.".log"],
@@ -320,9 +325,10 @@ usage: $prg [-hvf] [-c config] [-d number]
                           32 : ldap connectivity
                           64 : database status and connectivity
                          128 : main process 
+                         256 : creation of packages_list_db
+                         512 : ARP debug information
 EOF
-    print "\n" ;
+       exit(0);
 }
 
 
@@ -431,11 +437,7 @@ sub check_cmdline_param () {
        }
 
        # Exit if an error occour
-    if( $err_counter > 0 ) 
-       {
-        &usage( "", 1 );
-        exit( -1 );
-    }
+    if( $err_counter > 0 ) { &usage( "", 1 ); }
 }
 
 
@@ -996,7 +998,7 @@ sub send_msg_to_target {
             if($new_status eq "down"){
                 daemon_log("$session_id WARNING: set '$address' from status '$act_status' to '$new_status'", 3);
             } else {
-                daemon_log("$session_id INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+                daemon_log("$session_id DEBUG: set '$address' from status '$act_status' to '$new_status'", 138);
             }
         }
     }
@@ -1017,7 +1019,7 @@ sub send_msg_to_target {
             if($new_status eq "down"){
                 daemon_log("$session_id WARNING: set '$address' from status '$act_status' to '$new_status'", 3);
             } else {
-                daemon_log("$session_id INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+                daemon_log("$session_id DEBUG: set '$address' from status '$act_status' to '$new_status'", 138);
             }
         }
     }
@@ -1127,7 +1129,7 @@ sub msg_to_decrypt {
        ($msg, $msg_hash, $module) = &input_from_unknown_host($next_msg, $session_id);
 
        # msg is from a gosa-si-server
-       if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
+       if(((!$msg) || (!$msg_hash) || (!$module)) && ($serverPackages_enabled eq "true")){
                if (not defined $msg_source) 
                {
                        # Only needed, to be compatible with older gosa-si-server versions
@@ -1140,7 +1142,15 @@ sub msg_to_decrypt {
        }
        # msg is from a gosa-si-client
        if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
-               ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $msg_source, $session_id);
+               if (not defined $msg_source) 
+               {
+                       # Only needed, to be compatible with older gosa-si-server versions
+                       ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $heap->{'remote_ip'}, $session_id);
+               }
+               else
+               {
+                       ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $msg_source, $session_id);
+               }
        }
        # an error occurred
        if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
@@ -1148,7 +1158,7 @@ sub msg_to_decrypt {
                # or a server.  In case of a client, send a ping. If the client could not understand a msg from its 
                # server the client cause a re-registering process. In case of a server, decrease update_time in kown_server_db
                # and trigger a re-registering process for servers
-               if (defined $msg_source && $msg_source =~ /:$server_port$/)
+               if (defined $msg_source && $msg_source =~ /:$server_port$/ && $serverPackages_enabled eq "true")
                {
                        daemon_log("$session_id WARNING: Cannot understand incoming msg from server '$msg_source'. Cause re-registration process for servers.", 3);
                        my $update_statement = "UPDATE $known_server_tn SET update_time='19700101000000' WHERE hostname='$msg_source'"; 
@@ -1156,19 +1166,20 @@ sub msg_to_decrypt {
                        my $upadte_res = $known_server_db->exec_statement($update_statement);
                        $kernel->yield("register_at_foreign_servers");
                }
-               elsif (defined $msg_source)
+               elsif ((defined $msg_source) && (not $msg_source =~ /:$server_port$/))
                {
                        daemon_log("$session_id WARNING: Cannot understand incoming msg from client '$msg_source'. Send ping-msg to cause a re-registering of the client if necessary", 3);
                        #my $remote_ip = $heap->{'remote_ip'};
                        #my $remote_port = $heap->{'remote_port'};
                        my $ping_msg = "<xml> <header>gosa_ping</header> <source>$server_address</source><target>$msg_source</target></xml>";
                        my ($test_error, $test_error_string) = &send_msg_to_target($ping_msg, "$msg_source", "dummy-key", "gosa_ping", $session_id);
-                       daemon_log("$session_id WARNING: sending msg to cause re-registering: $ping_msg", 3);
+                       daemon_log("$session_id WARNING: Sending msg to cause re-registering: $ping_msg", 3);
                }
                else
                {
                        my $foreign_host = defined $msg_source ? $msg_source : $heap->{'remote_ip'};
-                       daemon_log("$session_id ERROR: incoming message from host '$foreign_host' cannot be understood. Processing aborted: $tmp_next_msg", 1);
+                       daemon_log("$session_id ERROR: Incoming message from host '$foreign_host' cannot be understood. Processing aborted!", 1);
+                       daemon_log("$session_id DEBUG: Aborted message: $tmp_next_msg", 11);
                }
 
                $error++
@@ -1331,7 +1342,7 @@ sub msg_to_decrypt {
                                $msg =~ s/<header>gosa_/<header>/;
                                my $error= &send_msg_to_target($msg, $hostname, $hostkey, $header, $session_id);
                                if ($error) {
-                                       &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostkey': $msg", 1);
+                                       &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostname': $msg", 1);
                                }
                        } 
                        else 
@@ -1597,7 +1608,7 @@ sub process_task {
 
                 # 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 and foreign_clients", 5);
+                    daemon_log("$session_id DEBUG: target is mac address '$answer_target', looking for host in known_clients and foreign_clients", 138);
 
                     # Looking for macaddress in known_clients
                     my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$answer_target'";
@@ -1704,16 +1715,35 @@ sub session_start {
 
 
 sub watch_for_done_jobs {
-       #CHECK: $heap for what?
-       my ($kernel,$heap) = @_[KERNEL, HEAP];
+       my $kernel = $_[KERNEL];
 
        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} ) {
-               my $jobdb_id = $hit->{id};
-               my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; 
-               my $res = $job_db->del_dbentry($sql_statement); 
+       while( my ($number, $hit) = each %{$res} ) 
+       {
+               # Non periodical jobs can be deleted.
+               if ($hit->{periodic} eq "none")
+               {
+                       my $jobdb_id = $hit->{id};
+                       my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; 
+                       my $res = $job_db->del_dbentry($sql_statement); 
+               }
+
+               # Periodical jobs should not be deleted but reactivated with new timestamp instead.
+               else
+               {
+                       my ($p_time, $periodic) = split("_", $hit->{periodic});
+                       my $reactivated_ts = $hit->{timestamp};
+                       my $act_ts = int(&get_time());
+                       while ($act_ts > int($reactivated_ts))   # Redo calculation to avoid multiple jobs in the past
+                       {
+                               $reactivated_ts = &calc_timestamp($reactivated_ts, "plus", $p_time, $periodic);
+                       }
+                       my $sql = "UPDATE $job_queue_tn SET status='waiting', timestamp='$reactivated_ts' WHERE id='".$hit->{id}."'"; 
+                       my $res = $job_db->exec_statement($sql);
+                       &daemon_log("J INFO: Update periodical job '".$hit->{headertag}."' for client '".$hit->{targettag}."'. New execution time '$reactivated_ts'.", 5);
+               }
        }
 
        $kernel->delay_set('watch_for_done_jobs',$job_queue_loop_delay);
@@ -1940,7 +1970,7 @@ sub watch_for_new_jobs {
                                        my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J");                    
 
                                        # update status in job queue to ...
-                    # ... 'processing', for jobs: 'reinstall', 'update'
+                    # ... 'processing', for jobs: 'reinstall', 'update', activate_new
                     if (($header =~ /gosa_trigger_action_reinstall/) 
                             || ($header =~ /gosa_trigger_activate_new/)
                             || ($header =~ /gosa_trigger_action_update/)) {
@@ -1951,7 +1981,7 @@ sub watch_for_new_jobs {
                     # ... 'done', for all other jobs, they are no longer needed in the jobqueue
                     else {
                         my $sql_statement = "UPDATE $job_queue_tn SET status='done' WHERE id=$jobdb_id";
-                        my $dbres = $job_db->update_dbentry($sql_statement);
+                        my $dbres = $job_db->exec_statement($sql_statement);
                     }
                 
 
@@ -3104,7 +3134,7 @@ sub parse_package_info {
     $repo_dirs{ "${repo_path}/pool" } = 1;
 
     foreach $package ("Packages.gz"){
-        daemon_log("$session_id DEBUG: create_packages_list: fetch $baseurl, $dist, $section", 7);
+        daemon_log("$session_id DEBUG: create_packages_list: fetch $baseurl, $dist, $section", 266);
         get_package( "$baseurl/dists/$dist/$section/binary-$arch/$package", "$outdir/$dist/$section", $session_id );
         parse_package( "$outdir/$dist/$section", $dist, $path, $session_id );
     }
@@ -3122,9 +3152,9 @@ sub get_package {
     # This is ugly, but I've no time to take a look at "how it works in perl"
     if(0 == system("wget '$url' -O '$dest' 2>/dev/null") ) {
         system("gunzip -cd '$dest' > '$dest.in'");
-        daemon_log("$session_id DEBUG: run command: gunzip -cd '$dest' > '$dest.in'", 7);
+        daemon_log("$session_id DEBUG: run command: gunzip -cd '$dest' > '$dest.in'", 266);
         unlink($dest);
-        daemon_log("$session_id DEBUG: delete file '$dest'", 7); 
+        daemon_log("$session_id DEBUG: delete file '$dest'", 266); 
     } else {
         daemon_log("$session_id ERROR: create_packages_list_db: get_packages: fetching '$url' into '$dest' failed!", 1);
     }
@@ -3231,7 +3261,7 @@ sub cleanup_and_extract {
 
                if( -f "$dir/DEBIAN/templates" ) {
 
-                       daemon_log("0 DEBUG: Found debconf templates in '$package' - $newver", 7);
+                       daemon_log("0 DEBUG: Found debconf templates in '$package' - $newver", 266);
 
                        my $tmpl= ""; {
                                local $/=undef;
@@ -3419,7 +3449,7 @@ GetOptions("h|help" => \&usage,
         "v|verbose+" => \$verbose,
         "no-arp+" => \$no_arp,
                "d=s" => \$debug_parts,
-           ) or (&usage("", 1)&&(exit(-1))); 
+           ) or &usage("", 1); 
 
 #  read and set config parameters
 &check_cmdline_param ;
@@ -3628,9 +3658,14 @@ POE::Component::Server::TCP->new(
        ClientInput => sub {
                my ($kernel, $input, $heap, $session) = @_[KERNEL, ARG0, HEAP, SESSION];
         my $session_id = $session->ID;
-               if ($input =~ /;([\d\.]+:[\d]+)$/) 
+               if ($input =~ /;([\d\.]+):([\d]+)$/) 
                {
-                       &daemon_log("$session_id DEBUG: incoming message from '$1'", 11);
+                       # Messages from other servers should be blocked if config option is set
+                       if (($2 eq $server_port) && ($serverPackages_enabled eq "false"))
+                       {
+                               return;
+                       }
+                       &daemon_log("$session_id DEBUG: incoming message from '$1:$2'", 11);
                }
                else
                {