Code

Added default for session lifetime
[gosa.git] / gosa-si / gosa-si-server
index 9bf2853a9137d9fa18c1c4376b79a91ebf6e75e7..1e56d7ce7066ed3b9cdf0f9ae743cc7880d81eb5 100755 (executable)
@@ -20,8 +20,6 @@
 #     REVISION:  ---
 #===============================================================================
 
-my $server_version = '$HeadURL: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si/gosa-si-server $:$Rev$';
-
 use strict;
 use warnings;
 use Getopt::Long;
@@ -51,6 +49,7 @@ use POE qw(Component::Server::TCP Wheel::Run Filter::Reference);
 use Net::LDAP;
 use Net::LDAP::Util qw(:escape);
 
+my $server_version = '$HeadURL: https://oss.gonicus.de/repositories/gosa/trunk/gosa-si/gosa-si-server $:$Rev$';
 
 # revision number of server and program name
 my $server_headURL;
@@ -248,7 +247,7 @@ our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minu
     "messaging"             => [\$messaging_file_name, '/var/lib/gosa-si/messaging.db'],
     "foreign-clients"       => [\$foreign_clients_file_name, '/var/lib/gosa-si/foreign_clients.db'],
     "source-list"           => [\$sources_list, '/etc/apt/sources.list'],
-    "repo-path"             => [\$repo_path, '/srv/www/repository'],
+    "repo-path"             => [\$repo_path, '/srv/www'],
     "debian-arch"           => [\$arch, 'i386'],     
     "ldap-uri"              => [\$ldap_uri, ""],
     "ldap-base"             => [\$ldap_base, ""],
@@ -319,10 +318,10 @@ usage: $prg [-hvf] [-c config] [-d number]
                         'vvvvvvv': debug plus info logs
            -no-arp   : starts $prg without connection to arp module
            -d <int>  : if verbose level is higher than 7x 'v' specified parts can be debugged
-                           1 : receiving messages
-                           2 : sending messages
-                           4 : encrypting/decrypting messages
-                           8 : verification if a message complies gosa-si requirements
+                           1 : report incoming messages
+                           2 : report unencrypted outgoing messages 
+                           4 : report encrypting key for messages
+                           8 : report decrypted incoming message and verification if the message complies gosa-si requirements
                           16 : message processing
                           32 : ldap connectivity
                           64 : database status and connectivity
@@ -455,28 +454,28 @@ sub check_cmdline_param () {
 sub check_pid {
     $pid = -1;
     # Check, if we are already running
-    if( open(LOCK_FILE, "<$pid_file") ) {
-        $pid = <LOCK_FILE>;
+    if( open( my $LOCK_FILE, "<", "$pid_file" ) ) {
+        $pid = <$LOCK_FILE>;
         if( defined $pid ) {
             chomp( $pid );
             if( -f "/proc/$pid/stat" ) {
                 my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/;
                 if( $stat ) {
                                        print STDERR "\nERROR: Already running!\n";
-                    close( LOCK_FILE );
+                    close( $LOCK_FILE );
                     exit -1;
                 }
             }
         }
-        close( LOCK_FILE );
+        close( $LOCK_FILE );
         unlink( $pid_file );
     }
 
     # create a syslog msg if it is not to possible to open PID file
-    if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
+    if (not sysopen(my $LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
         my($msg) = "Couldn't obtain lockfile '$pid_file' ";
-        if (open(LOCK_FILE, '<', $pid_file)
-                && ($pid = <LOCK_FILE>))
+        if (open(my $LOCK_FILE, '<', $pid_file)
+                && ($pid = <$LOCK_FILE>))
         {
             chomp($pid);
             $msg .= "(PID $pid)\n";
@@ -1548,8 +1547,7 @@ sub process_task {
             while ($answer_str =~ /<header>(\w+)<\/header>/g) {
                                push(@headers, $1);
             }
-                       daemon_log("$session_id INFO: got answer message(s) with header: '".join("', '", @headers)."'", 5);
-            daemon_log("$session_id DEBUG: $module: got answer from module: \n".$answer_str,26);
+                       daemon_log("$session_id DEBUG: got answer message(s) with header: '".join("', '", @headers)."'", 26);
         } else {
             daemon_log("$session_id DEBUG: $module: got no answer from module!" ,26);
         }
@@ -1607,6 +1605,9 @@ sub process_task {
                     if( defined $session_id ) {
                         $add_on = ".session_id=$session_id";
                     }
+                                       my $header = ($1) if $answer =~ /<header>(\S*)<\/header>/;
+                                       daemon_log("$session_id INFO: send ".$header." message to GOsa", 5);
+                                       daemon_log("$session_id DEBUG: message:\n$answer", 12);
                     # answer is for GOSA and has to returned to connected client
                     my $gosa_answer = &encrypt_msg($answer, $GosaPackages_key);
                     $client_answer = $gosa_answer.$add_on;
@@ -1766,7 +1767,6 @@ 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'))";
@@ -1790,10 +1790,14 @@ sub watch_for_opsi_jobs {
         };
         
         my $hres = $opsi_client->call($opsi_url, $callobj);
-        #my ($hres_err, $hres_err_string) = &check_opsi_res($hres);
+               # TODO : move all opsi relevant statments to opsi plugin
+               # The following 3 lines must be tested befor they can replace the rubbish above and below !!!
+               #my ($res, $err) = &opsi_com::_getProductStates_hash(hostId=>$hostId)
+               #if (not $err) {
+               #       my $htmp = $res->{$hostId};
+               # 
         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;
@@ -2875,8 +2879,7 @@ sub create_sources_list {
                &main::daemon_log("$session_id DEBUG: remove an old version of '$result'", 7); 
        }
 
-       my $fh;
-       open($fh, ">$result");
+       open(my $fh, ">", "$result");
        if (not defined $fh) {
                &main::daemon_log("$session_id DEBUG: cannot open '$result' for writing", 7); 
                return undef;
@@ -2959,14 +2962,14 @@ sub create_packages_list_db {
 
        my $line;
 
-       open(CONFIG, "<$sources_file") or do {
+       open(my $CONFIG, "<", "$sources_file") or do {
                daemon_log( "$session_id ERROR: create_packages_list_db: Failed to open '$sources_file'", 1);
                unlink($packages_list_under_construction);
                return;
        };
 
        # Read lines
-       while ($line = <CONFIG>){
+       while ($line = <$CONFIG>){
                # Unify
                chop($line);
                $line =~ s/^\s+//;
@@ -2988,9 +2991,12 @@ sub create_packages_list_db {
                                &parse_package_info( $baseurl, $dist, $section, $session_id );
                        }
                }
+    else {
+        daemon_log("$session_id ERROR: cannot parse line '$line'", 1);
+    }
        }
 
-       close (CONFIG);
+       close ($CONFIG);
 
        if(keys(%repo_dirs)) {
                find(\&cleanup_and_extract, keys( %repo_dirs ));
@@ -3178,7 +3184,6 @@ sub parse_package {
     my ($path, $dist, $srv_path, $session_id)= @_;
     if (not defined $session_id) { $session_id = 0;}
     my ($package, $version, $section, $description);
-    my $PACKAGES;
     my $timestamp = &get_time();
 
     if(not stat("$path.in")) {
@@ -3186,7 +3191,7 @@ sub parse_package {
         return;
     }
 
-    open($PACKAGES, "<$path.in");
+    open(my $PACKAGES, "<", "$path.in");
     if(not defined($PACKAGES)) {
         daemon_log("$session_id ERROR: create_packages_list_db: parse_package: cannot open '$path.in'",1); 
         return;
@@ -3277,9 +3282,9 @@ sub cleanup_and_extract {
 
                        my $tmpl= ""; {
                                local $/=undef;
-                               open FILE, "$dir/DEBIAN/templates";
-                               $tmpl = &encode_base64(<FILE>);
-                               close FILE;
+                               open(my $FILE, "$dir/DEBIAN/templates");
+                               $tmpl = &encode_base64(<$FILE>);
+                               close($FILE);
                        }
                        rmtree("$dir/DEBIAN/templates");
 
@@ -3489,9 +3494,9 @@ if( ! $foreground ) {
 
 # 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 );
+    open( my $LOCK_FILE, ">", "$pid_file" );
+    print $LOCK_FILE "$pid\n";
+    close( $LOCK_FILE );
     if( !$foreground ) { 
         exit( 0 ) 
     };
@@ -3511,8 +3516,8 @@ if ($server_headURL =~ /\/tag\// ||
 # Prepare log file and set permissions
 $root_uid = getpwnam('root');
 $adm_gid = getgrnam('adm');
-open(FH, ">>$log_file");
-close FH;
+open(my $FH, ">>", "$log_file");
+close($FH);
 chmod(0440, $log_file);
 chown($root_uid, $adm_gid, $log_file);
 chown($root_uid, $adm_gid, "/var/lib/gosa-si");