Code

Updated locales
[gosa.git] / gosa-si / gosa-si-server
index 7d03c9af8b75ed6b84e1d07f8e0663ea9f93c01b..81c0618e4a2f547bc6ce5d2ff5d9790bbfdf9e71 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);
             }
         }
     }
@@ -1054,8 +1056,17 @@ sub update_jobdb_status_for_send_msgs {
                     ||($job_header eq "trigger_action_reinstall") 
                     ||($job_header eq "trigger_activate_new")
                     ) {
-                &reactivate_job_with_delay($session_id, $job_target, $job_header, 30 );
-
+                                               if ($job_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) {
+                                                       &reactivate_job_with_delay($session_id, $job_target, $job_header, 30 );
+                                               } else {
+                                                       # If we don't have the mac adress at this time, we use the plainname
+                                                       my $plainname_result = $job_db->select_dbentry("SELECT plainname from jobs where id=$jobdb_id");
+                                                       my $plainname = $job_target;
+                                                       if ((keys(%$plainname_result) > 0) ) {
+                                                               $plainname = $plainname_result->{1}->{$job_target};
+                                                       }
+                                                       &reactivate_job_with_delay($session_id, $plainname, $job_header, 30 );
+                                               }
             # For all other messages
             } else {
                 my $sql_statement = "UPDATE $job_queue_tn ".
@@ -1097,7 +1108,7 @@ sub reactivate_job_with_delay {
     if (not defined $delay) { $delay = 30 } ;
     my $delay_timestamp = &calc_timestamp(&get_time(), "plus", $delay);
 
-    my $sql = "UPDATE $job_queue_tn Set timestamp='$delay_timestamp', status='waiting' WHERE (macaddress LIKE 'target' AND headertag='$header')"; 
+    my $sql = "UPDATE $job_queue_tn Set timestamp='$delay_timestamp', status='waiting' WHERE (macaddress LIKE '$target' OR plainname LIKE '$target') AND headertag='$header'"; 
     my $res = $job_db->update_dbentry($sql);
     daemon_log("$session_id INFO: '$header'-job will be reactivated at '$delay_timestamp' ".
             "cause client '$target' is currently not available", 5);
@@ -1140,7 +1151,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 )){
@@ -1332,7 +1351,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 
@@ -1598,7 +1617,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'";
@@ -1705,16 +1724,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);
@@ -1941,7 +1979,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/)) {
@@ -1952,7 +1990,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);
                     }
                 
 
@@ -3105,7 +3143,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 );
     }
@@ -3123,9 +3161,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);
     }
@@ -3232,7 +3270,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;
@@ -3420,7 +3458,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 ;