Code

Removed DEBUG output.
[gosa.git] / gosa-si / client / events / gosaTriggered.pm
index 1d70194a9d5a999c092380cd9b8e988ad860455a..9e57a5460aa794d0f90c5d514ef5ae6a21b236b5 100644 (file)
@@ -18,7 +18,7 @@ my @events = (
 
 use strict;
 use warnings;
-
+use GOSA::GosaSupportDaemon;
 
 BEGIN {}
 
@@ -77,154 +77,97 @@ sub trigger_action_faireboot {
 
 
 sub trigger_action_reboot {
-    my ($msg, $msg_hash) = @_;
-    print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
-    return;
-}
-
-
-sub trigger_action_halt {
     my ($msg, $msg_hash) = @_;
     my $timeout;
 
     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
-        $timeout = -1;
+        $timeout = 0;
     } 
     else {
         $timeout = @{$msg_hash->{timeout}}[0];
     }
 
     # check logged in user
-    my $logged_in_user = 1;
-    if( $logged_in_user ) {
-        # TODO do something
-    }
-    else {
-        $timeout = 0;
-    }
-
-    # execute function
-    if( $timeout == 0 ) {
-        print STDERR ("shutdown -h +$timeout\n");
-    }
-    elsif( $timeout > 0 ) {
-        print STDERR ("shutdown -h +$timeout\n");
-    }
-    elsif( $timeout < 0 ) {
-        print STDERR "The administrator has sent a signal to shutdown this workstation. It will shutdown after you've logged out.\n";
+    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 "trigger_action_halt\n";
+        print FILE "reboot\n";
         close(FILE);
     }
     else {
-        # TODO do something, error handling, logging
+       system( "/sbin/shutdown -r +$timeout &" );
     }
 
     return;
 }
 
 
-# TODO
-sub trigger_action_memcheck {
-    my ($msg, $msg_hash) = @_ ;
-    print STDERR "\n\njetzt würde ich trigger_action_memcheck ausführen\n\n";
-    return;
-}
-
-
-sub trigger_action_reinstall {
+sub trigger_action_halt {
     my ($msg, $msg_hash) = @_;
     my $timeout;
 
-    # check timeout
     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
-        $timeout = -1;
-    }
+        $timeout = 0;
+    } 
     else {
         $timeout = @{$msg_hash->{timeout}}[0];
     }
 
     # check logged in user
-    my $logged_in_user = 1;
-    if( $logged_in_user ) {
-        # 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 reinstall this workstation. It will reinstall after you've logged out.\n";
+    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 "trigger_action_reinstall\n";
+        print FILE "halt\n";
         close(FILE);
     }
     else {
-        # TODO do something, error handling, logging
+       system( "/sbin/shutdown -h +$timeout &" );
     }
 
     return;
 }
 
 
-sub trigger_action_update {
+sub trigger_action_reinstall {
     my ($msg, $msg_hash) = @_;
 
-    # execute function
-    open(FILE, "> /etc/gosa-si/event");
-    print FILE "trigger_action_reinstall\n";
-    close(FILE);
-
     # check logged in user
-    my $logged_in_user = 1;
-    if( $logged_in_user ) {
-        print STDERR "This system has been sent a signal for an update. The update will take place after you log out.\n";
+    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 {
-        # not jet
-        #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
+       system( "/sbin/shutdown -r now &" );
     }
 
     return;
 }
 
 
-sub trigger_action_instant_update {
+# Backward compatibility
+sub trigger_action_update {
     my ($msg, $msg_hash) = @_;
 
-    # check logged in user
-    my $logged_in_user = 1;
-    if( $logged_in_user ) {
-        print STDERR "This system has been sent a signal for an update. The update will take place now.\n";
-    }
-
-    # not jet
-    #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
+    # Execute update
+    system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
 
     return;
 }
 
-
-# TODO
-sub trigger_action_sysinfo {
+# Backward compatibility
+sub trigger_action_instant_update {
     my ($msg, $msg_hash) = @_;
-    print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n";
-    return;
-}
 
-# TODO
-sub trigger_action_rescan{
-    my ($msg, $msg_hash) = @_;
-    print STDERR "jetzt würde ich trigger_action_rescan ausführen\n";
+    # Execute update
+    system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
+
     return;
 }
 
+
 1;