ae10c2547661e0eff6e1b9dfe21392a617e6a471
1 package gosaTriggered;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 "get_events",
6 "get_login_usr_for_client",
7 "get_client_for_login_usr",
8 "gen_smb_hash",
9 "trigger_reload_ldap_config",
10 "ping",
11 "network_completition",
12 "set_activated_for_installation",
13 "new_key_for_client",
14 "detect_hardware",
15 "get_login_usr",
16 "get_login_client",
17 "trigger_action_localboot",
18 "trigger_action_faireboot",
19 "trigger_action_reboot",
20 "trigger_action_halt",
21 "trigger_action_update",
22 "trigger_action_reinstall",
23 "trigger_action_memcheck",
24 "trigger_action_sysinfo",
25 "trigger_action_instant_update",
26 "trigger_action_rescan",
27 "trigger_action_wake",
28 );
29 @EXPORT = @events;
31 use strict;
32 use warnings;
33 use GOSA::GosaSupportDaemon;
34 use Data::Dumper;
35 use Crypt::SmbHash;
36 use Net::ARP;
37 use Net::Ping;
38 use Socket;
41 BEGIN {}
43 END {}
45 ### Start ######################################################################
47 #&main::read_configfile($main::cfg_file, %cfg_defaults);
49 sub get_events {
50 return \@events;
51 }
54 sub get_login_usr_for_client {
55 my ($msg, $msg_hash, $session_id) = @_ ;
56 my $header = @{$msg_hash->{'header'}}[0];
57 my $source = @{$msg_hash->{'source'}}[0];
58 my $target = @{$msg_hash->{'target'}}[0];
59 my $client = @{$msg_hash->{'client'}}[0];
61 $header =~ s/^gosa_//;
63 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$client' OR macaddress='$client'";
64 my $res = $main::known_clients_db->select_dbentry($sql_statement);
66 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
67 $out_msg .= &db_res2xml($res);
68 $out_msg .= "</xml>";
70 my @out_msg_l = ( $out_msg );
71 return @out_msg_l;
72 }
75 sub get_client_for_login_usr {
76 my ($msg, $msg_hash, $session_id) = @_ ;
77 my $header = @{$msg_hash->{'header'}}[0];
78 my $source = @{$msg_hash->{'source'}}[0];
79 my $target = @{$msg_hash->{'target'}}[0];
80 my $usr = @{$msg_hash->{'usr'}}[0];
82 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
83 my $res = $main::known_clients_db->select_dbentry($sql_statement);
85 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
86 $out_msg .= &db_res2xml($res);
87 $out_msg .= "</xml>";
88 my @out_msg_l = ( $out_msg );
89 return @out_msg_l;
91 }
94 sub ping {
95 my ($msg, $msg_hash, $session_id) = @_ ;
96 my $source = @{$msg_hash->{source}}[0];
97 my $target = @{$msg_hash->{target}}[0];
98 my $out_hash = &create_xml_hash("ping", $source, $target);
99 &add_content2xml_hash($out_hash, "session_id", $session_id);
100 my $out_msg = &create_xml_string($out_hash);
102 my @out_msg_l = ( $out_msg );
103 return @out_msg_l;
104 }
107 sub gen_smb_hash {
108 my ($msg, $msg_hash, $session_id) = @_ ;
109 my $source = @{$msg_hash->{source}}[0];
110 my $target = @{$msg_hash->{target}}[0];
111 my $password = @{$msg_hash->{password}}[0];
113 my %data= ('hash' => join(q[:], ntlmgen $password));
114 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
115 }
118 sub network_completition {
119 my ($msg, $msg_hash, $session_id) = @_ ;
120 my $source = @{$msg_hash->{source}}[0];
121 my $target = @{$msg_hash->{target}}[0];
122 my $name = @{$msg_hash->{hostname}}[0];
124 # Can we resolv the name?
125 my %data;
126 if (inet_aton($name)){
127 my $address = inet_ntoa(inet_aton($name));
128 my $p = Net::Ping->new('tcp');
129 my $mac= "";
130 if ($p->ping($address, 1)){
131 $mac = Net::ARP::arp_lookup("", $address);
132 }
134 %data= ('ip' => $address, 'mac' => $mac);
135 } else {
136 %data= ('ip' => '', 'mac' => '');
137 }
139 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
141 return ( $out_msg );
142 }
145 sub detect_hardware {
146 my ($msg, $msg_hash) = @_ ;
147 # just forward msg to client, but dont forget to split off 'gosa_' in header
148 my $source = @{$msg_hash->{source}}[0];
149 my $target = @{$msg_hash->{target}}[0];
151 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
152 my $out_msg = &create_xml_string($out_hash);
154 my @out_msg_l = ( $out_msg );
155 return @out_msg_l;
157 }
160 sub trigger_reload_ldap_config {
161 my ($msg, $msg_hash) = @_ ;
162 my $target = @{$msg_hash->{target}}[0];
164 my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target);
165 my $out_msg = &create_xml_string($out_hash);
166 my @out_msg_l;
167 push(@out_msg_l, $out_msg);
168 return @out_msg_l;
169 }
172 sub set_activated_for_installation {
173 my ($msg, $msg_hash) = @_;
175 my $header = @{$msg_hash->{header}}[0];
176 my $source = @{$msg_hash->{source}}[0];
177 my $target = @{$msg_hash->{target}}[0];
179 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
180 my $out_msg = &create_xml_string($out_hash);
182 my @out_msg_l = ( $out_msg );
183 return @out_msg_l;
184 }
187 sub trigger_action_faireboot {
188 my ($msg, $msg_hash) = @_;
189 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
190 my @out_msg_l = ($msg);
191 return @out_msg_l;
192 }
195 sub trigger_action_localboot {
196 my ($msg, $msg_hash) = @_;
197 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
198 my @out_msg_l = ($msg);
199 return @out_msg_l;
200 }
203 sub trigger_action_halt {
204 my ($msg, $msg_hash) = @_;
205 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
206 my @out_msg_l = ($msg);
207 return @out_msg_l;
208 }
211 sub trigger_action_reboot {
212 my ($msg, $msg_hash) = @_;
213 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
214 my @out_msg_l = ($msg);
215 return @out_msg_l;
216 }
219 sub trigger_action_memcheck {
220 my ($msg, $msg_hash) = @_ ;
221 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
222 my @out_msg_l = ($msg);
223 return @out_msg_l;
224 }
227 sub trigger_action_reinstall {
228 my ($msg, $msg_hash) = @_;
229 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
230 my @out_msg_l = ($msg);
231 return @out_msg_l;
232 }
235 sub trigger_action_update {
236 my ($msg, $msg_hash) = @_;
237 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
238 my @out_msg_l = ($msg);
239 return @out_msg_l;
240 }
243 sub trigger_action_instant_update {
244 my ($msg, $msg_hash) = @_;
245 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
246 my @out_msg_l = ($msg);
247 return @out_msg_l;
248 }
251 sub trigger_action_sysinfo {
252 my ($msg, $msg_hash) = @_;
253 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
254 my @out_msg_l = ($msg);
255 return @out_msg_l;
256 }
259 sub new_key_for_client {
260 my ($msg, $msg_hash) = @_;
261 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
262 my @out_msg_l = ($msg);
263 return @out_msg_l;
264 }
267 sub trigger_action_rescan {
268 my ($msg, $msg_hash) = @_;
269 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
270 my @out_msg_l = ($msg);
271 return @out_msg_l;
272 }
275 sub trigger_action_wake {
276 my ($msg, $msg_hash) = @_;
277 my %data = ( 'macAddress' => \@{$msg_hash->{macAddress}} );
278 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
279 my @out_msg_l = ($out_msg);
280 return @out_msg_l;
281 }
283 1;