index 1eeba0c359f2dd7ab00bb277ed32162e8b8f42bb..7ce7c33efc056d19ae9ff4e64543f95d6e317744 100644 (file)
$soa.=" ".$zone[$attr];
}
$obj['sOARecord'] = trim($soa);
$soa.=" ".$zone[$attr];
}
$obj['sOARecord'] = trim($soa);
+ $obj['nSRecord'] = $zone['sOAprimary'];
/* If reverse zone was renamed, move entry
*/
/* If reverse zone was renamed, move entry
*/
/* Add new Records
*/
foreach($zone['RECORDS'] as $rec){
/* Add new Records
*/
foreach($zone['RECORDS'] as $rec){
+ if(!isset($obj[$rec['type']])||!is_array($obj[$rec['type']])){
+ $obj[$rec['type']] = array();
+ }
$obj[$rec['type']][] = $rec['value'];
}
$obj[$rec['type']][] = $rec['value'];
}
*/
foreach($oldZones as $zone) {
$oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
*/
foreach($oldZones as $zone) {
$oldDn = "zoneName=".$zone['InitialzoneName'].",".$HostDn;
- $del[$oldDn] = "";
+ $del[$oldDn] = $zone;
}
/* Check for entries which must be updated
}
/* Check for entries which must be updated
*/
$foundIn = array();
$zones = getAvailableZones($config);
*/
$foundIn = array();
$zones = getAvailableZones($config);
- foreach($zones as $zone){
- $zoneDn = getDNSZoneDN($config,$zone);
- $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*"));
- while($attrs = $ldap->fetch()){
- $foundIn [] = $attrs['dn'];
+
+ $zonesArr = array();
+ foreach($zones as $zoneMix){
+ $zoneIndex = split("/",$zoneMix);
+ if(!array_key_exists($zoneIndex[0],$zonesArr)) {
+ $zonesArr[$zoneIndex[0]] = array();
}
}
+ array_push($zonesArr[$zoneIndex[0]],$zoneIndex[1]);
}
}
-
- /* Alert if there is more than one zone with an entry named like $name
- */
- if((count($foundIn) > 1) && (!$silent)) {
- print_red(sprintf(_("Found more than one dns zone which contains an entry named '%s'. Aborting getting dns informations for this device."),$name));
+
+ foreach($zonesArr as $nameServer => $nameServerArr){
+ $foundInTmp = array();
+ foreach($nameServerArr as $zoneArr => $zone){
+ $zoneMix = $nameServer."/".$zone;
+ $zoneDn = getDNSZoneDN($config,$zoneMix);
+ $ldap->ls("(&(objectClass=dNSZone)(zoneName=*)(relativeDomainName=".$name.")(!(relativeDomainName=@)))", $zoneDn,$attrs = array("*"));
+ while($attrs = $ldap->fetch()){
+ $foundInTmp [$zoneMix] = $attrs['dn'];
+ $foundIn [$zoneMix] = $attrs['dn'];
+ }
+ }
}
/* No zone found which contains an entry for us
}
/* No zone found which contains an entry for us
/* Get host informations from zone
*/
/* Get host informations from zone
*/
- $ldap->cd($foundIn[0]);
+ $id_tmp = key($foundIn);
+ $ldap->cd($foundIn[$id_tmp]);
$ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("*"));
while($attrs = $ldap->fetch()){
$ldap->search("(&(objectClass=dNSZone)(zoneName=*)(!(relativeDomainName=@)))",array("*"));
while($attrs = $ldap->fetch()){
*/
if($attrs['relativeDomainName'][0] == $name){
$ret['exists'] = true;
*/
if($attrs['relativeDomainName'][0] == $name){
$ret['exists'] = true;
- foreach(array("dNSClass","zoneName","dNSTTL") as $atr){
+ $ret['zoneName'] = $id_tmp;
+ foreach(array("dNSClass","dNSTTL") as $atr){
if(isset($attrs[$atr][0])){
$ret[$atr] = $attrs[$atr][0];
}
if(isset($attrs[$atr][0])){
$ret[$atr] = $attrs[$atr][0];
}
$del = array();
$move = array();
$del = array();
$move = array();
+ /* Don't go further if there is nothing to do
+ * Is no account / was no account
+ */
+ if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
+ return(array("move"=>$move,"add"=>$add,"del"=>$del));
+ }
+
$zones = getAvailableZones($config);
$specialAttributes = array("cNAMERecord","pTRRecord");
$newRecords = array(); // Used to remember which records are removed
$zones = getAvailableZones($config);
$specialAttributes = array("cNAMERecord","pTRRecord");
$newRecords = array(); // Used to remember which records are removed
- $zoneName = $newEntry['zoneName'];
- $zoneDn = getDNSZoneDN($config,$zoneName);
+ $zoneNameMix = $newEntry['zoneName'];
+ $zoneDn = getDNSZoneDN($config,$zoneNameMix);
$tmp = array_flip($zones);
$tmp = array_flip($zones);
+ $zoneName = getNameFromMix($zoneNameMix);
/* If reverseZone can't be resolved ... this
* can't be a valid entry, so remove this account
*/
/* If reverseZone can't be resolved ... this
* can't be a valid entry, so remove this account
*/
- if(isset($tmp[$zoneName])){
- $reverseName = $tmp[$zoneName];
- $reverseDn = getDNSZoneDN($config,$reverseName);
+ if(isset($tmp[$zoneNameMix])){
+ $reverseNameMix = $tmp[$zoneNameMix];
+ $reverseDn = getDNSZoneDN($config,$reverseNameMix);
if(empty($reverseDn)){
$newEntry['exists'] = false;
}
if(empty($reverseDn)){
$newEntry['exists'] = false;
}
$newEntry['exists'] = false;
}
$newEntry['exists'] = false;
}
- /* Don't go further if there is nothing to do
- * Is no account / was no account
- */
- if(($newEntry['exists'] == false )&& ($oldEntry['exists'] == false)){
- return(array("move"=>$move,"add"=>$add,"del"=>$del));
- }
-
/* If account was edited prepare some
* attributes & arrays ... if required add some
* dns to $move
/* If account was edited prepare some
* attributes & arrays ... if required add some
* dns to $move
* like pTRRecord or CNAMERecord
*/
if($rec['type'] == "pTRRecord"){
* like pTRRecord or CNAMERecord
*/
if($rec['type'] == "pTRRecord"){
- $PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn;
+ $PTRdn= "relativeDomainName=".FlipIP($rec['value']).",".$baseDn;
$ptrObj = $baseObj;
$ptrObj = $baseObj;
+ $reverseName = getNameFromMix($reverseNameMix);
$ptrObj['zoneName'] = $reverseName;
$ptrObj['zoneName'] = $reverseName;
- $ptrObj['pTRRecord'] = $newName.".".$zoneName;
- $ptrObj['relativeDomainName'] = $rec['value'];
-
+ if(!preg_match("/\.$/",$newName)){
+ $ptrObj['pTRRecord'] = preg_replace("/\.\.$/",".",$newName.".".$zoneName.".");
+ }else{
+ $ptrObj['pTRRecord'] = preg_replace("/\.\.$/",".",$newName.".");
+ }
+ $ptrObj['relativeDomainName'] = FlipIP($rec['value']);
+
$add[$PTRdn] = $ptrObj;
}else
if($rec['type'] == "cNAMERecord"){
$PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn;
$ptrObj = $baseObj;
$add[$PTRdn] = $ptrObj;
}else
if($rec['type'] == "cNAMERecord"){
$PTRdn= "relativeDomainName=".$rec['value'].",".$baseDn;
$ptrObj = $baseObj;
- $ptrObj['zoneName'] = $reverseName;
- $ptrObj['cNAMERecord'] = $newName.".".$zoneName;
+ $ptrObj['zoneName'] = $zoneName;
+ $ptrObj['cNAMERecord'] = $newName;
$ptrObj['relativeDomainName'] = $rec['value'];
$add[$PTRdn] = $ptrObj;
$ptrObj['relativeDomainName'] = $rec['value'];
$add[$PTRdn] = $ptrObj;
return($ret);
}
return($ret);
}
+function getNameFromMix($zoneMix){
+ $ret = "";
+ if(!strstr($zoneMix, '/')) return($ret);
+ $zoneIndex = split("/",$zoneMix);
+ return($zoneIndex[1]);
+}
/* returns the dn for a specified zone
*/
/* returns the dn for a specified zone
*/
-function getDNSZoneDN($config,$zoneName){
+function getDNSZoneDN($config,$zoneNameMix)
+{
$ret = "";
$ret = "";
- $ldap = $config->get_ldap_link();
+ if(!strstr($zoneNameMix, '/')) {
+ print_red(sprintf(_("Undefined zone name '%s'. Zone name must look like this 'server/zone.com'."),$zoneNameMix));
+ return($ret);
+ }
+
+ $zoneNameIndex = split("/",$zoneNameMix);
+ $zoneName = $zoneNameIndex[1];
+ $nameServer = strtolower($zoneNameIndex[0]);
+ $ldap = $config->get_ldap_link();
+
+ /* search for the nameserver */
$ldap-> cd($config->current['BASE']);
$ldap-> cd($config->current['BASE']);
+ $ldap->search("(&(objectClass=goServer)(cn=".$nameServer."))",array("cn"));
+ if($ldap->count()){
+ $attr = $ldap->fetch();
+ } else {
+ return($ret);
+ }
+
+ $ldap-> cd($attr['dn']);
$ldap->search("(&(objectClass=dNSZone)(sOARecord=*)(zoneName=".$zoneName."))",array("zoneName"));
if($ldap->count()){
$attr = $ldap->fetch();
return($attr['dn']);
}
$ldap->search("(&(objectClass=dNSZone)(sOARecord=*)(zoneName=".$zoneName."))",array("zoneName"));
if($ldap->count()){
$attr = $ldap->fetch();
return($attr['dn']);
}
+
return($ret);
}
return($ret);
}
*/
foreach($ReverseZones as $Rdn => $Robj ){
if(preg_match("/".$dn."/",$Rdn)){
*/
foreach($ReverseZones as $Rdn => $Robj ){
if(preg_match("/".$dn."/",$Rdn)){
- $zones[$Robj['zoneName'][0]] = $obj['zoneName'][0];
+ $zones[strtoupper($ldap->getCn($dn))."/".$Robj['zoneName'][0]] =
+ strtoupper($ldap->getCn($dn))."/".$obj['zoneName'][0];
}
}
- }
+ }
}
return($zones);
}
}
return($zones);
}