From 33e38b5c7bcdd1a8828f640c055401c6bf3b707b Mon Sep 17 00:00:00 2001 From: rettenbe Date: Mon, 14 Jan 2008 13:49:48 +0000 Subject: [PATCH] no comment git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8325 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/debian/gosa-si-server.init | 4 +- gosa-si/gosa-si-client | 9 ++++ gosa-si/gosa-si-server | 69 +++++++++++++++--------------- gosa-si/modules/DBsqlite.pm | 25 +++++++++-- gosa-si/modules/GosaPackages.pm | 9 ++-- gosa-si/modules/ServerPackages.pm | 1 + gosa-si/tests/client.php | 2 +- 7 files changed, 74 insertions(+), 45 deletions(-) diff --git a/gosa-si/debian/gosa-si-server.init b/gosa-si/debian/gosa-si-server.init index 26fb1cbcf..18e68aefc 100755 --- a/gosa-si/debian/gosa-si-server.init +++ b/gosa-si/debian/gosa-si-server.init @@ -26,12 +26,12 @@ START_BUS=0 start_bus() { - start-stop-daemon --start --quiet --pidfile /var/run/gosa-si-bus.pid --name gosa-si-bus --startas /usr/sbin/gosa-si-bus + start-stop-daemon --start --quiet --pidfile /var/run/gosa-si-bus.pid --name gosa-si-bus --startas /usr/sbin/gosa-si-bus -- } start_server() { - start-stop-daemon --start --quiet --pidfile /var/run/gosa-si-server.pid --name gosa-si-server --startas /usr/sbin/gosa-si-server -- $1 + start-stop-daemon --start --quiet --pidfile /var/run/gosa-si-server.pid --name gosa-si-server --startas /usr/sbin/gosa-si-server -- -vvvvv $1 } diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client index e0143000c..2ee9b4d0d 100755 --- a/gosa-si/gosa-si-client +++ b/gosa-si/gosa-si-client @@ -481,6 +481,9 @@ sub register_at_server { my ($rout, $wout, $reg_server); foreach my $server (@servers) { + +# TODO : server abhängige macadress und ipadresse eintragen + # create msg hash my $register_hash = &create_xml_hash("here_i_am", $client_address, $server); &add_content2xml_hash($register_hash, "new_passwd", $new_server_passwd); @@ -1251,6 +1254,12 @@ GetOptions("h|help" => \&usage, &read_configfile; &check_pid; + +open STDIN, ‘/dev/null’ or die “Can’t read /dev/null: $!”; +open STDOUT, ‘>>/dev/null’ or die “Can’t write to /dev/null: $!”; +open STDERR, ‘>>/dev/null’ or die “Can’t write to /dev/null: $!”; + + # restart daemon log file if(-e $log_file ) { unlink $log_file } daemon_log(" ", 1); diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server index dfec2b882..b9a1cc6d6 100755 --- a/gosa-si/gosa-si-server +++ b/gosa-si/gosa-si-server @@ -204,7 +204,19 @@ sub daemon_log { return } chomp($msg); if($level <= $verbose){ - print LOG_HANDLE "$level $msg\n"; + my ($seconds, $minutes, $hours, $monthday, $month, + $year, $weekday, $yearday, $sommertime) = localtime(time); + $hours = $hours < 10 ? $hours = "0".$hours : $hours; + $minutes = $minutes < 10 ? $minutes = "0".$minutes : $minutes; + $seconds = $seconds < 10 ? $seconds = "0".$seconds : $seconds; + my @monthnames = ("Jan", "Feb", "Mar", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); + $month = $monthnames[$month]; + $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday; + $year+=1900; + my $name = $0; + $name =~ s/\.\///; + + print LOG_HANDLE "$month $monthday $hours:$minutes:$seconds $name $msg\n"; if($foreground) { print $msg."\n" } } } @@ -316,18 +328,16 @@ sub import_modules { } eval { require $file; }; if ($@) { - daemon_log("ERROR: gosa-sd could not load module $file", 1); + daemon_log("ERROR: gosa-si-server could not load module $file", 1); daemon_log("$@", 5); - next; - } - my $mod_name = $1; - #my $module_tag_hash = eval( $mod_name.'::get_module_tags()' ); - - my $info = eval($mod_name.'::get_module_info()'); - my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info}; - $known_modules->{$mod_name} = $info; + } else { + my $mod_name = $1; + my $info = eval($mod_name.'::get_module_info()'); + my ($input_address, $input_key, $input, $input_active, $input_type) = @{$info}; + $known_modules->{$mod_name} = $info; - daemon_log("module $mod_name loaded", 1); + daemon_log("module $mod_name loaded", 1); + } } # for debugging @@ -347,23 +357,8 @@ sub import_modules { #=============================================================================== sub sig_int_handler { my ($signal) = @_; - if($server){ - close($server); - daemon_log("daemon server closed", 1); - } - if( -p $arp_fifo_path ) { - close $arp_fifo ; - unlink($arp_fifo_path) ; - daemon_log("ARP_FIFO closed", 1) ; - } - - if($gosa_server){ - close($gosa_server); - daemon_log("gosa server closed", 1); - } - print STDERR "$signal\n"; - + daemon_log("shutting down gosa-si-server", 1); exit(1); } $SIG{INT} = \&sig_int_handler; @@ -496,8 +491,8 @@ sub get_processing_child { if (defined $answer) { print $PARENT_wr $answer."\n"; - daemon_log("with answer: $answer", 5); - daemon_log(" ", 5); + daemon_log("with answer:", 5); + daemon_log("$answer", 5); } else { print $PARENT_wr "done"."\n"; daemon_log(" ", 5); @@ -913,11 +908,13 @@ GetOptions("h|help" => \&usage, $SIG{CHLD} = 'IGNORE'; -# restart daemon log file -daemon_log(" ", 1); -daemon_log("$0 started!", 1); +# forward error messages to logfile +if( ! $foreground ) { + open(STDERR, '>>', $log_file); + open(STDOUT, '>>', $log_file); +} -# Just fork, if we"re not in foreground mode +# Just fork, if we are not in foreground mode if( ! $foreground ) { chdir '/' or die "Can't chdir to /: $!"; $pid = fork; @@ -937,8 +934,12 @@ if( 0 != $pid ) { }; } +daemon_log(" ", 1); +daemon_log("$0 started!", 1); + + # connect to gosa-si job queue -my @job_col_names = ("timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress"); +my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress"); $job_db = GOSA::DBsqlite->new($job_queue_file_name); $job_db->create_table('jobs', \@job_col_names); diff --git a/gosa-si/modules/DBsqlite.pm b/gosa-si/modules/DBsqlite.pm index 5bee915c4..21d720071 100644 --- a/gosa-si/modules/DBsqlite.pm +++ b/gosa-si/modules/DBsqlite.pm @@ -46,11 +46,27 @@ sub add_dbentry { } # specify primary key in table + if (not exists $arg->{primkey}) { + return 2; + } my $primkey = $arg->{primkey}; + # if primkey is id, fetch max id from table and give new job id= max(id)+1 + if ($primkey eq 'id') { + my $id; + my $sql_statement = "SELECT MAX(id) FROM $table"; + my $max_id = @{ @{ $obj->{dbh}->selectall_arrayref($sql_statement) }[0] }[0]; + if( defined $max_id) { + $id = $max_id + 1; + } else { + $id = 1; + } + $arg->{id} = $id; + } + # check wether value to primary key is specified - if ( ( defined $primkey ) && ( not $arg->{ $primkey } ) ) { - return 2; + if ( not exists $arg->{ $primkey } ) { + return 3; } # if timestamp is not provided, add timestamp @@ -59,7 +75,8 @@ sub add_dbentry { } # check wether primkey is unique in table, otherwise return errorflag 3 - my $res = @{ $obj->{dbh}->selectall_arrayref( "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'") }; + my $sql_statement = "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'"; + my $res = @{ $obj->{dbh}->selectall_arrayref($sql_statement) }; if ($res == 0) { # fetch column names of table my $col_names = $obj->get_table_columns($table); @@ -261,7 +278,7 @@ sub select_dbentry { sub show_table { my $obj = shift; my $table_name = shift; - my @res = @{$obj->{dbh}->selectall_arrayref( "SELECT ROWID, * FROM $table_name")}; + my @res = @{$obj->{dbh}->selectall_arrayref( "SELECT * FROM $table_name")}; my @answer; foreach my $hit (@res) { push(@answer, "hit: ".join(', ', @{$hit})); diff --git a/gosa-si/modules/GosaPackages.pm b/gosa-si/modules/GosaPackages.pm index 70e998bfb..18423d87b 100644 --- a/gosa-si/modules/GosaPackages.pm +++ b/gosa-si/modules/GosaPackages.pm @@ -76,6 +76,7 @@ if ($gosa_activ eq "on") { ); if (not defined $gosa_server) { &main::daemon_log("cannot start tcp server at $gosa_port for communication to gosa: $@", 1); + die; } else { &main::daemon_log("start server for communication to gosa: $gosa_address", 1); @@ -221,8 +222,7 @@ sub process_incoming_msg { my $header = @{$msg_hash->{header}}[0]; - &main::daemon_log("recieve '$header' at GosaPackages from $host", 1); - &main::daemon_log("$msg", 7); + &main::daemon_log("GosaPackages: recieve '$header' from $host", 1); my $out_msg; if ($header =~ /^job_/) { @@ -303,13 +303,14 @@ sub process_job_msg { my $header = @{$msg_hash->{header}}[0]; $header =~ s/job_//; - &main::daemon_log("GosaPackages: got a job msg $header", 5); + &main::daemon_log("GosaPackages: got a job msg for queue: $header", 5); # check wether mac address is already known in known_daemons or known_clients - my $target = 'not known until now'; + my $target = 'none'; # add job to job queue my $func_dic = {table=>$main::job_queue_table_name, + primkey=>'id', timestamp=>@{$msg_hash->{timestamp}}[0], status=>'waiting', result=>'none', diff --git a/gosa-si/modules/ServerPackages.pm b/gosa-si/modules/ServerPackages.pm index 45d4cac4a..7ef62d41b 100644 --- a/gosa-si/modules/ServerPackages.pm +++ b/gosa-si/modules/ServerPackages.pm @@ -78,6 +78,7 @@ if($server_activ eq "on"){ ); if(not defined $server){ &main::daemon_log("cannot be a tcp server at $server_port : $@"); + die; } else { &main::daemon_log("start server: $server_address", 1); } diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index e825d57c9..3ccd88d5f 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -4,7 +4,7 @@ require_once("../../gosa-core/include/class_socketClient.inc"); error_reporting(E_ALL); -$sock = new Socket_Client("10.89.1.155","20082",TRUE,1); +$sock = new Socket_Client("10.89.1.156","20082",TRUE,1); #$sock = new Socket_Client("169.254.2.248","9999",TRUE,1); $sock->setEncryptionKey("secret-gosa-password"); -- 2.30.2