Code

Implemented usr_msg.
[gosa.git] / gosa-si / client / events / gosaTriggered.pm
1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5     "get_events",
6     "usr_msg",
7     "trigger_action_localboot",
8     "trigger_action_halt",
9     "trigger_action_faireboot",
10     "trigger_action_reboot",
11     "trigger_action_memcheck",
12     "trigger_action_reinstall",
13     "trigger_action_update",
14     "trigger_action_instant_update",
15     "trigger_action_sysinfo",
16     );
17 @EXPORT = @events;
19 use strict;
20 use warnings;
21 use GOSA::GosaSupportDaemon;
22 use Data::Dumper;
23 use MIME::Base64;
25 BEGIN {}
27 END {}
30 sub get_events { return \@events; }
32 sub usr_msg {
33     my ($msg, $msg_hash) = @_;
36     my $to = @{$msg_hash->{'usr'}}[0];
37     my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
38     my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
39     system( "/usr/bin/goto-notify user-message '$to' '$subject' '$message'" );
41     # give gosa-si-server feedback, that msg was received
42     $msg =~ s/<header>usr_msg<\/header>/<header>confirm_usr_msg<\/header>/g;
43     return $msg;
44 }
47 sub trigger_action_localboot {
48     my ($msg, $msg_hash) = @_;
49     my $timeout;
51     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
52         $timeout = -1;
53     } 
54     else {
55         $timeout = @{$msg_hash->{timeout}}[0];
56     }
58     # check logged in user
59     my $logged_in_user = 1;
60     if( $logged_in_user ) {
61         # TODO do something
62     }
63     else {
64         $timeout = 0;
65     }
66         
67     # execute function
68     if( $timeout == 0 ) {
69         print STDERR ("shutdown -r +$timeout\n");
70     }
71     elsif( $timeout > 0 ) {
72         print STDERR ("shutdown -r +$timeout\n");
73     }
74     elsif( $timeout < 0 ) {
75         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
76         open(FILE, "> /etc/gosa-si/event");
77         print FILE "trigger_action_localboot\n";
78         close(FILE);
79     }
80     else {
81         # TODO do something, error handling, logging
82     }
84     return;
85 }
88 sub trigger_action_faireboot {
89     my ($msg, $msg_hash) = @_;
90         &main::daemon_log("DEBUG: run /usr/sbin/faireboot\n", 7); 
91     system("/usr/sbin/faireboot");
92     return;
93 }
96 sub trigger_action_reboot {
97     my ($msg, $msg_hash) = @_;
98     my $timeout;
100     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
101         $timeout = 0;
102     } 
103     else {
104         $timeout = @{$msg_hash->{timeout}}[0];
105     }
107     # check logged in user
108     my @user_list = &get_logged_in_users;
109     if( @user_list >= 1 ) {
110         system( "/usr/bin/goto-notify reboot" );
111         open(FILE, "> /etc/gosa-si/event");
112         print FILE "reboot\n";
113         close(FILE);
114     }
115     else {
116         system( "/sbin/shutdown -r +$timeout &" );
117     }
119     return;
123 sub trigger_action_halt {
124     my ($msg, $msg_hash) = @_;
125     my $timeout;
127     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
128         $timeout = 0;
129     } 
130     else {
131         $timeout = @{$msg_hash->{timeout}}[0];
132     }
134     # check logged in user
135     my @user_list = &get_logged_in_users;
136     if( @user_list >= 1 ) {
137         system( "/usr/bin/goto-notify halt" );
138         open(FILE, "> /etc/gosa-si/event");
139         print FILE "halt\n";
140         close(FILE);
141     }
142     else {
143         system( "/sbin/shutdown -h +$timeout &" );
144     }
146     return;
150 sub trigger_action_reinstall {
151     my ($msg, $msg_hash) = @_;
153     # check logged in user
154     my @user_list = &get_logged_in_users;
155     if( @user_list >= 1 ) {
156         system( "/usr/bin/goto-notify install" );
157         open(FILE, "> /etc/gosa-si/event");
158         print FILE "install\n";
159         close(FILE);
160     }
161     else {
162         system( "/sbin/shutdown -r now &" );
163     }
165     return;
169 # Backward compatibility
170 sub trigger_action_update {
171     my ($msg, $msg_hash) = @_;
173     # Execute update
174     system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
176     return;
179 # Backward compatibility
180 sub trigger_action_instant_update {
181     my ($msg, $msg_hash) = @_;
183     # Execute update
184     system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
186     return;
190 1;