f8185db75b21e7a4af1eb4130714086b55681b0f
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;
39 use utf8;
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];
81 $header =~ s/^gosa_//;
83 my $sql_statement = "SELECT * FROM known_clients WHERE login LIKE '%$usr%'";
84 my $res = $main::known_clients_db->select_dbentry($sql_statement);
86 my $out_msg = "<xml><header>$header</header><source>$target</source><target>$source</target>";
87 $out_msg .= &db_res2xml($res);
88 $out_msg .= "</xml>";
89 my @out_msg_l = ( $out_msg );
90 return @out_msg_l;
92 }
95 sub ping {
96 my ($msg, $msg_hash, $session_id) = @_ ;
97 my $source = @{$msg_hash->{source}}[0];
98 my $target = @{$msg_hash->{target}}[0];
99 my $out_hash = &create_xml_hash("ping", $source, $target);
100 &add_content2xml_hash($out_hash, "session_id", $session_id);
101 my $out_msg = &create_xml_string($out_hash);
103 my @out_msg_l = ( $out_msg );
104 return @out_msg_l;
105 }
108 sub gen_smb_hash {
109 my ($msg, $msg_hash, $session_id) = @_ ;
110 my $source = @{$msg_hash->{source}}[0];
111 my $target = @{$msg_hash->{target}}[0];
112 my $password = @{$msg_hash->{password}}[0];
114 my %data= ('hash' => join(q[:], ntlmgen $password));
115 my $out_msg = &build_msg("gen_smb_hash", $target, 'GOSA', \%data );
116 }
119 sub network_completition {
120 my ($msg, $msg_hash, $session_id) = @_ ;
121 my $source = @{$msg_hash->{source}}[0];
122 my $target = @{$msg_hash->{target}}[0];
123 my $name = @{$msg_hash->{hostname}}[0];
125 # Can we resolv the name?
126 my %data;
127 if (inet_aton($name)){
128 my $address = inet_ntoa(inet_aton($name));
129 my $p = Net::Ping->new('tcp');
130 my $mac= "";
131 if ($p->ping($address, 1)){
132 $mac = Net::ARP::arp_lookup("", $address);
133 }
135 %data= ('ip' => $address, 'mac' => $mac);
136 } else {
137 %data= ('ip' => '', 'mac' => '');
138 }
140 my $out_msg = &build_msg("network_completition", $target, 'GOSA', \%data );
142 return ( $out_msg );
143 }
146 sub detect_hardware {
147 my ($msg, $msg_hash) = @_ ;
148 # just forward msg to client, but dont forget to split off 'gosa_' in header
149 my $source = @{$msg_hash->{source}}[0];
150 my $target = @{$msg_hash->{target}}[0];
152 my $out_hash = &create_xml_hash("detect_hardware", $source, $target);
153 my $out_msg = &create_xml_string($out_hash);
155 my @out_msg_l = ( $out_msg );
156 return @out_msg_l;
158 }
161 sub trigger_reload_ldap_config {
162 my ($msg, $msg_hash) = @_ ;
163 my $target = @{$msg_hash->{target}}[0];
165 my $out_hash = &create_xml_hash("reload_ldap_config", $main::server_address, $main::server_address, $target);
166 my $out_msg = &create_xml_string($out_hash);
167 my @out_msg_l;
168 push(@out_msg_l, $out_msg);
169 return @out_msg_l;
170 }
173 sub set_activated_for_installation {
174 my ($msg, $msg_hash) = @_;
176 my $header = @{$msg_hash->{header}}[0];
177 my $source = @{$msg_hash->{source}}[0];
178 my $target = @{$msg_hash->{target}}[0];
180 my $out_hash = &create_xml_hash("set_activated_for_installation", $source, $target);
181 my $out_msg = &create_xml_string($out_hash);
183 my @out_msg_l = ( $out_msg );
184 return @out_msg_l;
185 }
188 sub trigger_action_faireboot {
189 my ($msg, $msg_hash) = @_;
190 $msg =~ s/<header>gosa_trigger_action_faireboot<\/header>/<header>trigger_action_faireboot<\/header>/;
191 my @out_msg_l = ($msg);
192 return @out_msg_l;
193 }
196 sub trigger_action_localboot {
197 my ($msg, $msg_hash) = @_;
198 $msg =~ s/<header>gosa_trigger_action_localboot<\/header>/<header>trigger_action_localboot<\/header>/;
199 my @out_msg_l = ($msg);
200 return @out_msg_l;
201 }
204 sub trigger_action_halt {
205 my ($msg, $msg_hash) = @_;
206 $msg =~ s/<header>gosa_trigger_action_halt<\/header>/<header>trigger_action_halt<\/header>/;
207 my @out_msg_l = ($msg);
208 return @out_msg_l;
209 }
212 sub trigger_action_reboot {
213 my ($msg, $msg_hash) = @_;
214 $msg =~ s/<header>gosa_trigger_action_reboot<\/header>/<header>trigger_action_reboot<\/header>/;
215 my @out_msg_l = ($msg);
216 return @out_msg_l;
217 }
220 sub trigger_action_memcheck {
221 my ($msg, $msg_hash) = @_ ;
222 $msg =~ s/<header>gosa_trigger_action_memcheck<\/header>/<header>trigger_action_memcheck<\/header>/;
223 my @out_msg_l = ($msg);
224 return @out_msg_l;
225 }
228 sub trigger_action_reinstall {
229 my ($msg, $msg_hash) = @_;
230 $msg =~ s/<header>gosa_trigger_action_reinstall<\/header>/<header>trigger_action_reinstall<\/header>/;
231 my @out_msg_l = ($msg);
232 return @out_msg_l;
233 }
236 sub trigger_action_update {
237 my ($msg, $msg_hash) = @_;
238 $msg =~ s/<header>gosa_trigger_action_update<\/header>/<header>trigger_action_update<\/header>/;
239 my @out_msg_l = ($msg);
240 return @out_msg_l;
241 }
244 sub trigger_action_instant_update {
245 my ($msg, $msg_hash) = @_;
246 $msg =~ s/<header>gosa_trigger_action_instant_update<\/header>/<header>trigger_action_instant_update<\/header>/;
247 my @out_msg_l = ($msg);
248 return @out_msg_l;
249 }
252 sub trigger_action_sysinfo {
253 my ($msg, $msg_hash) = @_;
254 $msg =~ s/<header>gosa_trigger_action_sysinfo<\/header>/<header>trigger_action_sysinfo<\/header>/;
255 my @out_msg_l = ($msg);
256 return @out_msg_l;
257 }
260 sub new_key_for_client {
261 my ($msg, $msg_hash) = @_;
262 $msg =~ s/<header>gosa_new_key_for_client<\/header>/<header>new_key<\/header>/;
263 my @out_msg_l = ($msg);
264 return @out_msg_l;
265 }
268 sub trigger_action_rescan {
269 my ($msg, $msg_hash) = @_;
270 $msg =~ s/<header>gosa_trigger_action_rescan<\/header>/<header>trigger_action_rescan<\/header>/;
271 my @out_msg_l = ($msg);
272 return @out_msg_l;
273 }
276 sub trigger_action_wake {
277 my ($msg, $msg_hash) = @_;
278 my %data = ( 'macAddress' => \@{$msg_hash->{macAddress}} );
279 my $out_msg = &build_msg("trigger_wake", "GOSA", "KNOWN_SERVER", \%data);
280 my @out_msg_l = ($out_msg);
281 return @out_msg_l;
282 }
284 1;