From 9d774b43f8c8d323f365e38a775e57ad15c05a62 Mon Sep 17 00:00:00 2001 From: rettenbe Date: Wed, 5 Dec 2007 16:08:46 +0000 Subject: [PATCH] automatic detection of ip and mac address ip and mac address have no longe be defined in cfg file git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8028 594d385d-05f5-0310-b6e9-bd551577e9d8 --- contrib/daemon/gosa-sd | 37 ++++++++++++++++++++++++++++- contrib/daemon/gosa-sd.cfg-template | 1 - 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/contrib/daemon/gosa-sd b/contrib/daemon/gosa-sd index b02c31417..613987bad 100755 --- a/contrib/daemon/gosa-sd +++ b/contrib/daemon/gosa-sd @@ -43,7 +43,7 @@ my $modules_path = "/etc/gosad/modules"; my ($cfg_file, %cfg_defaults, $foreground, $verbose, $ping_timeout); my ($bus, $msg_to_bus, $bus_cipher); -my ($server, $server_mac, $server_events); +my ($server, $server_mac_address, $server_events); my ($gosa_server); my ($known_daemons, $shmda, $known_clients, $shmcl, $known_modules); my ($max_clients); @@ -287,6 +287,33 @@ sub check_pid { } +#=== FUNCTION ================================================================ +# NAME: get_ip_and_mac +# PARAMETERS: nothing +# RETURNS: (ip, mac) +# DESCRIPTION: executes /sbin/ifconfig and parses the output, the first occurence +# of a inet address is returned as well as the mac address in the line +# above the inet address +#=============================================================================== +sub get_ip_and_mac { + my $ip = "0.0.0.0.0"; # Defualt-IP + my $mac = "00:00:00:00:00:00"; # Default-MAC + my @ifconfig = qx(/sbin/ifconfig); + foreach(@ifconfig) { + if (/Hardware Adresse (\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2}):(\S{2})/) { + $mac = "$1:$2:$3:$4:$5:$6"; + next; + } + if (/inet Adresse:(\d+).(\d+).(\d+).(\d+)/) { + $ip = "$1.$2.$3.$4"; + last; + } + } + return ($ip, $mac); +} + + + #=== FUNCTION ================================================================ # NAME: import_modules # PARAMETERS: module_path - string - abs. path to the directory the modules are stored @@ -1761,6 +1788,14 @@ close( LOCK_FILE ); if( !$foreground ) { exit( 0 ) }; } +# detect own ip and mac address +($server_ip, $server_mac_address) = &get_ip_and_mac(); +if (not defined $server_ip) { + die "EXIT: ip address of $0 could not be detected"; +} +daemon_log("server ip address detected: $server_ip", 1); +daemon_log("server mac address detected: $server_mac_address", 1); + # setup xml parser $xml = new XML::Simple(); diff --git a/contrib/daemon/gosa-sd.cfg-template b/contrib/daemon/gosa-sd.cfg-template index 3ccaaaba7..56f57c992 100644 --- a/contrib/daemon/gosa-sd.cfg-template +++ b/contrib/daemon/gosa-sd.cfg-template @@ -13,7 +13,6 @@ child_timeout = 10 [server] server_activ = on -server_ip = 10.89.1.155 server_port = 10001 server_passwd = tester max_clients = 5 -- 2.30.2