PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » File Formats » File_DNS » Bug #6275

Added features/Patch

Details

Request #6275Added features/Patch
Submitted2005-12-17 22:09 UTC
Frompear at bekar dot id dot au
Assignedcipri
StatusBogus
PackageFile_DNS
PHP Version4.3.11
OSLinux
Roadmaps(Not assigned)

Comments

[2005-12-17 22: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()

[2006-07-02 15:27 UTC] metz at php dot net

your Patch is broken.
$record['data'] = $item;
in _parseRR should not be removed.

[2006-07-05 09:25 UTC] neufeind at php dot net

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.)