Script set private NSes for reseller trouble

andreas.r

Member
PartnerNOC
Nov 1, 2011
7
0
51
cPanel Access Level
DataCenter Provider
Hello!

I've wrote a script using cpanel XML API. Cpanel version is 11.30.6(build 3). The script written in perl using corresponding perl modules.
The script edites the reseller's domain changes NSes and SOA, adds IN A records for new nameservers to zone.
All these done as denoted in cpanel docs, i.e EditZoneRecord < SoftwareDevelopmentKit < TWiki and so on.

Firstly I dump domain and get SOA and NSes records, for instance:
soa: 4
ns:11, 12

Next I'm adding IN A record:
htps://server.com:2087/xml-api/addzonerecord?domain=aaaaaaaaaa.com&name=ns1.aaaaaaaaaa.com.&address=192.168.0.10&type=A&class=IN

Next I'm editting IN NS record, using this URL
htps://server.com:2087/xml-api/editzonerecord?domain=aaaaaaaaaa.com&Line=11&nsdname=ns1.aaaaaaaaaa.com

And each time I'm getting the following error
NS update error 'aaaaaaaaaa.com' domain. Reason: 'Failed to serialize record: unknown error'

Please, would you like to get me a key to solve this problem?

--
Thank you for any assistance.
 

andreas.r

Member
PartnerNOC
Nov 1, 2011
7
0
51
cPanel Access Level
DataCenter Provider
By the way, the new IN A record was added to the example zone 'aaaaaaaaaa.com' above and also, please note that the corresponding IN NS line(11) in the zone file became blank.

Also when I manualy delete this IN A entry in 'Edit DNS Zone' section , i.e.:
ns1 1200 IN A 192.168.0.10

Next time I calling my script and it does all its job well, i.e. adds all corresponding records and changes a resellers default name servers in reseller center.
 
Last edited:

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
If you're trying to add an A record for ns.domain.com, you only need to add the ns as the name part of the record.

Try adding the record like so:

Code:
https://hostname:2087/xml-api/addzonerecord?zone=ddomain.com&name=ns1&address=192.168.0.10&type=A&class=IN
Adding ns1.domain.com actually adds ns1.domain.com.domain.com as the A records are relative to the domain name.



After that, I was able to change the first NS record using the following API call:

Code:
https://hostname:2087/xml-api/editzonerecord?domain=domain.com&Line=11&name=domain.com&nsdname=ns1.somedomain.com&type=NS
 

andreas.r

Member
PartnerNOC
Nov 1, 2011
7
0
51
cPanel Access Level
DataCenter Provider
Thank you for your answer. You are correct.

I've put only hostname. i.e. 'ns1' and 'ns2' without domain. I've wrote it here incorrectly.

So the error still exists, i.e. I've successfully added 'IN A' record but when next time I try to add 'IN NS ' glue record it's failing and the corresponding IN NS line(11) in the zone file became blank'. It is strange!
 

KostonConsulting

Well-Known Member
Verifed Vendor
Jun 17, 2010
255
1
68
San Francisco, CA
cPanel Access Level
Root Administrator
Interesting. It's quite possible that you have a zone type that cPanel can't deal with inside your DNS zone. The code for serializing zone records is in /usr/local/cpanel/Cpanel/ZoneFile.pm and it appears that it is failing on the dns_zone_obj_to_zonelines() call for that zone:


Code:
sub serialize_single_record {
    my ( $self, $record ) = @_;
    my ( $status, $statusmsg, $zonelines_ref ) = $self->dns_zone_obj_to_zonelines( [$record] );
    if ( !$zonelines_ref || !$zonelines_ref->[0] ) {
        return ( 0, "Failed to serialize record: unknown error", '' );
    }
    return ( $status, $statusmsg, $zonelines_ref->[0] );
}
Check /usr/local/cpanel/logs/error_log to see if you get any errors messages that may indicate why the function can't continue.
 

andreas.r

Member
PartnerNOC
Nov 1, 2011
7
0
51
cPanel Access Level
DataCenter Provider
In the '/usr/local/cpanel/logs/error_log' the following info message appeared:
"Whostmgr::DNS::sanitize_record: No sanitizer available for record type :RAW"

And the corresponding XML error is
xml_url:
https://server:2087/xml-api/editzonerecord?domain=aaaaaaaaaa.com&Line=11&nsdname=ns1.aaaaaaaaaa.com

NS update error for 'aaaaaaaaaa.com' domain. Reason:
'Failed to serialize record: unknown error'

I've also checked on cpanel 'WHM 11.30.5 (build 2)' the script is working fine, i.e. makes all respective changes...
 

andreas.r

Member
PartnerNOC
Nov 1, 2011
7
0
51
cPanel Access Level
DataCenter Provider
Solved.
After each zone modification it needs to re-dump it to get correct lines you want to change as a zone file usually reformated by cpanel during the API call.