1 #!/usr/bin/perl
2 #===============================================================================
3 #
4 # FILE: gosa-sd
5 #
6 # USAGE: ./gosa-sd
7 #
8 # DESCRIPTION:
9 #
10 # OPTIONS: ---
11 # REQUIREMENTS: libconfig-inifiles-perl libcrypt-rijndael-perl libxml-simple-perl
12 # libdata-dumper-simple-perl libdbd-sqlite3-perl libnet-ldap-perl
13 # libpoe-perl
14 # BUGS: ---
15 # NOTES:
16 # AUTHOR: (Andreas Rettenberger), <rettenberger@gonicus.de>
17 # COMPANY:
18 # VERSION: 1.0
19 # CREATED: 12.09.2007 08:54:41 CEST
20 # REVISION: ---
21 #===============================================================================
23 use strict;
24 use warnings;
25 use Getopt::Long;
26 use Config::IniFiles;
27 use POSIX;
28 use Time::HiRes qw( gettimeofday );
30 use Fcntl;
31 use IO::Socket::INET;
32 use IO::Handle;
33 use IO::Select;
34 use Symbol qw(qualify_to_ref);
35 use Crypt::Rijndael;
36 use MIME::Base64;
37 use Digest::MD5 qw(md5 md5_hex md5_base64);
38 use XML::Simple;
39 use Data::Dumper;
40 use Sys::Syslog qw( :DEFAULT setlogsock);
41 use Cwd;
42 use File::Spec;
43 use GOSA::GosaSupportDaemon;
44 use GOSA::DBsqlite;
45 use POE qw(Component::Server::TCP);
47 my $modules_path = "/usr/lib/gosa-si/modules";
48 use lib "/usr/lib/gosa-si/modules";
50 my (%cfg_defaults, $foreground, $verbose, $ping_timeout);
51 my ($bus, $msg_to_bus, $bus_cipher);
52 my ($server, $server_mac_address, $server_events);
53 my ($gosa_server, $job_queue_timeout, $job_queue_table_name, $job_queue_file_name);
54 my ($known_modules, $known_clients_file_name, $known_server_file_name);
55 my ($max_clients);
56 my ($pid_file, $procid, $pid, $log_file);
57 my (%free_child, %busy_child, $child_max, $child_min, %child_alive_time, $child_timeout);
58 my ($arp_activ, $arp_fifo, $arp_fifo_path);
60 # variables declared in config file are always set to 'our'
61 our (%cfg_defaults, $log_file, $pid_file,
62 $bus_activ, $bus_passwd, $bus_ip, $bus_port,
63 $server_activ, $server_ip, $server_port, $server_passwd, $max_clients,
64 $arp_activ, $arp_fifo_path,
65 $gosa_activ, $gosa_passwd, $gosa_ip, $gosa_port, $gosa_timeout,
66 );
68 # additional variable which should be globaly accessable
69 our $xml;
70 our $server_address;
71 our $bus_address;
72 our $gosa_address;
73 our $no_bus;
74 our $no_arp;
75 our $verbose;
76 our $forground;
77 our $cfg_file;
79 # specifies the verbosity of the daemon_log
80 $verbose = 0 ;
82 # if foreground is not null, script will be not forked to background
83 $foreground = 0 ;
85 # specifies the timeout seconds while checking the online status of a registrating client
86 $ping_timeout = 5;
88 $no_bus = 0;
90 $no_arp = 0;
92 # name of table for storing gosa jobs
93 our $job_queue_table_name = 'jobs';
94 our $job_db;
96 # holds all other gosa-sd as well as the gosa-sd-bus
97 our $known_server_db;
99 # holds all registrated clients
100 our $known_clients_db;
102 %cfg_defaults =
103 ("general" =>
104 {"log_file" => [\$log_file, "/var/run/".$0.".log"],
105 "pid_file" => [\$pid_file, "/var/run/".$0.".pid"],
106 "child_max" => [\$child_max, 10],
107 "child_min" => [\$child_min, 3],
108 "child_timeout" => [\$child_timeout, 180],
109 "job_queue_timeout" => [\$job_queue_timeout, undef],
110 "job_queue_file_name" => [\$job_queue_file_name, '/var/lib/gosa-si/jobs.db'],
111 "known_clients_file_name" => [\$known_clients_file_name, '/var/lib/gosa-si/known_clients.db' ],
112 "known_server_file_name" => [\$known_server_file_name, '/var/lib/gosa-si/known_server.db'],
113 },
114 "bus" =>
115 {"bus_activ" => [\$bus_activ, "on"],
116 "bus_passwd" => [\$bus_passwd, ""],
117 "bus_ip" => [\$bus_ip, "0.0.0.0"],
118 "bus_port" => [\$bus_port, "20080"],
119 },
120 "server" =>
121 {"server_activ" => [\$server_activ, "on"],
122 "server_ip" => [\$server_ip, "0.0.0.0"],
123 "server_port" => [\$server_port, "20081"],
124 "server_passwd" => [\$server_passwd, ""],
125 "max_clients" => [\$max_clients, 100],
126 },
127 "arp" =>
128 {"arp_activ" => [\$arp_activ, "on"],
129 "arp_fifo_path" => [\$arp_fifo_path, "/var/run/gosa-si/arp-notify"],
130 },
131 "gosa" =>
132 {"gosa_activ" => [\$gosa_activ, "on"],
133 "gosa_ip" => [\$gosa_ip, "0.0.0.0"],
134 "gosa_port" => [\$gosa_port, "20082"],
135 "gosa_passwd" => [\$gosa_passwd, "none"],
136 },
137 );
140 #=== FUNCTION ================================================================
141 # NAME: usage
142 # PARAMETERS: nothing
143 # RETURNS: nothing
144 # DESCRIPTION: print out usage text to STDERR
145 #===============================================================================
146 sub usage {
147 print STDERR << "EOF" ;
148 usage: $0 [-hvf] [-c config]
150 -h : this (help) message
151 -c <file> : config file
152 -f : foreground, process will not be forked to background
153 -v : be verbose (multiple to increase verbosity)
154 -no-bus : starts $0 without connection to bus
155 -no-arp : starts $0 without connection to arp module
157 EOF
158 print "\n" ;
159 }
162 #=== FUNCTION ================================================================
163 # NAME: read_configfile
164 # PARAMETERS: cfg_file - string -
165 # RETURNS: nothing
166 # DESCRIPTION: read cfg_file and set variables
167 #===============================================================================
168 sub read_configfile {
169 my $cfg;
170 if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
171 if( -r $cfg_file ) {
172 $cfg = Config::IniFiles->new( -file => $cfg_file );
173 } else {
174 print STDERR "Couldn't read config file!\n";
175 }
176 } else {
177 $cfg = Config::IniFiles->new() ;
178 }
179 foreach my $section (keys %cfg_defaults) {
180 foreach my $param (keys %{$cfg_defaults{ $section }}) {
181 my $pinfo = $cfg_defaults{ $section }{ $param };
182 ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] );
183 }
184 }
185 }
188 #=== FUNCTION ================================================================
189 # NAME: logging
190 # PARAMETERS: level - string - default 'info'
191 # msg - string -
192 # facility - string - default 'LOG_DAEMON'
193 # RETURNS: nothing
194 # DESCRIPTION: function for logging
195 #===============================================================================
196 sub daemon_log {
197 # log into log_file
198 my( $msg, $level ) = @_;
199 if(not defined $msg) { return }
200 if(not defined $level) { $level = 1 }
201 if(defined $log_file){
202 open(LOG_HANDLE, ">>$log_file");
203 if(not defined open( LOG_HANDLE, ">>$log_file" )) {
204 print STDERR "cannot open $log_file: $!";
205 return }
206 chomp($msg);
207 if($level <= $verbose){
208 my ($seconds, $minutes, $hours, $monthday, $month,
209 $year, $weekday, $yearday, $sommertime) = localtime(time);
210 $hours = $hours < 10 ? $hours = "0".$hours : $hours;
211 $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
212 $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
213 my @monthnames = ("Jan", "Feb", "Mar", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
214 $month = $monthnames[$month];
215 $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
216 $year+=1900;
217 my $name = $0;
218 $name =~ s/\.\///;
220 my $log_msg = "$month $monthday $hours:$minutes:$seconds $name $msg\n";
221 print LOG_HANDLE $log_msg;
222 if( $foreground ) {
223 print STDERR $log_msg;
224 }
225 }
226 close( LOG_HANDLE );
227 }
228 #log into syslog
229 # my ($msg, $level, $facility) = @_;
230 # if(not defined $msg) {return}
231 # if(not defined $level) {$level = "info"}
232 # if(not defined $facility) {$facility = "LOG_DAEMON"}
233 # openlog($0, "pid,cons,", $facility);
234 # syslog($level, $msg);
235 # closelog;
236 # return;
237 }
240 #=== FUNCTION ================================================================
241 # NAME: check_cmdline_param
242 # PARAMETERS: nothing
243 # RETURNS: nothing
244 # DESCRIPTION: validates commandline parameter
245 #===============================================================================
246 sub check_cmdline_param () {
247 my $err_config;
248 my $err_counter = 0;
249 if(not defined($cfg_file)) {
250 $cfg_file = "/etc/gosa-si/server.conf";
251 if(! -r $cfg_file) {
252 $err_config = "please specify a config file";
253 $err_counter += 1;
254 }
255 }
256 if( $err_counter > 0 ) {
257 &usage( "", 1 );
258 if( defined( $err_config)) { print STDERR "$err_config\n"}
259 print STDERR "\n";
260 exit( -1 );
261 }
262 }
265 #=== FUNCTION ================================================================
266 # NAME: check_pid
267 # PARAMETERS: nothing
268 # RETURNS: nothing
269 # DESCRIPTION: handels pid processing
270 #===============================================================================
271 sub check_pid {
272 $pid = -1;
273 # Check, if we are already running
274 if( open(LOCK_FILE, "<$pid_file") ) {
275 $pid = <LOCK_FILE>;
276 if( defined $pid ) {
277 chomp( $pid );
278 if( -f "/proc/$pid/stat" ) {
279 my($stat) = `cat /proc/$pid/stat` =~ m/$pid \((.+)\).*/;
280 if( $0 eq $stat ) {
281 close( LOCK_FILE );
282 exit -1;
283 }
284 }
285 }
286 close( LOCK_FILE );
287 unlink( $pid_file );
288 }
290 # create a syslog msg if it is not to possible to open PID file
291 if (not sysopen(LOCK_FILE, $pid_file, O_WRONLY|O_CREAT|O_EXCL, 0644)) {
292 my($msg) = "Couldn't obtain lockfile '$pid_file' ";
293 if (open(LOCK_FILE, '<', $pid_file)
294 && ($pid = <LOCK_FILE>))
295 {
296 chomp($pid);
297 $msg .= "(PID $pid)\n";
298 } else {
299 $msg .= "(unable to read PID)\n";
300 }
301 if( ! ($foreground) ) {
302 openlog( $0, "cons,pid", "daemon" );
303 syslog( "warning", $msg );
304 closelog();
305 }
306 else {
307 print( STDERR " $msg " );
308 }
309 exit( -1 );
310 }
311 }
313 #=== FUNCTION ================================================================
314 # NAME: import_modules
315 # PARAMETERS: module_path - string - abs. path to the directory the modules
316 # are stored
317 # RETURNS: nothing
318 # DESCRIPTION: each file in module_path which ends with '.pm' is imported by
319 # "require 'file';"
320 #===============================================================================
321 sub import_modules {
322 daemon_log(" ", 1);
324 if (not -e $modules_path) {
325 daemon_log("ERROR: cannot find directory or directory is not readable: $modules_path", 1);
326 }
328 opendir (DIR, $modules_path) or die "ERROR while loading modules from directory $modules_path : $!\n";
329 while (defined (my $file = readdir (DIR))) {
330 if (not $file =~ /(\S*?).pm$/) {
331 next;
332 }
333 eval { require $file; };
334 if ($@) {
335 daemon_log("ERROR: gosa-si-server could not load module $file", 1);
336 daemon_log("$@", 5);
337 } else {
338 my $mod_name = $1;
339 my $info = eval($mod_name.'::get_module_info()');
340 my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info};
341 $known_modules->{$mod_name} = $info;
343 daemon_log("module $mod_name loaded", 1);
344 }
345 }
347 # for debugging
348 #while ( my ($module, $tag_hash) = each(%$known_modules)) {
349 # print "\tmodule: $module"."\n";
350 # print "\ttags: ".join(", ", keys(%$tag_hash))."\n";
351 #}
352 close (DIR);
353 }
356 #=== FUNCTION ================================================================
357 # NAME: sig_int_handler
358 # PARAMETERS: signal - string - signal arose from system
359 # RETURNS: noting
360 # DESCRIPTION: handels tasks to be done befor signal becomes active
361 #===============================================================================
362 sub sig_int_handler {
363 my ($signal) = @_;
365 daemon_log("shutting down gosa-si-server", 1);
366 exit(1);
367 }
368 $SIG{INT} = \&sig_int_handler;
371 #=== FUNCTION ================================================================
372 # NAME: create_known_client
373 # PARAMETERS: hostname - string - key for the hash known_clients
374 # RETURNS: nothing
375 # DESCRIPTION: creates a dummy entry for hostname in known_clients
376 #===============================================================================
377 sub create_known_client {
378 my ($hostname) = @_;
380 my $entry = { table=>'known_clients',
381 hostname=>$hostname,
382 status=>'none',
383 hostkey=>'none',
384 timestamp=>'none',
385 macaddress=>'none',
386 events=>'none',
387 };
388 my $res = $known_clients_db->add_dbentry($entry);
389 if ($res > 0) {
390 daemon_log("ERROR: cannot add entry to known_clients.db: $res", 1);
391 }
393 return;
394 }
396 #==== MAIN = main ==============================================================
397 # parse commandline options
398 Getopt::Long::Configure( "bundling" );
399 GetOptions("h|help" => \&usage,
400 "c|config=s" => \$cfg_file,
401 "f|foreground" => \$foreground,
402 "v|verbose+" => \$verbose,
403 "no-bus+" => \$no_bus,
404 "no-arp+" => \$no_arp,
405 );
407 # read and set config parameters
408 &check_cmdline_param ;
409 &read_configfile;
410 &check_pid;
412 $SIG{CHLD} = 'IGNORE';
414 # forward error messages to logfile
415 if( ! $foreground ) {
416 open(STDERR, '>>', $log_file);
417 open(STDOUT, '>>', $log_file);
418 }
420 # Just fork, if we are not in foreground mode
421 if( ! $foreground ) {
422 chdir '/' or die "Can't chdir to /: $!";
423 $pid = fork;
424 setsid or die "Can't start a new session: $!";
425 umask 0;
426 } else {
427 $pid = $$;
428 }
430 # Do something useful - put our PID into the pid_file
431 if( 0 != $pid ) {
432 open( LOCK_FILE, ">$pid_file" );
433 print LOCK_FILE "$pid\n";
434 close( LOCK_FILE );
435 if( !$foreground ) {
436 exit( 0 )
437 };
438 }
440 daemon_log(" ", 1);
441 daemon_log("$0 started!", 1);
443 # delete old DBsqlite lock files
444 system('rm -f /tmp/gosa_si_lock*');
446 # connect to gosa-si job queue
447 my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
448 $job_db = GOSA::DBsqlite->new($job_queue_file_name);
449 $job_db->create_table('jobs', \@job_col_names);
451 # connect to known_clients_db
452 my @clients_col_names = ('hostname', 'status', 'hostkey', 'timestamp', 'macaddress', 'events');
453 $known_clients_db = GOSA::DBsqlite->new($known_clients_file_name);
454 $known_clients_db->create_table('known_clients', \@clients_col_names);
456 # connect to known_server_db
457 my @server_col_names = ('hostname', 'status', 'hostkey', 'timestamp');
458 $known_server_db = GOSA::DBsqlite->new($known_server_file_name);
459 $known_server_db->create_table('known_server', \@server_col_names);
461 # import all modules
462 &import_modules;
464 # check wether all modules are gosa-si valid passwd check
466 # create reading and writing vectors
467 my $rbits = my $wbits = my $ebits = "";
469 # add all module inputs to listening vector
470 # while( my ($mod_name, $info) = each %$known_modules ) {
471 # my ($input_address, $input_key, $input, $input_activ, $input_type) = @{$info};
472 # vec($rbits, fileno $input, 1) = 1;
473 #
474 # }
477 ## start arp fifo
478 #if ($no_arp > 0) {
479 # $arp_activ = "off";
480 #}
481 #my $my_fifo;
482 #if($arp_activ eq "on") {
483 # daemon_log(" ", 1);
484 # $my_fifo = &open_fifo($arp_fifo_path);
485 # if($my_fifo == 0) { die "fifo file disappeared\n" }
486 # sysopen($arp_fifo, $arp_fifo_path, O_RDWR) or die "can't read from $arp_fifo: $!" ;
487 #
488 # vec($rbits, fileno $arp_fifo, 1) = 1;
489 #}
490 #
492 ###################################
493 ##everything ready, okay, lets start
494 ###################################
495 #while(1) {
496 #
497 # # add all handles from the childs
498 # while ( my ($pid, $child_hash) = each %busy_child ) {
499 #
500 # # check whether process still exists
501 # my $exitus_pid = waitpid($pid, WNOHANG);
502 # if($exitus_pid != 0) {
503 # delete $busy_child{$pid};
504 # next;
505 # }
506 #
507 # # add child fhd to the listener
508 # my $fhd = $$child_hash{'pipe_rd'};
509 # vec($rbits, fileno $fhd, 1) = 1;
510 # }
511 #
512 # my ($rout, $wout);
513 # my $nf = select($rout=$rbits, $wout=$wbits, undef, $job_queue_timeout);
514 #
515 # # error handling
516 # if($nf < 0 ) {
517 # }
518 #
519 #
520 ## if($arp_activ eq "on" && vec($rout, fileno $arp_fifo, 1)) {
521 ## my $in_msg = <$arp_fifo>;
522 ## chomp($in_msg);
523 ## print "arp_activ: msg: $in_msg\n";
524 ## my $act_passwd = $known_daemons->{$bus_address}->{passwd};
525 ## print "arp_activ: arp_passwd: $act_passwd\n";
526 ##
527 ## my $in_msg_hash = $xml->XMLin($in_msg, ForceArray=>1);
528 ##
529 ## my $target = &get_content_from_xml_hash($in_msg_hash, 'target');
530 ##
531 ## if ($target eq $server_address) {
532 ## print "arp_activ: forward to server\n";
533 ## my $arp_cipher = &create_ciphering($act_passwd);
534 ## my $crypted_msg = &encrypt_msg($in_msg, $arp_cipher);
535 ## &activating_child($crypted_msg, $server_ip);
536 ## } else {
537 ## print "arp_activ: send to bus\n";
538 ## &send_msg_hash2address($in_msg_hash, $bus_address);
539 ## }
540 ## print "\n";
541 ## }
542 #
543 #
544 # # check input fhd of all modules
545 # while ( my ($mod_name, $info) = each %$known_modules) {
546 # my $input_fhd = @{$info}[2];
547 # my $input_activ = @{$info}[3];
548 # if (vec($rout, fileno $input_fhd, 1) && $input_activ eq 'on') {
549 # daemon_log(" ", 1);
550 # my $client = $input_fhd->accept();
551 # my $other_end = getpeername($client);
552 # if(not defined $other_end) {
553 # daemon_log("client cannot be identified: $!");
554 # } else {
555 # my ($port, $iaddr) = unpack_sockaddr_in($other_end);
556 # my $actual_ip = inet_ntoa($iaddr);
557 # daemon_log("accept client at daemon socket from $actual_ip", 5);
558 # my $in_msg = &read_from_socket($client);
559 # if(defined $in_msg){
560 # chomp($in_msg);
561 # &activating_child($in_msg, $actual_ip, $client);
562 # } else {
563 # daemon_log("cannot read from $actual_ip", 5);
564 # }
565 # }
566 # }
567 # }
568 #
569 # # check all processing childs whether they are finished ('done') or
570 # while ( my ($pid, $child_hash) = each %busy_child ) {
571 # my $fhd = $$child_hash{'pipe_rd'};
572 #
573 # if (vec($rout, fileno $fhd, 1) ) {
574 # daemon_log("process child $pid is ready to read", 5);
575 #
576 # my $in_msg;
577 # while (1) {
578 # my $part_in_msg = <$fhd>;
579 # if( $part_in_msg eq "ENDMESSAGE\n") {
580 # last;
581 # }
582 # $in_msg .= $part_in_msg;
583 # }
584 # chomp($in_msg);
585 #
586 # if (not defined $in_msg) {
587 # next;
588 # } elsif ($in_msg =~ "done") {
589 # daemon_log("process child read: $in_msg", 7);
590 # delete $busy_child{$pid};
591 # $free_child{$pid} = $child_hash;
592 #
593 # } else {
594 # daemon_log("process child read:", 7);
595 # daemon_log("\n$in_msg", 8);
596 # # send computed answer back to connected client
597 # my $act_client = $busy_child{$pid}{client_ref};
598 # print $act_client $in_msg."\n";
599 # delete $busy_child{$pid};
600 # $free_child{$pid} = $child_hash;
601 #
602 # }
603 # }
604 # }
605 #
606 # # check gosa job queue for jobs with executable timestamp
607 # my ($seconds, $minutes, $hours, $monthday, $month,
608 # $year, $weekday, $yearday, $sommertime) = localtime(time);
609 # $hours = $hours < 10 ? $hours = "0".$hours : $hours;
610 # $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes;
611 # $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds;
612 # $month+=1;
613 # $month = $month < 10 ? $month = "0".$month : $month;
614 # $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
615 # $year+=1900;
616 # my $timestamp = "$year$month$monthday$hours$minutes$seconds";
617 #
618 #
619 # my $res = $job_db->select_dbentry( { table=>$job_queue_table_name, status=>'waiting', timestamp=>$timestamp } );
620 #
621 # while( my ($id, $hit) = each %{$res} ) {
622 #
623 # my $jobdb_id = $hit->{id};
624 # my $macaddress = $hit->{macaddress};
625 # my $job_msg_hash = &transform_msg2hash($hit->{xmlmessage});
626 # my $out_msg_hash = $job_msg_hash;
627 # my $res_hash = $known_clients_db->select_dbentry( {table=>'known_clients', macaddress=>$macaddress} );
628 # # expect macaddress is unique!!!!!!
629 # my $target = $res_hash->{1}->{hostname};
630 #
631 # if (not defined $target) {
632 # &daemon_log("ERROR: no host found for mac address: $job_msg_hash->{mac}[0]", 1);
633 # &daemon_log("xml message: $hit->{xmlmessage}", 5);
634 # my $update_hash = { table=>$job_queue_table_name,
635 # update=> [ { status=>['error'], result=>["no host found for mac address"] } ],
636 # where=> [ { id=>[$jobdb_id] } ],
637 # };
638 # my $res = $job_db->update_dbentry($update_hash);
639 #
640 # next;
641 # }
642 #
643 # # add target
644 # &add_content2xml_hash($out_msg_hash, "target", $target);
645 #
646 # # add new header
647 # my $out_header = $job_msg_hash->{header}[0];
648 # $out_header =~ s/job_/gosa_/;
649 # delete $out_msg_hash->{header};
650 # &add_content2xml_hash($out_msg_hash, "header", $out_header);
651 #
652 # # add sqlite_id
653 # &add_content2xml_hash($out_msg_hash, "jobdb_id", $jobdb_id);
654 #
655 # my $out_msg = &create_xml_string($out_msg_hash);
656 #
657 # # encrypt msg as a GosaPackage module
658 # my $cipher = &create_ciphering($gosa_passwd);
659 # my $crypted_out_msg = &encrypt_msg($out_msg, $cipher);
660 #
661 # my $error = &send_msg_hash2address($out_msg_hash, "$gosa_ip:$gosa_port", $gosa_passwd);
662 #
663 # if ($error == 0) {
664 # my $sql = "UPDATE '$job_queue_table_name' SET status='processing', targettag='$target' WHERE id='$jobdb_id'";
665 # my $res = $job_db->exec_statement($sql);
666 # } else {
667 # my $update_hash = { table=>$job_queue_table_name,
668 # update=> [ { status=>'error' } ],
669 # where=> [ { id=>$jobdb_id } ],
670 # };
671 # my $res = $job_db->update_dbentry($update_hash);
672 # }
673 #
674 # }
675 #
676 #
677 #}
679 POE::Component::Server::TCP->new
680 (
681 Port => $server_port,
682 ClientInput => \&client_input,
683 );
685 POE::Kernel->run();
686 exit;
688 sub client_input {
689 my ($heap,$input,$wheel) = @_[HEAP, ARG0, ARG1];
690 ######################################
691 # forward msg to all imported modules
692 no strict "refs";
693 my $answer;
694 my %act_modules = %$known_modules;
695 while( my ($module, $info) = each(%act_modules)) {
696 daemon_log("Processing module ".$module, 3);
697 my $tmp = &{ $module."::process_incoming_msg" }($input.".".$heap->{remote_ip}."\n");
698 if (defined $tmp) {
699 $answer = $tmp;
700 }
701 daemon_log("Got answer from module ".$module.": ".$answer,3);
702 }
703 daemon_log("processing of msg finished", 5);
705 if (defined $answer) {
706 $heap->{client}->put($answer);
707 } else {
708 $heap->{client}->put("done\n");
709 }
710 }