PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/tools/ipv6_ptr.php

http://freshdns.googlecode.com/
PHP | 70 lines | 54 code | 15 blank | 1 comment | 1 complexity | b7bbb0b601a59507a16097d7231c1e5d MD5 | raw file
 1<?php
 2$prefix = "2001:888:2000:0013::/64";	// You're assigned IPv6 prefix
 3$stdptr = 'ipv6.example.com';			// The default FQDN we return when reverse DNS is looked up
 4
 5$config['DNS']['templates']['ipv6ptr'] = array( # DO NOT CHANGE, UNLESS YOU KNOW WHAT YOU ARE DOING!
 6array("name" => "{#DOMAIN#}",		"type" => "SOA",	"content" => "{#NS0#} {#HOSTMASTER#} {#SOACODE#}",				"prio" => "0",	"ttl" => "3600"),
 7array("name" => "{#DOMAIN#}",		"type" => "NS",		"content" => "{#NS0#}",								"prio" => "0",	"ttl" => "3600"),
 8array("name" => "{#DOMAIN#}",		"type" => "NS",		"content" => "{#NS1#}",								"prio" => "0",	"ttl" => "3600"),
 9array("name" => "{#DOMAIN#}",		"type" => "NS",		"content" => "{#NS2#}",								"prio" => "0",	"ttl" => "3600"),
10array("name" => "*.{#DOMAIN#}",		"type" => "PTR",	"content" => "{#STDPTR#}",							"prio" => "0",  "ttl" => "3600"));
11
12/* DO NOT EDIT BELOW THIS LINE! */
13include_once("./config.inc.php");
14
15$manager = new Manager($config['database']);
16
17function generateIPv6ARPA ($prefix)
18{
19	$prefix = explode("::", $prefix);
20	$prefix = $prefix[0];
21
22	$parts = explode(":", $prefix);
23
24	foreach($parts AS $key => $part)
25	{
26		while(strlen($part) < 4)
27		{
28			$part = '0'.$part;
29		}
30	
31		$parts[$key] = $part;
32	}
33
34	$reverse = implode("", $parts);
35
36	$arpa = "ip6.arpa";
37
38	for($i=0; $i<strlen($reverse); $i++)
39	{
40		$char = substr($reverse, $i, 1);
41		$arpa = $char.'.'.$arpa;
42	}
43
44	return $arpa;
45}
46
47$name = generateIPv6ARPA($prefix);
48
49try {
50	$domainId = $manager->addDomain ($name, '', 0, 'NATIVE', 0, '');
51	$manager->addZone($domainId, 1, "");
52	
53	foreach($config['DNS']['templates']['ipv6ptr'] AS $record)
54	{
55		$record['name']		= str_replace("{#DOMAIN#}",			$name,								$record['name']);
56		$record['content']	= str_replace("{#DOMAIN#}",			$name,								$record['content']);
57		$record['content']	= str_replace("{#NS0#}",			$config['DNS']['ns0'],				$record['content']);
58		$record['content']	= str_replace("{#NS1#}",			$config['DNS']['ns1'],				$record['content']);
59		$record['content']	= str_replace("{#NS2#}",			$config['DNS']['ns2'],				$record['content']);
60		$record['content']	= str_replace("{#HOSTMASTER#}", 	$config['DNS']['hostmaster'],		$record['content']);
61		$record['content']	= str_replace("{#SOACODE#}",		$manager->createNewSoaSerial(),		$record['content']);
62		$record['content']	= str_replace("{#STDPTR#}",			$stdptr,							$record['content']);
63		
64		$manager->addRecord ($domainId, $record['name'], $record['type'], $record['content'], $record['ttl'], $record['prio'], $record['changeDate']);
65	}
66}catch (Exception $ex)
67{
68	echo $ex->getMessage();
69}
70?>