3.7. named

3.7.1. NAME

named - Guardian Digital WebTool module interface to the BIND DNS server.

3.7.2. SYNOPSIS

use named;
my $named   = new named($page);

3.7.3. DESCRIPTION

This Guardian Digital WebTool module provides an interface to manipulating the BIND DNS server. This module allows you to manage forward and reverse master and slave zones and zone records such as A (address), CNAME (name alias), MX (mail exchanger), NS (nameserver), and PTR (reverse addresses).

3.7.4. METHODS

is_installed()

This function is used to check DNS is installed or not.

Example Usage:

if (!$named->is_installed()) ...

inaddr2foo($)

This subroutine takes an in-addr.arpa address as an argument and turns it into the IP address.

Example Usage:

$named->inaddr2foo($zone);

reload()

This function checks to see if named service is running, if its running than it reloads else it returns zero.

Example Usage:

$named->reload();

restart()

This function checks to see if named service is running, if its running than it restarts else it returns zero.

Example Usage:

$named->restart();

read_named_conf()

This function processes and returns the named.conf file in a complex hash reference. For details on the return value you should look at the file.

Example Usage:

my $named_conf = $named->read_named_conf();

write_named_conf($)

Basic function is to write(edit) a named.conf file. It receives a hash reference of array reference of configuration parameters(allow-query,allow-transfer,listen-on etc). It reads through the named.conf file and compare parameters and values with provided parameters and ultimately updates/writes named.conf file.

Example Usage:

my $cfg = {
      'allow-query'           => \@allow_query,
      'allow-transfer'        => \@allow_transfer,
      'forwarders'            => \@forwarders,
      'listen-on'             => \@listen_on,
      'forward-only'          => ($forwarders[0]) ? 1 : 0,
};
$named->write_named_conf($cfg);

zone_generate_email($)

This function receives an email as argument, it substitute '@' with '.', and '.' is attached at the end of string if it doesnt have it.

Example Usage:

my $email = $named->zone_generate_email($email);

zone_generate_filename($$)

This function receives zone type and origin as arguments and it returns string like this master/db.' . $origin(generating file under master directory).

Example Usage:

my $filename  = $named->zone_generate_filename($type, $origin);

zone_generate_origin($$)

This function receives zone type and name as arguments. If type is 'forward' and name doesnt end with '.' then name is appended with '.'. If type is 'reverse' then name is split with '.' and splited string is concated with '.', and whole string now is concated with 'in-addr.arpa.' and returned.

Example Usage:

my $origin = $named->zone_generate_origin($type, $name);

zone_exists($$)

This function checks existance of zone in named.conf. It receives zone type and name as arguments. It looks for given type and name in named.conf, it it find this pair then it returns 1 else it returns 0.

Example Usage:

$exists = $named->zone_exists('master', $origin);

zone_create($)

This function basically creates a master zone in named.conf. It receives hash reference containing zone type, name, email as argument. Using these information it creates origing, email and filename values.Finally it writes out these information in named.conf.

Example Usage:

my $zone = {
      'TTL'                   => $in{'ttl_a'} . $in{'ttl_b'},
      'allow-query'           => \@allow_query,
      'allow-transfer'        => \@allow_transfer,
      'type'                  => $in{'type'},
      'master'                => $in{'master'},
      'email'                 => $in{'email'},
      'name'                  => $in{'zone_name'},
};
$create = $named->zone_create($zone);

zone_update($)

This function basically updates given zone. It receives hash reference containing zone type, name, email as argument. Using zone type it generates email specific to that zone. Finally it updates named.conf and zone file too.

Example Usage:

my $zone  = {
      'TTL'                   => $in{'ttl_a'} . $in{'ttl_b'},
      'allow-query'           => \@allow_query,
      'allow-transfer'        => \@allow_transfer,
      'type'                  => $in{'type'},
      'master'                => $in{'master'},
      'email'                 => $in{'email'},
      'name'                  => $in{'zone_name'},
};
$named->zone_update($zone);

zone_delete($)

This function is used to delete a specified zone. It receives hash reference containing zone name as argument. It reads through named.conf file and deletes that zone information. Zone file is also deleted from respective directory(master/slave).

Example Usage:

$named->zone_delete($zone);

zone_get($)

This function retrieves the specified zone, including all data from the named.conf and the records/SOA from the zone file. It receives a hash reference of zone information as argument.

Example Usage:

my $zone_data = $named->zone_get($zone);

zone_create_slave($)

This function is used to create a slave zone. It receives hash reference containing zone information as argument. It writes out these information in named.conf. It also creates zone file at appropriate location(slave/).

Example Usage:

my $zone   = {
      'allow-query'           => \@allow_query,
      'allow-transfer'        => \@allow_transfer,
      'masters'               => \@masters,
      'type'                  => $in{'type'},
      'name'                  => $in{'zone_name'},
};
$named->zone_create_slave($zone);

zone_update_slave($)

This function is used to update slave zone. It receives hash reference containing zone information as argument. It updates these information in named.conf.

Example Usage:

my $zone = {
      'allow-query'           => \@allow_query,
      'allow-transfer'        => \@allow_transfer,
      'masters'               => \@masters,
      'name'                  => $in{'zone_name'},
};
$named->zone_update_slave($zone);

bump_serial($)

This function is used to change provided(argument) zonefile. It reads through zone file, and it updates a line with timestamp, it just increases the serial number after the time stamp by 1.

Example Usage:

$named->bump_serial($zone);

record_clean($$)

This function receives two arguments. First argument is type(rval or lval). If type will be rval and second argument will not end with '.' then it will just append '.' at the end in second argument and return it. If type will be lval and second argument ends up with '.' then it splits second argument with '.' and returns first element of second argument.

Example Usage:

my $master  = $named->record_clean('rval', $zone->{'master'});

record_create($@)

This function basically creates a record in zone file. It receives two arguments. First argument is a hash reference containing record data and the second (optional) argument (yes or no, default is yes) dictates whether or not the zones serial number is updated.

Depending on the record type (A,CNAME,MX,NS etc) it writes out record details in appropriate zonefile.

Example Usage:

my $r = {
      'zone'          => $in{'zone'},
      'type'          => $in{'type'},
      'left'          => $in{'field1'},
      'right'         => $in{'field2'},
      'weight'        => $in{'field2'},
};
$named->record_create($r);

record_delete($@)

This function basically deletes a record from a zone file. It receives two arguments. First argument is a hash reference containing record data and the second (optional) argument (yes or no, default is yes) dictates whether or not the zones serial number is updated.

Depending on the record type (A,CNAME,MX,NS etc) it deletes record details from zone file.

Example Usage:

my $r = {
      'zone'          => $in{'zone'},
      'type'          => $in{'type'},
      'left'          => $in{'field1'},
      'right'         => $in{'field2'},
      'weight'        => $in{'field2'},
};
$named->record_delete($r);

3.7.5. AUTHORS

Ryan W. Maple <ryan@guardiandigital.com>

3.7.6. COPYRIGHT AND LICENSE

Copyright Guardian Digital, Inc., All Rights Reserved