diff --git a/gosa-si/gosa-si-client b/gosa-si/gosa-si-client
index 3f438595316ce7303b77f7d5029e9a993242ffa9..be282a52de1d65c005a366224c30e8f04f2c4374 100755 (executable)
--- a/gosa-si/gosa-si-client
+++ b/gosa-si/gosa-si-client
# DESCRIPTION:
#===============================================================================
sub daemon_log {
- # log into log_file
+# log into log_file
my( $msg, $level ) = @_;
if(not defined $msg) { return }
if(not defined $level) { $level = 1 }
chmod 0600, $log_file;
if(not defined open( LOG_HANDLE, ">>$log_file" )) {
print STDERR "cannot open $log_file: $!";
- return }
- chomp($msg);
- if($level <= $verbose){
- 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", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
- $month = $monthnames[$month];
- $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
- $year+=1900;
-
- my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n";
- print LOG_HANDLE $log_msg;
- if( $foreground ) {
- print STDERR $log_msg;
- }
+ return
+ }
+ chomp($msg);
+ if($level <= $verbose){
+ 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", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
+ $month = $monthnames[$month];
+ $monthday = $monthday < 10 ? $monthday = "0".$monthday : $monthday;
+ $year+=1900;
+
+ my $log_msg = "$month $monthday $hours:$minutes:$seconds $prg $msg\n";
+ print LOG_HANDLE $log_msg;
+ if( $foreground ) {
+ print STDERR $log_msg;
}
+ }
close( LOG_HANDLE );
}
}
-#=== FUNCTION ================================================================
-# NAME: get_interfaces
-# PARAMETERS: none
-# RETURNS: (list of interfaces)
-# DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
-#===============================================================================
-sub get_interfaces {
- my @result;
- my $PROC_NET_DEV= ('/proc/net/dev');
-
- open(PROC_NET_DEV, "<$PROC_NET_DEV")
- or die "Could not open $PROC_NET_DEV";
-
- my @ifs = <PROC_NET_DEV>;
-
- close(PROC_NET_DEV);
-
- # Eat first two line
- shift @ifs;
- shift @ifs;
-
- chomp @ifs;
- foreach my $line(@ifs) {
- my $if= (split /:/, $line)[0];
- $if =~ s/^\s+//;
- push @result, $if;
- }
-
- return @result;
-}
-
#=== FUNCTION ================================================================
# NAME: get_mac
# PARAMETERS: interface name (i.e. eth0)
}
-#=== FUNCTION ================================================================
-# NAME: get_interface_for_ip
-# PARAMETERS: ip address (i.e. 192.168.0.1)
-# RETURNS: array: list of interfaces if ip=0.0.0.0, matching interface if found, undef else
-# DESCRIPTION: Uses proc fs (/proc/net/dev) to get list of interfaces.
-#===============================================================================
-sub get_interface_for_ip {
- my $result;
- my $ip= shift;
- if ($ip && length($ip) > 0) {
- my @ifs= &get_interfaces();
- if($ip eq "0.0.0.0") {
- $result = "all";
- } else {
- foreach (@ifs) {
- my $if=$_;
- if(get_ip($if) eq $ip) {
- $result = $if;
- last;
- }
- }
- }
- }
- return $result;
-}
-
-
-#=== FUNCTION ================================================================
-# NAME: get_ip
-# PARAMETERS: interface name (i.e. eth0)
-# RETURNS: (ip address)
-# DESCRIPTION: Uses ioctl to get ip address directly from system.
-#===============================================================================
-sub get_ip {
- my $ifreq= shift;
- my $result= "";
- my $SIOCGIFADDR= 0x8915; # man 2 ioctl_list
- my $proto= getprotobyname('ip');
-
- socket SOCKET, PF_INET, SOCK_DGRAM, $proto
- or die "socket: $!";
-
- if(ioctl SOCKET, $SIOCGIFADDR, $ifreq) {
- my ($if, $sin) = unpack 'a16 a16', $ifreq;
- my ($port, $addr) = sockaddr_in $sin;
- my $ip = inet_ntoa $addr;
-
- if ($ip && length($ip) > 0) {
- $result = $ip;
- }
- }
-
- return $result;
-}
-
#=== FUNCTION ================================================================
# NAME: get_local_mac_for_remote_ip
# encrypt xml msg
my $crypted_msg = &encrypt_msg($msg, $encrypt_key);
- # xxxxxxxxxxxxxx
-
-
-
# opensocket
my $socket = &open_socket($address);
if( !$socket ) {
daemon_log("ERROR: cannot send ".$msg_header."msg to $address , host not reachable", 1);
- $REGISTERED = 0; # if server is not available, cause reregistering
- #$global_kernel->yield('register_at_gosa_si_server');
+ if ($REGISTERED == 1) {
+ $REGISTERED = 0; # if server is not available, cause reregistering
+ daemon_log("INFO: cause reregistering at gosa-si-server", 5);
+ $global_kernel->yield('register_at_gosa_si_server');
+
+ }
$error++;
}
if( $error == 0 ) {
print $socket $crypted_msg."\n";
daemon_log("INFO: send ".$msg_header."msg to $address", 5);
- daemon_log("DEBUG: message:\n$msg", 8);
+ daemon_log("DEBUG: message:\n$msg", 9);
}
# close socket in any case
my $msg_hash;
eval{
$msg = &decrypt_msg($crypted_msg, $module_key);
- &main::daemon_log("decrypted_msg: \n$msg", 8);
+ &main::daemon_log("decrypted_msg: \n$msg", 9);
$msg_hash = $xml->XMLin($msg, ForceArray=>1);
daemon_log("INFO: Incoming msg from '$remote_ip'", 5);
- daemon_log("DEBUG: Incoming msg:\n$input\n", 8);
+ daemon_log("DEBUG: Incoming msg:\n$input\n", 9);
my ($msg, $msg_hash) = &check_key_and_xml_validity($input, $server_key);
if( (!$msg) || (!$msg_hash) ) {
if( exists $event_hash->{$header} ) {
# a event exists with the header as name
- daemon_log("DEBUG: found event '$header' at event-module '".$event_hash->{$header}."'", 7);
+ daemon_log("INFO: found event '$header' at event-module '".$event_hash->{$header}."'", 5);
no strict 'refs';
$answer = &{$event_hash->{$header}."::$header"}($msg, $msg_hash);
}
else {
- daemon_log("WARNING: no event '$header' found in event modules under $event_dir", 1);
+ daemon_log("WARNING: no event '$header' found in event modules under $event_dir", 3);
}
}