-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from samuelwilliams/bind-resolver
Bind resolver
- Loading branch information
Showing
10 changed files
with
365 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
$ORIGIN example.com. | ||
$TTL 1337 | ||
$INCLUDE hq.example.com.txt | ||
@ IN SOA ( | ||
example.com. ; MNAME | ||
post.example.com. ; RNAME | ||
2014110501 ; SERIAL | ||
3600 ; REFRESH | ||
14400 ; RETRY | ||
604800 ; EXPIRE | ||
3600 ; MINIMUM | ||
); This is my Start of Authority Record; AKA SOA. | ||
|
||
; NS RECORDS | ||
@ NS ns1.nameserver.com. | ||
@ NS ns2.nameserver.com. | ||
|
||
info TXT "This is some additional \"information\"" | ||
|
||
; A RECORDS | ||
sub.domain A 192.168.1.42 ; This is a local ip. | ||
|
||
; AAAA RECORDS | ||
ipv6.domain AAAA ::1 ; This is an IPv6 domain. | ||
|
||
; MX RECORDS | ||
@ MX 10 mail-gw1.example.net. | ||
@ MX 20 mail-gw2.example.net. | ||
@ MX 30 mail-gw3.example.net. | ||
|
||
mail IN TXT "THIS IS SOME TEXT; WITH A SEMICOLON" | ||
|
||
multicast APL ( | ||
1:192.168.0.0/23 | ||
2:2001:acad:1::/112 | ||
!1:192.168.1.64/28 | ||
!2:2001:acad:1::8/128 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PHP DNS Server. | ||
* | ||
* (c) Yif Swery <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace yswery\DNS\Resolver; | ||
|
||
use ArrayAccess; | ||
use Badcow\DNS\Rdata\RdataInterface; | ||
use Symfony\Component\PropertyAccess\PropertyAccess; | ||
use Symfony\Component\PropertyAccess\PropertyAccessor; | ||
|
||
/** | ||
* Represents Badcow\DNS\Rdata\RdataInterface as an array. | ||
*/ | ||
class ArrayRdata implements ArrayAccess | ||
{ | ||
/** | ||
* @var RdataInterface | ||
*/ | ||
private $rdata; | ||
|
||
/** | ||
* @var PropertyAccessor | ||
*/ | ||
private $propertyAccessor; | ||
|
||
public function __construct(RdataInterface $rdata) | ||
{ | ||
$this->rdata = $rdata; | ||
$this->propertyAccessor = PropertyAccess::createPropertyAccessor(); | ||
} | ||
|
||
public function getBadcowRdata(): RdataInterface | ||
{ | ||
return $this->rdata; | ||
} | ||
|
||
public function offsetExists($offset): bool | ||
{ | ||
return $this->propertyAccessor->isReadable($this->rdata, $offset); | ||
} | ||
|
||
public function offsetGet($offset) | ||
{ | ||
return $this->propertyAccessor->getValue($this->rdata, $offset); | ||
} | ||
|
||
public function offsetSet($offset, $value): void | ||
{ | ||
$this->propertyAccessor->setValue($this->rdata, $offset, $value); | ||
} | ||
|
||
public function offsetUnset($offset): void | ||
{ | ||
$this->propertyAccessor->setValue($this->rdata, $offset, null); | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->rdata->toText(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of PHP DNS Server. | ||
* | ||
* (c) Yif Swery <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace yswery\DNS\Resolver; | ||
|
||
use Badcow\DNS\Parser\ParseException; | ||
use Badcow\DNS\Parser\Parser; | ||
use Badcow\DNS\ResourceRecord as BadcowRR; | ||
use Badcow\DNS\ZoneBuilder; | ||
use yswery\DNS\ResourceRecord; | ||
|
||
class BindResolver extends AbstractResolver | ||
{ | ||
/** | ||
* BindResolver constructor. | ||
* | ||
* @param array $files | ||
* | ||
* @throws ParseException | ||
*/ | ||
public function __construct(array $files) | ||
{ | ||
$this->isAuthoritative = true; | ||
$this->allowRecursion = false; | ||
|
||
$resourceRecords = []; | ||
|
||
foreach ($files as $file) { | ||
$fileContents = file_get_contents($file); | ||
$zone = Parser::parse('.', $fileContents); | ||
ZoneBuilder::fillOutZone($zone); | ||
|
||
foreach ($zone as $rr) { | ||
$resourceRecords[] = self::convertResourceRecord($rr); | ||
} | ||
} | ||
|
||
$this->addZone($resourceRecords); | ||
} | ||
|
||
/** | ||
* Converts Badcow\DNS\ResourceRecord object to yswery\DNS\ResourceRecord object. | ||
* | ||
* @return ResourceRecord | ||
*/ | ||
public static function convertResourceRecord(BadcowRR $badcowResourceRecord, bool $isQuestion = false): ResourceRecord | ||
{ | ||
$rr = new ResourceRecord(); | ||
$rr->setName($badcowResourceRecord->getName()); | ||
$rr->setClass($badcowResourceRecord->getClassId()); | ||
$rr->setRdata(new ArrayRdata($badcowResourceRecord->getRdata())); | ||
$rr->setTtl($badcowResourceRecord->getTtl()); | ||
$rr->setType($badcowResourceRecord->getRdata()->getTypeCode()); | ||
$rr->setQuestion($isQuestion); | ||
|
||
return $rr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.