851216043215bd6894832e6f5c54d6465d475d03
1 package clMessages;
2 use Exporter;
3 @ISA = qw(Exporter);
4 my @events = (
5 "PROGRESS",
6 "FAIREBOOT",
7 "TASKSKIP",
8 "TASKBEGIN",
9 "TASKEND",
10 "TASKERROR",
11 "HOOK",
12 "GOTOACTIVATION",
13 "LOGIN",
14 "LOGOUT",
15 );
16 @EXPORT = @events;
18 use strict;
19 use warnings;
20 use Data::Dumper;
21 use GOSA::GosaSupportDaemon;
25 BEGIN {}
27 END {}
29 ### Start ######################################################################
31 #&read_configfile($main::cfg_file, %cfg_defaults);
34 sub get_events {
35 return \@events;
36 }
38 sub read_configfile {
39 my ($cfg_file, %cfg_defaults) = @_;
40 my $cfg;
42 if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
43 if( -r $cfg_file ) {
44 $cfg = Config::IniFiles->new( -file => $cfg_file );
45 } else {
46 &main::daemon_log("ERROR: clMessages.pm couldn't read config file!", 1);
47 }
48 } else {
49 $cfg = Config::IniFiles->new() ;
50 }
51 foreach my $section (keys %cfg_defaults) {
52 foreach my $param (keys %{$cfg_defaults{ $section }}) {
53 my $pinfo = $cfg_defaults{ $section }{ $param };
54 ${@$pinfo[0]} = $cfg->val( $section, $param, @$pinfo[1] );
55 }
56 }
57 }
59 sub LOGIN {
60 my ($msg, $msg_hash, $session_id) = @_;
61 my $header = @{$msg_hash->{'header'}}[0];
62 my $source = @{$msg_hash->{'source'}}[0];
63 my $login = @{$msg_hash->{$header}}[0];
65 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'";
66 my $res = $main::known_clients_db->select_dbentry($sql_statement);
67 if( 1 != keys(%$res) ) {
68 &main::daemon_log("DEBUG: clMessages.pm: LOGIN: no or more hits found in known_clients_db for host '$source'");
69 return;
70 }
72 my $act_login = $res->{'1'}->{'login'};
73 if( $act_login eq "nobody" ) {
74 $act_login = "";
75 }
77 $act_login =~ s/$login,?//gi;
78 my @act_login = split(",", $act_login);
79 unshift(@act_login, $login);
80 $act_login = join(",", @act_login);
82 #print STDERR "source: $source\n";
83 #print STDERR "login: $login\n";
84 #print STDERR "act_login: $act_login\n";
85 #print STDERR "dbres: ".Dumper($res)."\n";
86 $sql_statement = "UPDATE known_clients ".
87 "SET login='$act_login' ".
88 "WHERE hostname='$source'";
89 $res = $main::known_clients_db->update_dbentry($sql_statement);
90 return;
91 }
94 sub LOGOUT {
95 my ($msg, $msg_hash, $session_id) = @_;
96 my $header = @{$msg_hash->{'header'}}[0];
97 my $source = @{$msg_hash->{'source'}}[0];
98 my $login = @{$msg_hash->{$header}}[0];
100 my $sql_statement = "SELECT * FROM known_clients WHERE hostname='$source'";
101 my $res = $main::known_clients_db->select_dbentry($sql_statement);
102 if( 1 != keys(%$res) ) {
103 &main::daemon_log("DEBUG: clMessages.pm: LOGOUT: no or more hits found in known_clients_db for host '$source'");
104 return;
105 }
107 my $act_login = $res->{'1'}->{'login'};
108 $act_login =~ s/$login,?//gi;
110 if( $act_login eq "" ){ $act_login = "nobody"; }
112 $sql_statement = "UPDATE known_clients ".
113 "SET login='$act_login' ".
114 "WHERE hostname='$source'";
115 $res = $main::known_clients_db->update_dbentry($sql_statement);
117 return;
118 }
122 # echo "GOTOACTIVATION" > /var/run/gosa-si-client.socket
123 sub GOTOACTIVATION {
124 my ($msg, $msg_hash, $session_id) = @_;
125 my $out_msg = &build_result_update_msg($msg_hash);
126 my @out_msg_l = ($out_msg);
127 return @out_msg_l;
128 }
131 # echo "PROGRESS 15" > /var/run/gosa-si-client.socket
132 sub PROGRESS {
133 my ($msg, $msg_hash, $session_id) = @_;
134 my $out_msg = &build_progress_update_msg($msg_hash);
135 my @out_msg_l = ($out_msg);
136 return @out_msg_l;
137 }
139 # echo "FAIREBOOT" > /tmp/gosa-si-client-fifo
140 sub FAIREBOOT {
141 my ($msg, $msg_hash, $session_id) = @_;
142 my $out_msg = &build_status_result_update_msg($msg_hash);
143 my @out_msg_l = ($out_msg);
144 return @out_msg_l;
145 }
147 # echo "TASKSKIP hallo welt" > /tmp/gosa-si-client-fifo
148 sub TASKSKIP {
149 my ($msg, $msg_hash, $session_id) = @_;
150 my $out_msg = &build_status_result_update_msg($msg_hash);
151 my @out_msg_l = ($out_msg);
152 return @out_msg_l;
153 }
156 # echo "TASKBEGIN hallo welt" > /tmp/gosa-si-client-fifo
157 sub TASKBEGIN {
158 my ($msg, $msg_hash, $session_id) = @_;
159 my $out_msg = &build_status_result_update_msg($msg_hash);
160 my @out_msg_l = ($out_msg);
161 return @out_msg_l;
162 }
164 # echo "TASKEND hallo welt" > /tmp/gosa-si-client-fifo
165 sub TASKEND {
166 my ($msg, $msg_hash, $session_id) = @_;
167 my $out_msg = &build_status_result_update_msg($msg_hash);
168 my @out_msg_l = ($out_msg);
169 return @out_msg_l;
170 }
173 # echo "TASKERROR hallo welt" > /tmp/gosa-si-client-fifo
174 sub TASKERROR {
175 my ($msg, $msg_hash, $session_id) = @_;
176 my $out_msg = &build_status_result_update_msg($msg_hash);
177 my @out_msg_l = ($out_msg);
178 return @out_msg_l;
179 }
182 # echo "HOOK hallo welt" > /tmp/gosa-si-client-fifo
183 sub HOOK {
184 my ($msg, $msg_hash, $session_id) = @_;
185 my $out_msg = &build_status_result_update_msg($msg_hash);
186 my @out_msg_l = ($out_msg);
187 return @out_msg_l;
188 }
191 sub build_status_result_update_msg {
192 my ($msg_hash) = @_;
194 my $header = @{$msg_hash->{'header'}}[0];
195 my $source = @{$msg_hash->{'target'}}[0];
196 my $target = @{$msg_hash->{'target'}}[0];
197 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
199 # test whether content is an empty hash or a string which is required
200 my $content = @{$msg_hash->{$header}}[0];
201 eval{
202 if( 0 == keys(%$content) ) {
203 $content = "";
204 }
205 };
206 if( $@ ) {
207 $content = " $content";
208 }
210 $header =~ s/CLMSG_//g;
211 my $out_msg = sprintf("<xml> ".
212 "<header>gosa_update_status_jobdb_entry</header> ".
213 "<source>%s</source> ".
214 "<target>%s</target>".
215 "<where> ".
216 "<clause> ".
217 "<phrase> ".
218 "<status>processing</status> ".
219 "<macaddress>%s</macaddress> ".
220 "</phrase> ".
221 "</clause> ".
222 "</where> ".
223 "<update> ".
224 "<status>processing</status> ".
225 "<result>%s</result> ".
226 "</update> ".
227 "</xml>", $source, "JOBDB", $macaddress, $header.$content);
228 return $out_msg;
229 }
232 sub build_progress_update_msg {
233 my ($msg_hash) = @_;
235 my $header = @{$msg_hash->{'header'}}[0];
236 my $source = @{$msg_hash->{'target'}}[0];
237 my $target = @{$msg_hash->{'target'}}[0];
238 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
240 # test whether content is an empty hash or a string which is required
241 my $content = @{$msg_hash->{$header}}[0];
242 eval{
243 if( 0 == keys(%$content) ) {
244 $content = "";
245 }
246 };
247 if( $@ ) {
248 $content = "$content";
249 }
251 $header =~ s/CLMSG_//g;
252 my $out_msg = sprintf("<xml> ".
253 "<header>gosa_update_status_jobdb_entry</header> ".
254 "<source>%s</source> ".
255 "<target>%s</target>".
256 "<where> ".
257 "<clause> ".
258 "<phrase> ".
259 "<status>processing</status> ".
260 "<macaddress>%s</macaddress> ".
261 "</phrase> ".
262 "</clause> ".
263 "</where> ".
264 "<update> ".
265 "<progress>%s</progress> ".
266 "</update> ".
267 "</xml>", $source, "JOBDB", $macaddress, $content);
268 return $out_msg;
269 }
272 sub build_result_update_msg {
273 my ($msg_hash) = @_;
275 my $header = @{$msg_hash->{'header'}}[0];
276 my $source = @{$msg_hash->{'target'}}[0];
277 my $target = @{$msg_hash->{'target'}}[0];
278 my $macaddress = @{$msg_hash->{'macaddress'}}[0];
280 # test whether content is an empty hash or a string which is required
281 my $content = @{$msg_hash->{$header}}[0];
282 eval{
283 if( 0 == keys(%$content) ) {
284 $content = "";
285 }
286 };
287 if( $@ ) {
288 $content = " $content";
289 }
291 $header =~ s/CLMSG_//g;
292 my $out_msg = sprintf("<xml> ".
293 "<header>gosa_update_status_jobdb_entry</header> ".
294 "<source>%s</source> ".
295 "<target>%s</target>".
296 "<where> ".
297 "<clause> ".
298 "<phrase> ".
299 "<status>processing</status> ".
300 "<macaddress>%s</macaddress> ".
301 "</phrase> ".
302 "</clause> ".
303 "</where> ".
304 "<update> ".
305 "<result>%s</result> ".
306 "</update> ".
307 "</xml>", $source, "JOBDB", $macaddress, $header.$content);
308 return $out_msg;
309 }
312 1;