diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index cb759af22cdd18b31ae4d14ab575408d268cc7b2..cb243deff3879981da39f477314cdf26463fae52 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
my ($bus_activ, $bus, $msg_to_bus, $bus_cipher);
my ($server);
my ($gosa_server, $job_queue_timeout, $job_queue_loop_delay);
+my ($messaging_db_loop_delay);
my ($known_modules);
my ($pid_file, $procid, $pid, $log_file);
my ($arp_activ, $arp_fifo);
"targettag DEFAULT 'none'",
"xmlmessage DEFAULT 'none'",
"macaddress DEFAULT 'none'",
+ "plainname DEFAULT 'none'",
);
# holds all other gosa-sd as well as the gosa-sd-bus
# holds all messages which should be delivered to a user
our $messaging_db;
our $messaging_tn = "messaging";
-our @messaging_col_names = ('subject', 'from', 'to', 'flag', 'direction', 'delivery_time', 'message', 'timestamp', 'id INTEGER', );
+our @messaging_col_names = ('subject', 'message_from', 'message_to', 'flag', 'direction', 'delivery_time', 'message', 'timestamp', 'id INTEGER' );
my $messaging_file_name;
# path to directory to store client install log files
"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"],
},
"SIPackages" => {
#===============================================================================
sub read_configfile {
my $cfg;
- if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
+ if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
if( -r $cfg_file ) {
$cfg = Config::IniFiles->new( -file => $cfg_file );
} else {
daemon_log("shutting down gosa-si-server", 1);
- system("killall gosa-si-server");
+ system("kill `ps -C gosa-si-server -o pid=`");
}
$SIG{INT} = \&sig_int_handler;
$kernel->yield('create_fai_server_db', $fai_server_tn );
$kernel->yield('create_fai_release_db', $fai_release_tn );
$kernel->sig(USR1 => "sig_handler");
+ $kernel->sig(USR2 => "create_packages_list_db");
}
sub sig_handler {
sub trigger_db_loop {
my ($kernel) = @_ ;
$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_done_jobs', $job_queue_loop_delay);
+ $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
+ $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay);
}
sub watch_for_done_jobs {
my ($kernel,$heap) = @_[KERNEL, HEAP];
# check gosa job queue 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) + 120) < $timestamp ORDER BY timestamp";
+ my $res = $job_db->exec_statement( $sql_statement );
+
+ # Merge all new jobs that would do the same actions
+ my @drops;
+ my $hits;
+ foreach my $hit (reverse @{$res} ) {
+ my $macaddress= lc @{$hit}[8];
+ my $headertag= @{$hit}[5];
+ if(defined($hits->{$macaddress}->{$headertag})) {
+ push @drops, "DELETE FROM $job_queue_tn WHERE id = '$hits->{$macaddress}->{$headertag}[0]'";
+ }
+ $hits->{$macaddress}->{$headertag}= $hit;
+ }
+
+ # Delete new jobs with a matching job in state 'processing'
+ foreach my $macaddress (keys %{$hits}) {
+ foreach my $jobdb_headertag (keys %{$hits->{$macaddress}}) {
+ my $jobdb_id = @{$hits->{$macaddress}->{$jobdb_headertag}}[0];
+ my $sql_statement = "SELECT * FROM $job_queue_tn WHERE macaddress LIKE '$macaddress' AND headertag='$jobdb_headertag' AND status='processing'";
+ my $res = $job_db->exec_statement( $sql_statement );
+ foreach my $hit (@{$res}) {
+ push @drops, "DELETE FROM $job_queue_tn WHERE id = '$jobdb_id'";
+ }
+ }
+ }
+
+ # Commit deletion
+ $job_db->exec_statementlist(\@drops);
+
+ # Look for new jobs that could be executed
+ foreach my $macaddress (keys %{$hits}) {
+
+ # Look if there is an executing job
+ my $sql_statement = "SELECT * FROM $job_queue_tn WHERE macaddress LIKE '$macaddress' AND status='processing'";
+ my $res = $job_db->exec_statement( $sql_statement );
+
+ # Skip new jobs for host if there is a processing job
+ if(defined($res) and defined @{$res}[0]) {
+ next;
+ }
+
+ foreach my $jobdb_headertag (keys %{$hits->{$macaddress}}) {
+ my $jobdb_id = @{$hits->{$macaddress}->{$jobdb_headertag}}[0];
+ my $job_msg = @{$hits->{$macaddress}->{$jobdb_headertag}}[7];
+
+ daemon_log("J DEBUG: its time to execute $job_msg", 7);
+ my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$macaddress'";
+ my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
+
+ # expect macaddress is unique!!!!!!
+ my $target = $res_hash->{1}->{hostname};
+
+ # change header
+ $job_msg =~ s/<header>job_/<header>gosa_/;
+
+ # add sqlite_id
+ $job_msg =~ s/<\/xml>$/<jobdb_id>$jobdb_id<\/jobdb_id><\/xml>/;
+
+ $job_msg =~ /<header>(\S+)<\/header>/;
+ my $header = $1 ;
+ my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J");
+
+ # update status in job queue to 'processing'
+ $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id='$jobdb_id'";
+ my $res = $job_db->update_dbentry($sql_statement);
+
+ # We don't want parallel processing
+ last;
+ }
+ }
+
+ $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
+}
+
+
+sub watch_for_new_messages {
+ my ($kernel,$heap) = @_[KERNEL, HEAP];
+ my @coll_user_msg; # collection list of outgoing messages
+
+ # check messaging_db for new incoming messages with executable timestamp
my $timestamp = &get_time();
- my $sql_statement = "SELECT * FROM ".$job_queue_tn.
- " WHERE status='waiting' AND timestamp<'$timestamp'";
- my $res = $job_db->select_dbentry( $sql_statement );
+ #my $sql_statement = "SELECT * FROM $messaging_tn WHERE (CAST (delivery_time AS INTEGER) + 120) < $timestamp";
+ my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( (CAST(timestamp AS INTEGER))<$timestamp AND flag='n' AND direction='in' )";
+ my $res = $messaging_db->exec_statement( $sql_statement );
+
+ foreach my $hit (@{$res}) {
+
+ # create outgoing messages
+ my $message_to = @{$hit}[2];
+
+ # translate message_to to plain login name
+ my @reciever_l = ($message_to);
+ my $message_id = @{$hit}[8];
+
+ #add each outgoing msg to messaging_db
+ my $reciever;
+ foreach $reciever (@reciever_l) {
+ my $sql_statement = "INSERT INTO $messaging_tn (subject, message_from, message_to, flag, direction, delivery_time, message, timestamp, id) ".
+ "VALUES ('".
+ @{$hit}[0]."', '". # subject
+ @{$hit}[1]."', '". # message_from
+ $reciever."', '". # message_to
+ "none"."', '". # flag
+ "out"."', '". # direction
+ @{$hit}[5]."', '". # delivery_time
+ @{$hit}[6]."', '". # message
+ $timestamp."', '". # timestamp
+ @{$hit}[8]. # id
+ "')";
+ &daemon_log("M DEBUG: $sql_statement", 1);
+ my $res = $messaging_db->exec_statement($sql_statement);
+ &daemon_log("M INFO: message '".@{$hit}[8]."' is prepared for delivery to reciever '$reciever'", 5);
+ }
+
+ # send outgoing messages
+ my $sql_statement = "SELECT * FROM $messaging_tn WHERE ( flag='p' AND direction='out' )";
+ my $res = $messaging_db->exec_statement( $sql_statement );
+ foreach my $hit (@{$res}) {
+ # add subject, from, to and message to list coll_user_msg
+ my @user_msg = [@{$hit}[0], @{$hit}[1], $reciever, @{$hit}[6]];
+ push( @coll_user_msg, \@user_msg);
+ }
+
+ # send outgoing list to myself (gosa-si-server) to deliver each message to user
+ # reason for this workaround: if to much messages have to be delivered, it can come to
+ # denial of service problems of the server. so, the incoming message list can be processed
+ # by a forked child and gosa-si-server is always ready to work.
+ my $collection_out_msg = &create_xml_hash("collection_user_messages", $server_address, $server_address);
+ # add to hash 'msg1' => [subject, from, to, message]
+ # hash to string
+ # send msg to myself
+# TODO
+
+ # set incoming message to flag d=deliverd
+ $sql_statement = "UPDATE $messaging_tn SET flag='p' WHERE id='$message_id'";
+ &daemon_log("M DEBUG: $sql_statement", 7);
+ $res = $messaging_db->update_dbentry($sql_statement);
+ &daemon_log("M INFO: message '".@{$hit}[8]."' is set to flag 'p' (processed)", 5);
- while( my ($id, $hit) = each %{$res} ) {
- my $jobdb_id = $hit->{id};
- my $macaddress = $hit->{'macaddress'};
- my $job_msg = $hit->{'xmlmessage'};
- daemon_log("J DEBUG: its time to execute $job_msg", 7);
- my $sql_statement = "SELECT * FROM known_clients WHERE macaddress LIKE '$macaddress'";
- my $res_hash = $known_clients_db->select_dbentry( $sql_statement );
- # expect macaddress is unique!!!!!!
- my $target = $res_hash->{1}->{hostname};
-
- # change header
- $job_msg =~ s/<header>job_/<header>gosa_/;
-
- # add sqlite_id
- $job_msg =~ s/<\/xml>$/<jobdb_id>$jobdb_id<\/jobdb_id><\/xml>/;
-
- $job_msg =~ /<header>(\S+)<\/header>/;
- my $header = $1 ;
- my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J");
-
- # update status in job queue to 'processing'
- $sql_statement = "UPDATE $job_queue_tn SET status='processing' WHERE id='$jobdb_id'";
- my $res = $job_db->update_dbentry($sql_statement);
}
+
+ $kernel->delay_set('watch_for_new_messages', $messaging_db_loop_delay);
- $kernel->delay_set('watch_for_new_jobs', $job_queue_loop_delay);
+
+ return;
+}
+
+
+sub watch_for_done_messages {
+ my ($kernel,$heap) = @_[KERNEL, HEAP];
+
+ $kernel->delay_set('watch_for_done_messages', $messaging_db_loop_delay);
+ return;
}
my $heap;
my $ldap_handle;
- if (not defined $session_id ) { $session_id = 0 };
+ if (not defined $session_id ) { $session_id = 0 };
if ($session_id == 0) {
- daemon_log("$session_id DEBUG: get_ldap_handle invoked without a session_id, create a new ldap_handle", 7);
- $ldap_handle = Net::LDAP->new( $ldap_uri );
+ daemon_log("$session_id DEBUG: get_ldap_handle invoked without a session_id, create a new ldap_handle", 7);
+ $ldap_handle = Net::LDAP->new( $ldap_uri );
+ $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password);
} else {
- my $session_reference = $global_kernel->ID_id_to_session($session_id);
- if( defined $session_reference ) {
- $heap = $session_reference->get_heap();
- }
-
- if (not defined $heap) {
- daemon_log("$session_id DEBUG: cannot get heap for session_id '$session_id'", 7);
- return;
- }
-
- if (not exists $heap->{ldap_handle}) {
- # create new ldap handle
- $ldap_handle = Net::LDAP->new( $ldap_uri );
- # add ldap handle to heap
- $heap->{ldap_handle} = $ldap_handle;
- }
- }
+ my $session_reference = $global_kernel->ID_id_to_session($session_id);
+ if( defined $session_reference ) {
+ $heap = $session_reference->get_heap();
+ }
+ if (not defined $heap) {
+ daemon_log("$session_id DEBUG: cannot get heap for session_id '$session_id'", 7);
+ return;
+ }
+ # TODO: This "if" is nonsense, because it doesn't prove that the
+ # used handle is still valid - or if we've to reconnect...
+ #if (not exists $heap->{ldap_handle}) {
+ $ldap_handle = Net::LDAP->new( $ldap_uri );
+ $ldap_handle->bind($ldap_admin_dn, password => $ldap_admin_password);
+ $heap->{ldap_handle} = $ldap_handle;
+ #}
+ }
return $ldap_handle;
}
my $state= $mapActions{ $st };
- my $ldap_handle = get_ldap_handle($session_id);
+ my $ldap_handle = &get_ldap_handle($session_id);
if( defined($ldap_handle) ) {
# Build search filter for hosts
filter => "$search"
);
- if ($mesg->count) {
- my @entries = $mesg->entries;
- foreach my $entry (@entries) {
- # Only modify entry if it is not set to '$state'
- if ($entry->get_value("FAIstate") ne "$state"){
- daemon_log("$session_id INFO: Setting FAIstate to '$state' for ".$entry->dn, 5);
- my $result;
- my %tmp = map { $_ => 1 } $entry->get_value("objectClass");
- if (exists $tmp{'FAIobject'}){
- if ($state eq ''){
- $result= $ldap_handle->modify($entry->dn, changes => [
- delete => [ FAIstate => [] ] ]);
- } else {
- $result= $ldap_handle->modify($entry->dn, changes => [
- replace => [ FAIstate => $state ] ]);
- }
- } elsif ($state ne ''){
- $result= $ldap_handle->modify($entry->dn, changes => [
- add => [ objectClass => 'FAIobject' ],
- add => [ FAIstate => $state ] ]);
- }
-
- # Errors?
- if ($result->code){
- daemon_log("$session_id Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
- }
-
- } else {
- daemon_log("$session_id DEBUG FAIstate at host '$_' already at state '$st'", 7);
- }
- }
- }
+ if ($mesg->count) {
+ my @entries = $mesg->entries;
+ foreach my $entry (@entries) {
+ # Only modify entry if it is not set to '$state'
+ if ($entry->get_value("FAIstate") ne "$state"){
+ daemon_log("$session_id INFO: Setting FAIstate to '$state' for ".$entry->dn, 5);
+ my $result;
+ my %tmp = map { $_ => 1 } $entry->get_value("objectClass");
+ if (exists $tmp{'FAIobject'}){
+ if ($state eq ''){
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ delete => [ FAIstate => [] ] ]);
+ } else {
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ replace => [ FAIstate => $state ] ]);
+ }
+ } elsif ($state ne ''){
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ add => [ objectClass => 'FAIobject' ],
+ add => [ FAIstate => $state ] ]);
+ }
+
+ # Errors?
+ if ($result->code){
+ daemon_log("$session_id Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
+ }
+ } else {
+ daemon_log("$session_id DEBUG FAIstate at host '".$entry->dn."' already at state '$st'", 7);
+ }
+ }
+ }
# if no ldap handle defined
} else {
daemon_log("$session_id ERROR: no LDAP handle defined for update FAIstate", 1);
);
if($mesg->count) {
foreach my $entry(@{$mesg->{'entries'}}) {
- my ($server, $tag, $release, $sections)= split /\|/, $entry->get_value('FAIrepository');
- my $line = "deb $server $release";
- $sections =~ s/,/ /g;
- $line.= " $sections";
- print $fh $line."\n";
+ foreach my $value(@{$entry->get_value('FAIrepository', asref => 1)}) {
+ my ($server, $tag, $release, $sections)= split /\|/, $value;
+ my $line = "deb $server $release";
+ $sections =~ s/,/ /g;
+ $line.= " $sections";
+ print $fh $line."\n";
+ }
}
}
}
sub create_packages_list_db {
my ($ldap_handle, $sources_file) = @_ ;
- if (not defined $ldap_handle) {
- daemon_log("0 ERROR: no ldap_handle available to create_packages_list_db", 1);
- return;
- }
+ if (not defined $ldap_handle) {
+ $ldap_handle= &get_ldap_handle();
+
+ if (not defined $ldap_handle) {
+ daemon_log("0 ERROR: no ldap_handle available to create_packages_list_db", 1);
+ return;
+ }
+ }
+
if (not defined $sources_file) {
$sources_file = &create_sources_list($ldap_handle);
}
$bus_activ = "false"
}
-
-
-# delete old DBsqlite lock files
-#unlink('/tmp/gosa_si_lock*');
-
# connect to gosa-si job queue
$job_db = GOSA::DBsqlite->new($job_queue_file_name);
$job_db->create_table($job_queue_tn, \@job_queue_col_names);
$login_users_db->create_table($login_users_tn, \@login_users_col_names);
# connect to fai_server_db and fai_release_db
+unlink($fai_server_file_name);
$fai_server_db = GOSA::DBsqlite->new($fai_server_file_name);
$fai_server_db->create_table($fai_server_tn, \@fai_server_col_names);
$fai_server_db->create_table($fai_release_tn, \@fai_release_col_names);
inline_states => {
_start => \&_start,
sig_handler => \&sig_handler,
+ watch_for_new_messages => \&watch_for_new_messages,
+ watch_for_done_messages => \&watch_for_done_messages,
watch_for_new_jobs => \&watch_for_new_jobs,
watch_for_done_jobs => \&watch_for_done_jobs,
create_packages_list_db => \&run_create_packages_list_db,