Code

msgPool
[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     "trigger_action_localboot",
7     "trigger_action_halt",
8     "trigger_action_faireboot",
9     "trigger_action_reboot",
10     "trigger_action_memcheck",
11     "trigger_action_reinstall",
12     "trigger_action_update",
13     "trigger_action_instant_update",
14     "trigger_action_sysinfo",
15     "trigger_action_rescan",
16     );
17 @EXPORT = @events;
19 use strict;
20 use warnings;
21 use GOSA::GosaSupportDaemon;
23 BEGIN {}
25 END {}
28 sub get_events { return \@events; }
31 sub trigger_action_localboot {
32     my ($msg, $msg_hash) = @_;
33     my $timeout;
35     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
36         $timeout = -1;
37     } 
38     else {
39         $timeout = @{$msg_hash->{timeout}}[0];
40     }
42     # check logged in user
43     my $logged_in_user = 1;
44     if( $logged_in_user ) {
45         # TODO do something
46     }
47     else {
48         $timeout = 0;
49     }
50         
51     # execute function
52     if( $timeout == 0 ) {
53         print STDERR ("shutdown -r +$timeout\n");
54     }
55     elsif( $timeout > 0 ) {
56         print STDERR ("shutdown -r +$timeout\n");
57     }
58     elsif( $timeout < 0 ) {
59         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
60         open(FILE, "> /etc/gosa-si/event");
61         print FILE "trigger_action_localboot\n";
62         close(FILE);
63     }
64     else {
65         # TODO do something, error handling, logging
66     }
68     return;
69 }
72 sub trigger_action_faireboot {
73     my ($msg, $msg_hash) = @_;
74     system("/usr/sbin/faireboot");
75     return;
76 }
79 sub trigger_action_reboot {
80     my ($msg, $msg_hash) = @_;
81     my $timeout;
83     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
84         $timeout = -1;
85     } 
86     else {
87         $timeout = @{$msg_hash->{timeout}}[0];
88     }
90     # check logged in user
91     my @user_list = &get_logged_in_users;
92     if( @user_list >= 1 ) {
93         # TODO do something
94     }
95     else {
96         $timeout = 0;
97     }
98         
99     # execute function
100     if( $timeout == 0 ) {
101         print STDERR ("shutdown -r +$timeout\n");
102     }
103     elsif( $timeout > 0 ) {
104         print STDERR ("shutdown -r +$timeout\n");
105     }
106     elsif( $timeout < 0 ) {
107         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
108         open(FILE, "> /etc/gosa-si/event");
109         print FILE "trigger_action_reboot\n";
110         close(FILE);
111     }
112     else {
113         # TODO do something, error handling, logging
114     }
116     return;
118     
121     print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
122     return;
126 sub trigger_action_halt {
127     my ($msg, $msg_hash) = @_;
128     my $timeout;
130     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
131         $timeout = -1;
132     } 
133     else {
134         $timeout = @{$msg_hash->{timeout}}[0];
135     }
137     # check logged in user
138     my $logged_in_user = 1;
139     if( $logged_in_user ) {
140         # TODO do something
141     }
142     else {
143         $timeout = 0;
144     }
146     # execute function
147     if( $timeout == 0 ) {
148         print STDERR ("shutdown -h +$timeout\n");
149     }
150     elsif( $timeout > 0 ) {
151         print STDERR ("shutdown -h +$timeout\n");
152     }
153     elsif( $timeout < 0 ) {
154         print STDERR "The administrator has sent a signal to shutdown this workstation. It will shutdown after you've logged out.\n";
155         open(FILE, "> /etc/gosa-si/event");
156         print FILE "trigger_action_halt\n";
157         close(FILE);
158     }
159     else {
160         # TODO do something, error handling, logging
161     }
163     return;
167 # TODO
168 sub trigger_action_memcheck {
169     my ($msg, $msg_hash) = @_ ;
170     print STDERR "\n\njetzt würde ich trigger_action_memcheck ausführen\n\n";
171     return;
175 sub trigger_action_reinstall {
176     my ($msg, $msg_hash) = @_;
177     my $timeout;
179     # check timeout
180     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
181         $timeout = -1;
182     }
183     else {
184         $timeout = @{$msg_hash->{timeout}}[0];
185     }
187     # check logged in user
188     my $logged_in_user = 1;
189     if( $logged_in_user ) {
190         # TODO do something
191     }
192     else {
193         $timeout = 0;
194     }
196     # execute function
197     if( $timeout == 0 ) {
198         print STDERR ("shutdown -r +$timeout\n");
199     }
200     elsif( $timeout > 0 ) {
201         print STDERR ("shutdown -r +$timeout\n");
203     }
204     elsif( $timeout < 0 ) {
205         print STDERR "The administrator has sent a signal to reinstall this workstation. It will reinstall after you've logged out.\n";
206         open(FILE, "> /etc/gosa-si/event");
207         print FILE "trigger_action_reinstall\n";
208         close(FILE);
209     }
210     else {
211         # TODO do something, error handling, logging
212     }
214     return;
218 sub trigger_action_update {
219     my ($msg, $msg_hash) = @_;
221     # execute function
222     open(FILE, "> /etc/gosa-si/event");
223     print FILE "trigger_action_reinstall\n";
224     close(FILE);
226     # check logged in user
227     my $logged_in_user = 1;
228     if( $logged_in_user ) {
229         print STDERR "This system has been sent a signal for an update. The update will take place after you log out.\n";
230     }
231     else {
232         # not jet
233         #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
234     }
236     return;
240 sub trigger_action_instant_update {
241     my ($msg, $msg_hash) = @_;
243     # check logged in user
244     my $logged_in_user = 1;
245     if( $logged_in_user ) {
246         print STDERR "This system has been sent a signal for an update. The update will take place now.\n";
247                 if(stat('/usr/bin/fai-softupdate-notify')) {
248                         system('/usr/bin/fai-softupdate-notify start');
249                 }
250     }
252     # not jet
253     #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
255     return;
259 # TODO
260 sub trigger_action_sysinfo {
261     my ($msg, $msg_hash) = @_;
262     print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n";
263     return;
266 # TODO
267 sub trigger_action_rescan{
268     my ($msg, $msg_hash) = @_;
269     print STDERR "jetzt würde ich trigger_action_rescan ausführen\n";
270     return;
273 1;