Code

change procedure keeping jobqueue up-to-date, closes #359
[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 utf8;
22 use GOSA::GosaSupportDaemon;
24 BEGIN {}
26 END {}
29 sub get_events { return \@events; }
32 sub trigger_action_localboot {
33     my ($msg, $msg_hash) = @_;
34     my $timeout;
36     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
37         $timeout = -1;
38     } 
39     else {
40         $timeout = @{$msg_hash->{timeout}}[0];
41     }
43     # check logged in user
44     my $logged_in_user = 1;
45     if( $logged_in_user ) {
46         # TODO do something
47     }
48     else {
49         $timeout = 0;
50     }
51         
52     # execute function
53     if( $timeout == 0 ) {
54         print STDERR ("shutdown -r +$timeout\n");
55     }
56     elsif( $timeout > 0 ) {
57         print STDERR ("shutdown -r +$timeout\n");
58     }
59     elsif( $timeout < 0 ) {
60         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
61         open(FILE, "> /etc/gosa-si/event");
62         print FILE "trigger_action_localboot\n";
63         close(FILE);
64     }
65     else {
66         # TODO do something, error handling, logging
67     }
69     return;
70 }
73 sub trigger_action_faireboot {
74     my ($msg, $msg_hash) = @_;
75     system("/usr/sbin/faireboot");
76     return;
77 }
80 sub trigger_action_reboot {
81     my ($msg, $msg_hash) = @_;
82     my $timeout;
84     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
85         $timeout = -1;
86     } 
87     else {
88         $timeout = @{$msg_hash->{timeout}}[0];
89     }
91     # check logged in user
92     my @user_list = &get_logged_in_users;
93     if( @user_list >= 1 ) {
94         # TODO do something
95     }
96     else {
97         $timeout = 0;
98     }
99         
100     # execute function
101     if( $timeout == 0 ) {
102         print STDERR ("shutdown -r +$timeout\n");
103     }
104     elsif( $timeout > 0 ) {
105         print STDERR ("shutdown -r +$timeout\n");
106     }
107     elsif( $timeout < 0 ) {
108         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
109         open(FILE, "> /etc/gosa-si/event");
110         print FILE "trigger_action_reboot\n";
111         close(FILE);
112     }
113     else {
114         # TODO do something, error handling, logging
115     }
117     return;
119     
122     print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
123     return;
127 sub trigger_action_halt {
128     my ($msg, $msg_hash) = @_;
129     my $timeout;
131     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
132         $timeout = -1;
133     } 
134     else {
135         $timeout = @{$msg_hash->{timeout}}[0];
136     }
138     # check logged in user
139     my $logged_in_user = 1;
140     if( $logged_in_user ) {
141         # TODO do something
142     }
143     else {
144         $timeout = 0;
145     }
147     # execute function
148     if( $timeout == 0 ) {
149         print STDERR ("shutdown -h +$timeout\n");
150     }
151     elsif( $timeout > 0 ) {
152         print STDERR ("shutdown -h +$timeout\n");
153     }
154     elsif( $timeout < 0 ) {
155         print STDERR "The administrator has sent a signal to shutdown this workstation. It will shutdown after you've logged out.\n";
156         open(FILE, "> /etc/gosa-si/event");
157         print FILE "trigger_action_halt\n";
158         close(FILE);
159     }
160     else {
161         # TODO do something, error handling, logging
162     }
164     return;
168 # TODO
169 sub trigger_action_memcheck {
170     my ($msg, $msg_hash) = @_ ;
171     print STDERR "\n\njetzt würde ich trigger_action_memcheck ausführen\n\n";
172     return;
176 sub trigger_action_reinstall {
177     my ($msg, $msg_hash) = @_;
178     my $timeout;
180     # check timeout
181     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
182         $timeout = -1;
183     }
184     else {
185         $timeout = @{$msg_hash->{timeout}}[0];
186     }
188     # check logged in user
189     my $logged_in_user = 1;
190     if( $logged_in_user ) {
191         # TODO do something
192     }
193     else {
194         $timeout = 0;
195     }
197     # execute function
198     if( $timeout == 0 ) {
199         print STDERR ("shutdown -r +$timeout\n");
200     }
201     elsif( $timeout > 0 ) {
202         print STDERR ("shutdown -r +$timeout\n");
204     }
205     elsif( $timeout < 0 ) {
206         print STDERR "The administrator has sent a signal to reinstall this workstation. It will reinstall after you've logged out.\n";
207         open(FILE, "> /etc/gosa-si/event");
208         print FILE "trigger_action_reinstall\n";
209         close(FILE);
210     }
211     else {
212         # TODO do something, error handling, logging
213     }
215     return;
219 sub trigger_action_update {
220     my ($msg, $msg_hash) = @_;
222     # execute function
223     open(FILE, "> /etc/gosa-si/event");
224     print FILE "trigger_action_reinstall\n";
225     close(FILE);
227     # check logged in user
228     my $logged_in_user = 1;
229     if( $logged_in_user ) {
230         print STDERR "This system has been sent a signal for an update. The update will take place after you log out.\n";
231     }
232     else {
233         # not jet
234         #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
235     }
237     return;
241 sub trigger_action_instant_update {
242     my ($msg, $msg_hash) = @_;
244     # check logged in user
245     my $logged_in_user = 1;
246     if( $logged_in_user ) {
247         print STDERR "This system has been sent a signal for an update. The update will take place now.\n";
248     }
250     # not jet
251     #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
253     return;
257 # TODO
258 sub trigger_action_sysinfo {
259     my ($msg, $msg_hash) = @_;
260     print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n";
261     return;
264 # TODO
265 sub trigger_action_rescan{
266     my ($msg, $msg_hash) = @_;
267     print STDERR "jetzt würde ich trigger_action_rescan ausführen\n";
268     return;
271 1;