Code

Updated gosa updater
[gosa.git] / gosa-si / gosa-si-server
index 19fdc07d1f0725bc33dad6aa2c5e046ca5c1a825..351878bc6199f9107a3297ce2d34c318459df50c 100755 (executable)
@@ -394,239 +394,6 @@ sub create_known_client {
     return;  
 }
 
-#==== MAIN = main ==============================================================
-#  parse commandline options
-Getopt::Long::Configure( "bundling" );
-GetOptions("h|help" => \&usage,
-        "c|config=s" => \$cfg_file,
-        "f|foreground" => \$foreground,
-        "v|verbose+" => \$verbose,
-        "no-bus+" => \$no_bus,
-        "no-arp+" => \$no_arp,
-           );
-
-#  read and set config parameters
-&check_cmdline_param ;
-&read_configfile;
-&check_pid;
-
-$SIG{CHLD} = 'IGNORE';
-
-# forward error messages to logfile
-if( ! $foreground ) {
-    open(STDERR, '>>', $log_file);
-    open(STDOUT, '>>', $log_file);
-}
-
-# Just fork, if we are not in foreground mode
-if( ! $foreground ) { 
-    chdir '/'                 or die "Can't chdir to /: $!";
-    $pid = fork;
-    setsid                    or die "Can't start a new session: $!";
-    umask 0;
-} else { 
-    $pid = $$; 
-}
-
-# 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 );
-    if( !$foreground ) { 
-        exit( 0 ) 
-    };
-}
-
-daemon_log(" ", 1);
-daemon_log("$0 started!", 1);
-
-# delete old DBsqlite lock files
-system('rm -f /tmp/gosa_si_lock*');
-
-# connect to gosa-si job queue
-my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
-$job_db = GOSA::DBsqlite->new($job_queue_file_name);
-$job_db->create_table('jobs', \@job_col_names);
-
-# connect to known_clients_db
-my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events');
-$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
-$known_clients_db->create_table('known_clients', \@clients_col_names);
-
-# connect to known_server_db
-my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp');
-$known_server_db = GOSA::DBsqlite->new($known_server_file_name);
-$known_server_db->create_table('known_server', \@server_col_names);
-
-# import all modules
-&import_modules;
-
-# check wether all modules are gosa-si valid passwd check
-
-# create reading and writing vectors
-my $rbits = my $wbits = my $ebits = "";
-
-# add all module inputs to listening vector
-# while( my ($mod_name, $info) = each %$known_modules ) {
-#     my ($input_address, $input_key, $input, $input_activ, $input_type) = @{$info};
-#     vec($rbits, fileno $input, 1) = 1;   
-# 
-# }
-
-
-## start arp fifo
-#if ($no_arp > 0) {
-#    $arp_activ = "off";
-#}
-#my $my_fifo;
-#if($arp_activ eq "on") {
-#    daemon_log(" ", 1);
-#    $my_fifo = &open_fifo($arp_fifo_path);
-#    if($my_fifo == 0) { die "fifo file disappeared\n" }
-#    sysopen($arp_fifo, $arp_fifo_path, O_RDWR) or die "can't read from $arp_fifo: $!" ;
-#    
-#    vec($rbits, fileno $arp_fifo, 1) = 1;
-#}
-#
-
-###################################
-##everything ready, okay, lets start
-###################################
-#while(1) {
-#
-#    # add all handles from the childs
-#    while ( my ($pid, $child_hash) = each %busy_child ) {
-#        
-#        # check whether process still exists
-#        my $exitus_pid = waitpid($pid, WNOHANG);
-#        if($exitus_pid != 0) {
-#            delete $busy_child{$pid};
-#            next;
-#        }
-#     
-#        # add child fhd to the listener    
-#        my $fhd = $$child_hash{'pipe_rd'};
-#        vec($rbits, fileno $fhd, 1) = 1;
-#    }
-#
-#    my ($rout, $wout);
-#    my $nf = select($rout=$rbits, $wout=$wbits, undef, $job_queue_timeout);
-#
-#    # error handling
-#    if($nf < 0 ) {
-#    }
-#
-#
-##    if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) {
-##        my $in_msg = <$arp_fifo>;
-##        chomp($in_msg);
-##        print "arp_activ: msg: $in_msg\n";
-##        my $act_passwd = $known_daemons->{$bus_address}->{passwd};
-##        print "arp_activ: arp_passwd: $act_passwd\n";
-##
-##        my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1);
-##
-##        my $target = &get_content_from_xml_hash($in_msg_hash, 'target');
-##
-##        if ($target eq $server_address) { 
-##             print "arp_activ: forward to server\n";
-##            my $arp_cipher = &create_ciphering($act_passwd);
-##            my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher);
-##            &activating_child($crypted_msg, $server_ip);
-##        } else {
-##            print "arp_activ: send to bus\n";
-##            &send_msg_hash2address($in_msg_hash, $bus_address);
-##        }
-##        print "\n";
-##    }
-#
-#
-#    # check input fhd of all modules 
-#    while ( my ($mod_name, $info) = each %$known_modules) {
-#        my $input_fhd = @{$info}[2];    
-#        my $input_activ = @{$info}[3];
-#        if (vec($rout, fileno $input_fhd, 1) && $input_activ eq 'on') {
-#            daemon_log(" ", 1);
-#            my $client = $input_fhd->accept();
-#            my $other_end = getpeername($client);
-#            if(not defined $other_end) {
-#                daemon_log("client cannot be identified: $!");
-#            } else {
-#                my ($port, $iaddr) = unpack_sockaddr_in($other_end);
-#                my $actual_ip = inet_ntoa($iaddr);
-#                daemon_log("accept client at daemon socket from $actual_ip", 5);
-#                my $in_msg = &read_from_socket($client);
-#                if(defined $in_msg){
-#                    chomp($in_msg);
-#                    &activating_child($in_msg, $actual_ip, $client);
-#                } else {
-#                    daemon_log("cannot read from $actual_ip", 5);
-#                }
-#            }
-#        }
-#    }
-#
-#    # check all processing childs whether they are finished ('done') or 
-#    while ( my ($pid, $child_hash) = each %busy_child ) {
-#        my $fhd = $$child_hash{'pipe_rd'};
-#
-#        if (vec($rout, fileno $fhd, 1) ) {
-#            daemon_log("process child $pid is ready to read", 5);
-# 
-#            my $in_msg;
-#            while (1) {
-#                my $part_in_msg = <$fhd>;
-#                if( $part_in_msg eq "ENDMESSAGE\n") {
-#                    last;
-#                }
-#                $in_msg .= $part_in_msg;
-#            }
-#            chomp($in_msg);
-#            
-#            if (not defined $in_msg) { 
-#                next; 
-#            } elsif ($in_msg =~ "done") {
-#                daemon_log("process child read: $in_msg", 7);
-#                delete $busy_child{$pid};
-#                $free_child{$pid} = $child_hash;
-#
-#            } else {
-#                daemon_log("process child read:", 7);
-#                daemon_log("\n$in_msg", 8);
-#                # send computed answer back to connected client
-#                my $act_client = $busy_child{$pid}{client_ref};
-#                print $act_client $in_msg."\n";
-#                delete $busy_child{$pid};
-#                $free_child{$pid} = $child_hash;
-#
-#            }
-#        }
-#    }
-#
-#
-#    }  
-#
-#
-#}
-
-POE::Session->create
-(
-       inline_states => {
-               _start => \&trigger_db_loop,
-               watch_for_new_jobs => \&watch_for_new_jobs,
-       }
-);
-
-POE::Component::Server::TCP->new
-(
-       Port => $server_port,
-       ClientInput => \&client_input,
-);
-
-POE::Kernel->run();
-exit;
-
 sub client_input {
        my ($heap,$input,$wheel) = @_[HEAP, ARG0, ARG1];
        ######################################
@@ -640,7 +407,7 @@ sub client_input {
                if (defined $tmp) {
                        $answer = $tmp;
                }
-               daemon_log("Got answer from module ".$module.": ".$answer,3);
+               daemon_log("Got answer from module ".$module.": ".$answer,8);
        }        
        daemon_log("processing of msg finished", 5);
 
@@ -660,16 +427,17 @@ sub watch_for_new_jobs {
        my ($kernel,$heap) = @_[KERNEL, HEAP];
 
        # check gosa job queue for jobs with executable timestamp
-       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;
-       $month+=1;
-       $month = $month < 10 ? $month = "0".$month : $month;
-       $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
-       $year+=1900;
-       my $timestamp = "$year$month$monthday$hours$minutes$seconds";
+#      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;
+#      $month+=1;
+#      $month = $month < 10 ? $month = "0".$month : $month;
+#      $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+#      $year+=1900;
+#      my $timestamp = "$year$month$monthday$hours$minutes$seconds";
+    my $timestamp = &get_time();
 
        my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>$timestamp  } );
 
@@ -729,3 +497,96 @@ sub watch_for_new_jobs {
 
        $kernel->delay_set('watch_for_new_jobs',3);
 }
+
+
+#==== MAIN = main ==============================================================
+#  parse commandline options
+Getopt::Long::Configure( "bundling" );
+GetOptions("h|help" => \&usage,
+        "c|config=s" => \$cfg_file,
+        "f|foreground" => \$foreground,
+        "v|verbose+" => \$verbose,
+        "no-bus+" => \$no_bus,
+        "no-arp+" => \$no_arp,
+           );
+
+#  read and set config parameters
+&check_cmdline_param ;
+&read_configfile;
+&check_pid;
+
+$SIG{CHLD} = 'IGNORE';
+
+# forward error messages to logfile
+if( ! $foreground ) {
+    open(STDERR, '>>', $log_file);
+    open(STDOUT, '>>', $log_file);
+}
+
+# Just fork, if we are not in foreground mode
+if( ! $foreground ) { 
+    chdir '/'                 or die "Can't chdir to /: $!";
+    $pid = fork;
+    setsid                    or die "Can't start a new session: $!";
+    umask 0;
+} else { 
+    $pid = $$; 
+}
+
+# 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 );
+    if( !$foreground ) { 
+        exit( 0 ) 
+    };
+}
+
+daemon_log(" ", 1);
+daemon_log("$0 started!", 1);
+
+# delete old DBsqlite lock files
+system('rm -f /tmp/gosa_si_lock*');
+
+# connect to gosa-si job queue
+my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
+$job_db = GOSA::DBsqlite->new($job_queue_file_name);
+$job_db->create_table('jobs', \@job_col_names);
+
+# connect to known_clients_db
+my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events');
+$known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
+$known_clients_db->create_table('known_clients', \@clients_col_names);
+
+# connect to known_server_db
+my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp');
+$known_server_db = GOSA::DBsqlite->new($known_server_file_name);
+$known_server_db->create_table('known_server', \@server_col_names);
+
+# import all modules
+&import_modules;
+
+# check wether all modules are gosa-si valid passwd check
+
+# create session for repeatedly checking the job queue for jobs
+POE::Session->create
+(
+       inline_states => {
+               _start => \&trigger_db_loop,
+               watch_for_new_jobs => \&watch_for_new_jobs,
+       }
+);
+
+# create socket for incoming xml messages
+POE::Component::Server::TCP->new
+(
+       Port => $server_port,
+       ClientInput => \&client_input,
+);
+daemon_log("start socket for incoming xml messages at port '$server_port' ", 1);
+
+POE::Kernel->run();
+exit;
+
+