Code

new function for GOsa, trigger_action_faireboot
[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;
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     print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
82     return;
83 }
86 sub trigger_action_halt {
87     my ($msg, $msg_hash) = @_;
88     my $timeout;
90     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
91         $timeout = -1;
92     } 
93     else {
94         $timeout = @{$msg_hash->{timeout}}[0];
95     }
97     # check logged in user
98     my $logged_in_user = 1;
99     if( $logged_in_user ) {
100         # TODO do something
101     }
102     else {
103         $timeout = 0;
104     }
106     # execute function
107     if( $timeout == 0 ) {
108         print STDERR ("shutdown -h +$timeout\n");
109     }
110     elsif( $timeout > 0 ) {
111         print STDERR ("shutdown -h +$timeout\n");
112     }
113     elsif( $timeout < 0 ) {
114         print STDERR "The administrator has sent a signal to shutdown this workstation. It will shutdown after you've logged out.\n";
115         open(FILE, "> /etc/gosa-si/event");
116         print FILE "trigger_action_halt\n";
117         close(FILE);
118     }
119     else {
120         # TODO do something, error handling, logging
121     }
123     return;
127 # TODO
128 sub trigger_action_memcheck {
129     my ($msg, $msg_hash) = @_ ;
130     print STDERR "\n\njetzt würde ich trigger_action_memcheck ausführen\n\n";
131     return;
135 sub trigger_action_reinstall {
136     my ($msg, $msg_hash) = @_;
137     my $timeout;
139     # check timeout
140     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
141         $timeout = -1;
142     }
143     else {
144         $timeout = @{$msg_hash->{timeout}}[0];
145     }
147     # check logged in user
148     my $logged_in_user = 1;
149     if( $logged_in_user ) {
150         # TODO do something
151     }
152     else {
153         $timeout = 0;
154     }
156     # execute function
157     if( $timeout == 0 ) {
158         print STDERR ("shutdown -r +$timeout\n");
159     }
160     elsif( $timeout > 0 ) {
161         print STDERR ("shutdown -r +$timeout\n");
163     }
164     elsif( $timeout < 0 ) {
165         print STDERR "The administrator has sent a signal to reinstall this workstation. It will reinstall after you've logged out.\n";
166         open(FILE, "> /etc/gosa-si/event");
167         print FILE "trigger_action_reinstall\n";
168         close(FILE);
169     }
170     else {
171         # TODO do something, error handling, logging
172     }
174     return;
178 sub trigger_action_update {
179     my ($msg, $msg_hash) = @_;
181     # execute function
182     open(FILE, "> /etc/gosa-si/event");
183     print FILE "trigger_action_reinstall\n";
184     close(FILE);
186     # check logged in user
187     my $logged_in_user = 1;
188     if( $logged_in_user ) {
189         print STDERR "This system has been sent a signal for an update. The update will take place after you log out.\n";
190     }
191     else {
192         # not jet
193         #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
194     }
196     return;
200 sub trigger_action_instant_update {
201     my ($msg, $msg_hash) = @_;
203     # check logged in user
204     my $logged_in_user = 1;
205     if( $logged_in_user ) {
206         print STDERR "This system has been sent a signal for an update. The update will take place now.\n";
207     }
209     # not jet
210     #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
212     return;
216 # TODO
217 sub trigger_action_sysinfo {
218     my ($msg, $msg_hash) = @_;
219     print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n";
220     return;
223 # TODO
224 sub trigger_action_rescan{
225     my ($msg, $msg_hash) = @_;
226     print STDERR "jetzt würde ich trigger_action_rescan ausführen\n";
227     return;
230 1;