From: cajus Date: Wed, 5 Mar 2008 16:30:56 +0000 (+0000) Subject: Updated trigger X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8f6d2aa203cd824dbc518a994986add63d90cc5c;p=gosa.git Updated trigger git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9369 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-si/server/events/gosaTriggered.pm b/gosa-si/server/events/gosaTriggered.pm index 81137df2d..eb081e099 100644 --- a/gosa-si/server/events/gosaTriggered.pm +++ b/gosa-si/server/events/gosaTriggered.pm @@ -459,51 +459,104 @@ sub change_fai_state { $search.= ")"; # If there's any host inside of the search string, procress them - if ($search =~ /macAddress/){ - # Perform search for Unit Tag - my $mesg = $main::ldap_handle->search( - base => $main::ldap_base, - scope => 'sub', - attrs => ['dn', 'FAIstate', 'objectClass'], - filter => "$search" - ); - - if ($mesg->count) { - my @entries = $mesg->entries; - foreach my $entry (@entries) { - - # Only modify entry if it is not set to 'localboot' - if ($entry->get_value("FAIstate") ne 'localboot'){ - - &main::daemon_log("INFO: Setting FAIstate to 'localboot' for ".$entry->dn, 5); - my $result; - my %tmp = map { $_ => 1 } $entry->get_value("objectClass"); - if (exists $tmp{'FAIobject'}){ - if ($state eq ''){ - $result= $main::ldap_handle->modify($entry->dn, changes => [ - delete => [ FAIstate => [] ] ]); - } else { - $result= $main::ldap_handle->modify($entry->dn, changes => [ - replace => [ FAIstate => $state ] ]); - } - } elsif ($state ne ''){ - $result= $main::ldap_handle->modify($entry->dn, changes => [ - add => [ objectClass => 'FAIobject' ], - add => [ FAIstate => $state ] ]); - } + if (!($search =~ /macAddress/)){ + return; + } - # Errors? - if ($result->code){ - &main::daemon_log("Error: Setting FAIstate to 'localboot' for ".$entry->dn. "failed: ".$result->error, 1); + # Perform search for Unit Tag + my $mesg = $main::ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + attrs => ['dn', 'FAIstate', 'objectClass'], + 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"){ + + &main::daemon_log("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= $main::ldap_handle->modify($entry->dn, changes => [ + delete => [ FAIstate => [] ] ]); + } else { + $result= $main::ldap_handle->modify($entry->dn, changes => [ + replace => [ FAIstate => $state ] ]); } + } elsif ($state ne ''){ + $result= $main::ldap_handle->modify($entry->dn, changes => [ + add => [ objectClass => 'FAIobject' ], + add => [ FAIstate => $state ] ]); + } + # Errors? + if ($result->code){ + &main::daemon_log("Error: Setting FAIstate to '$state' for ".$entry->dn. "failed: ".$result->error, 1); } + } } + } + } +} + + +sub change_goto_state { + my ($st, $targets) = @_; + + # Switch on or off? + my $state= $st eq 'active' ? 'active': 'locked'; + &main::refresh_ldap_handle(); + if( defined($main::ldap_handle) ) { + + # Build search filter for hosts + my $search= "(&(objectClass=GOhard)"; + foreach (@{$targets}){ + $search.= "(macAddress=$_)"; + } + $search.= ")"; + + # If there's any host inside of the search string, procress them + if ($search !=~ /macAddress/){ + return; + } + + # Perform search for Unit Tag + my $mesg = $main::ldap_handle->search( + base => $main::ldap_base, + scope => 'sub', + attrs => ['dn', 'gotoMode'], + 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("gotoMode") ne $state){ + + &main::daemon_log("INFO: Setting gotoMode to '$state' for ".$entry->dn, 5); + my $result; + $result= $main::ldap_handle->modify($entry->dn, changes => [ + replace => [ gotoMode => $state ] ]); + + # Errors? + if ($result->code){ + &main::daemon_log("Error: Setting gotoMode to '$state' for ".$entry->dn. "failed: ".$result->error, 1); + } + + } + } } } } - 1;