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 = 0;
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 system( "/usr/bin/goto-notify reboot" );
94 open(FILE, "> /etc/gosa-si/event");
95 print FILE "reboot\n";
96 close(FILE);
97 }
98 else {
99 system( "/sbin/shutdown -r +$timeout &" );
100 }
102 return;
103 }
106 sub trigger_action_halt {
107 my ($msg, $msg_hash) = @_;
108 my $timeout;
110 if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
111 $timeout = 0;
112 }
113 else {
114 $timeout = @{$msg_hash->{timeout}}[0];
115 }
117 # check logged in user
118 my @user_list = &get_logged_in_users;
119 if( @user_list >= 1 ) {
120 system( "/usr/bin/goto-notify halt" );
121 open(FILE, "> /etc/gosa-si/event");
122 print FILE "halt\n";
123 close(FILE);
124 }
125 else {
126 system( "/sbin/shutdown -h +$timeout &" );
127 }
129 return;
130 }
133 sub trigger_action_reinstall {
134 my ($msg, $msg_hash) = @_;
136 # check logged in user
137 my @user_list = &get_logged_in_users;
138 if( @user_list >= 1 ) {
139 system( "/usr/bin/goto-notify install" );
140 open(FILE, "> /etc/gosa-si/event");
141 print FILE "install\n";
142 close(FILE);
143 }
144 else {
145 system( "/sbin/shutdown -r now &" );
146 }
148 return;
149 }
152 # Backward compatibility
153 sub trigger_action_update {
154 my ($msg, $msg_hash) = @_;
156 # Execute update
157 system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
159 return;
160 }
162 # Backward compatibility
163 sub trigger_action_instant_update {
164 my ($msg, $msg_hash) = @_;
166 # Execute update
167 system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
169 return;
170 }
173 1;