f71d8df84872dfa70be293363d7783334813d9d3
1 package GOSA::GosaSupportDaemon;
3 use Exporter;
4 @ISA = qw(Exporter);
5 my @functions = (
6 "create_passwd",
7 "create_xml_hash",
8 "get_content_from_xml_hash",
9 "add_content2xml_hash",
10 "create_xml_string",
11 "transform_msg2hash",
12 "get_time",
13 "build_msg",
14 "db_res2xml",
15 "db_res2si_msg",
16 "get_where_statement",
17 "get_select_statement",
18 "get_update_statement",
19 "get_limit_statement",
20 "get_orderby_statement",
21 "get_dns_domains",
22 "get_server_addresses",
23 "get_logged_in_users",
24 "import_events",
25 "del_doubles",
26 "get_ip",
27 "get_interface_for_ip",
28 "get_interfaces",
29 "get_mac_for_interface",
30 "get_local_ip_for_remote_ip",
31 "is_local",
32 "run_as",
33 "inform_all_other_si_server",
34 "read_configfile",
35 "check_opsi_res",
36 );
37 @EXPORT = @functions;
38 use strict;
39 use warnings;
40 use IO::Socket::INET;
41 use Crypt::Rijndael;
42 use Digest::MD5 qw(md5 md5_hex md5_base64);
43 use MIME::Base64;
44 use XML::Simple;
45 use Data::Dumper;
46 use Net::DNS;
49 my $op_hash = {
50 'eq' => '=',
51 'ne' => '!=',
52 'ge' => '>=',
53 'gt' => '>',
54 'le' => '<=',
55 'lt' => '<',
56 'like' => ' LIKE ',
57 };
60 BEGIN {}
62 END {}
64 ### Start ######################################################################
66 my $xml = new XML::Simple();
68 sub daemon_log {
69 my ($msg, $level) = @_ ;
70 &main::daemon_log($msg, $level);
71 return;
72 }
75 sub create_passwd {
76 my $new_passwd = "";
77 for(my $i=0; $i<31; $i++) {
78 $new_passwd .= ("a".."z","A".."Z",0..9)[int(rand(62))]
79 }
81 return $new_passwd;
82 }
85 sub del_doubles {
86 my %all;
87 $all{$_}=0 for @_;
88 return (keys %all);
89 }
92 #=== FUNCTION ================================================================
93 # NAME: create_xml_hash
94 # PARAMETERS: header - string - message header (required)
95 # source - string - where the message come from (required)
96 # target - string - where the message should go to (required)
97 # [header_value] - string - something usefull (optional)
98 # RETURNS: hash - hash - nomen est omen
99 # DESCRIPTION: creates a key-value hash, all values are stored in a array
100 #===============================================================================
101 sub create_xml_hash {
102 my ($header, $source, $target, $header_value) = @_;
103 my $hash = {
104 header => [$header],
105 source => [$source],
106 target => [$target],
107 $header => [$header_value],
108 };
109 return $hash
110 }
113 #=== FUNCTION ================================================================
114 # NAME: create_xml_string
115 # PARAMETERS: xml_hash - hash - hash from function create_xml_hash
116 # RETURNS: xml_string - string - xml string representation of the hash
117 # DESCRIPTION: transform the hash to a string using XML::Simple module
118 #===============================================================================
119 sub create_xml_string {
120 my ($xml_hash) = @_ ;
121 my $xml_string = $xml->XMLout($xml_hash, RootName => 'xml');
122 #$xml_string =~ s/[\n]+//g;
123 #daemon_log("create_xml_string:",7);
124 #daemon_log("$xml_string\n", 7);
125 return $xml_string;
126 }
129 sub transform_msg2hash {
130 my ($msg) = @_ ;
131 my $hash = $xml->XMLin($msg, ForceArray=>1);
133 # xml tags without a content are created as an empty hash
134 # substitute it with an empty list
135 eval {
136 while( my ($xml_tag, $xml_content) = each %{ $hash } ) {
137 if( 1 == @{ $xml_content } ) {
138 # there is only one element in xml_content list ...
139 my $element = @{ $xml_content }[0];
140 if( ref($element) eq "HASH" ) {
141 # and this element is an hash ...
142 my $len_element = keys %{ $element };
143 if( $len_element == 0 ) {
144 # and this hash is empty, then substitute the xml_content
145 # with an empty string in list
146 $hash->{$xml_tag} = [ "none" ];
147 }
148 }
149 }
150 }
151 };
152 if( $@ ) {
153 $hash = undef;
154 }
156 return $hash;
157 }
160 #=== FUNCTION ================================================================
161 # NAME: add_content2xml_hash
162 # PARAMETERS: xml_ref - ref - reference to a hash from function create_xml_hash
163 # element - string - key for the hash
164 # content - string - value for the hash
165 # RETURNS: nothing
166 # DESCRIPTION: add key-value pair to xml_ref, if key alread exists,
167 # then append value to list
168 #===============================================================================
169 sub add_content2xml_hash {
170 my ($xml_ref, $element, $content) = @_;
171 if(not exists $$xml_ref{$element} ) {
172 $$xml_ref{$element} = [];
173 }
174 my $tmp = $$xml_ref{$element};
175 push(@$tmp, $content);
176 return;
177 }
180 sub get_time {
181 my ($seconds, $minutes, $hours, $monthday, $month,
182 $year, $weekday, $yearday, $sommertime) = localtime(time);
183 $hours = $hours < 10 ? $hours = "0".$hours : $hours;
184 $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
185 $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
186 $month+=1;
187 $month = $month < 10 ? $month = "0".$month : $month;
188 $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
189 $year+=1900;
190 return "$year$month$monthday$hours$minutes$seconds";
192 }
195 #=== FUNCTION ================================================================
196 # NAME: build_msg
197 # DESCRIPTION: Send a message to a destination
198 # PARAMETERS: [header] Name of the header
199 # [from] sender ip
200 # [to] recipient ip
201 # [data] Hash containing additional attributes for the xml
202 # package
203 # RETURNS: nothing
204 #===============================================================================
205 sub build_msg ($$$$) {
206 my ($header, $from, $to, $data) = @_;
208 # data is of form, i.e.
209 # %data= ('ip' => $address, 'mac' => $mac);
211 my $out_hash = &create_xml_hash($header, $from, $to);
213 while ( my ($key, $value) = each(%$data) ) {
214 if(ref($value) eq 'ARRAY'){
215 map(&add_content2xml_hash($out_hash, $key, $_), @$value);
216 } else {
217 &add_content2xml_hash($out_hash, $key, $value);
218 }
219 }
220 my $out_msg = &create_xml_string($out_hash);
221 return $out_msg;
222 }
225 sub db_res2xml {
226 my ($db_res) = @_ ;
227 my $xml = "";
229 my $len_db_res= keys %{$db_res};
230 for( my $i= 1; $i<= $len_db_res; $i++ ) {
231 $xml .= "\n<answer$i>";
232 my $hash= $db_res->{$i};
233 while ( my ($column_name, $column_value) = each %{$hash} ) {
234 $xml .= "<$column_name>";
235 my $xml_content;
236 if( $column_name eq "xmlmessage" ) {
237 $xml_content = &encode_base64($column_value);
238 } else {
239 $xml_content = $column_value;
240 }
241 $xml .= $xml_content;
242 $xml .= "</$column_name>";
243 }
244 $xml .= "</answer$i>";
246 }
248 return $xml;
249 }
252 sub db_res2si_msg {
253 my ($db_res, $header, $target, $source) = @_;
255 my $si_msg = "<xml>";
256 $si_msg .= "<header>$header</header>";
257 $si_msg .= "<source>$source</source>";
258 $si_msg .= "<target>$target</target>";
259 $si_msg .= &db_res2xml;
260 $si_msg .= "</xml>";
261 }
264 sub get_where_statement {
265 my ($msg, $msg_hash) = @_;
266 my $error= 0;
268 my $clause_str= "";
269 if( (not exists $msg_hash->{'where'}) || (not exists @{$msg_hash->{'where'}}[0]->{'clause'}) ) {
270 $error++;
271 }
273 if( $error == 0 ) {
274 my @clause_l;
275 my @where = @{@{$msg_hash->{'where'}}[0]->{'clause'}};
276 foreach my $clause (@where) {
277 my $connector = $clause->{'connector'}[0];
278 if( not defined $connector ) { $connector = "AND"; }
279 $connector = uc($connector);
280 delete($clause->{'connector'});
282 my @phrase_l ;
283 foreach my $phrase (@{$clause->{'phrase'}}) {
284 my $operator = "=";
285 if( exists $phrase->{'operator'} ) {
286 my $op = $op_hash->{$phrase->{'operator'}[0]};
287 if( not defined $op ) {
288 &main::daemon_log("ERROR: Can not translate operator '$operator' in where-".
289 "statement to sql valid syntax. Please use 'eq', ".
290 "'ne', 'ge', 'gt', 'le', 'lt' in xml message\n", 1);
291 &main::daemon_log($msg, 8);
292 $op = "=";
293 }
294 $operator = $op;
295 delete($phrase->{'operator'});
296 }
298 my @xml_tags = keys %{$phrase};
299 my $tag = $xml_tags[0];
300 my $val = $phrase->{$tag}[0];
301 if( ref($val) eq "HASH" ) { next; } # empty xml-tags should not appear in where statement
303 # integer columns do not have to have single quotes besides the value
304 if ($tag eq "id") {
305 push(@phrase_l, "$tag$operator$val");
306 } else {
307 push(@phrase_l, "$tag$operator'$val'");
308 }
309 }
311 if (not 0 == @phrase_l) {
312 my $clause_str .= join(" $connector ", @phrase_l);
313 push(@clause_l, "($clause_str)");
314 }
315 }
317 if( not 0 == @clause_l ) {
318 $clause_str = join(" AND ", @clause_l);
319 $clause_str = "WHERE ($clause_str) ";
320 }
321 }
323 return $clause_str;
324 }
326 sub get_select_statement {
327 my ($msg, $msg_hash)= @_;
328 my $select = "*";
329 if( exists $msg_hash->{'select'} ) {
330 my $select_l = \@{$msg_hash->{'select'}};
331 $select = join(', ', @{$select_l});
332 }
333 return $select;
334 }
337 sub get_update_statement {
338 my ($msg, $msg_hash) = @_;
339 my $error= 0;
340 my $update_str= "";
341 my @update_l;
343 if( not exists $msg_hash->{'update'} ) { $error++; };
345 if( $error == 0 ) {
346 my $update= @{$msg_hash->{'update'}}[0];
347 while( my ($tag, $val) = each %{$update} ) {
348 my $val= @{$update->{$tag}}[0];
349 push(@update_l, "$tag='$val'");
350 }
351 if( 0 == @update_l ) { $error++; };
352 }
354 if( $error == 0 ) {
355 $update_str= join(', ', @update_l);
356 $update_str= "SET $update_str ";
357 }
359 return $update_str;
360 }
362 sub get_limit_statement {
363 my ($msg, $msg_hash)= @_;
364 my $error= 0;
365 my $limit_str = "";
366 my ($from, $to);
368 if( not exists $msg_hash->{'limit'} ) { $error++; };
370 if( $error == 0 ) {
371 eval {
372 my $limit= @{$msg_hash->{'limit'}}[0];
373 $from= @{$limit->{'from'}}[0];
374 $to= @{$limit->{'to'}}[0];
375 };
376 if( $@ ) {
377 $error++;
378 }
379 }
381 if( $error == 0 ) {
382 $limit_str= "LIMIT $from, $to";
383 }
385 return $limit_str;
386 }
388 sub get_orderby_statement {
389 my ($msg, $msg_hash)= @_;
390 my $error= 0;
391 my $order_str= "";
392 my $order;
394 if( not exists $msg_hash->{'orderby'} ) { $error++; };
396 if( $error == 0) {
397 eval {
398 $order= @{$msg_hash->{'orderby'}}[0];
399 };
400 if( $@ ) {
401 $error++;
402 }
403 }
405 if( $error == 0 ) {
406 $order_str= "ORDER BY $order";
407 }
409 return $order_str;
410 }
412 sub get_dns_domains() {
413 my $line;
414 my @searches;
415 open(RESOLV, "</etc/resolv.conf") or return @searches;
416 while(<RESOLV>){
417 $line= $_;
418 chomp $line;
419 $line =~ s/^\s+//;
420 $line =~ s/\s+$//;
421 $line =~ s/\s+/ /;
422 if ($line =~ /^domain (.*)$/ ){
423 push(@searches, $1);
424 } elsif ($line =~ /^search (.*)$/ ){
425 push(@searches, split(/ /, $1));
426 }
427 }
428 close(RESOLV);
430 my %tmp = map { $_ => 1 } @searches;
431 @searches = sort keys %tmp;
433 return @searches;
434 }
437 sub get_server_addresses {
438 my $domain= shift;
439 my @result;
440 my $error_string;
442 my $error = 0;
443 my $res = Net::DNS::Resolver->new;
444 my $query = $res->send("_gosa-si._tcp.".$domain, "SRV");
445 my @hits;
447 if ($query) {
448 foreach my $rr ($query->answer) {
449 push(@hits, $rr->target.":".$rr->port);
450 }
451 }
452 else {
453 $error_string = "determination of '_gosa-si._tcp' server in domain '$domain' failed: ".$res->errorstring;
454 $error++;
455 }
457 if( $error == 0 ) {
458 foreach my $hit (@hits) {
459 my ($hit_name, $hit_port) = split(/:/, $hit);
460 chomp($hit_name);
461 chomp($hit_port);
463 my $address_query = $res->send($hit_name);
464 if( 1 == length($address_query->answer) ) {
465 foreach my $rr ($address_query->answer) {
466 push(@result, $rr->address.":".$hit_port);
467 }
468 }
469 }
470 }
472 return \@result, $error_string;
473 }
476 sub get_logged_in_users {
477 my $result = qx(/usr/bin/w -hs);
478 my @res_lines;
480 if( defined $result ) {
481 chomp($result);
482 @res_lines = split("\n", $result);
483 }
485 my @logged_in_user_list;
486 foreach my $line (@res_lines) {
487 chomp($line);
488 my @line_parts = split(/\s+/, $line);
489 push(@logged_in_user_list, $line_parts[0]);
490 }
492 return @logged_in_user_list;
494 }
497 sub import_events {
498 my ($event_dir) = @_;
499 my $event_hash;
500 my $error = 0;
501 my @result = ();
502 if (not -e $event_dir) {
503 $error++;
504 push(@result, "cannot find directory or directory is not readable: $event_dir");
505 }
507 my $DIR;
508 if ($error == 0) {
509 opendir ($DIR, $event_dir) or do {
510 $error++;
511 push(@result, "cannot open directory '$event_dir' for reading: $!\n");
512 }
513 }
515 if ($error == 0) {
516 while (defined (my $event = readdir ($DIR))) {
517 if( $event eq "." || $event eq ".." ) { next; }
519 # try to import event module
520 eval{ require $event; };
521 if( $@ ) {
522 $error++;
523 #push(@result, "import of event module '$event' failed: $@");
524 #next;
526 &main::daemon_log("ERROR: Import of event module '$event' failed: $@",1);
527 exit(1);
528 }
530 # fetch all single events
531 $event =~ /(\S*?).pm$/;
532 my $event_module = $1;
533 my $events_l = eval( $1."::get_events()") ;
534 foreach my $event_name (@{$events_l}) {
535 $event_hash->{$event_module}->{$event_name} = "";
536 }
537 my $events_string = join( ", ", @{$events_l});
538 push(@result, "import of event module '$event' succeed: $events_string");
539 }
541 close $DIR;
542 }
544 return ($error, \@result, $event_hash);
546 }
549 #=== FUNCTION ================================================================
550 # NAME: get_ip
551 # PARAMETERS: interface name (i.e. eth0)
552 # RETURNS: (ip address)
553 # DESCRIPTION: Uses ioctl to get ip address directly from system.
554 #===============================================================================
555 sub get_ip {
556 my $ifreq= shift;
557 my $result= "";
558 my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list
559 my $proto= getprotobyname('ip');
561 socket SOCKET, PF_INET, SOCK_DGRAM, $proto
562 or die "socket: $!";
564 if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) {
565 my ($if, $sin) = unpack 'a16 a16', $ifreq;
566 my ($port, $addr) = sockaddr_in $sin;
567 my $ip = inet_ntoa $addr;
569 if ($ip && length($ip) > 0) {
570 $result = $ip;
571 }
572 }
574 return $result;
575 }
578 #=== FUNCTION ================================================================
579 # NAME: get_interface_for_ip
580 # PARAMETERS: ip address (i.e. 192.168.0.1)
581 # RETURNS: array: list of interfaces if ip=0.0.0.0, matching interface if found, undef else
582 # DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
583 #===============================================================================
584 sub get_interface_for_ip {
585 my $result;
586 my $ip= shift;
587 if ($ip && length($ip) > 0) {
588 my @ifs= &get_interfaces();
589 if($ip eq "0.0.0.0") {
590 $result = "all";
591 } else {
592 foreach (@ifs) {
593 my $if=$_;
594 if(&get_ip($if) eq $ip) {
595 $result = $if;
596 }
597 }
598 }
599 }
600 return $result;
601 }
603 #=== FUNCTION ================================================================
604 # NAME: get_interfaces
605 # PARAMETERS: none
606 # RETURNS: (list of interfaces)
607 # DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
608 #===============================================================================
609 sub get_interfaces {
610 my @result;
611 my $PROC_NET_DEV= ('/proc/net/dev');
613 open(PROC_NET_DEV, "<$PROC_NET_DEV")
614 or die "Could not open $PROC_NET_DEV";
616 my @ifs = <PROC_NET_DEV>;
618 close(PROC_NET_DEV);
620 # Eat first two line
621 shift @ifs;
622 shift @ifs;
624 chomp @ifs;
625 foreach my $line(@ifs) {
626 my $if= (split /:/, $line)[0];
627 $if =~ s/^\s+//;
628 push @result, $if;
629 }
631 return @result;
632 }
634 sub get_local_ip_for_remote_ip {
635 my $remote_ip= shift;
636 my $result="0.0.0.0";
638 if($remote_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) {
639 if($remote_ip eq "127.0.0.1") {
640 $result = "127.0.0.1";
641 } else {
642 my $PROC_NET_ROUTE= ('/proc/net/route');
644 open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE")
645 or die "Could not open $PROC_NET_ROUTE";
647 my @ifs = <PROC_NET_ROUTE>;
649 close(PROC_NET_ROUTE);
651 # Eat header line
652 shift @ifs;
653 chomp @ifs;
654 foreach my $line(@ifs) {
655 my ($Iface,$Destination,$Gateway,$Flags,$RefCnt,$Use,$Metric,$Mask,$MTU,$Window,$IRTT)=split(/\s/, $line);
656 my $destination;
657 my $mask;
658 my ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Destination);
659 $destination= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
660 ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Mask);
661 $mask= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
662 if(new NetAddr::IP($remote_ip)->within(new NetAddr::IP($destination, $mask))) {
663 # destination matches route, save mac and exit
664 $result= &get_ip($Iface);
665 last;
666 }
667 }
668 }
669 } else {
670 daemon_log("0 WARNING: get_local_ip_for_remote_ip() was called with a non-ip parameter: '$remote_ip'", 1);
671 }
672 return $result;
673 }
676 sub get_mac_for_interface {
677 my $ifreq= shift;
678 my $result;
679 if ($ifreq && length($ifreq) > 0) {
680 if($ifreq eq "all") {
681 $result = "00:00:00:00:00:00";
682 } else {
683 my $SIOCGIFHWADDR= 0x8927; # man 2 ioctl_list
685 # A configured MAC Address should always override a guessed value
686 if ($main::server_mac_address and length($main::server_mac_address) > 0) {
687 $result= $main::server_mac_address;
688 }
690 socket SOCKET, PF_INET, SOCK_DGRAM, getprotobyname('ip')
691 or die "socket: $!";
693 if(ioctl SOCKET, $SIOCGIFHWADDR, $ifreq) {
694 my ($if, $mac)= unpack 'h36 H12', $ifreq;
696 if (length($mac) > 0) {
697 $mac=~ m/^([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$/;
698 $mac= sprintf("%s:%s:%s:%s:%s:%s", $1, $2, $3, $4, $5, $6);
699 $result = $mac;
700 }
701 }
702 }
703 }
704 return $result;
705 }
708 #=== FUNCTION ================================================================
709 # NAME: is_local
710 # PARAMETERS: Server Address
711 # RETURNS: true if Server Address is on this host, false otherwise
712 # DESCRIPTION: Checks all interface addresses, stops on first match
713 #===============================================================================
714 sub is_local {
715 my $server_address = shift || "";
716 my $result = 0;
718 my $server_ip = $1 if $server_address =~ /^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):\d{1,6}$/;
720 if(defined($server_ip) && length($server_ip) > 0) {
721 foreach my $interface(&get_interfaces()) {
722 my $ip_address= &get_ip($interface);
723 if($ip_address eq $server_ip) {
724 $result = 1;
725 last;
726 }
727 }
728 }
730 return $result;
731 }
734 #=== FUNCTION ================================================================
735 # NAME: run_as
736 # PARAMETERS: uid, command
737 # RETURNS: hash with keys 'resultCode' = resultCode of command and
738 # 'output' = program output
739 # DESCRIPTION: Runs command as uid using the sudo utility.
740 #===============================================================================
741 sub run_as {
742 my ($uid, $command) = @_;
743 my $sudo_cmd = `which sudo`;
744 chomp($sudo_cmd);
745 if(! -x $sudo_cmd) {
746 &main::daemon_log("ERROR: The sudo utility is not available! Please fix this!");
747 }
748 my $cmd_line= "$sudo_cmd su - $uid -c '$command'";
749 open(PIPE, "$cmd_line |");
750 my $result = {'resultCode' => $?};
751 $result->{'command'} = $cmd_line;
752 push @{$result->{'output'}}, <PIPE>;
753 return $result;
754 }
757 #=== FUNCTION ================================================================
758 # NAME: inform_other_si_server
759 # PARAMETERS: message
760 # RETURNS: nothing
761 # DESCRIPTION: Sends message to all other SI-server found in known_server_db.
762 #===============================================================================
763 sub inform_all_other_si_server {
764 my ($msg) = @_;
766 # determine all other si-server from known_server_db
767 my $sql_statement= "SELECT * FROM $main::known_server_tn";
768 my $res = $main::known_server_db->select_dbentry( $sql_statement );
770 while( my ($hit_num, $hit) = each %$res ) {
771 my $act_target_address = $hit->{hostname};
772 my $act_target_key = $hit->{hostkey};
774 # determine the source address corresponding to the actual target address
775 my ($act_target_ip, $act_target_port) = split(/:/, $act_target_address);
776 my $act_source_address = &main::get_local_ip_for_remote_ip($act_target_ip).":$act_target_port";
778 # fill into message the correct target and source addresses
779 my $act_msg = $msg;
780 $act_msg =~ s/<target>\w*<\/target>/<target>$act_target_address<\/target>/g;
781 $act_msg =~ s/<source>\w*<\/source>/<source>$act_source_address<\/source>/g;
783 # send message to the target
784 &main::send_msg_to_target($act_msg, $act_target_address, $act_target_key, "foreign_job_updates" , "J");
785 }
787 return;
788 }
791 sub read_configfile {
792 my ($cfg_file, %cfg_defaults) = @_ ;
793 my $cfg;
794 if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
795 if( -r $cfg_file ) {
796 $cfg = Config::IniFiles->new( -file => $cfg_file );
797 } else {
798 print STDERR "Couldn't read config file!";
799 }
800 } else {
801 $cfg = Config::IniFiles->new() ;
802 }
803 foreach my $section (keys %cfg_defaults) {
804 foreach my $param (keys %{$cfg_defaults{ $section }}) {
805 my $pinfo = $cfg_defaults{ $section }{ $param };
806 ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] );
807 }
808 }
809 }
812 sub check_opsi_res {
813 my $res= shift;
815 if($res) {
816 if ($res->is_error) {
817 my $error_string;
818 if (ref $res->error_message eq "HASH") {
819 $error_string = $res->error_message->{'message'};
820 } else {
821 $error_string = $res->error_message;
822 }
823 return 1, $error_string;
824 }
825 } else {
826 return 1, $main::opsi_client->status_line;
827 }
828 return 0;
829 }
832 1;