Modify DNS zone file with Cpanel Hooks Perl Module

Murray Trainer

Registered
Jun 10, 2015
4
0
1
Perth WA
cPanel Access Level
Reseller Owner
Hi,

I need to list and modify DNS records within Cpanel Hook perl code. I assume I have to use Cpanel API's as it runs as the cpanel user and needs privilege escalation to modify the DNS zone files. I have tried various methods without success ....

Code:
Cpanel::API::execute( 'ZoneEdit', 'add_zone_record', { domain => $domain, name => 'autoconfig.' . $sub, type => 'CNAME', cname => $domain . '.' } ); #  didn't work

use Cpanel::ZoneEdit;
my %result = Cpanel::ZoneEdit::api2_fetchzone_records( { domain => $domain } );
my $filename = '/tmp/dumper.txt';
open(my $fh, '>', $filename) or die "Could not open file '$filename' $!";
use Data::Dumper qw(Dumper);
print $fh  Dumper \%result;
close $fh;   # this just returned undefined
What is the recommended method of doing this? A working example of listing zone records and modify one would be greatly appreciated.

Thanks

Murray
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,211
363

Murray Trainer

Registered
Jun 10, 2015
4
0
1
Perth WA
cPanel Access Level
Reseller Owner

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,211
363