Ejemplo n.º 1
0
/**
 * Search for a host in the DNS Zone file and return the details in an array
 *
 * @param xml $zoneXML
 * @param string $host
 * @return array
 */
function cpanel_ddns_SearchForHostInZoneFile($zoneXML, $host)
{
    // Count the number of zone records
    $dns_records_count = count($zoneXML->children());
    // PHP < 5.3 version
    /*
     * Loop though the zone records until we find the one that contains the record 
     * we wish to update. Also locate the SOA record if exists.
     */
    for ($i = 0; $i <= $dns_records_count; $i++) {
        // Search for the record we want to update
        if ($zoneXML->record[$i]->name == $host . '.' && $zoneXML->record[$i]->type == 'A') {
            $zone_number_to_update = $i;
        }
        // Look for the SOA record
        if ($zoneXML->record[$i]->type == 'SOA') {
            $zone_number_of_SOA_record = $i;
        }
    }
    /*
     * Check if we were able to locate an SOA record and return the serial if so
     */
    if (!is_null($zone_number_of_SOA_record)) {
        // We were able to locate an SOA record
        $SOA_record = cpanel_ddns_FetchRecordFromXMLByNumber($zoneXML, $zone_number_of_SOA_record);
        //        echo ' % ' . $SOA_record['serial'] . ' % ';
    } else {
        // We were not able to locate an SOA record for this domain.
        cpanel_ddns_ErrorMessageAdd('SOA not found for this domain.');
        return FALSE;
    }
    /*
     * Were we able to locate the host record?
     */
    if (!is_null($zone_number_to_update)) {
        // We were able to locate an A record
        $zone_record = cpanel_ddns_FetchRecordFromXMLByNumber($zoneXML, $zone_number_to_update);
        //        echo ' % ' . $zone_record['name'] . ' % ';
    } else {
        // We were not able to locate an A record for this host.
        cpanel_ddns_ErrorMessageAdd('A record was not found for this host.');
        return FALSE;
    }
    return $zone_record;
}
Ejemplo n.º 2
0
 /**
  * Convert xml node to array.
  * @param  xml $xml Xml file content object.
  * @return array      array of xml data.
  */
 public function wpgmp_xml_2array($xml)
 {
     $arr = array();
     foreach ($xml->children() as $r) {
         $t = array();
         if (count($r->children()) == 0) {
             $arr[$r->getName()] = strval($r);
         } else {
             $arr[$r->getName()][] = $this->wpgmp_xml_2array($r);
         }
     }
     return $arr;
 }