Edit DNS Zone Records By PHP Code
How Can Edit/Add/Delete DNS Zone Record by PHP?
Best Regards
-
thanks but how can define(Or Include) CPANEL class? 0 -
include "xmlapi.php"; $cpanel = new CPANEL(); // Connect to cPanel - only do this once. // Edit a type "A" zone record on "example.com" $edit_zone_record = $cpanel->api2( 'ZoneRecord', 'edit_zone_record', array( 'Line' => '10', 'domain' => 'domain.ir', 'name' => 'sub', 'type' => 'A', 'address' => '10.10.10.10', 'ttl' => '10', 'class' => 'IN', ) );
what is line?0 -
what is line?
It's documented in the initial URL you were provided: The line in the zone file to edit. Thank you.0 -
i so dissied i include xmlapi.php error in error_log wrote "fetal error" __________________ my codes: include "xmlapi.php"; $cpanel = new CPANEL(); // Connect to cPanel - only do this once. // Add a type "A" zone record to "example.com" $add_zone_record = $cpanel->api2( 'ZoneRecord', 'add_zone_record', array( 'domain' => 'domain.ir', 'name' => 'sub', 'type' => 'A', 'address' => '10.10.10.10', 'ttl' => '10', 'class' => 'IN', ) ); print_r($add_zone_record);
______________________ why dont work? my host just use 2082 port0 -
now errored: [18-Sep-2015 20:25:44 Asia/Tehran] PHP Fatal error: Class 'CPANEL' not found in /home/khazrait/public_html/dns/tst.php on line 3 0 -
Could you let us know the exact steps you took to upload the PHP client class to your account? Thank you. 0 -
first uploaded xmlapi.php to dns folder at root and create a file for write script to add/change/delete zone. i write include xmlapi.php in that. and wrote this codes: api2( 'ZoneRecord', 'add_zone_record', array( 'domain' => 'example.ir', 'name' => 'sub', 'type' => 'A', 'address' => '10.10.10.10', 'ttl' => '10', 'class' => 'IN', ) ); print_r($add_zone_record); ?>
code page url: - Removed -Could you let us know the exact steps you took to upload the PHP client class to your account? Thank you.
0 -
You may want to start by using one of the example scripts at: xmlapi-php/api2_example_withargs.php at master " CpanelInc/xmlapi-php " GitHub This post may help with the authentication: Remote Authentication - cPanel (No WHM) - ListPopAccounts Try getting the example script working for a specific email account on your system so you are successful with an example script before proceeding to writing your own. Thank you. 0 -
thanks for reply and sorry for late answer why show this problem? [21-Apr-2016 17:49:12 Asia/Tehran] PHP Fatal error: Uncaught exception 'Exception' with message 'No host defined' in /home/khazrait/public_html/aa/cp/xmlapi.php:237 Stack trace: #0 /home/khazrait/public_html/aa/cp/Examples/listzones_example.php(30): xmlapi->__construct(false) #1 {main} thrown in /home/khazrait/public_html/aa/cp/xmlapi.php on line 237
and i must fill this parameters at "xmlapi.php"? [PHP] private $debug = false; // The host to connect to private $host = '127.0.0.1'; // the port to connect to private $port = '2087'; // should be the literal strings http or https private $protocol = 'https'; // output that should be given by the xml-api private $output = 'simplexml'; // literal strings hash or password private $auth_type = null; // the actual password or hash private $auth = null; // username to authenticate as private $user = null; // The HTTP Client to use private $http_client = 'curl';[/PHP]0 -
You should not have to manually modify the xmlapi.php file. It should match what's available for download at: xmlapi-php/xmlapi.php at master " CpanelInc/xmlapi-php " GitHub You may also find a thread like this helpful an example of the concept: xmlapi add SRV record Thank you. 0 -
thank you. now i need know how get a zone record line and how remove it. i can't find help and example for $xmlapi->api2_query [PHP] print $xmlapi->api2_query( 'ZoneEdit', 'remove_zone_record', array( 'domain' => 'example.com', 'line' => '42', ) ); [/PHP] I used to remove zone record but sho this error [HTML]{"cpanelresult":{"apiversion":"2","error":"The "cpanel_jsonapi_func" parameter is required.","data":{"reason":"The "cpanel_jsonapi_func" parameter is required.","result":"0"},"type":"text"}}[/HTML] 0 -
Hello, Could you let us know the full PHP code you are implementing, without the real authentication credentials? Thank you. 0 -
Hello This is my Code, it is not more than .. ?! but i set [PHP]private $port = '2083';[/PHP] because i cant access WHM. then i use cpanel port. add zone record worked. [PHP]password_auth("userroot","passroot"); $xmlapi->set_output('json'); $xmlapi->set_debug(0); $rand=rand(0,10000); /* print $xmlapi->api2_query("cPanelUserAccount", "ZoneEdit", "add_zone_record", array( 'domain' => 'mydomain.com', #Already an addon domain for the account 'name' => 'test'.$rand, #Took this from a working SRV record I created using the advanced web editor 'type' => 'CNAME', 'cname' => 'cname.dom', #server1.mydomain.com has an existing A record 'ttl' => '300', 'class' => 'IN',) ); */ //print $xmlapi->api2_query( 'ZoneEdit', 'fetchzones',); print $xmlapi->api2_query( 'ZoneEdit', 'remove_zone_record', '42', ) ); ?>[/PHP] 0 -
thanks i found my resault until now. no need answer. 0 -
thanks i found my resault until now. no need answer.
I'm happy to see you were able to resolve the problem. Feel free to share your findings here for others who may encounter a similar problem. Thank you.0
Please sign in to leave a comment.
Comments
17 comments