From: hickert Date: Wed, 24 Jun 2009 13:50:49 +0000 (+0000) Subject: Updated terminal dns X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b9fd31eeafebce9726838811dea2457f845f1d29;p=gosa.git Updated terminal dns -provides uniqe IPs now. git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@13786 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/gosa-plugins/systems/admin/systems/class_termDNS.inc b/gosa-plugins/systems/admin/systems/class_termDNS.inc index ef6f8252a..a1aa50bcd 100644 --- a/gosa-plugins/systems/admin/systems/class_termDNS.inc +++ b/gosa-plugins/systems/admin/systems/class_termDNS.inc @@ -391,7 +391,7 @@ class termDNS extends plugin foreach($this->Zones as $key => $name){ if($name == $this->dnsEntry['zoneName']){ $net = DNS::FlipIp(str_replace(".in-addr.arpa","",DNS::getNameFromMix($key))); - $this->ipHostNumber = $this->generateRandomIp($net); + $this->ipHostNumber = $this->generateRandomIP($net); } } } @@ -1105,13 +1105,48 @@ class termDNS extends plugin { $str = $net; $cnt = 4; - while(substr_count($str,".") < 3 && $cnt > 0){ - $str .= ".".rand(0,255); - $str = preg_replace("/\.\.*/",".",$str); - $str = trim($str,". "); - $cnt --; + + // first gather all IPs + $ldap = $this->config->get_ldap_link(); + $ocs = + "(objectClass=goFonHardware)". + "(objectClass=goServer)". + "(objectClass=GOhard)". + "(objectClass=gotoTerminal)". + "(objectClass=gotoWorkstation)". + "(objectClass=gotoPrinter)". + "(objectClass=ipHost)"; + $list = array(); + $ldap->search("(&(|{$ocs})(ipHostNumber={$net}*))",array("ipHostNumber")); + while($attrs = $ldap->fetch()){ + $list[] = $attrs['ipHostNumber'][0]; } - return($str); + + // Set starting ip. + $ip_data = preg_split("/\./",$net); + for($i=0;$i<4;$i++){ + if(!isset($ip_data[$i])) $ip_data[$i] = 0; + } + + // Search the next free and valid ip. + while(in_array(implode(".",$ip_data),$list) || $ip_data[3] <= 1){ + $ip_data[3] ++ ; + if($ip_data[3] > 255){ + $ip_data[3] = 1 ; + $ip_data[2] ++ ; + } + if($ip_data[2] > 255){ + $ip_data[2] = 1 ; + $ip_data[1] ++ ; + } + if($ip_data[1] > 255){ + $ip_data[1] = 1 ; + $ip_data[0] ++ ; + } + if($ip_data[0] > 255) break; + } + + return(implode(".",$ip_data)); }