The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
  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:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page