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.

Edit DNS zones problem!

Discussion in 'Bind / DNS / Nameserver Issues' started by gemby, Mar 12, 2003.

  1. gemby

    gemby Well-Known Member
    PartnerNOC

    Joined:
    Feb 16, 2002
    Messages:
    182
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Pula, Croatia
    cPanel Access Level:
    DataCenter Provider
    I have two servers, one is master DNS. With little tweaking and help from forum i established trusted relationship between the
    m. When i add DNS zone on webserver, sam
    e zone autmagicly apears in master. When i remove DNS zone in webserver, it automagicly desapears in master. As far as i understood, it looks like my trusted relationship between servers work like it should.


    Ok, when i try to "Edit DNS zone", first
    problem is that i couldn't see all entries in edit dns zone form, but they exist in domain.com.db file on both servers!!!
    When i try to edit, and pres "Save", whm says: blah, blah, erros highlighted below....
    <highlighted part>
    14400 IN CNAME domain.com. domain.com: CNAME and other data
    </highlighted part>

    Or it gives 404 in frame where you expect result!





    I noticed that when you try to make subd
    omain, it apears in whm and cpanel after
    submiting, but it does not add entry in
    DNS zone for domain from that subdomain belo
    ngs to. I think that this same problem, but WHM does not gives error becouse it couldn't edit DNS zone!!!


    And the most strange thing, when i edit domain.com.db file and manualy add subdomains A record and restart named, it's working, but still doesen't shows in WHM!

    What is wrong!?
     
  2. gemby

    gemby Well-Known Member
    PartnerNOC

    Joined:
    Feb 16, 2002
    Messages:
    182
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Pula, Croatia
    cPanel Access Level:
    DataCenter Provider
    Ok, i found what's wrong....

    $ORGIN entry in all zones!

    I asked cpanel, they says - no solution for it!

    Ill have to edit all by hand!

    850 zones - oh god!:mad:
     
  3. gemby

    gemby Well-Known Member
    PartnerNOC

    Joined:
    Feb 16, 2002
    Messages:
    182
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Pula, Croatia
    cPanel Access Level:
    DataCenter Provider
    I found solution for $ORIGIN ina domainame.com.db files on master DNS

    Here is php script to fix uneditable DNS entries!

    <?php
    ############################################################################################
    ############################################################################################
    # This php script for fixing /var/named entries wrecked with transfering zones
    # WHM from one server to master DNS
    # Please, edit ns entries to suit your needs
    # It does not work with ip entered as domainame
    # Use it on your own risk, allways backup first all .db files in /var/named!!!!
    # Version 0.02 beta
    # Usage:
    # mkdir /var/tempnamed
    # php zonefix.php
    # check all .db files that apears in /var/tempnamed and see if they look like they should look!
    # cp -f /var/named/checked_domain.com.db /var/named
    # Restart bind (named)
    # #########################################################################################
    ###########################################################################################
    # Script is made under our own copyleft:
    # You may edit it to suit your needs.
    # You may use it if it you like it
    #If you want to buy us beer, you may contact us at zvonimir@plus.hr or nikola@plus.hr
    # Have fun!
    ##########################################################################################
    ##########################################################################################
    $dir = opendir("/var/named");


    while($item = readdir($dir)) {

    if($item=="." or $item==".." or $item=="named.ca" or $item=="named.local" or $item=="localhost.zone" or ereg("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})", $item)) continue;

    $domena = substr($item, 0, -2);
    $fajl = file("/var/named/" . $item);

    $subdomene = false;
    $localhost_found = 0;
    $mail = 0;
    $www = 0;
    $ftp = 0;

    foreach($fajl as $red) {

    if(stristr($red, "\$ORIGIN .")){
    $fp = fopen ("/var/tempnamed/".$item, "w+");

    echo "\n\nFajl: " . $item . "\n";

    // Mijenja prvi sjebani red
    foreach($fajl as $red1){

    if(stristr($red1, "SOA")){
    fwrite($fp, "@ 14400 IN SOA ns1.mojsite.com. server.plus.hr. (\n");
    fwrite($fp, " 1047643867\n");
    fwrite($fp, " 28800\n");
    fwrite($fp, " 7200\n");
    fwrite($fp, " 3600000\n");
    fwrite($fp, " 86400\n");
    fwrite($fp, " )\n\n");
    }
    }

    foreach($fajl as $red_ip){
    if(stristr($red_ip, "A") and ereg("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})", $red_ip, $ip_a)){
    # $red_ip = str_replace("A", "", $red_ip);
    $ip = $ip_a[1];
    break;
    }
    }

    for($i = 0; $fajl; $i++){
    if(stristr($fajl[$i], "NS") and stristr($fajl[$i], "ns1.hostnoc.net")){
    fwrite($fp,"$domena 14400 IN NS ns1.mojsite.com.\n"); #Your first DNS
    fwrite($fp,"$domena 14400 IN NS ns2.mojsite.com.\n"); #Your second DNS
    fwrite($fp,"$domena 14400 IN NS ns1.hostnoc.net.\n"); #Your third DNS
    fwrite($fp,"$domena 14400 IN NS ns2.hostnoc.net.\n"); #Your forth DNS
    fwrite($fp,"$domena 14400 IN A $ip\n\n");
    break;
    }
    }

    //Mijenja red di je localhost statement
    foreach($fajl as $red2){
    if(stristr($red2, "\$ORIGIN") and stristr($red2, $domena) and $localhost_found == 0){
    fwrite($fp, "localhost.$domena 14400 IN A 127.0.0.1\n\n");
    $localhost_found++; // ? ne znam kako ovo izbje├Ži
    }
    }

    //Mijenja red za MX statement
    foreach($fajl as $red3){
    if(stristr($red3, "MX") and stristr($red3, "0")){
    $mx = str_replace("MX", "", $red3);
    $mx = str_replace("0", "", $mx);
    $mx = trim($mx);
    fwrite($fp, "$domena 14400 IN MX 0 $mx\n\n");
    echo $mx . "\n";
    }
    }

    foreach($fajl as $red5){
    if(stristr($red5, "mail") and ereg("CNAME", $red5) and $mail == 0){
    $red5 = str_replace("CNAME", "", $red5);
    $red5 = str_replace("mail", "", $red5);
    $red5 = trim($red5);
    fwrite($fp,"mail 14400 IN CNAME $red5\n");
    $mail++;
    }}

    foreach($fajl as $red6){
    if(stristr($red6, "mail") and ereg("([A]{1})", $red6) and ereg("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})", $red6)
    and $mail == 0){
    $red6 = str_replace("A", "", $red6);
    $red6 = str_replace("mail", "", $red6);
    $red6 = trim($red6);
    fwrite($fp,"mail 14400 IN A $red6\n");
    $mail++;
    }}

    foreach($fajl as $red7){
    if(stristr($red7, "www") and ereg("CNAME", $red7) and $www == 0){
    $red7 = str_replace("CNAME", "", $red7);
    $red7 = str_replace("www", "", $red7);
    $red7 = trim($red7);
    fwrite($fp,"www 14400 IN CNAME $red7\n");
    $www++;
    }}

    foreach($fajl as $red8){
    if(stristr($red8, "www") and ereg("[A]{1}", $red8) and ereg("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})", $red8)
    and $www == 0){
    $red8 = str_replace("A", "", $red8);
    $red8 = str_replace("www", "", $red8);
    $red8 = trim($red8);
    fwrite($fp,"www 14400 IN A $red8\n");
    $www++;
    }}


    foreach($fajl as $red9){
    if(stristr($red9, "ftp") and ereg("CNAME", $red9)){
    $red9 = str_replace("CNAME", "", $red9);
    $red9 = str_replace("ftp", "", $red9);
    $red9 = trim($red9);
    fwrite($fp,"ftp 14400 IN CNAME $red7\n");
    }}

    foreach($fajl as $red0){
    if(stristr($red0, "ftp") and ereg("[A]{1}", $red0) and ereg("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})", $red0)){
    $red0 = str_replace("A", "", $red0);
    $red0 = str_replace("ftp", "", $red0);
    $red0 = trim($red0);
    fwrite($fp,"ftp 14400 IN A $red8\n");
    }}


    foreach($fajl as $red4){
    if(stristr($red4, "\$ORIGIN") and stristr($red4, $domena)){
    $subdomene = true;
    }

    if (($subdomene) and stristr($red4, "A") and ereg("((.){1,}) (A) ([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})", $red4, $regs)) {
    $poddomena = str_replace("A", "", $regs[1]);
    $poddomena = trim($poddomena);
    if ($poddomena != (eregi("ftp", $red4) or eregi("mail", $red4) or eregi("www", $red4) or eregi("localhost", $red4))) {
    if(stristr($poddomena, "localhost")){
    $ip_sub = "127.0.0.1";} else {
    $ip_sub = $regs[4];}
    fwrite($fp,$poddomena." 14400 IN A $ip_sub\n");
    };
    if (($subdomene) and ereg("((.){1,}) (CNAME) ($domena)", $red4, $regs1)){
    $poddomena = str_replace("IN", "", $regs1[1]);
    $poddomena = str_replace("CNAME", "", $poddomena);
    $poddomena = trim($poddomena);
    if ($poddomena != (eregi("ftp", $red4) or eregi("mail", $red4) or eregi("www", $red4) or eregi("localhost", $red4))) {

    fwrite($fp,$poddomena." 14400 IN CNAME $domena\n");
    };
    }
    }
    }

    $count++;
    fclose($fp);
    }

    }
    }

    ?>
     
    #3 gemby, Mar 19, 2003
    Last edited: Mar 21, 2003
  4. pingo

    pingo Well-Known Member

    Joined:
    Nov 16, 2002
    Messages:
    430
    Likes Received:
    0
    Trophy Points:
    16
    Gemby, did you run this script successfully? I tried uploading it to an account with root access but couldn't run it from there. I then uploaded it to the /scripts folder and chmoded to 755 but still can't run it. From where/how did you run it? I have about 1700 accounts and it is horrible thinking about having to edit them all manually. Hope that you can help.

    Thanks
    John

    cPanel.net Support Ticket Number:
     
  5. gemby

    gemby Well-Known Member
    PartnerNOC

    Joined:
    Feb 16, 2002
    Messages:
    182
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Pula, Croatia
    cPanel Access Level:
    DataCenter Provider
    On the beggining of file add

    #!/usr/bin/php -q
    before <?php tags....

    ...or run it like this

    php ./script.php

    This is alpha version of my file, it does more or less what it has to do, but i made few fixes of zones after that...



    If you need it, ill post scripts for you, but remember BACKUP FIRST!!!!

    Mail me i'll be glad to help!

    cPanel.net Support Ticket Number:
     
Loading...

Share This Page