diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index 1aae6effd35bd4c9a02a2290b0db763d38dcb8a8..d9bf2393d29dd576ce5850a5106a87a3e39ecf01 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
use POSIX;
use Time::HiRes qw( gettimeofday );
use POSIX;
use Time::HiRes qw( gettimeofday );
-use POE qw(Component::Server::TCP Wheel::FollowTail);
+use POE qw(Component::Server::TCP Wheel::FollowTail Wheel::Run);
use IO::Socket::INET;
use NetAddr::IP;
use Data::Dumper;
use IO::Socket::INET;
use NetAddr::IP;
use Data::Dumper;
# in function register_at_gosa_si_server, after which period of seconds a new registration should be tried if a registration was
# not successful until now
# in function register_at_gosa_si_server, after which period of seconds a new registration should be tried if a registration was
# not successful until now
-my $delay_set_time = 5;
+my $delay_set_time = 10;
our $prg= basename($0);
# all x seconds the client reports logged_in users to gosa-si-server
our $prg= basename($0);
# all x seconds the client reports logged_in users to gosa-si-server
sub read_configfile {
my ($cfg_file, %cfg_defaults) = @_ ;
my $cfg;
sub read_configfile {
my ($cfg_file, %cfg_defaults) = @_ ;
my $cfg;
- if( defined( $cfg_file) && ( length($cfg_file) > 0 )) {
+ if( defined( $cfg_file) && ( (-s $cfg_file) > 0 )) {
if( -r $cfg_file ) {
$cfg = Config::IniFiles->new( -file => $cfg_file );
} else {
if( -r $cfg_file ) {
$cfg = Config::IniFiles->new( -file => $cfg_file );
} else {
foreach my $section (keys %cfg_defaults) {
foreach my $param (keys %{$cfg_defaults{ $section }}) {
my $pinfo = $cfg_defaults{ $section }{ $param };
foreach my $section (keys %cfg_defaults) {
foreach my $param (keys %{$cfg_defaults{ $section }}) {
my $pinfo = $cfg_defaults{ $section }{ $param };
- ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] );
+ ${@$pinfo[ 0 ]} = $cfg->val( $section, $param, @$pinfo[ 1 ] );
}
}
}
}
}
}
my ($signal) = @_;
daemon_log("shutting down gosa-si-client", 1);
my ($signal) = @_;
daemon_log("shutting down gosa-si-client", 1);
- system("killall gosa-si-client");
+ system("kill `ps -C gosa-si-client -o pid=`");
}
$SIG{INT} = \&sig_int_handler;
}
$SIG{INT} = \&sig_int_handler;
# encrypt xml msg
my $crypted_msg = &encrypt_msg($msg, $encrypt_key);
# encrypt xml msg
my $crypted_msg = &encrypt_msg($msg, $encrypt_key);
+ # xxxxxxxxxxxxxx
+
+
+
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
my $events = join( ",", keys %{$event_hash} );
while(1) {
my $events = join( ",", keys %{$event_hash} );
while(1) {
-
- if( $try_to_register >= @servers ) { last; }
-
# fetch first gosa-si-server from @servers
my $server = shift(@servers);
# fetch first gosa-si-server from @servers
my $server = shift(@servers);
exit(1);
}
exit(1);
}
- # create registration msg
- 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", $local_mac);
- &add_content2xml_hash($register_hash, "events", $events);
- &add_content2xml_hash($register_hash, "gotoHardwareChecksum", $gotoHardwareChecksum);
-
- # Add $HOSTNAME from ENV if force-hostname is set
- if( defined($client_force_hostname) &&
- $client_force_hostname eq "true") {
- if(defined($ENV{HOSTNAME}) &&
- length($ENV{HOSTNAME}) >0 ) {
- &add_content2xml_hash($register_hash, "force-hostname", $ENV{HOSTNAME});
- } else {
- &main::daemon_log("force-hostname was set to true, but no \$HOSTNAME was found in Environment!",0);
- }
- }
-
- # send xml hash to server with general server passwd
- my $res = &send_msg_hash_to_target($register_hash, $server, $default_server_key);
+ # create registration msg
+ 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", $local_mac);
+ &add_content2xml_hash($register_hash, "events", $events);
+ &add_content2xml_hash($register_hash, "gotoHardwareChecksum", $gotoHardwareChecksum);
+
+ # Add $HOSTNAME from ENV if force-hostname is set
+ if( defined($client_force_hostname) && $client_force_hostname eq "true") {
+ if(defined($ENV{HOSTNAME}) && length($ENV{HOSTNAME}) >0 ) {
+ &add_content2xml_hash($register_hash, "force-hostname", $ENV{HOSTNAME});
+ } else {
+ &main::daemon_log("force-hostname was set to true, but no \$HOSTNAME was found in Environment!",0);
+ }
+ }
+
+ # send xml hash to server with general server passwd
+ my $res = &send_msg_hash_to_target($register_hash, $server, $default_server_key);
- # if delivery of registration msg succeed
- if($res == 0) {
- # reset try_to_register
- $try_to_register = 0;
-
- # Set fixed client address and mac address
- $client_ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/));
- $client_address= "$client_ip:$client_port";
- $client_mac_address = $local_mac;
- $client_dnsname = $dnsname;
-
- last;
-
- # delivery of registration msg failed
- } else {
- $try_to_register++;
- # wait 1 sec until trying to register again
- sleep(1);
- next;
- }
+ if( $try_to_register >= @servers ) { last; }
+
+ # if delivery of registration msg succeed
+ if($res == 0) {
+ # reset try_to_register
+ $try_to_register = 0;
+
+ # Set fixed client address and mac address
+ $client_ip= &get_local_ip_for_remote_ip(sprintf("%s", $server =~ /^([0-9\.]*?):.*$/));
+ $client_address= "$client_ip:$client_port";
+ $client_mac_address = $local_mac;
+ $client_dnsname = $dnsname;
+ last;
+
+ # delivery of registration msg failed
+ } else {
+ $try_to_register++;
+ # wait 1 sec until trying to register again
+ sleep(1);
+ next;
+ }
} # end of while
} # end of while
# just do if client is registered already
if( $REGISTERED ) {
# just do if client is registered already
if( $REGISTERED ) {
- my $result = qx(/usr/bin/w -hs);
- my @res_lines;
-
- if( defined $result ) {
- chomp($result);
- @res_lines = split("\n", $result);
- }
-
- my @logged_in_user_list;
- foreach my $line (@res_lines) {
- chomp($line);
- my @line_parts = split(/\s+/, $line);
- push(@logged_in_user_list, $line_parts[0]);
- }
+ my $result = qx(/usr/bin/users);
+ my @logged_in_user_list;
+ if( defined $result ) {
+ chomp($result);
+ @logged_in_user_list = split(/\s/, $result);
+ }
+
system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si-client.socket");
$kernel->delay_set('trigger_logged_in_users_report', $trigger_logged_in_users_report_delay);
} else {
system("echo 'CURRENTLY_LOGGED_IN ".join(" ", @logged_in_user_list)."' > /var/run/gosa-si-client.socket");
$kernel->delay_set('trigger_logged_in_users_report', $trigger_logged_in_users_report_delay);
} else {
- # try it in 1 sec again
- $kernel->delay_set('trigger_logged_in_users_report', 1);
+ # try it in 10 sec again
+ $kernel->delay_set('trigger_logged_in_users_report', 10);
}
}
}
}
-sub generic_file_reset {
- my ( $heap, $wheel_id ) = @_[ HEAP, ARG0 ];
-
- my $service = $heap->{services}->{$wheel_id};
- daemon_log("INFO: '$service' watching reset", 5);
- return;
-}
+#sub generic_file_reset {
+# my ( $heap, $wheel_id ) = @_[ HEAP, ARG0 ];
+#
+# my $service = $heap->{services}->{$wheel_id};
+# daemon_log("INFO: '$service' watching reset", 5);
+# return;
+#}
sub generic_file_error {
my ( $heap, $operation, $errno, $error_string, $wheel_id ) =
sub generic_file_error {
my ( $heap, $operation, $errno, $error_string, $wheel_id ) =
$kernel->yield('register_at_gosa_si_server');
# install all file watcher defined
$kernel->yield('register_at_gosa_si_server');
# install all file watcher defined
- while( my($file_name, $file) = each %files_to_watch ) {
- my $file_watcher = POE::Wheel::FollowTail->new(
+ while( my($name, $file) = each %files_to_watch ) {
+ my $watcher = POE::Wheel::FollowTail->new(
Filename => $file,
Filename => $file,
- InputEvent => $file_name."_record",
- ResetEvent => "file_reset",
+ InputEvent => $name."_record",
+ # ResetEvent => "file_reset",
ErrorEvent => "file_error",
);
ErrorEvent => "file_error",
);
- $heap->{services}->{ $file_watcher->ID } = $file_name;
- $heap->{watchers}->{ $file_watcher->ID } = $file_watcher;
+# $heap->{tail} = POE::Wheel::Run->new(
+# Program => [ "/usr/bin/tail", "-f", $file ],
+# StdoutEvent => $file_name."_record",
+# );
+ $heap->{services}->{ $watcher->ID } = $name;
+ $heap->{watchers}->{ $watcher->ID } = $watcher;
}
$kernel->yield('trigger_logged_in_users_report');
}
}
$kernel->yield('trigger_logged_in_users_report');
}
# got a msg from gosa-si-server which can not be decrypted, may the secrete not up-to-date
# cause a reregistering with a new secrete handshake
daemon_log("WARNING: Message from gosa-si-server could not be understood, cause reregistering at server", 3);
# got a msg from gosa-si-server which can not be decrypted, may the secrete not up-to-date
# cause a reregistering with a new secrete handshake
daemon_log("WARNING: Message from gosa-si-server could not be understood, cause reregistering at server", 3);
- $REGISTERED = 0;
- $kernel->post('client_session', 'register_at_gosa_si_server');
+
+ # if client is alread in a registration process, that means not registered, do nothing
+ # if not, cause re-registration
+ if (not $REGISTERED) {
+ &daemon_log("WARNING: gosa-si-client is already in a registration process so ignore this message", 3);
+ } else {
+ $REGISTERED = 0;
+ $kernel->post('client_session', 'register_at_gosa_si_server');
+ }
}
$error++;
}
}
$error++;
}
# add gosa-si-server address from config file at first position of server list
my $server_check_cfg = Config::IniFiles->new( -file => $cfg_file );
# add gosa-si-server address from config file at first position of server list
my $server_check_cfg = Config::IniFiles->new( -file => $cfg_file );
-my $server_check = $server_check_cfg->val( "server", "ip");
+my $server_check = (defined($server_check_cfg))?$server_check_cfg->val( "server", "ip"):undef;
if( defined $server_check ) {
unshift(@servers, $server_address);
my $servers_string = join(", ", @servers);
if( defined $server_check ) {
unshift(@servers, $server_address);
my $servers_string = join(", ", @servers);