d6efde3b8345173aa241b1f8e7a683a177d53a25
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;
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 }
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 print STDERR "jetzt würde ich trigger_action_reboot ausführen\n";
83 return;
84 }
87 sub trigger_action_halt {
88 my ($msg, $msg_hash) = @_;
89 my $timeout;
91 if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
92 $timeout = -1;
93 }
94 else {
95 $timeout = @{$msg_hash->{timeout}}[0];
96 }
98 # check logged in user
99 my $logged_in_user = 1;
100 if( $logged_in_user ) {
101 # TODO do something
102 }
103 else {
104 $timeout = 0;
105 }
107 # execute function
108 if( $timeout == 0 ) {
109 print STDERR ("shutdown -h +$timeout\n");
110 }
111 elsif( $timeout > 0 ) {
112 print STDERR ("shutdown -h +$timeout\n");
113 }
114 elsif( $timeout < 0 ) {
115 print STDERR "The administrator has sent a signal to shutdown this workstation. It will shutdown after you've logged out.\n";
116 open(FILE, "> /etc/gosa-si/event");
117 print FILE "trigger_action_halt\n";
118 close(FILE);
119 }
120 else {
121 # TODO do something, error handling, logging
122 }
124 return;
125 }
128 # TODO
129 sub trigger_action_memcheck {
130 my ($msg, $msg_hash) = @_ ;
131 print STDERR "\n\njetzt würde ich trigger_action_memcheck ausführen\n\n";
132 return;
133 }
136 sub trigger_action_reinstall {
137 my ($msg, $msg_hash) = @_;
138 my $timeout;
140 # check timeout
141 if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
142 $timeout = -1;
143 }
144 else {
145 $timeout = @{$msg_hash->{timeout}}[0];
146 }
148 # check logged in user
149 my $logged_in_user = 1;
150 if( $logged_in_user ) {
151 # TODO do something
152 }
153 else {
154 $timeout = 0;
155 }
157 # execute function
158 if( $timeout == 0 ) {
159 print STDERR ("shutdown -r +$timeout\n");
160 }
161 elsif( $timeout > 0 ) {
162 print STDERR ("shutdown -r +$timeout\n");
164 }
165 elsif( $timeout < 0 ) {
166 print STDERR "The administrator has sent a signal to reinstall this workstation. It will reinstall after you've logged out.\n";
167 open(FILE, "> /etc/gosa-si/event");
168 print FILE "trigger_action_reinstall\n";
169 close(FILE);
170 }
171 else {
172 # TODO do something, error handling, logging
173 }
175 return;
176 }
179 sub trigger_action_update {
180 my ($msg, $msg_hash) = @_;
182 # execute function
183 open(FILE, "> /etc/gosa-si/event");
184 print FILE "trigger_action_reinstall\n";
185 close(FILE);
187 # check logged in user
188 my $logged_in_user = 1;
189 if( $logged_in_user ) {
190 print STDERR "This system has been sent a signal for an update. The update will take place after you log out.\n";
191 }
192 else {
193 # not jet
194 #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
195 }
197 return;
198 }
201 sub trigger_action_instant_update {
202 my ($msg, $msg_hash) = @_;
204 # check logged in user
205 my $logged_in_user = 1;
206 if( $logged_in_user ) {
207 print STDERR "This system has been sent a signal for an update. The update will take place now.\n";
208 }
210 # not jet
211 #system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai -N softupdate &" )
213 return;
214 }
217 # TODO
218 sub trigger_action_sysinfo {
219 my ($msg, $msg_hash) = @_;
220 print STDERR "jetzt würde ich trigger_action_sysinfo ausführen\n";
221 return;
222 }
224 # TODO
225 sub trigger_action_rescan{
226 my ($msg, $msg_hash) = @_;
227 print STDERR "jetzt würde ich trigger_action_rescan ausführen\n";
228 return;
229 }
231 1;