Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Created September 6, 2011 18:08
Show Gist options
  • Save marcoceppi/1198459 to your computer and use it in GitHub Desktop.
Save marcoceppi/1198459 to your computer and use it in GitHub Desktop.
public static function generate( $user, $domain )
{
// This will pull the META data from disk and return in an assoc array
$meta = Bind_Client::get($user, $domain, true);
$template_path = OWN_PATH . '/templates';
$parsed = array();
foreach( $meta['lines'] as $key => $entries )
{
$is_opt = $is_ns = false;
switch( $key )
{
case 'SOA':
$zone = str_replace('[USER]', $user, file_get_contents("$template_path/zone.tpl"));
$zone = str_replace('[DOMAIN]', $domain, $zone);
foreach( $entries as $el => $val )
{
$el = strtoupper($el);
$zone = str_replace("[$el]", $val, $zone);
}
break;
case 'MX':
case 'TXT':
$is_opt = true;
case 'NS':
case 'A':
case 'CNAME':
default:
if( !array_key_exists($key, $parsed) )
{
$parsed[$key] = array();
}
foreach( $entries as $entry )
{
$line = ($is_opt) ? file_get_contents("$template_path/opt-line.tpl") : file_get_contents("$template_path/line.tpl");
$line = str_replace('[CLASS]', $key, $line);
foreach( $entry as $el => $val )
{
$el = strtoupper($el);
$line = str_replace("[$el]", $val, $line);
}
$parsed[$key][] = $line;
unset($line);
}
break;
}
}
$zone .= implode('', $parsed['NS']);
unset($parsed['NS']);
foreach( $parsed as $lines )
{
$zone .= implode('', $lines);
}
var_dump($zone);
// This really should never occur based on our previous check. Though you can never be too sure
if( preg_match("/\[(A-Z)*?\]/", $config) )
{
throw new Exception(APACHE_TEMPLATE_MISMATCH);
}
}
php > require_once('Bind.php');
php > Bind_Server::generate('ondina', 'ondina.co');
string(813) ";
; ondina - ondina.co
;
$TTL [TTL]
@ IN SOA ns1.ondina.co. dnsadmin.ondina.co. (
201106051 ; Serial
10800 ; Refresh
3600 ; Retry
1209600 ; Expire
43200 ; Negative Cache TTL
)
;
@ IN NS ns1.ondina.co. ; [COMMENT]
@ IN NS ns2.ondina.co. ; [COMMENT]
mail IN A 205.186.156.60 ; [COMMENT]
* IN A 205.186.156.60 ; [COMMENT]
ns2 IN A 50.19.253.207 ; [COMMENT]
@ IN A 205.186.156.60 ; [COMMENT]
cp IN A 205.186.156.60 ; [COMMENT]
ns1 IN A 50.19.253.206 ; [COMMENT]
code IN A 205.186.156.60 ; [COMMENT]
@ IN MX 10 mail.ondina.co.ondina.co. ; [COMMENT]
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment