summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cc2bf4b)
raw | patch | inline | side by side (parent: cc2bf4b)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 8 Feb 2008 16:40:11 +0000 (16:40 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Fri, 8 Feb 2008 16:40:11 +0000 (16:40 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8789 594d385d-05f5-0310-b6e9-bd551577e9d8
index de0539aa8cfed04104466252d21fea243ea52fd4..d68f981600be5b6cb38e29de32446b03e59afdf1 100644 (file)
package corefunctions;
use Exporter;
@ISA = qw(Exporter);
-my @events = qw(get_events registered set_activated_for_installation new_ldap_config new_key generate_hw_digest detect_hardware reboot halt reinstall softupdate);
+my @events = qw(get_events registered set_activated_for_installation new_ldap_config new_key generate_hw_digest detect_hardware reboot halt reinstall softupdate confirm_new_key);
@EXPORT = @events;
use strict;
}
+sub confirm_new_key {
+ my ($msg, $msg_hash) = @_ ;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $target = @{$msg_hash->{'target'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+
+ &main::daemon_log("confirm new key from $source", 5);
+ return;
+
+}
+
sub detect_hardware {
diff --git a/gosa-si/gosa-si-bus b/gosa-si/gosa-si-bus
index 29e31ff3754786ef86f3ce8a0014c8cf5d10cf7e..8f3935256c7af4674f6eb070afc0160f3562fbca 100755 (executable)
--- a/gosa-si/gosa-si-bus
+++ b/gosa-si/gosa-si-bus
sub send_msg_to_target {
my ($msg, $address, $encrypt_key, $msg_header) = @_ ;
my $error = 0;
+ my $header;
+ my $new_status;
+ my $act_status;
+ my ($sql_statement, $res);
if( $msg_header ) {
- $msg_header = "'$msg_header'-";
+ $header = "'$msg_header'-";
}
else {
- $msg_header = "";
+ $header = "";
}
# encrypt xml msg
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
- daemon_log("cannot send ".$msg_header."msg to $address , host not reachable", 1);
+ daemon_log("cannot send ".$header."msg to $address , host not reachable", 1);
$error++;
}
# send xml msg
print $socket $crypted_msg."\n";
- daemon_log("send ".$msg_header."msg to $address", 1);
+ daemon_log("send ".$header."msg to $address", 1);
daemon_log("message:\n$msg", 8);
}
close $socket;
}
+ if( $error > 0 ) { $new_status = "down"; }
+ else { $new_status = $msg_header; }
+
+
+ # known_clients
+ $sql_statement = "SELECT * FROM bus_known_clients WHERE hostname='$address'";
+ $res = $bus_known_clients_db->select_dbentry($sql_statement);
+ if( keys(%$res) > 0 ) {
+ $act_status = $res->{1}->{'status'};
+ if( $act_status eq "down" ) {
+ $sql_statement = "DELETE FROM bus_known_clients WHERE hostname='$address'";
+ $res = $bus_known_clients_db->del_dbentry($sql_statement);
+ daemon_log("WARNING: failed 2x to send msg to host '$address', delete host from bus_known_clients", 3);
+ }
+ else {
+ $sql_statement = "UPDATE bus_known_clients SET status='$new_status' WHERE hostname='$address'";
+ $res = $bus_known_clients_db->update_dbentry($sql_statement);
+ daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+ }
+ }
+
+ # known_server
+ $sql_statement = "SELECT * FROM bus_known_server WHERE hostname='$address'";
+ $res = $bus_known_server_db->select_dbentry($sql_statement);
+ if( keys(%$res) > 0) {
+ $act_status = $res->{1}->{'status'};
+ if( $act_status eq "down" ) {
+ $sql_statement = "DELETE FROM bus_known_clients WHERE hostname='$address'";
+ $res = $bus_known_clients_db->del_dbentry($sql_statement);
+ daemon_log("WARNING: failed 2x to a send msg to host '$address', delete host from bus_known_server", 3);
+ }
+ else {
+ $sql_statement = "UPDATE bus_known_server SET status='$new_status' WHERE hostname='$address'";
+ $res = $bus_known_server_db->update_dbentry($sql_statement);
+ daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5)
+ }
+ }
+
return;
}
_start => \&_start,
_default => \&_default,
here_i_am => \&here_i_am,
- confirm_new_passwd => \&confirm_new_key,
+ confirm_new_key => \&confirm_new_key,
new_client => \&new_client,
}
);
diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index d4e17c29f187f21dbe6cbc92efe4b16b76c7e468..84396db07ce5a39be9b36c5f844aa9a0bc22666d 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
if( $REGISTERED_FLAG == 1 ) {
-
# create new passwd and ciphering object for client-server communication
$server_key = &create_passwd();
# fetch first gosa-si-server from @servers
my $server = shift(@servers);
-
+ if( !$server ) {
+ daemon_log("no gosa-si-server left in list of servers", 1);
+ daemon_log("unable to register at a gosa-si-server, force shutdown", 1);
+ exit(1);
+ }
+
# Check if our ip is resolvable - if not: don't try to register
my $ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/));
my $resolver= Net::DNS::Resolver->new;
exit(1);
}
- if( !$server ) {
- daemon_log("no gosa-si-server left in list of servers", 1);
- daemon_log("unable to register at a gosa-si-server, force shutdown", 1);
- exit(1);
- }
-
# create registration msg
- my $register_hash = &create_xml_hash("here_i_am", &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)).":".$client_port, $server);
+ my $local_ip = &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/));
+ my $local_mac = &get_local_mac_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/));
+ my $register_hash = &create_xml_hash("here_i_am", $local_ip.":".$client_port, $server);
&add_content2xml_hash($register_hash, "new_passwd", $server_key);
- &add_content2xml_hash($register_hash, "mac_address", &get_local_mac_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/)));
+ &add_content2xml_hash($register_hash, "mac_address", $local_mac);
&add_content2xml_hash($register_hash, "events", $events);
&add_content2xml_hash($register_hash, "gotoHardwareChecksum", $gotoHardwareChecksum);
}
}
daemon_log("waiting for msg 'register_at_gosa_si_server'",1);
- $kernel->delay_set('register_at_gosa_si_server',180);
+# $kernel->delay_set('register_at_gosa_si_server', 180);
+ $kernel->delay_set('register_at_gosa_si_server', 5);
# clear old settings and set it again
$kernel->delay_set('trigger_new_key', $server_key_lifetime);
}
$error++;
}
+
######################
# process incoming msg
if( $error == 0 ) {
diff --git a/gosa-si/gosa-si-server b/gosa-si/gosa-si-server
index bc7d4f52f3576d1f2ce6305491252ac8e8015f43..8482e8d72e10a4416ebc041d51dc21de000138b2 100755 (executable)
--- a/gosa-si/gosa-si-server
+++ b/gosa-si/gosa-si-server
};
if($@) {
- &main::daemon_log("WARNING: do not understand the message:", 5);
+ &main::daemon_log("WARNING: do not understand the message", 5);
&main::daemon_log("$@", 8);
}
# check if module can open msg envelope with module key
($msg, $msg_hash) = &check_key_and_xml_validity($input, $module_key);
if( (!$msg) || (!$msg_hash) ) {
- daemon_log("$mod: deciphering failed", 5);
+ #daemon_log("$mod: deciphering failed", 5);
next;
}
else {
sub send_msg_to_target {
my ($msg, $address, $encrypt_key, $msg_header) = @_ ;
my $error = 0;
-
+ my $header;
+ my $new_status;
+ my $act_status;
+ my ($sql_statement, $res);
+
if( $msg_header ) {
- $msg_header = "'$msg_header'-";
+ $header = "'$msg_header'-";
}
else {
- $msg_header = "";
+ $header = "";
}
# encrypt xml msg
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
- daemon_log("cannot send ".$msg_header."msg to $address , host not reachable", 1);
+ daemon_log("cannot send ".$header."msg to $address , host not reachable", 1);
$error++;
}
# send xml msg
print $socket $crypted_msg."\n";
- daemon_log("send ".$msg_header."msg to $address", 1);
+ daemon_log("send ".$header."msg to $address", 1);
daemon_log("message:\n$msg", 8);
-
+
}
# close socket in any case
close $socket;
}
- return;
+ if( $error > 0 ) { $new_status = "down"; }
+ else { $new_status = $msg_header; }
+
+
+ # known_clients
+ $sql_statement = "SELECT * FROM known_clients WHERE hostname='$address'";
+ $res = $known_clients_db->select_dbentry($sql_statement);
+ if( keys(%$res) > 0) {
+ $act_status = $res->{1}->{'status'};
+ if( $act_status eq "down" ) {
+ $sql_statement = "DELETE FROM known_clients WHERE hostname='$address'";
+ $res = $known_clients_db->del_dbentry($sql_statement);
+ daemon_log("WARNING: failed 2x to send msg to host '$address', delete host from known_clients", 3);
+ }
+ else {
+ $sql_statement = "UPDATE known_clients SET status='$new_status' WHERE hostname='$address'";
+ $res = $known_clients_db->update_dbentry($sql_statement);
+ if($new_status eq "down"){
+ daemon_log("WARNING: set '$address' from status '$act_status' to '$new_status'", 3);
+ }
+ else {
+ daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+ }
+ }
+ }
+
+ # known_server
+ $sql_statement = "SELECT * FROM known_server WHERE hostname='$address'";
+ $res = $known_server_db->select_dbentry($sql_statement);
+ if( keys(%$res) > 0 ) {
+ $act_status = $res->{1}->{'status'};
+ if( $act_status eq "down" ) {
+ $sql_statement = "DELETE FROM known_server WHERE hostname='$address'";
+ $res = $known_clients_db->del_dbentry($sql_statement);
+ daemon_log("WARNING: failed 2x to a send msg to host '$address', delete host from known_server", 3);
+ }
+ else {
+ $sql_statement = "UPDATE known_server SET status='$new_status' WHERE hostname='$address'";
+ $res = $known_server_db->update_dbentry($sql_statement);
+ if($new_status eq "down"){
+ daemon_log("WARNING: set '$address' from status '$act_status' to '$new_status'", 3);
+ }
+ else {
+ daemon_log("INFO: set '$address' from status '$act_status' to '$new_status'", 5);
+ }
+ }
+ }
+
+ return;
}
my $host_name = $hit->{hostname};
my $host_key = $hit->{hostkey};
&send_msg_to_target($answer, $host_name, $host_key, $answer_header);
- }
+ }
}
elsif( $answer_target eq "GOSA" ) {
# answer is for GOSA and has to returned to connected client
}
if( $found_ip_flag == 0) {
daemon_log("WARNING: no host found in known_clients with mac address '$answer_target', forward msg to bus", 1);
- my $sql_statement = "SELECT * FROM known_server WHERE status='bus'";
+ my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'";
my $query_res = $known_server_db->select_dbentry( $sql_statement );
while( my ($hit_num, $hit) = each %{ $query_res } ) {
my $bus_address = $hit->{hostname};
if( !$encrypt_key ) {
# unknown target, forward msg to bus
daemon_log("WARNING: unknown target '$answer_target', forward msg to bus", 3);
- my $sql_statement = "SELECT * FROM known_server WHERE status='bus'";
+ my $sql_statement = "SELECT * FROM known_server WHERE hostname='$bus_address'";
my $query_res = $known_server_db->select_dbentry( $sql_statement );
- my $bus_address = $query_res->{1}->{hostname};
my $bus_key = $query_res->{1}->{hostkey};
&send_msg_to_target($answer, $bus_address, $bus_key, $answer_header);
next;
index bb2809fdb9e954beaf3c5eeff3be70a327cb01f2..44a74978be93efeed71655c3ff80d48cc523b812 100644 (file)
}
}
$hosts_database->{$packet->{source_haddr}}->{dnsname}=$dnsname;
- &main::daemon_log("Host was found in LDAP as ".$ldap_result->{dn}, 6);
+ &main::daemon_log("Host was found in LDAP as ".$ldap_result->{dn}, 8);
} else {
$hosts_database->{$packet->{source_haddr}}={
macAddress => $packet->{source_haddr},
);
}
- &main::daemon_log("Host already in cache (".($hosts_database->{$packet->{source_haddr}}->{device})."->".($hosts_database->{$packet->{source_haddr}}->{dnsname}).")",6);
+ &main::daemon_log("Host already in cache (".($hosts_database->{$packet->{source_haddr}}->{device})."->".($hosts_database->{$packet->{source_haddr}}->{dnsname}).")",8);
}
}
index 96a6edc15dd00e19bd95039ea4a0d900add8ae8c..6494c4f7d4a7291197da2bbabd434a6eb55ec67b 100644 (file)
use IO::Socket::INET;
use XML::Simple;
use Data::Dumper;
+use NetAddr::IP;
use Net::LDAP;
use Socket;
use Net::hostent;
END {}
my ($known_clients_file_name);
-my ($server_activ, $server_ip, $server_mac_address, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password);
+my ($server_activ, $server_ip, $server_mac_address, $server_port, $SIPackages_key, $max_clients, $ldap_uri, $ldap_base, $ldap_admin_dn, $ldap_admin_password, $server_interface);
my ($bus_activ, $bus_key, $bus_ip, $bus_port);
my $server;
my $network_interface;
"server" =>
{"server_activ" => [\$server_activ, "on"],
"server_ip" => [\$server_ip, "0.0.0.0"],
- "server_mac_address" => [\$server_mac_address, ""],
+ "server_mac_address" => [\$server_mac_address, "00:00:00:00:00"],
"server_port" => [\$server_port, "20081"],
"SIPackages_key" => [\$SIPackages_key, ""],
"max_clients" => [\$max_clients, 100],
# read configfile and import variables
&read_configfile();
-# detect interfaces and mac address
+$server_ip = &get_local_ip_for_remote_ip($server_ip);
+
$network_interface= &get_interface_for_ip($server_ip);
-$server_mac_address= &get_mac($network_interface);
+$server_mac_address= &get_mac($network_interface);
# complete addresses
if( $server_ip eq "0.0.0.0" ) {
$server_ip = "127.0.0.1";
}
my $server_address = "$server_ip:$server_port";
+$main::server_address = $server_address;
my $bus_address = "$bus_ip:$bus_port";
+$main::bus_address = $bus_address;
# create general settings for this module
my $xml = new XML::Simple();
}
+sub get_local_ip_for_remote_ip {
+ my $server_ip= shift;
+ my $result="0.0.0.0";
+
+ if($server_ip =~ /^(\d\d?\d?\.){3}\d\d?\d?$/) {
+ if($server_ip eq "127.0.0.1") {
+ $result="127.0.0.1";
+ } else {
+ my $PROC_NET_ROUTE= ('/proc/net/route');
+
+ open(PROC_NET_ROUTE, "<$PROC_NET_ROUTE")
+ or die "Could not open $PROC_NET_ROUTE";
+
+ my @ifs = <PROC_NET_ROUTE>;
+
+ close(PROC_NET_ROUTE);
+
+ # Eat header line
+ shift @ifs;
+ chomp @ifs;
+ foreach my $line(@ifs) {
+ my ($Iface,$Destination,$Gateway,$Flags,$RefCnt,$Use,$Metric,$Mask,$MTU,$Window,$IRTT)=split(/\s/, $line);
+ my $destination;
+ my $mask;
+ my ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Destination);
+ $destination= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
+ ($d,$c,$b,$a)=unpack('a2 a2 a2 a2', $Mask);
+ $mask= sprintf("%d.%d.%d.%d", hex($a), hex($b), hex($c), hex($d));
+ if(new NetAddr::IP($server_ip)->within(new NetAddr::IP($destination, $mask))) {
+ # destination matches route, save mac and exit
+ $result= &get_ip($Iface);
+ last;
+ }
+ }
+ }
+ } else {
+ daemon_log("get_local_ip_for_remote_ip was called with a non-ip parameter: $server_ip", 1);
+ }
+ return $result;
+}
+
+
#=== FUNCTION ================================================================
# NAME: register_at_bus
# PARAMETERS: nothing
&main::send_msg_to_target($msg, $bus_address, $bus_key, "here_i_am");
return $msg;
-# my $answer = "";
-# $answer = &send_msg_hash2address($msg_hash, $bus_address, $bus_passwd);
-# if ($answer == 0) {
-# &main::daemon_log("register at bus: $bus_address", 1);
-# } else {
-# &main::daemon_log("unable to send 'register'-msg to bus '$bus_address': $answer", 1);
-# }
-# return;
}
"SET hostkey='$source_key', timestamp='$act_time' ".
"WHERE hostname='$source_name'";
my $res = $main::known_clients_db->update_dbentry( $sql_statement );
- my $hash = &create_xml_hash("confirm_new_passwd", $server_address, $source_name);
+ my $hash = &create_xml_hash("confirm_new_key", $server_address, $source_name);
my $out_msg = &create_xml_string($hash);
push(@out_msg_l, $out_msg);
}
"WHERE hostname='$source_name'";
my $res = $main::known_server_db->update_dbentry( $sql_statement );
- my $hash = &create_xml_hash("confirm_new_passwd", $server_address, $source_name);
+ my $hash = &create_xml_hash("confirm_new_key", $server_address, $source_name);
my $out_msg = &create_xml_string($hash);
push(@out_msg_l, $out_msg);
}
filter => "(&(objectClass=GOhard)(|(macAddress=$macaddress)(dhcpHWaddress=ethernet $macaddress)))"
);
} else {
- &main::daemon_log("There was a problem adding the entry", 1);
+ &main::daemon_log("ERROR: There was a problem adding the entry", 1);
}
}
diff --git a/gosa-si/server.conf b/gosa-si/server.conf
index 22b42fb8078838c3091fae2a2812f7ae74ca4c8d..5ae3e923d39ca9df912b86050b0f38b4102a5041 100644 (file)
--- a/gosa-si/server.conf
+++ b/gosa-si/server.conf
[general]
log_file = /var/log/gosa-si-server.log
pid_file = /var/run/gosa-si-server.pid
-child_max = 10
-child_min = 2
-child_timeout = 10
-job_queue_timeout = 5
[bus]
bus_activ = on
[server]
server_activ = on
-server_ip = 10.89.1.31
server_port = 20081
SIPackages_key = secret-server-password
max_clients = 5
index f2a6ed4ca8504e6fd1ab3f373186bd68e7768e41..fd2f5566835637074ec792192765607f52a6abf5 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
#$data = "<xml> <header>gosa_halt</header> <target>10.89.1.31:20083</target> <source>10.89.1.31:20081</source> </xml>";
#$data = "<xml> <header>gosa_new_key_for_client</header> <target>00:01:6c:9d:b9:fa</target> <source>10.89.1.31:20081</source> </xml>";
#$data = "<xml> <header>gosa_new_key_for_client</header> <target>00:0c:29:bd:7b:e7</target> <source>10.89.1.31:20081</source> </xml>";
-$data = "<xml> <header>gosa_new_key_for_client</header> <target>10.89.1.197:20083</target> <source>10.89.1.31:20081</source> </xml>";
+#$data = "<xml> <header>gosa_new_key_for_client</header> <target>10.89.1.197:20083</target> <source>10.89.1.31:20081</source> </xml>";
+$data = "<xml> <header>gosa_new_key_for_client</header> <target>10.89.1.31:20083</target> <source>10.89.1.31:20081</source> </xml>";
$sock->write($data);