summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7d94653)
raw | patch | inline | side by side (parent: 7d94653)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 10 Mar 2008 12:12:24 +0000 (12:12 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 10 Mar 2008 12:12:24 +0000 (12:12 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@9556 594d385d-05f5-0310-b6e9-bd551577e9d8
index d6efde3b8345173aa241b1f8e7a683a177d53a25..ec01c4467d1008eb2bfbfa035496d1b323c7807f 100644 (file)
use strict;
use warnings;
use utf8;
-
+use GOSA::GosaSupportDaemon;
BEGIN {}
sub trigger_action_reboot {
my ($msg, $msg_hash) = @_;
+ my $timeout;
+
+ if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
+ $timeout = -1;
+ }
+ else {
+ $timeout = @{$msg_hash->{timeout}}[0];
+ }
+
+ # check logged in user
+ my @user_list = &get_logged_in_users;
+ if( @user_list >= 1 ) {
+ # TODO do something
+ }
+ else {
+ $timeout = 0;
+ }
+
+ # execute function
+ if( $timeout == 0 ) {
+ print STDERR ("shutdown -r +$timeout\n");
+ }
+ elsif( $timeout > 0 ) {
+ print STDERR ("shutdown -r +$timeout\n");
+ }
+ elsif( $timeout < 0 ) {
+ print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
+ open(FILE, "> /etc/gosa-si/event");
+ print FILE "trigger_action_reboot\n";
+ close(FILE);
+ }
+ else {
+ # TODO do something, error handling, logging
+ }
+
+ return;
+
+
+
+
print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
return;
}
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index 6e4fdc38dc909059e5c44aadb94263d007d78759..4841038ca30a8785d7103064b8893dfef574c1a0 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
eval{ require $event; };
if( $@ ) {
daemon_log("ERROR: import of event module '$event' failed", 1);
- daemon_log("$@", 8);
+ daemon_log("$@", 1);
next;
}
$REGISTERED = 1;
}
else {
- &send_msg_to_target($answer, $server_address, $server_key);
+ $answer =~ /<header>(\S+)<\/header>/;
+ &send_msg_to_target($answer, $server_address, $server_key, $1);
}
# postprocessing
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index d664cadc3185401752cc999a29f0baefb1dd1bfa..c721cd18f4f7900e5dffc8fa2f40444c132c78ef 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
$msg = &decrypt_msg($crypted_msg, $module_key);
if ($msg =~ /<xml>/i){
- &main::daemon_log("decrypted_msg: \n$msg", 8);
+ daemon_log("decrypted_msg: \n$msg", 8);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
##############
}
};
if($@) {
- &main::daemon_log("WARNING: do not understand the message: $@", 5);
+ daemon_log("WARNING: do not understand the message: $@", 5);
$msg = undef;
$msg_hash = undef;
}
}
if( (!$msg) || (!$msg_hash) || (!$module) ) {
- daemon_log("INFO: Incoming message is not from a known server", 5);
+ daemon_log("DEBUG: Incoming message is not from a known server", 7);
}
return ($msg, $msg_hash, $module);
}
if( (!$msg) || (!$msg_hash) || (!$module) ) {
- &daemon_log("INFO: Incoming message is not from a known client", 5);
+ &daemon_log("DEBUG: Incoming message is not from a known client", 5);
}
return ($msg, $msg_hash, $module);
}
if( (!$msg) || (!$msg_hash) || (!$module)) {
- daemon_log("INFO: Incoming message is not from an unknown host", 5);
+ daemon_log("DEBUG: Incoming message is not from an unknown host", 7);
}
return ($msg, $msg_hash, $module);
return $error;
}
-
+###
+#
+# HIER LÄUFT WAS SCHIEF - GENAU HIER KACK MIST
+#
+# ERROR
+#
+# TODO
+#
+###
sub update_jobdb_status_for_send_msgs {
my ($answer, $error) = @_;
if( $answer =~ /<jobdb_id>(\d+)<\/jobdb_id>/ ) {
# sending msg was successful
my $sql_statement = "UPDATE $job_queue_tn ".
"SET status='done' ".
- "WHERE id='$jobdb_id'";
+ "WHERE id='$jobdb_id' AND status='processed'";
my $res = $job_db->update_dbentry($sql_statement);
}
}
my ($answer_header, @answer_target_l, $answer_source);
my $client_answer;
+ daemon_log("", 5);
daemon_log("INFO: Incoming msg from '".$heap->{'remote_ip'}."'", 5);
- daemon_log("DEBUG: Incoming message:\n$input", 8);
+ daemon_log("DEBUG: Incoming message:\n$input", 9);
####################
# check incoming msg
}
+sub change_fai_state {
+ my ($st, $targets) = @_;
+
+ # Set FAI state to localboot
+ my %mapActions= (
+ reboot => '',
+ update => 'softupdate',
+ localboot => 'localboot',
+ reinstall => 'install',
+ rescan => '',
+ wake => '',
+ memcheck => 'memcheck',
+ sysinfo => 'sysinfo',
+ );
+
+ # Return if this is unknown
+ if (!exists $mapActions{ $st }){
+ return;
+ }
+
+ my $state= $mapActions{ $st };
+
+ &refresh_ldap_handle();
+ if( defined($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 = $ldap_handle->search(
+ base => $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"){
+
+ 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= $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("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';
+
+ &refresh_ldap_handle();
+ if( defined($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 = $ldap_handle->search(
+ base => $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){
+
+ daemon_log("INFO: Setting gotoMode to '$state' for ".$entry->dn, 5);
+ my $result;
+ $result= $ldap_handle->modify($entry->dn, changes => [
+ replace => [ gotoMode => $state ] ]);
+
+ # Errors?
+ if ($result->code){
+ &daemon_log("Error: Setting gotoMode to '$state' for ".$entry->dn. "failed: ".$result->error, 1);
+ }
+
+ }
+ }
+ }
+
+ }
+}
+
+
sub create_fai_server_db {
my ($table_name) = $_[ARG0];
my $result;
if(defined($ldap_handle)) {
daemon_log("Creating fai_server_db",4);
my $mesg= $ldap_handle->search(
- base => $main::ldap_base,
+ base => $ldap_base,
scope => 'sub',
attrs => ['FAIrepository', 'gosaUnitTag'],
filter => "(&(FAIrepository=*)(objectClass=FAIrepositoryServer))",
if(defined($ldap_handle)) {
daemon_log("Creating fai_release_db",4);
my $mesg= $ldap_handle->search(
- base => $main::ldap_base,
+ base => $ldap_base,
scope => 'sub',
attrs => [],
filter => "(&(objectClass=organizationalUnit)(ou=fai))",
index 8aa17e5316bac1aabdf1d6e081869d6637166c2b..d5a0a6b4b1f4f8abdef8c2a278e15df2c1948ba0 100644 (file)
@out_msg_l = &{$event_hash->{$header}."::$header"}($msg, $msg_hash, $session_id);
}
+ # if incoming 'gosa_'-msg is scheduled from job_queue, than it contains xml-tag 'jobdb_id'
+ # after procesing this msg, set status of this job in job_queue to done
+ if ($msg =~ /<jobdb_id>(\d+)<\/jobdb_id>/) {
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='done' ".
+ "WHERE id='$1'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: set job '$1' to status processed", 5);
+ }
+
# if delivery not possible raise error and return
if( not defined $out_msg_l[0] ) {
&main::daemon_log("WARNING: GosaPackages got no answer from event handler '$header'", 3);
index e33c83eaa5305d9ad72c3a07931ebb2d36fb77db..de26b59b58b6b0cc279294b907a74ac3b4f2f754 100644 (file)
"get_limit_statement",
"get_orderby_statement",
"get_dns_domains",
+ "get_logged_in_users",
);
@EXPORT = @functions;
use strict;
return @searches;
}
+
+sub get_logged_in_users {
+ my $result = qx(/usr/bin/w -hs);
+ my @res_lines;
+
+ if( defined $result ) {
+ chomp($result);
+ @res_lines = split("\n", $result);
+ }
+
+ my @logged_in_user_list;
+ foreach my $line (@res_lines) {
+ chomp($line);
+ my @line_parts = split(/\s+/, $line);
+ push(@logged_in_user_list, $line_parts[0]);
+ }
+
+ return @logged_in_user_list;
+
+}
+
1;
index 088ce5ab7964c339ac0baa69a62cdfe99c84a7bb..0ec31d5c177fe4ab75446118aaa8bf5abdf190d5 100644 (file)
sub GOTOACTIVATION {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+
+ # test whether content is an empty hash or a string which is required
+ my $content = @{$msg_hash->{$header}}[0];
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header"."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress'", 5);
+ return;
}
sub PROGRESS {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_progress_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+
+ # test whether content is an empty hash or a string which is required
+ my $content;
+ my $cont = @{$msg_hash->{$header}}[0];
+ eval{ if( 0 == keys(%$cont) ) { $content = ""; } };
+ if( $@ ) { $content = "$cont"; }
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET progress='$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - $content%", 5);
+
+ return;
}
sub FAIREBOOT {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_status_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+
+ # test whether content is an empty hash or a string which is required
+ my $content = @{$msg_hash->{$header}}[0];
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
+
+ return;
}
sub TASKSKIP {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_status_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+
+ # test whether content is an empty hash or a string which is required
+ my $content = @{$msg_hash->{$header}}[0];
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
+
+ return;
}
sub TASKBEGIN {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_status_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+ my $content = @{$msg_hash->{$header}}[0];
+
+ # test whether content is an empty hash or a string which is required
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ # check if installation finished
+ if (($content eq 'finish') || ($content eq 'faiend')){
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='done', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
+
+ # set fai_state to localboot
+ &main::change_fai_state('localboot', \@{$msg_hash->{target}});
+
+ } else {
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
+
# -----------------------> Update hier
# <CLMSG_TASKBEGIN>finish</CLMSG_TASKBEGIN>
# <header>CLMSG_TASKBEGIN</header>
# macaddress auslesen, Client im LDAP lokalisieren
# FAIstate auf "localboot" setzen, wenn FAIstate "install" oder "softupdate" war
+ }
- return @out_msg_l;
+ return;
}
sub TASKEND {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_status_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+
+ # test whether content is an empty hash or a string which is required
+ my $content = @{$msg_hash->{$header}}[0];
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
# -----------------------> Update hier
# <CLMSG_TASKBEGIN>finish</CLMSG_TASKBEGIN>
# macaddress auslesen, Client im LDAP lokalisieren
# FAIstate auf "error" setzen
- return @out_msg_l;
+ return;
}
sub TASKERROR {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_status_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'target'}}[0];
+ my $macaddress = @{$msg_hash->{'macaddress'}}[0];
+
+ # clean up header
+ $header =~ s/CLMSG_//g;
+
+ # test whether content is an empty hash or a string which is required
+ my $content = @{$msg_hash->{$header}}[0];
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
# -----------------------> Update hier
# <CLMSG_TASKBEGIN>finish</CLMSG_TASKBEGIN>
# macaddress auslesen, Client im LDAP lokalisieren
# FAIstate auf "error" setzen
- return @out_msg_l;
+ return;
}
sub HOOK {
my ($msg, $msg_hash, $session_id) = @_;
- my $out_msg = &build_status_result_update_msg($msg_hash);
- my @out_msg_l = ($out_msg);
- return @out_msg_l;
-}
-
-
-sub build_status_result_update_msg {
- my ($msg_hash) = @_;
-
my $header = @{$msg_hash->{'header'}}[0];
my $source = @{$msg_hash->{'target'}}[0];
- my $target = @{$msg_hash->{'target'}}[0];
my $macaddress = @{$msg_hash->{'macaddress'}}[0];
- # test whether content is an empty hash or a string which is required
- my $content = @{$msg_hash->{$header}}[0];
- eval{
- if( 0 == keys(%$content) ) {
- $content = "";
- }
- };
- if( $@ ) {
- $content = " $content";
- }
-
+ # clean up header
$header =~ s/CLMSG_//g;
- my $out_msg = sprintf("<xml> ".
- "<header>gosa_update_status_jobdb_entry</header> ".
- "<source>%s</source> ".
- "<target>%s</target>".
- "<where> ".
- "<clause> ".
- "<phrase> ".
- "<status>processing</status> ".
- "<macaddress>%s</macaddress> ".
- "</phrase> ".
- "</clause> ".
- "</where> ".
- "<update> ".
- "<status>processing</status> ".
- "<result>%s</result> ".
- "</update> ".
- "</xml>", $source, "JOBDB", $macaddress, $header.$content);
- return $out_msg;
-}
-
-
-sub build_progress_update_msg {
- my ($msg_hash) = @_;
-
- my $header = @{$msg_hash->{'header'}}[0];
- my $source = @{$msg_hash->{'target'}}[0];
- my $target = @{$msg_hash->{'target'}}[0];
- my $macaddress = @{$msg_hash->{'macaddress'}}[0];
# test whether content is an empty hash or a string which is required
my $content = @{$msg_hash->{$header}}[0];
- eval{
- if( 0 == keys(%$content) ) {
- $content = "";
- }
- };
- if( $@ ) {
- $content = "$content";
- }
-
- $header =~ s/CLMSG_//g;
- my $out_msg = sprintf("<xml> ".
- "<header>gosa_update_status_jobdb_entry</header> ".
- "<source>%s</source> ".
- "<target>%s</target>".
- "<where> ".
- "<clause> ".
- "<phrase> ".
- "<status>processing</status> ".
- "<macaddress>%s</macaddress> ".
- "</phrase> ".
- "</clause> ".
- "</where> ".
- "<update> ".
- "<progress>%s</progress> ".
- "</update> ".
- "</xml>", $source, "JOBDB", $macaddress, $content);
- return $out_msg;
-}
+ eval{ if( 0 == keys(%$content) ) { $content = ""; } };
+ if( $@ ) { $content = "$content"; }
+ my $sql_statement = "UPDATE $main::job_queue_tn ".
+ "SET status='processing', result='$header "."$content' ".
+ "WHERE status='processing' AND macaddress='$macaddress'";
+ &main::daemon_log("DEBUG: $sql_statement", 7);
+ my $res = $main::job_db->update_dbentry($sql_statement);
+ &main::daemon_log("INFO: $header at '$macaddress' - '$content'", 5);
-sub build_result_update_msg {
- my ($msg_hash) = @_;
-
- my $header = @{$msg_hash->{'header'}}[0];
- my $source = @{$msg_hash->{'target'}}[0];
- my $target = @{$msg_hash->{'target'}}[0];
- my $macaddress = @{$msg_hash->{'macaddress'}}[0];
-
- # test whether content is an empty hash or a string which is required
- my $content = @{$msg_hash->{$header}}[0];
- eval{
- if( 0 == keys(%$content) ) {
- $content = "";
- }
- };
- if( $@ ) {
- $content = " $content";
- }
-
- $header =~ s/CLMSG_//g;
- my $out_msg = sprintf("<xml> ".
- "<header>gosa_update_status_jobdb_entry</header> ".
- "<source>%s</source> ".
- "<target>%s</target>".
- "<where> ".
- "<clause> ".
- "<phrase> ".
- "<status>processing</status> ".
- "<macaddress>%s</macaddress> ".
- "</phrase> ".
- "</clause> ".
- "</where> ".
- "<update> ".
- "<result>%s</result> ".
- "</update> ".
- "</xml>", $source, "JOBDB", $macaddress, $header.$content);
- return $out_msg;
+ return;
}
index a0c8853218032a688a9cb8f013c856c03ab406e4..973d2b603a2cbbdc2fc11c19ac6912ba8db3cddb 100644 (file)
$msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
push(@out_msg_l, $msg);
- change_goto_state('locked', \@{$msg_hash->{target}});
- change_fai_state('localboot', \@{$msg_hash->{target}});
+ &main::change_goto_state('locked', \@{$msg_hash->{target}});
+ &main::change_fai_state('localboot', \@{$msg_hash->{target}});
# delete all jobs from jobqueue which correspond to fai
my $sql_statement = "DELETE FROM $main::job_queue_tn WHERE (macaddress='$macaddress' AND ".
my $macaddress = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
- change_goto_state('locked', \@{$msg_hash->{target}});
+ &main::change_goto_state('locked', \@{$msg_hash->{target}});
my @out_msg_l;
return @out_msg_l;
my $macaddress = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
- change_goto_state('active', \@{$msg_hash->{target}});
+ &main::change_goto_state('active', \@{$msg_hash->{target}});
my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $macaddress);
if( exists $msg_hash->{'jobdb_id'} ) {
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
- change_fai_state('localboot', \@{$msg_hash->{target}});
+ &main::change_fai_state('localboot', \@{$msg_hash->{target}});
my @out_msg_l = ($msg);
return @out_msg_l;
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
- change_fai_state('halt', \@{$msg_hash->{target}});
+ &main::change_fai_state('halt', \@{$msg_hash->{target}});
my @out_msg_l = ($msg);
return @out_msg_l;
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
- change_fai_state('reboot', \@{$msg_hash->{target}});
+ &main::change_fai_state('reboot', \@{$msg_hash->{target}});
my @out_msg_l = ($msg);
return @out_msg_l;
my ($msg, $msg_hash) = @_ ;
$msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
- change_fai_state('memcheck', \@{$msg_hash->{target}});
+ &main::change_fai_state('memcheck', \@{$msg_hash->{target}});
my @out_msg_l = ($msg);
return @out_msg_l;
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
- change_fai_state('reinstall', \@{$msg_hash->{target}});
+ &main::change_fai_state('reinstall', \@{$msg_hash->{target}});
my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
- change_fai_state('update', \@{$msg_hash->{target}});
+ &main::change_fai_state('update', \@{$msg_hash->{target}});
my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
- change_fai_state('update', \@{$msg_hash->{target}});
+ &main::change_fai_state('update', \@{$msg_hash->{target}});
my %data = ( 'macAddress' => \@{$msg_hash->{target}} );
my $wake_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
my ($msg, $msg_hash) = @_;
$msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
- change_fai_state('sysinfo', \@{$msg_hash->{target}});
+ &main::change_fai_state('sysinfo', \@{$msg_hash->{target}});
my @out_msg_l = ($msg);
return @out_msg_l;
}
-sub change_fai_state {
- my ($st, $targets) = @_;
-
- # Set FAI state to localboot
- my %mapActions= (
- reboot => '',
- update => 'softupdate',
- localboot => 'localboot',
- reinstall => 'install',
- rescan => '',
- wake => '',
- memcheck => 'memcheck',
- sysinfo => 'sysinfo',
- );
-
- # Return if this is unknown
- if (!exists $mapActions{ $st }){
- return;
- }
-
- my $state= $mapActions{ $st };
-
- &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', '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;