From a9fd1f1fa94d9aa30be176ba52ed0ae5ec6964fe Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 16 Sep 2009 12:49:26 +0000 Subject: [PATCH] user notification about admin activities can be switched on an off git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14258 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/client/events/gosaTriggered.pm | 114 +++++++++++++------------ 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/gosa-si/client/events/gosaTriggered.pm b/gosa-si/client/events/gosaTriggered.pm index 575a5663a..93ddbed27 100644 --- a/gosa-si/client/events/gosaTriggered.pm +++ b/gosa-si/client/events/gosaTriggered.pm @@ -53,6 +53,17 @@ BEGIN {} END {} +### Parameter declarations ################################################### +my $userNotification; +my %cfg_defaults = ( +"ClientPackages" => { + "user-notification-of-admin-activities" => [\$userNotification, 'enabled'], + }, +); + +# Read config file +&read_configfile($main::cfg_file, %cfg_defaults); + ############################################################################### =over @@ -168,37 +179,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 - } - 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); - } + # Check if user should be notificated or not + if ($userNotification eq "enabled") { + # Check logged in user + my @user_list = &get_logged_in_users; + if( @user_list >= 1 ) { + 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; @@ -278,6 +277,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; } @@ -285,14 +285,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 "enabled") { + # 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); + } + } else { system( "/sbin/shutdown -r +$timeout &" ); } @@ -336,6 +339,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; } @@ -343,15 +347,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 "enabled") { + # 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 { system( "/sbin/shutdown -h +$timeout &" ); } @@ -393,17 +399,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 "enabled") { + # 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 &" ); + } return; } -- 2.30.2