7273673aea107ffda616335ee28d67cc47dc4553
1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 "get_events",
6 "gen_smb_hash",
7 "reload_ldap_config",
8 "ping",
9 "network_completition",
10 "set_activated_for_installation",
11 "new_key_for_client",
12 "detect_hardware",
13 "trigger_action_localboot",
14 "trigger_action_reboot",
15 "trigger_action_halt",
16 "trigger_action_update",
17 "trigger_action_reinstall",
18 "trigger_action_memcheck",
19 "trigger_action_sysinfo",
20 "trigger_action_instant_update",
21 "trigger_action_rescan",
22 "trigger_action_wake",
23 );
24 @EXPORT = @events;
26 use strict;
27 use warnings;
28 use GOSA::GosaSupportDaemon;
29 use Crypt::SmbHash;
30 use Net::ARP;
31 use Net::Ping;
32 use Socket;
35 BEGIN {}
37 END {}
39 ### Start ######################################################################
41 #&main::read_configfile($main::cfg_file, %cfg_defaults);
43 sub get_events {
44 return \@events;
45 }
48 sub ping {
49 my ($msg, $msg_hash, $session_id) = @_ ;
50 my $source = @{$msg_hash->{source}}[0];
51 my $target = @{$msg_hash->{target}}[0];
52 my $out_hash = &create_xml_hash("ping", $source, $target);
53 &add_content2xml_hash($out_hash, "session_id", $session_id);
54 my $out_msg = &create_xml_string($out_hash);
56 my @out_msg_l = ( $out_msg );
57 return @out_msg_l;
58 }
61 sub gen_smb_hash {
62 my ($msg, $msg_hash, $session_id) = @_ ;
63 my $source = @{$msg_hash->{source}}[0];
64 my $target = @{$msg_hash->{target}}[0];
65 my $password = @{$msg_hash->{password}}[0];
67 my %data= ('hash' => join(q[:], ntlmgen $password));
68 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
69 }
72 sub network_completition {
73 my ($msg, $msg_hash, $session_id) = @_ ;
74 my $source = @{$msg_hash->{source}}[0];
75 my $target = @{$msg_hash->{target}}[0];
76 my $name = @{$msg_hash->{hostname}}[0];
78 # Can we resolv the name?
79 my %data;
80 if (inet_aton($name)){
81 my $address = inet_ntoa(inet_aton($name));
82 my $p = Net::Ping->new('tcp');
83 my $mac= "";
84 if ($p->ping($address, 1)){
85 $mac = Net::ARP::arp_lookup("", $address);
86 }
88 %data= ('ip' => $address, 'mac' => $mac);
89 } else {
90 %data= ('ip' => '', 'mac' => '');
91 }
93 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
95 return ( $out_msg );
96 }
99 sub detect_hardware {
100 my ($msg, $msg_hash) = @_ ;
101 # just forward msg to client, but dont forget to split off 'gosa_' in header
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 reload_ldap_config {
115 my ($msg, $msg_hash) = @_ ;
116 my $target = @{$msg_hash->{target}}[0];
118 my @out_msg_l;
119 push(@out_msg_l, &new_ldap_config($target));
120 return @out_msg_l;
121 }
124 sub set_activated_for_installation {
125 my ($msg, $msg_hash) = @_;
127 my $header = @{$msg_hash->{header}}[0];
128 my $source = @{$msg_hash->{source}}[0];
129 my $target = @{$msg_hash->{target}}[0];
131 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
132 my $out_msg = &create_xml_string($out_hash);
134 my @out_msg_l = ( $out_msg );
135 return @out_msg_l;
136 }
139 sub trigger_action_localboot {
140 my ($msg, $msg_hash) = @_;
141 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
142 my @out_msg_l = ($msg);
143 return @out_msg_l;
144 }
147 sub trigger_action_halt {
148 my ($msg, $msg_hash) = @_;
149 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
150 my @out_msg_l = ($msg);
151 return @out_msg_l;
152 }
155 sub trigger_action_reboot {
156 my ($msg, $msg_hash) = @_;
157 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
158 my @out_msg_l = ($msg);
159 return @out_msg_l;
160 }
163 sub trigger_action_memcheck {
164 my ($msg, $msg_hash) = @_ ;
165 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
166 my @out_msg_l = ($msg);
167 return @out_msg_l;
168 }
171 sub trigger_action_reinstall {
172 my ($msg, $msg_hash) = @_;
173 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
174 my @out_msg_l = ($msg);
175 return @out_msg_l;
176 }
179 sub trigger_action_update {
180 my ($msg, $msg_hash) = @_;
181 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
182 my @out_msg_l = ($msg);
183 return @out_msg_l;
184 }
187 sub trigger_action_instant_update {
188 my ($msg, $msg_hash) = @_;
189 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
190 my @out_msg_l = ($msg);
191 return @out_msg_l;
192 }
195 sub trigger_action_sysinfo {
196 my ($msg, $msg_hash) = @_;
197 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
198 my @out_msg_l = ($msg);
199 return @out_msg_l;
200 }
203 sub new_key_for_client {
204 my ($msg, $msg_hash) = @_;
205 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
206 my @out_msg_l = ($msg);
207 return @out_msg_l;
208 }
211 sub trigger_action_rescan {
212 my ($msg, $msg_hash) = @_;
213 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
214 my @out_msg_l = ($msg);
215 return @out_msg_l;
216 }
219 sub trigger_action_wake {
220 my ($msg, $msg_hash) = @_;
221 my %data = ( 'macAddress' => \@{$msg_hash->{macAddress}} );
222 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
223 my @out_msg_l = ($out_msg);
224 return @out_msg_l;
225 }
227 1;