a041a7229a0954c83d33546b4b00d41f3ac1ae90
1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 "get_events",
6 "gen_smb_hash",
7 "ping",
8 "network_completition",
9 "set_activated_for_installation",
10 "new_key_for_client",
11 "detect_hardware",
12 "trigger_action_localboot",
13 "trigger_action_reboot",
14 "trigger_action_halt",
15 "trigger_action_update",
16 "trigger_action_reinstall",
17 "trigger_action_memcheck",
18 "trigger_action_sysinfo",
19 "trigger_action_instant_update",
20 "trigger_action_rescan",
21 "trigger_action_wake",
22 );
23 @EXPORT = @events;
25 use strict;
26 use warnings;
27 use GOSA::GosaSupportDaemon;
28 use Crypt::SmbHash;
29 use Net::ARP;
30 use Net::Ping;
31 use Socket;
34 BEGIN {}
36 END {}
38 ### Start ######################################################################
40 #&main::read_configfile($main::cfg_file, %cfg_defaults);
42 sub get_events {
43 return \@events;
44 }
47 sub ping {
48 my ($msg, $msg_hash, $session_id) = @_ ;
49 my $source = @{$msg_hash->{source}}[0];
50 my $target = @{$msg_hash->{target}}[0];
51 my $out_hash = &create_xml_hash("ping", $source, $target);
52 &add_content2xml_hash($out_hash, "session_id", $session_id);
53 my $out_msg = &create_xml_string($out_hash);
55 my @out_msg_l = ( $out_msg );
56 return @out_msg_l;
57 }
60 sub gen_smb_hash {
61 my ($msg, $msg_hash, $session_id) = @_ ;
62 my $source = @{$msg_hash->{source}}[0];
63 my $target = @{$msg_hash->{target}}[0];
64 my $password = @{$msg_hash->{password}}[0];
66 my %data= ('hash' => join(q[:], ntlmgen $password));
67 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
68 }
71 sub network_completition {
72 my ($msg, $msg_hash, $session_id) = @_ ;
73 my $source = @{$msg_hash->{source}}[0];
74 my $target = @{$msg_hash->{target}}[0];
75 my $name = @{$msg_hash->{hostname}}[0];
77 # Can we resolv the name?
78 my %data;
79 if (inet_aton($name)){
80 my $address = inet_ntoa(inet_aton($name));
81 my $p = Net::Ping->new('tcp');
82 my $mac= "";
83 if ($p->ping($address, 1)){
84 $mac = Net::ARP::arp_lookup("", $address);
85 }
87 %data= ('ip' => $address, 'mac' => $mac);
88 } else {
89 %data= ('ip' => '', 'mac' => '');
90 }
92 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
94 return ( $out_msg );
95 }
98 sub detect_hardware {
99 my ($msg, $msg_hash) = @_ ;
100 # just forward msg to client, but dont forget to split off 'gosa_' in header
101 my $header = @{$msg_hash->{header}}[0];
102 my $source = @{$msg_hash->{source}}[0];
103 my $target = @{$msg_hash->{target}}[0];
105 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
106 my $out_msg = &create_xml_string($out_hash);
108 my @out_msg_l = ( $out_msg );
109 return @out_msg_l;
111 }
114 sub set_activated_for_installation {
115 my ($msg, $msg_hash) = @_;
117 my $header = @{$msg_hash->{header}}[0];
118 my $source = @{$msg_hash->{source}}[0];
119 my $target = @{$msg_hash->{target}}[0];
121 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
122 my $out_msg = &create_xml_string($out_hash);
124 my @out_msg_l = ( $out_msg );
125 return @out_msg_l;
126 }
129 sub trigger_action_localboot {
130 my ($msg, $msg_hash) = @_;
131 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
132 my @out_msg_l = ($msg);
133 return @out_msg_l;
134 }
137 sub trigger_action_halt {
138 my ($msg, $msg_hash) = @_;
139 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
140 my @out_msg_l = ($msg);
141 return @out_msg_l;
142 }
145 sub trigger_action_reboot {
146 my ($msg, $msg_hash) = @_;
147 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
148 my @out_msg_l = ($msg);
149 return @out_msg_l;
150 }
153 sub trigger_action_memcheck {
154 my ($msg, $msg_hash) = @_ ;
155 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
156 my @out_msg_l = ($msg);
157 return @out_msg_l;
158 }
161 sub trigger_action_reinstall {
162 my ($msg, $msg_hash) = @_;
163 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
164 my @out_msg_l = ($msg);
165 return @out_msg_l;
166 }
169 sub trigger_action_update {
170 my ($msg, $msg_hash) = @_;
171 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
172 my @out_msg_l = ($msg);
173 return @out_msg_l;
174 }
177 sub trigger_action_instant_update {
178 my ($msg, $msg_hash) = @_;
179 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
180 my @out_msg_l = ($msg);
181 return @out_msg_l;
182 }
185 sub trigger_action_sysinfo {
186 my ($msg, $msg_hash) = @_;
187 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
188 my @out_msg_l = ($msg);
189 return @out_msg_l;
190 }
193 sub new_key_for_client {
194 my ($msg, $msg_hash) = @_;
195 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
196 my @out_msg_l = ($msg);
197 return @out_msg_l;
198 }
201 sub trigger_action_rescan {
202 my ($msg, $msg_hash) = @_;
203 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
204 my @out_msg_l = ($msg);
205 return @out_msg_l;
206 }
209 sub trigger_action_wake {
210 my ($msg, $msg_hash) = @_;
211 my %data = ( 'macAddress' => \@{$msg_hash->{macAddress}} );
212 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
213 my @out_msg_l = ($out_msg);
214 return @out_msg_l;
215 }
217 1;