MyDNS - help with MyDNS management
use MyDNS;
# supply the DB location, or a DB handle
my $mydns=MyDNS->new($dbhost,$dbname,$dbuser,$dbpass);
# needed if you plan on creating anything
$mydns->set_defaults({
nameservers => ['ns1.domain.com','ns2.domain.com'],
mailbox => 'dnsadmin.domain.com',
});
$mydns->write_soa($domain);
# create a new reseource record
my $error=$mydns->write_rr($domain,{
name => '',
type => 'MX',
data => "mail.$domain.",
aux => 10,
ttl => 900,
});
$mydns->update_serial($domain);
if ($mydns->check_exists($domain)){
print "$domain exists!\n";
my $soa=$mydns->read_soa($domain);
foreach my $key (sort keys %$soa){
print "\t$key\t$soa->{$key}\n";
}
my @rrs=$mydns->get_all_rr($domain);
foreach my $rr (@rrs){
print "\t\t-----\n";
foreach my $key (sort keys %$rr){
print "\t\t$key\t$rr->{$key}\n";
}
}
}
else{
print "$domain not there!\n";
}
# delete the domain and all records
$mydns->delete_soa($domain);
The purpose for this module is to provide a simple and clean way to interface with a MyDNS database to manage zones and records. The module depends on Data::Validate::IP, DBI, and DBD::mysql.
new
Returns a new MyDNS object. You can optionally provide database connection args at this time (see db_connect).
db_connect
Establish a DB connetion with the mydns server DB. You can supply either an existing database handle, or the host, name, user and pass to use to make a new one.
set_defaults
Setup some default values that will be needed when creating records. Any writing for SOA or RR types will require this, and missing fields will be printing to STDERR when invoked. This can be skipped/ignored if no writing is to be done.
check_exists
Given a domain name, check to see if the zone exists in the database.
read_soa
Given a domain name, return the SOA record for it.
write_soa
Given a domain name, write or update a SOA record with the default information provided in set_defaults as the basis for the SOA info and a single NS record for each nameserver.
delete_soa
Given a domain name, delete the soa and all resource records.
update_serial
Given a domain name, update the serial for that domain.
get_all_rr
Given a domain name, returns an array of hashrefs, one for each resource record in that zone. An optional type filer can be provided that will limit the records to the type requested.
get_rr_by_id
Given an id number, retrieve the resource record that matches.
get_rr_by_info
Given a domain name, a resource record name, a type, and the rdata, return a resource record.
write_rr
Given a domain name and a properly built hash, create or update a resource record in the zone.
delete_rr
Given a domain name and a resource record id, delete the record.
This currently only works with the mysql schema defined in the mydns manual. No additional fields are used, but will be returned as normal with all other information.
Steve Bradford (steve at geek pro tem dot com)