Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Modify DNS zone file with Cpanel Hooks Perl Module

Discussion in 'cPanel Developers' started by Murray Trainer, Jun 10, 2015.

  1. Murray Trainer

    Murray Trainer Registered

    Joined:
    Jun 10, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
    #1 Murray Trainer, Jun 10, 2015
    Last edited by a moderator: Jun 10, 2015
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,378
    Likes Received:
    1,857
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Murray Trainer

    Murray Trainer Registered

    Joined:
    Jun 10, 2015
    Messages:
    4
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Perth WA
    cPanel Access Level:
    Reseller Owner
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,378
    Likes Received:
    1,857
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice