Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.0.8

Request #6275 Added features/Patch
Submitted: 2005-12-17 17:09 UTC Modified: 2008-04-05 15:16 UTC
From: pear at bekar dot id dot au Assigned: cipri
Status: Assigned Package: File_DNS
PHP Version: 4.3.11 OS: Linux
Roadmaps: 0.1.0    
Subscription  
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes. If this is not your bug, you can add a comment by following this link. If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: pear at bekar dot id dot au
New email:
PHP Version: Package Version: OS:

 

 [2005-12-17 17:09 UTC] pear at bekar dot id dot au
Description: ------------ A patch including bug 4528, plus Add/Remove items. Also expanded the allowed record types. --- DNS.php.orig 2004-06-29 06:52:26.000000000 +1000 +++ DNS.php 2005-12-18 09:05:01.000000000 +1100 @@ -200,10 +200,17 @@ * CNAME * PTR * + * // bekar@20050326 updates // + * Added support for a few extra record types: + * TXT + * NXT + * HINFO + * // end of updates // + * * @var array * @see _parseRR */ - var $_types = array('SOA', 'A', 'AAAA', 'NS', 'MX', 'CNAME', 'PTR'); + var $_types = array('SOA', 'A', 'AAAA', 'NS', 'MX', 'CNAME', 'PTR', 'TXT', 'NXT', 'HINFO'); /** * zonefile modification check @@ -490,16 +497,31 @@ case 'NS': case 'CNAME': case 'PTR': - $record['data'] = $item; + $zone[] = implode("\t", array( + $record['name'], + $record['ttl'], + $record['class'], + $record['type'], + $record['data'])); break; - case 'MX': //MX have an extra element. Save both right away. //The setting itself is in the next item. $record['data'] = $items[$key+1]; $record['options'] = array('MXPreference' => $item); break; - +// bekar@20050326 updates // + case 'TXT': + case 'NXT': + case 'HINFO': + //TXT and HINFO records are quoted text strings + if ( preg_match( '/TXT (.*)$/i', $line, $data ) ) { + $record['data'] = $data[1]; + } else { + $record['data'] = $items[$key+1]; + } + break; +// end updates // default: return PEAR::raiseError('Unable to parse RR. ' . $record['type'] . @@ -1127,6 +1149,88 @@ } // }}} + // {{{ addRecord() + + /** + * quick hack to add a record to the zone + * + * @param string $name The new record name + * @param int $ttl TTL for record (Defaults to SOA TTL) + * @param string $class Class of record (Default of 'IN') + * @param string $type record type + * @param string $data the data + * @param string $mx MX priority + * @return bool true/false based on validity of passed data + */ + function addRecord($name = NULL, $ttl = NULL, $class = "IN", $type, $data, $mx = 0) + { + if (array_search($type, $this->_types) && (($ttl == NULL) || is_int($ttl))) { + $quotedDomain = preg_quote($this->_domain); + if (ereg("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}", $data)) { + } else { + if (substr($data, -1) == '.') { + //String already correct. + } elseif (preg_match("/$quotedDomain" . '$/i', $data)) { + //String ends with this domain. Append a . + $data .= '.'; + } else { + //Subdomain specified. Append domainname + $data .= '.' . $this->_domain . '.'; + } + } + if ($name != null) { + if (substr($name, -1) == '.') { + //String already correct. + } elseif (preg_match("/$quotedDomain" . '$/i', $name)) { + //String ends with this domain. Append a . + $name .= '.'; + } else { + //Subdomain specified. Append domainname + $name .= '.' . $this->_domain . '.'; + } + } else { + $name = $this->_domain . '.'; + } + $this->_records[] = Array( + 'name' => $name, + 'ttl' => ( $ttl == NULL ? $this->_SOA['ttl'] : $ttl ), + 'class' => $class, + 'type' => $type, + 'data' => $data + ); + if ($type == "MX") { + $this->setMXPref($mx, $data, $name); + } + } else { + return false; + } + $this->_isModified = true; + return true; + } + // }}} + // {{{ delRecord() + + /** + * quick hack to remove a single named record from zone + * + * @param string $name name of record to remove + * @return bool true/falase based on whether a record was removed or not + */ + + function delRecord($name, $class = "IN", $type = null, $data = null) + { + foreach ($this->_records as $key => $record) { + if ( (strcasecmp($record['name'], $name) == 0) || (strcasecmp("$name.{$this->_domain}.", $record['name']) == 0) ) { + if ((($type == null) || ($type == $record['type'])) && (($data == null) || ($data == $record['data']))) { + unset($this->_records[$key]); + $this->_isModified = true; + return true; + } + } + } + return false; + } + // }}} // {{{ isIP()

Comments

 [2006-07-02 10:27 UTC] metz at php dot net (Michael Metz)
your Patch is broken. $record['data'] = $item; in _parseRR should not be removed.
 [2006-07-05 04:25 UTC] neufeind at php dot net (Stefan Neufeind)
Note: Still apply patch 4528 after this patch. Otherwise Zoneentries will be incorrectly generated. (Thought this new patch would already incorporate the other one - but it didn't.)