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 }
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 }
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;
121 print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
122 return;
123 }
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;
164 }
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;
172 }
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;
215 }
218 # Backward compatibility
219 sub trigger_action_update {
220 my ($msg, $msg_hash) = @_;
222 # Execute update
223 system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
225 return;
226 }
228 # Backward compatibility
229 sub trigger_action_instant_update {
230 my ($msg, $msg_hash) = @_;
232 # Execute update
233 system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
235 return;
236 }
239 # TODO
240 sub trigger_action_sysinfo {
241 my ($msg, $msg_hash) = @_;
242 print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n";
243 return;
244 }
246 # TODO
247 sub trigger_action_rescan{
248 my ($msg, $msg_hash) = @_;
249 print STDERR "jetzt würde ich trigger_action_rescan ausführen\n";
250 return;
251 }
253 1;