1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 "get_events",
6 "usr_msg",
7 "trigger_action_localboot",
8 "trigger_action_halt",
9 "trigger_action_faireboot",
10 "trigger_action_reboot",
11 "trigger_action_memcheck",
12 "trigger_action_reinstall",
13 "trigger_action_update",
14 "trigger_action_instant_update",
15 "trigger_action_sysinfo",
16 );
17 @EXPORT = @events;
19 use strict;
20 use warnings;
21 use GOSA::GosaSupportDaemon;
22 use Data::Dumper;
23 use MIME::Base64;
25 BEGIN {}
27 END {}
30 sub get_events { return \@events; }
32 sub usr_msg {
33 my ($msg, $msg_hash) = @_;
36 my $to = @{$msg_hash->{'usr'}}[0];
37 my $subject = &decode_base64(@{$msg_hash->{'subject'}}[0]);
38 my $message = &decode_base64(@{$msg_hash->{'message'}}[0]);
40 print STDERR "\n\n\n##############################\n";
41 print STDERR "message to: $to\n";
42 print STDERR "subject: $subject\n";
43 print STDERR "message: $message\n";
44 print STDERR "##############################\n\n\n";
45 # do, what ever you want
46 # konch
47 # kdialog
48 # ...
52 # give gosa-si-server feedback, that msg was received
53 $msg =~ s/<header>usr_msg<\/header>/<header>confirm_usr_msg<\/header>/g;
54 return $msg;
55 }
58 sub trigger_action_localboot {
59 my ($msg, $msg_hash) = @_;
60 my $timeout;
62 if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
63 $timeout = -1;
64 }
65 else {
66 $timeout = @{$msg_hash->{timeout}}[0];
67 }
69 # check logged in user
70 my $logged_in_user = 1;
71 if( $logged_in_user ) {
72 # TODO do something
73 }
74 else {
75 $timeout = 0;
76 }
78 # execute function
79 if( $timeout == 0 ) {
80 print STDERR ("shutdown -r +$timeout\n");
81 }
82 elsif( $timeout > 0 ) {
83 print STDERR ("shutdown -r +$timeout\n");
84 }
85 elsif( $timeout < 0 ) {
86 print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
87 open(FILE, "> /etc/gosa-si/event");
88 print FILE "trigger_action_localboot\n";
89 close(FILE);
90 }
91 else {
92 # TODO do something, error handling, logging
93 }
95 return;
96 }
99 sub trigger_action_faireboot {
100 my ($msg, $msg_hash) = @_;
101 &main::daemon_log("DEBUG: run /usr/sbin/faireboot\n", 7);
102 system("/usr/sbin/faireboot");
103 return;
104 }
107 sub trigger_action_reboot {
108 my ($msg, $msg_hash) = @_;
109 my $timeout;
111 if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
112 $timeout = 0;
113 }
114 else {
115 $timeout = @{$msg_hash->{timeout}}[0];
116 }
118 # check logged in user
119 my @user_list = &get_logged_in_users;
120 if( @user_list >= 1 ) {
121 system( "/usr/bin/goto-notify reboot" );
122 open(FILE, "> /etc/gosa-si/event");
123 print FILE "reboot\n";
124 close(FILE);
125 }
126 else {
127 system( "/sbin/shutdown -r +$timeout &" );
128 }
130 return;
131 }
134 sub trigger_action_halt {
135 my ($msg, $msg_hash) = @_;
136 my $timeout;
138 if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
139 $timeout = 0;
140 }
141 else {
142 $timeout = @{$msg_hash->{timeout}}[0];
143 }
145 # check logged in user
146 my @user_list = &get_logged_in_users;
147 if( @user_list >= 1 ) {
148 system( "/usr/bin/goto-notify halt" );
149 open(FILE, "> /etc/gosa-si/event");
150 print FILE "halt\n";
151 close(FILE);
152 }
153 else {
154 system( "/sbin/shutdown -h +$timeout &" );
155 }
157 return;
158 }
161 sub trigger_action_reinstall {
162 my ($msg, $msg_hash) = @_;
164 # check logged in user
165 my @user_list = &get_logged_in_users;
166 if( @user_list >= 1 ) {
167 system( "/usr/bin/goto-notify install" );
168 open(FILE, "> /etc/gosa-si/event");
169 print FILE "install\n";
170 close(FILE);
171 }
172 else {
173 system( "/sbin/shutdown -r now &" );
174 }
176 return;
177 }
180 # Backward compatibility
181 sub trigger_action_update {
182 my ($msg, $msg_hash) = @_;
184 # Execute update
185 system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
187 return;
188 }
190 # Backward compatibility
191 sub trigger_action_instant_update {
192 my ($msg, $msg_hash) = @_;
194 # Execute update
195 system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
197 return;
198 }
201 1;