Code

Updated locales
[gosa.git] / gosa-si / client / events / gosaTriggered.pm
index 71da3267a4ba50a0ef7efb1dc33b5dd33170a89b..4a304eb9304d70b99dacfe85499e0cc500b97b43 100644 (file)
@@ -7,8 +7,6 @@ gosaTriggered.pm
 
 use GOSA::GosaSupportDaemon;
 
-use Data::Dumper;
-
 use MIME::Base64
 
 =head1 DESCRIPTION
@@ -27,10 +25,19 @@ Andreas Rettenberger <rettenberger at gonicus dot de>
 
 =cut
 
-
 package gosaTriggered;
+
+use strict;
+use warnings;
+
+use MIME::Base64;
+use File::Temp qw/ tempfile/;
+use GOsaSI::GosaSupportDaemon;
+
 use Exporter;
-@ISA = qw(Exporter);
+
+our @ISA = qw(Exporter);
+
 my @events = (
     "get_events",
     "usr_msg",
@@ -43,18 +50,24 @@ my @events = (
     "trigger_action_instant_update",
     "trigger_goto_settings_reload",
     );
-@EXPORT = @events;
-
-use strict;
-use warnings;
-use GOSA::GosaSupportDaemon;
-use Data::Dumper;
-use MIME::Base64;
+    
+our @EXPORT = @events;
 
 BEGIN {}
 
 END {}
 
+### Parameter declarations ###################################################
+my $userNotification;
+my %cfg_defaults = (
+"client" => {
+       "user-notification-of-admin-activities" => [\$userNotification, 'true'],
+       },
+);
+
+# Read config file
+&read_configfile($main::cfg_file, %cfg_defaults);
+
 ###############################################################################
 =over 
 
@@ -125,17 +138,13 @@ sub usr_msg {
     my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
     my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
 
-    system( "/usr/bin/goto-notify user-message '$to' '$subject' '$message'" );
-
-    # give gosa-si-server feedback, that msg was received
-    $msg =~ s/<header>usr_msg<\/header>/<header>confirm_usr_msg<\/header>/g;
-    my $out_hash = &create_xml_hash("confirm_usr_msg", $target, $source);
-    &add_content2xml_hash($out_hash, 'usr', $to);
-    &add_content2xml_hash($out_hash, 'subject', @{$msg_hash->{'subject'}}[0]);
-    &add_content2xml_hash($out_hash, 'message', @{$msg_hash->{'message'}}[0]);
+    my ($rand_fh, $rand_file) = tempfile( SUFFIX => '.goto_notify');
+    print $rand_fh "source:$source\ntarget:$target\nusr:$to\nsubject:".@{$msg_hash->{'subject'}}[0]."\nmessage:".@{$msg_hash->{'message'}}[0]."\n";
+    close $rand_fh;
+       
+    my $feedback = system("/usr/bin/goto-notify user-message '$to' '$subject' '$message' '$rand_file' &" );
 
-
-    return &create_xml_string($out_hash);
+    return
 }
 
 
@@ -174,37 +183,25 @@ sub trigger_action_localboot {
     my ($msg, $msg_hash) = @_;
     my $timeout;
 
+       # Invalid timeout parameter are set to 0
     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
         $timeout = -1;
-    } 
-    else {
+    } else {
         $timeout = @{$msg_hash->{timeout}}[0];
     }
 
-    # check logged in user
-    my $logged_in_user = 1;
-    if( $logged_in_user ) {
-        # TODO do something
-    }
+       # Check if user should be notificated or not
+       if ($userNotification eq "true") {
+               # Check logged in user
+               my @user_list = &get_logged_in_users;
+               if( @user_list >= 1 ) {
+                       open(my $FILE, ">", "/etc/gosa-si/event");
+                       print $FILE "trigger_action_localboot\n";
+                       close($FILE);
+               }
+       }
     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_localboot\n";
-        close(FILE);
-    }
-    else {
-        # TODO do something, error handling, logging
+       system( "/sbin/shutdown -r +$timeout &" );
     }
 
     return;
@@ -284,6 +281,7 @@ sub trigger_action_reboot {
     my ($msg, $msg_hash) = @_;
     my $timeout;
 
+       # Invalid timeout parameter are set to 0
     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
         $timeout = 0;
     } 
@@ -291,14 +289,17 @@ sub trigger_action_reboot {
         $timeout = @{$msg_hash->{timeout}}[0];
     }
 
-    # check logged in user
-    my @user_list = &get_logged_in_users;
-    if( @user_list >= 1 ) {
-       system( "/usr/bin/goto-notify reboot" );
-        open(FILE, "> /etc/gosa-si/event");
-        print FILE "reboot\n";
-        close(FILE);
-    }
+       # Check if user should be notificated or not
+       if ($userNotification eq "true") {
+               # Check logged in user
+               my @user_list = &get_logged_in_users;
+               if( @user_list >= 1 ) {
+                       system( "/usr/bin/goto-notify reboot" );
+                       open(my $FILE, ">", "/etc/gosa-si/event");
+                       print $FILE "reboot\n";
+                       close($FILE);
+               }
+       }
     else {
        system( "/sbin/shutdown -r +$timeout &" );
     }
@@ -342,6 +343,7 @@ sub trigger_action_halt {
     my ($msg, $msg_hash) = @_;
     my $timeout;
 
+       # Invalid timeout parameter are set to 0
     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
         $timeout = 0;
     } 
@@ -349,15 +351,17 @@ sub trigger_action_halt {
         $timeout = @{$msg_hash->{timeout}}[0];
     }
 
-    # check logged in user
-    my @user_list = &get_logged_in_users;
-    if( @user_list >= 1 ) {
-       system( "/usr/bin/goto-notify halt" );
-        open(FILE, "> /etc/gosa-si/event");
-        print FILE "halt\n";
-        close(FILE);
-    }
-    else {
+       # Check if user should be notificated or not
+       if ($userNotification eq "true") {
+               # Check logged in user
+               my @user_list = &get_logged_in_users;
+               if( @user_list >= 1 ) {
+                       system( "/usr/bin/goto-notify halt" );
+                       open(my $FILE, ">", "/etc/gosa-si/event");
+                       print $FILE "halt\n";
+                       close($FILE);
+               }
+    } else {
        system( "/sbin/shutdown -h +$timeout &" );
     }
 
@@ -399,17 +403,19 @@ sub trigger_action_halt {
 sub trigger_action_reinstall {
     my ($msg, $msg_hash) = @_;
 
-    # check logged in user
-    my @user_list = &get_logged_in_users;
-    if( @user_list >= 1 ) {
-       system( "/usr/bin/goto-notify install" );
-        open(FILE, "> /etc/gosa-si/event");
-        print FILE "install\n";
-        close(FILE);
-    }
-    else {
-       system( "/sbin/shutdown -r now &" );
-    }
+       # Check if user should be notificated or not
+       if ($userNotification eq "true") {
+               # Check logged in user
+               my @user_list = &get_logged_in_users;
+               if( @user_list >= 1 ) {
+                       system( "/usr/bin/goto-notify install" );
+                       open(my $FILE, ">", "/etc/gosa-si/event");
+                       print $FILE "install\n";
+                       close($FILE);
+               }
+       } else {
+               system( "/sbin/shutdown -r now &" );
+       }
 
     return;
 }
@@ -500,7 +506,7 @@ sub trigger_goto_settings_reload {
     my ($msg, $msg_hash) = @_;
 
     # Execute goto settings reload
-    my $cmd = "/etc/init.d/goto-configure";
+    my $cmd = "/etc/init.d/goto-agents";
     my $pram = "start";
     if (-f $cmd){
         my $feedback = system("$cmd $pram") or &main::daemon_log("ERROR: $@");