summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f4f5181)
raw | patch | inline | side by side (parent: f4f5181)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 16 Jan 2008 13:30:13 +0000 (13:30 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 16 Jan 2008 13:30:13 +0000 (13:30 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8390 594d385d-05f5-0310-b6e9-bd551577e9d8
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index 544030cdbdd2a0786cbf940193d951ffe6ff9817..bd23dcd54ad01d292771257fffe66e40097f38c5 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
# DESCRIPTION:
#
# OPTIONS: ---
-# REQUIREMENTS: ---
+# REQUIREMENTS: libnetaddr-ip-perl
# BUGS: ---
# NOTES:
# AUTHOR: (Andreas Rettenberger), <rettenberger@gonicus.de>
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index f0b59ce9c83c195429b2270e6d2940a0f8808862..c103cda3489c578ff98e441791ee2cccbd506662 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
$answer = $tmp;
}
}
-
- #&print_known_daemons();
- #&print_known_clients();
-
daemon_log("processing of msg finished", 5);
if (defined $answer) {
daemon_log("\n$answer", 7);
} else {
print $PARENT_wr "done"."\n";
- daemon_log(" ", 7);
+ print $PARENT_wr "ENDMESSAGE\n";
}
redo;
}
return;
}
-sub sysreadline(*;$) {
- my ($hd, $timeout) = @_;
-
- $hd = qualify_to_ref($hd, caller());
- my $infinitely_patient = (@_ == 1 || $timeout < 0);
- my $start_time = time();
- my $selector = IO::Select->new();
- $selector->add($hd);
- my $line = "";
-
-SLEEP:
- until( at_eol($line)) {
- if (not $infinitely_patient) {
- return $line if time() > ($start_time + $timeout);
- }
- next SLEEP unless $selector->can_read(1.0);
-INPUT_READY:
- while( $selector->can_read(0.0)) {
- my $was_blocking = $hd->blocking(0);
-CHAR: while (sysread($hd, my $nextbyte, 1)) {
- $line .= $nextbyte;
- last CHAR if $nextbyte eq "\n";
-
- }
- $hd->blocking($was_blocking);
- next SLEEP unless at_eol($line);
- last INPUT_READY;
- }
- }
- return $line;
-}
-
-sub at_eol($) {
- $_[0] =~ /\n\z/ ;
-}
+#sub sysreadline(*;$) {
+# my ($hd, $timeout) = @_;
+#
+# $hd = qualify_to_ref($hd, caller());
+# my $infinitely_patient = (@_ == 1 || $timeout < 0);
+# my $start_time = time();
+# my $selector = IO::Select->new();
+# $selector->add($hd);
+# my $line = "";
+#
+#SLEEP:
+# until( at_eol($line)) {
+# if (not $infinitely_patient) {
+# return $line if time() > ($start_time + $timeout);
+# }
+# next SLEEP unless $selector->can_read(1.0);
+#INPUT_READY:
+# while( $selector->can_read(0.0)) {
+# my $was_blocking = $hd->blocking(0);
+#CHAR: while (sysread($hd, my $nextbyte, 1)) {
+# $line .= $nextbyte;
+# last CHAR if $nextbyte eq "\n";
+#
+# }
+# $hd->blocking($was_blocking);
+# next SLEEP unless at_eol($line);
+# last INPUT_READY;
+# }
+# }
+# return $line;
+#}
+#
+#sub at_eol($) {
+# $_[0] =~ /\n\z/ ;
+#}
#==== MAIN = main ==============================================================
daemon_log(" ", 1);
daemon_log("$0 started!", 1);
+# delete old DBsqlite lock files
+system('rm -f /tmp/gosa_si_lock*');
# connect to gosa-si job queue
my @job_col_names = ("id", "timestamp", "status", "result", "headertag", "targettag", "xmlmessage", "macaddress");
}
chomp($in_msg);
- daemon_log("process child read:", 7);
- daemon_log("\n$in_msg", 7);
if (not defined $in_msg) {
next;
} elsif ($in_msg =~ "done") {
+ daemon_log("process child read: $in_msg", 7);
delete $busy_child{$pid};
$free_child{$pid} = $child_hash;
} else {
+ daemon_log("process child read:", 7);
+ daemon_log("\n$in_msg", 8);
# send computed answer back to connected client
my $act_client = $busy_child{$pid}{client_ref};
print $act_client $in_msg."\n";
-
- #my $act_pipe = $busy_child{$pid}{pipe_rd};
delete $busy_child{$pid};
$free_child{$pid} = $child_hash;
- # give the client a chance to read
- #sleep(1);
- #close ($act_client);
-
}
}
}
index 618dd00c7869a624b9ea9a955ed835afbb068e26..05946095c28a968793cbbe79ba3860badda7e648 100644 (file)
my $lock = $self->{db_lock};
my $result=(-f $lock);
if($result) {
- print STDERR "(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden\n";
+ #print STDERR "(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden\n";
usleep 100;
}
return $result;
sub create_lock : locked {
my $self=shift;
my $funcname=shift;
- print STDERR "(".((defined $funcname)?$funcname:"").") Erzeuge Lock (PID ".$$.") ".($self->{db_lock})."\n";
+ #print STDERR "(".((defined $funcname)?$funcname:"").") Erzeuge Lock (PID ".$$.") ".($self->{db_lock})."\n";
my $lock = $self->{db_lock};
while( -f $lock ) {
- print STDERR "(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden\n";
+ #print STDERR "(".((defined $funcname)?$funcname:"").") Lock (PID ".$$.") $lock gefunden\n";
sleep 1;
}
sub remove_lock : locked {
my $self=shift;
my $funcname=shift;
- print STDERR "(".((defined $funcname)?$funcname:"").") Entferne Lock (PID ".$$.") ".$self->{db_lock}."\n";
+ #print STDERR "(".((defined $funcname)?$funcname:"").") Entferne Lock (PID ".$$.") ".$self->{db_lock}."\n";
close($self->{db_lock_handle});
unlink($self->{db_lock});
}
my $col_names_ref = shift;
$col_names->{ $table_name } = $col_names_ref;
my $col_names_string = join(', ', @{$col_names_ref});
- while(&lock_exists($self,'create_table')) {
- print STDERR "Lock in create_table\n";
- }
- &create_lock($self,'create_table');
my $sql_statement = "CREATE TABLE IF NOT EXISTS $table_name ( $col_names_string )";
+ &create_lock($self,'create_table');
$self->{dbh}->do($sql_statement);
&remove_lock($self,'create_table');
return 0;
sub add_dbentry {
-
my $self = shift;
my $arg = shift;
- while(&lock_exists($self,'add_dbentry')) {
- print STDERR "Lock in add_dbentry\n";
- }
- &create_lock($self,'add_dbentry');
# if dbh not specified, return errorflag 1
my $table = $arg->{table};
- if (not defined $table) {
- &remove_lock($self,'add_dbentry');
- return 1;
+ if( not defined $table ) {
+ return 1 ;
}
# specify primary key in table
if (not exists $arg->{primkey}) {
- &remove_lock($self,'add_dbentry');
return 2;
}
my $primkey = $arg->{primkey};
if ($primkey eq 'id') {
my $id;
my $sql_statement = "SELECT MAX(id) FROM $table";
+ &create_lock($self,'add_dbentry');
my $max_id = @{ @{ $self->{dbh}->selectall_arrayref($sql_statement) }[0] }[0];
+ &remove_lock($self,'add_dbentry');
if( defined $max_id) {
$id = $max_id + 1;
} else {
# check wether value to primary key is specified
if ( not exists $arg->{ $primkey } ) {
- &remove_lock($self,'add_dbentry');
return 3;
}
$arg->{timestamp} = &get_time;
}
- # check wether primkey is unique in table, otherwise return errorflag 3
+ # check wether primkey is unique in table, otherwise return errorflag
my $sql_statement = "SELECT * FROM $table WHERE $primkey='$arg->{$primkey}'";
+ &create_lock($self,'add_dbentry');
my $res = @{ $self->{dbh}->selectall_arrayref($sql_statement) };
+ &remove_lock($self,'add_dbentry');
if ($res == 0) {
# fetch column names of table
my $col_names = &get_table_columns("",$table);
}
}
- my $sql_statement = "BEGIN TRANSACTION; INSERT INTO $table VALUES ('".join("', '", @add_list)."'); COMMIT;";
+ my $sql_statement = "INSERT INTO $table VALUES ('".join("', '", @add_list)."')";
+ print STDERR $sql_statement;
+ &create_lock($self,'add_dbentry');
my $db_res = $self->{dbh}->do($sql_statement);
+ &remove_lock($self,'add_dbentry');
if( $db_res != 1 ) {
- &remove_lock($self,'add_dbentry');
- return 1;
+ return 4;
} else {
- &remove_lock($self,'add_dbentry');
return 0;
}
}
my $db_res = &update_dbentry( $self, $update_hash );
if( $db_res != 1 ) {
- &remove_lock($self,'add_dbentry');
- return 1;
+ return 5;
} else {
- &remove_lock($self,'add_dbentry');
return 0;
}
}
- &remove_lock($self,'add_dbentry');
}
my $self = shift;
my $arg = shift;
- while(&lock_exists($self,'update_dbentry')) {
- print STDERR "Lock in update_dbentry\n";
- }
- &create_lock($self,'update_dbentry');
+
# check completeness of function parameter
# extract table statement from arg hash
my $table = $arg->{table};
if (not defined $table) {
- &remove_lock($self,'update_dbentry');
return 1;
} else {
delete $arg->{table};
$update_statement .= join(', ', @update_list);
}
- my $sql_statement = "BEGIN TRANSACTION; UPDATE $table SET $update_statement $where_statement; COMMIT;";
+ my $sql_statement = "UPDATE $table SET $update_statement $where_statement";
+ &create_lock($self,'update_dbentry');
my $db_answer = $self->{dbh}->do($sql_statement);
&remove_lock($self,'update_dbentry');
return $db_answer;
my $self = shift;
my $arg = shift;
- while(&lock_exists($self,'del_dbentry')) {
- print STDERR "Lock in del_dbentry\n";
- }
- &create_lock($self,'del_dbentry');
+
# check completeness of function parameter
# extract table statement from arg hash
my $table = $arg->{table};
if (not defined $table) {
- &remove_lock($self,'del_dbentry');
return 1;
} else {
delete $arg->{table};
$where_statement = "WHERE ".join(' AND ', @del_list);
}
- my $sql_statement = "BEGIN TRANSACTION; DELETE FROM $table $where_statement; COMMIT;";
+ my $sql_statement = "DELETE FROM $table $where_statement";
+ &create_lock($self,'del_dbentry');
my $db_res = $self->{dbh}->do($sql_statement);
-
&remove_lock($self,'del_dbentry');
return $db_res;
}
sub get_table_columns {
my $self = shift;
my $table = shift;
-
- my @column_names = @{$col_names->{$table}};
+ my @column_names;
+
+ if(exists $col_names->{$table}) {
+ @column_names = @{$col_names->{$table}};
+ } else {
+ &create_lock($self,'get_table_columns');
+ my @res = @{$self->{dbh}->selectall_arrayref("pragma table_info('$table')")};
+ &remove_lock($self,'get_table_columns');
+ foreach my $column (@res) {
+ push(@column_names, @$column[1]);
+ }
+ }
return \@column_names;
}
my $self = shift;
my $arg = shift;
- while(&lock_exists($self,'select_dbentry')) {
- print STDERR "Lock in select_dbentry\n";
- }
- &create_lock($self,'select_dbentry');
# check completeness of function parameter
# extract table statement from arg hash
my $table = $arg->{table};
if (not defined $table) {
- &remove_lock($self,'select_dbentry');
return 1;
} else {
delete $arg->{table};
}
# query db
+ &create_lock($self,'select_dbentry');
my $query_answer = $self->{dbh}->selectall_arrayref($sql_statement);
+ &remove_lock($self,'select_dbentry');
# fetch column list of db and create a hash with column_name->column_value of the select query
my $column_list = &get_table_columns($self, $table);
}
}
- &remove_lock($self,'select_dbentry');
return $answer;
}
sub show_table {
my $self = shift;
my $table_name = shift;
- while(&lock_exists($self,'show_table')) {
- print STDERR "Lock in show_table\n";
- }
&create_lock($self,'show_table');
my @res = @{$self->{dbh}->selectall_arrayref( "SELECT * FROM $table_name")};
+ &remove_lock($self,'show_table');
my @answer;
foreach my $hit (@res) {
push(@answer, "hit: ".join(', ', @{$hit}));
}
- &remove_lock($self,'show_table');
return join("\n", @answer);
}
sub exec_statement {
my $self = shift;
my $sql_statement = shift;
- while(&lock_exists($self,'exec_statement')) {
- print STDERR "Lock in exec_statement\n";
- }
&create_lock($self,'exec_statement');
my @res = @{$self->{dbh}->selectall_arrayref($sql_statement)};
- &remove_locK;
+ &remove_lock($self, 'exec_statement');
return \@res;
}
index 7f211a59dc3c12b3fcb3a42c093fc86b64edde38..73dd6b26c68c1c5c15a137b571c2567d1aa6a1fa 100644 (file)
if ($out_msg =~ /<jobdb_id>(\d*?)<\/jobdb_id>/) {
my $job_id = $1;
- my $sql = "BEGIN TRANSATION; UPDATE '$main::job_queue_table_name' SET status='done', result='$out_msg' WHERE id='$job_id'; COMMIT;";
+ my $sql = "BEGIN TRANSATION; UPDATE '".$main::job_queue_table_name.
+ "' SET status='done', result='".$out_msg.
+ "' WHERE id='$job_id'; COMMIT;";
my $res = $main::job_db->exec_statement($sql);
return;
my ($msg, $header) = @_ ;
my $out_msg;
$header =~ s/gosa_//;
- &main::daemon_log("GosaPackages: got a gosa msg $header", 5);
# decide wether msg is a core function or a event handler
if ( $header eq 'query_jobdb') { $out_msg = &query_jobdb }
my $header = @{$msg_hash->{header}}[0];
$header =~ s/job_//;
- &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 = 'none';
index e3da5c0379e998b8fba195f83230ba053047dc25..002308e537d574d997c2268e4eeaea10f99f5e31 100644 (file)
close $socket;
daemon_log("send '$header'-msg to $address", 1);
- daemon_log("$msg_xml", 5);
+ daemon_log("message:\n$msg_xml", 8);
return 0;
}
if(not defined $socket) {
return;
}
- &daemon_log("open_socket:", 7);
- &daemon_log("\t$PeerAddr", 7);
+ &daemon_log("open_socket: $PeerAddr", 7);
return $socket;
}
index 074a0ddf855a30e3de3cdee4fc425341825be8da..1aa8db2a82beb1f73298853dcfa16c31b80f61ee 100644 (file)
}
}
-# TODO
-# füge den server selbst zu known_server hinzu, msgs können nämlich auch von sich selbst kommen (gosa!!!)
-
# register at bus
if ($main::no_bus > 0) {
### functions #################################################################
-#sub get_module_tags {
-#
-# # lese config file aus dort gibt es eine section Basic
-# # dort stehen drei packettypen, für die sich das modul anmelden kann, gosa-admin-packages,
-# # server-packages, client-packages
-# my %tag_hash = (gosa_admin_packages => "yes",
-# server_packages => "yes",
-# client_packages => "yes",
-# );
-# return \%tag_hash;
-#}
-
sub get_module_info {
my @info = ($server_address,
# RETURNS: socket IO::Socket::INET
# DESCRIPTION: open a socket to PeerAddr
#===============================================================================
-sub open_socket {
- my ($PeerAddr, $PeerPort) = @_ ;
- if(defined($PeerPort)){
- $PeerAddr = $PeerAddr.":".$PeerPort;
- }
- my $socket;
- $socket = new IO::Socket::INET(PeerAddr => $PeerAddr ,
- Porto => "tcp" ,
- Type => SOCK_STREAM,
- Timeout => 5,
- );
- if(not defined $socket) {
- return;
- }
- &main::daemon_log("open_socket to: $PeerAddr", 7);
- return $socket;
-}
+#sub open_socket {
+# my ($PeerAddr, $PeerPort) = @_ ;
+# if(defined($PeerPort)){
+# $PeerAddr = $PeerAddr.":".$PeerPort;
+# }
+# my $socket;
+# $socket = new IO::Socket::INET(PeerAddr => $PeerAddr ,
+# Porto => "tcp" ,
+# Type => SOCK_STREAM,
+# Timeout => 5,
+# );
+# if(not defined $socket) {
+# return;
+# }
+# &main::daemon_log("open_socket to: $PeerAddr", 7);
+# return $socket;
+#}
#=== FUNCTION ================================================================
# NAME: register_at_bus
hostkey=>$bus_passwd,
timestamp=>&get_time,
} );
-# if ($res == 3) {
-# my $update_hash = { table=>'known_server' };
-# $update_hash->{where} = [ { hostname=>[$bus_address] } ];
-# $update_hash->{update} = [ {
-# hostkey=>[$bus_passwd],
-# timestamp=>[&get_time],
-# } ];
-# $res = $main::known_server_db->update_dbentry( $update_hash );
-# }
-
my $msg_hash = &create_xml_hash("here_i_am", $server_address, $bus_address);
my $answer = "";
$answer = &send_msg_hash2address($msg_hash, $bus_address, $bus_passwd);
&main::daemon_log("function 'process_incoming_msg': got no msg", 7);
}
- &main::daemon_log("ServerPackages: incoming msg: \n$crypted_msg", 7);
+ &main::daemon_log("ServerPackages: incoming msg: \n$crypted_msg", 8);
$crypted_msg =~ /^([\s\S]*?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)\.(\d{1,3}?)$/;
$crypted_msg = $1;
my $source = @{$msg_hash->{source}}[0];
&main::daemon_log("recieve '$header' at ServerPackages from $host", 1);
- &main::daemon_log("ServerPackages: msg to process: \n$msg", 5);
+ &main::daemon_log("ServerPackages: msg to process: \n$msg", 7);
my @targets = @{$msg_hash->{target}};
my $len_targets = @targets;
my $target = $targets[0];
&main::daemon_log("SeverPackages: msg is for: $target", 7);
- if ($target eq $server_address) {
- # msg is for server
- if ($header eq 'new_passwd'){ &new_passwd($msg_hash)}
- elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)}
- elsif ($header eq 'who_has') { &who_has($msg_hash) }
- elsif ($header eq 'who_has_i_do') { &who_has_i_do($msg_hash)}
- elsif ($header eq 'update_status') { &update_status($msg_hash) }
- elsif ($header eq 'got_ping') { &got_ping($msg_hash)}
- elsif ($header eq 'get_load') { &execute_actions($msg_hash)}
- else { &main::daemon_log("ERROR: ServerPackages: no function assigned to this msg", 5) }
-
- } elsif ($target eq "*") {
- # msg is for all clients
- my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients'} );
- while( my ($hit_num, $hit) = each %{ $query_res } ) {
- $host_name = $hit->{hostname};
- $host_key = $hit->{hostkey};
- $msg_hash->{target} = [$host_name];
- &send_msg_hash2address($msg_hash, $host_name, $host_key);
- }
- return;
-
- } else {
- # msg is for one host
- my $query_res;
- $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} );
- if( 1 == keys %{$query_res} ) {
- $host_key = $query_res->{1}->{host_key};
- &send_msg_hash2address($msg_hash, $target, $host_key);
- return;
- }
+ # msg is for server
+ if ($header eq 'new_passwd'){ &new_passwd($msg_hash)}
+ elsif ($header eq 'here_i_am') { &here_i_am($msg_hash)}
+ elsif ($header eq 'who_has') { &who_has($msg_hash) }
+ elsif ($header eq 'who_has_i_do') { &who_has_i_do($msg_hash)}
+ elsif ($header eq 'update_status') { &update_status($msg_hash) }
+ elsif ($header eq 'got_ping') { &got_ping($msg_hash)}
+ elsif ($header eq 'get_load') { &execute_actions($msg_hash)}
+ else {
+ if ($target eq "*") {
+ # msg is for all clients
+ my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients'} );
+ while( my ($hit_num, $hit) = each %{ $query_res } ) {
+ $host_name = $hit->{hostname};
+ $host_key = $hit->{hostkey};
+ $msg_hash->{target} = [$host_name];
+ &send_msg_hash2address($msg_hash, $host_name, $host_key);
+ }
- $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} );
- if( 1 == keys %{$query_res} ) {
- $host_key = $query_res->{1}->{host_key};
- &send_msg_hash2address($msg_hash, $target, $host_key);
- return;
+ } else {
+ # msg is for one host
+ my $host_key;
+
+
+ if( not defined $host_key ) {
+ my $query_res = $main::known_clients_db->select_dbentry( {table=>'known_clients', hostname=>$target} );
+ if( 1 == keys %{$query_res} ) {
+ $host_key = $query_res->{1}->{host_key};
+ }
+ }
+
+ if( not defined $host_key ) {
+ my $query_res = $main::known_server_db->select_dbentry( {table=>'known_server', hostname=>$target} );
+ if( 1 == keys %{$query_res} ) {
+ $host_key = $query_res->{1}->{host_key};
+ }
+ }
+
+ if( not defined $host_key ) {
+ &main::daemon_log("ERROR: ServerPackages: target '".$target.
+ "' is not known neither in known_clients nor in known_server",1);
+ } else {
+ &send_msg_hash2address($msg_hash, $target, $host_key);
+ }
}
-
- &main::daemon_log("ERROR: ServerPackages: target '$target' is not known neither in known_clients nor in known_server",1);
- return;
}
} elsif ($len_targets > 1 ) {
# we have more than one target
- return;
+ # TODO to be implemented
}
return ;
my $out_hash;
# number of known clients
- my $nu_clients = keys %{$main::known_clients_db->select_dbentry( {table=>'known_clients'} )};
+ my $nu_clients = keys %{ $main::known_clients_db->select_dbentry( {table=>'known_clients'} ) };
# check wether client address or mac address is already known
if (exists $main::known_clients->{$source}) {