Beispiel #1
0
 /**
  * @param  string         $exchange
  * @throws RdataException
  */
 public function setExchange($exchange)
 {
     if (!Validator::validateFqdn($exchange)) {
         throw new RdataException(sprintf('The exchange "%s" is not a Fully Qualified Domain Name', $exchange));
     }
     $this->exchange = $exchange;
 }
Beispiel #2
0
 /**
  * @param string $address
  *
  * @throws RdataException
  */
 public function setAddress($address)
 {
     if (!Validator::validateIpv4Address($address)) {
         throw new RdataException(sprintf('Address "%s" is not a valid IPv4 address', $address));
     }
     $this->address = $address;
 }
Beispiel #3
0
 /**
  * @param string $name
  *
  * @throws DNSException
  */
 public function setName($name)
 {
     if (!Validator::rrName($name)) {
         throw new DNSException(sprintf('"%s" is not a valid resource record name.', $name));
     }
     $this->name = (string) $name;
 }
Beispiel #4
0
 /**
  * @param $target
  * @throws RdataException
  */
 public function setTarget($target)
 {
     if (!Validator::validateFqdn($target)) {
         throw new RdataException(sprintf('The target "%s" is not a Fully Qualified Domain Name', $target));
     }
     $this->target = $target;
 }
Beispiel #5
0
 /**
  * @param $name
  * @throws DNSException
  */
 public function setName($name)
 {
     if (!Validator::validateFqdn($name, false)) {
         throw new DNSException('The name is not a Fully Qualified Domain Name');
     }
     $this->name = (string) $name;
 }
Beispiel #6
0
 /**
  * Expands an IPv6 address to its full, non-short hand representation.
  *
  * @param $ip
  * @throws \InvalidArgumentException
  *
  * @return string
  */
 public static function expandIpv6($ip)
 {
     if (!Validator::validateIpv6Address($ip)) {
         throw new \InvalidArgumentException(sprintf('"%s" is not a valid IPv6 address.', $ip));
     }
     $hex = unpack('H*hex', inet_pton($ip));
     $ip = substr(preg_replace('/([A-f0-9]{4})/', '$1:', $hex['hex']), 0, -1);
     return $ip;
 }
Beispiel #7
0
 /**
  * Takes a valid IPv6 address and contracts it
  * to its shorter version.
  *
  * E.g.: 2001:0000:0000:acad:0000:0000:0000:0001 -> 2001:0:0:acad::1
  *
  * Note: If there is more than one set of consecutive hextets, the function
  * will favour the larger of the sets. If both sets of zeroes are the same
  * the second will be favoured in the omission of zeroes.
  *
  * E.g.: 2001:0000:0000:ab80:2390:0000:0000:000a -> 2001:0:0:ab80:2390::a
  *
  * @param string $ip IPv6 address
  * @throws \InvalidArgumentException
  *
  * @return string Contracted IPv6 address
  */
 public static function contractIpv6($ip)
 {
     if (!Validator::validateIpv6Address($ip)) {
         throw new \InvalidArgumentException(sprintf('"%s" is not a valid IPv6 address.', $ip));
     }
     $ip = self::expandIpv6($ip);
     $decimals = array_map('hexdec', explode(':', $ip));
     //Find the larget streak of zeroes
     $streak = $longestStreak = 0;
     $streak_i = $longestStreak_i = -1;
     foreach ($decimals as $i => $decimal) {
         if (0 !== $decimal) {
             $streak_i = -1;
             $streak = 0;
             continue;
         }
         $streak_i = $streak_i === -1 ? $i : $streak_i;
         $streak += 1;
         if ($streak >= $longestStreak) {
             $longestStreak = $streak;
             $longestStreak_i = $streak_i;
         }
     }
     $ip = '';
     foreach ($decimals as $i => $decimal) {
         if ($i > $longestStreak_i && $i < $longestStreak_i + $longestStreak) {
             continue;
         }
         if ($i === $longestStreak_i) {
             $ip .= '::';
             continue;
         }
         $ip .= (string) dechex($decimal);
         $ip .= $i < 7 ? ':' : '';
     }
     return preg_replace('/\\:{3}/', '::', $ip);
 }
Beispiel #8
0
 /**
  *
  */
 public function testValidate()
 {
     $zone = $this->buildTestZone();
     $this->assertTrue(Validator::validate($zone));
 }
Beispiel #9
0
 /**
  * Tests a zone file using Bind's Check Zone feature. If CHECKZONE_PATH environment variable has been set.
  *
  * @param ZoneInterface        $zone
  * @param ZoneBuilderInterface $builder
  */
 protected function bindTest(ZoneInterface $zone, ZoneBuilderInterface $builder)
 {
     if (null === ($check_zone_path = $this->getEnvVariable(self::PHP_ENV_CHECKZONE_PATH))) {
         $this->markTestSkipped('Bind checkzone path is not defined.');
         return;
     }
     if (!`which {$check_zone_path}`) {
         $this->markTestSkipped(sprintf('The checkzone path specified "%s" could not be found.', $check_zone_path));
         return;
     }
     $zoneFile = $builder->build($zone);
     $tmpFile = new TempFile('badcow_dns_test_');
     $tmpFile->write($zoneFile);
     $this->assertTrue(Validator::validateZoneFile($zone->getName(), $tmpFile->getPath(), $check_zone_path));
 }
Beispiel #10
0
 /**
  * @param $rname
  * @throws RdataException
  */
 public function setRname($rname)
 {
     if (!Validator::validateFqdn($rname)) {
         throw new RdataException(sprintf('RName "%s" is not a Fully Qualified Domain Name', $rname));
     }
     $this->rname = $rname;
 }
Beispiel #11
0
 public function testFqdn()
 {
     //Pass cases
     $fqdn1 = 'example.com.';
     $fqdn2 = 'www.example.com.';
     $fqdn3 = 'ex-ample.com.';
     $fqdn4 = 'ex-ampl3.com.au.';
     $fqdn5 = 'alt2.aspmx.l.google.com.';
     $fqdn6 = 'www.eXAMple.cOm.';
     //Fail cases
     $fqdn7 = '3xample.com.';
     $fqdn8 = '_example.com.';
     $fqdn9 = '-example.com.';
     $fqdn10 = 'example.com';
     $fqdn11 = 'e&ample.com.';
     $this->assertTrue(Validator::fqdn($fqdn1));
     $this->assertTrue(Validator::fqdn($fqdn2));
     $this->assertTrue(Validator::fqdn($fqdn3));
     $this->assertTrue(Validator::fqdn($fqdn4));
     $this->assertTrue(Validator::fqdn($fqdn5));
     $this->assertTrue(Validator::fqdn($fqdn6));
     $this->assertFalse(Validator::fqdn($fqdn7));
     $this->assertFalse(Validator::fqdn($fqdn8));
     $this->assertFalse(Validator::fqdn($fqdn9));
     $this->assertFalse(Validator::fqdn($fqdn10));
     $this->assertFalse(Validator::fqdn($fqdn11));
 }