Code

trigger_action_rescan broken, raise new ticket
[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     );
16 @EXPORT = @events;
18 use strict;
19 use warnings;
20 use GOSA::GosaSupportDaemon;
22 BEGIN {}
24 END {}
27 sub get_events { return \@events; }
30 sub trigger_action_localboot {
31     my ($msg, $msg_hash) = @_;
32     my $timeout;
34     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
35         $timeout = -1;
36     } 
37     else {
38         $timeout = @{$msg_hash->{timeout}}[0];
39     }
41     # check logged in user
42     my $logged_in_user = 1;
43     if( $logged_in_user ) {
44         # TODO do something
45     }
46     else {
47         $timeout = 0;
48     }
49         
50     # execute function
51     if( $timeout == 0 ) {
52         print STDERR ("shutdown -r +$timeout\n");
53     }
54     elsif( $timeout > 0 ) {
55         print STDERR ("shutdown -r +$timeout\n");
56     }
57     elsif( $timeout < 0 ) {
58         print STDERR "The administrator has sent a signal to reboot this workstation. It will reboot after you've logged out.\n";
59         open(FILE, "> /etc/gosa-si/event");
60         print FILE "trigger_action_localboot\n";
61         close(FILE);
62     }
63     else {
64         # TODO do something, error handling, logging
65     }
67     return;
68 }
71 sub trigger_action_faireboot {
72     my ($msg, $msg_hash) = @_;
73     system("/usr/sbin/faireboot");
74     return;
75 }
78 sub trigger_action_reboot {
79     my ($msg, $msg_hash) = @_;
80     my $timeout;
82     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
83         $timeout = 0;
84     } 
85     else {
86         $timeout = @{$msg_hash->{timeout}}[0];
87     }
89     # check logged in user
90     my @user_list = &get_logged_in_users;
91     if( @user_list >= 1 ) {
92         system( "/usr/bin/goto-notify reboot" );
93         open(FILE, "> /etc/gosa-si/event");
94         print FILE "reboot\n";
95         close(FILE);
96     }
97     else {
98         #system( "/sbin/shutdown -r +$timeout &" );
99     }
101     return;
105 sub trigger_action_halt {
106     my ($msg, $msg_hash) = @_;
107     my $timeout;
109     if((not exists $msg_hash->{timeout} ) || (1 != @{$msg_hash->{timeout}} ) ) {
110         $timeout = 0;
111     } 
112     else {
113         $timeout = @{$msg_hash->{timeout}}[0];
114     }
116     # check logged in user
117     my @user_list = &get_logged_in_users;
118     if( @user_list >= 1 ) {
119         system( "/usr/bin/goto-notify halt" );
120         open(FILE, "> /etc/gosa-si/event");
121         print FILE "halt\n";
122         close(FILE);
123     }
124     else {
125         system( "/sbin/shutdown -h +$timeout &" );
126     }
128     return;
132 sub trigger_action_reinstall {
133     my ($msg, $msg_hash) = @_;
135     # check logged in user
136     my @user_list = &get_logged_in_users;
137     if( @user_list >= 1 ) {
138         system( "/usr/bin/goto-notify install" );
139         open(FILE, "> /etc/gosa-si/event");
140         print FILE "install\n";
141         close(FILE);
142     }
143     else {
144         system( "/sbin/shutdown -r now &" );
145     }
147     return;
151 # Backward compatibility
152 sub trigger_action_update {
153     my ($msg, $msg_hash) = @_;
155     # Execute update
156     system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
158     return;
161 # Backward compatibility
162 sub trigger_action_instant_update {
163     my ($msg, $msg_hash) = @_;
165     # Execute update
166     system( "DEBIAN_FRONTEND=noninteractive /usr/sbin/fai-softupdate &" );
168     return;
172 1;