MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/park
#!/usr/bin/perl
# cpanel - park                                   Copyright(c) 2010 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use POSIX;
use Cpanel::RcsRecord ();
use Socket;
require '/scripts/safetybits.pl';

print <<'EOM';
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!! This script is deprecated and will be removed in future builds !!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!



Park 2.0 ...
Warning, this only adds dns to the local server ...
If this server is not the dns master, this will not work.


EOM

sleep 5;

my $namedconf = find_namedconf();

if ( -e "/usr/sbin/named-checkconf" ) {
    $checkconf = `/usr/sbin/named-checkconf`;
    if ( $checkconf =~ /error/ ) {
        print "Cannot continue... $namedconf is corrupt\n";
        print "[$checkconf]\n";
        exit;
    }
}

$indomain = $ARGV[0];
$ndomain  = $ARGV[1];

die if ( !-t STDIN ) && ( $indomain eq "" || $ndomain eq "" );

open( CONF, "/etc/wwwacct.conf" ) || die "/etc/wwwacct.conf not found\n";
while (<CONF>) {
    $_ =~ s/\n//g;
    if ( $_ !~ /^;/ ) {
        if (/^NS (\S+)$/) {
            $nameserver = $1;
        }
        if (/^NS2 (\S+)$/) {
            $nameserver2 = $1;
        }
        if (/^CONTACTEMAIL/) {
            ( undef, $contactemail ) = split( / /, $_ );
        }
    }
}

if ( $contactemail eq "" ) {
    my ($hostname);
    chomp( $hostname = `hostname` );
    $contactemail = 'root@' . $hostname;
}

my $rpemail = $contactemail;

$rpemail =~ s/\,.*$//g;
$rpemail =~ s/\;.*$//g;
$rpemail =~ s/\s|\n//g;

$rpemail =~ s/\@/\./g;

if ( $nameserver eq "" || $nameserver2 eq "" ) {
    die "Can't figure out your nameservers, your /etc/wwwacct.conf is 
incomplete.  Please fill in values for NS and NS2";
}

if ( $indomain eq "" ) {
    print "Enter the domain name you wish to park on top of? ";
    chomp( $indomain = <STDIN> );
}
$iaddr = gethostbyname($indomain) || die "Can't resolve $indomain to  and ip address .. does it have a dns entry?";
$ip = inet_ntoa($iaddr);
if ( $ndomain eq "" ) {
    print "Enter the new domain? ";
    chomp( $ndomain = <STDIN> );
}

$exists = 0;
open( NDC, "<", "$namedconf" );
while (<NDC>) {
    if (/zone\s+\"$ndomain\"/i) {
        $exists = 1;
        last;
    }
}
close(NDC);

if ( !$exists ) {

    open( NCD, ">>", "$namedconf" );
    print NCD <<EOM;
	
zone "$ndomain" {
        type master;
        file "/var/named/$ndomain.db";
};
EOM
    close(NCD);
}

open( VAF, "/etc/valiases/$indomain" );
while (<VAF>) {
    if (/^\*/) {
        ( undef, $user ) = split( /:/, $_ );
        last;
    }
}
close(VAF);

if ( $user ne "" ) {
    open( VAF, ">/etc/valiases/$ndomain" );
    print VAF "*: $user\n";
    close(VAF);

    open( LD, ">>/etc/localdomains" );
    print LD "$ndomain\n";
    close(LD);
    safe_chmod( 0644, $user, "/etc/valiases/$ndomain" );

    print "Setup Mail forward $ndomain -> $indomain\n";
}

$time = time();
my $sr = getnewsrnum(0);
open( ZONE, ">/var/named/$ndomain.db" ) || die "Can't open zone file";
print ZONE<<EOM;
@       IN      SOA     $nameserver. ${rpemail}. (
                        ${sr}      ; serial, todays date+todays serial #
                        28800           ; refresh, seconds
                        7200            ; retry, seconds
			3600000         ; expire, seconds
			86400 ) ; minimum, seconds 

$ndomain. IN NS $nameserver.
$ndomain. IN NS $nameserver2.
$ndomain. IN A $ip

localhost.$ndomain.       IN A       127.0.0.1

$ndomain.    IN MX 0 $ndomain.

mail            IN CNAME    $ndomain.
www            IN CNAME    $ndomain.
ftp            IN CNAME    $ndomain.
EOM
close(ZONE);
system("/usr/sbin/ndc reload");
print "Setup $ndomain OK\n";

Cpanel::RcsRecord::rcsrecord("$namedconf");

sub getnewsrnum {
    my ($sr) = @_;
    my $todaytime = POSIX::strftime( "%Y%m%d", localtime( time() ) );
    if ( $sr =~ /^${todaytime}/ ) {
        $sr++;
    }
    else {
        $sr = "${todaytime}00";
    }
    return ($sr);
}

sub find_namedconf {
    if ( -e "/etc/namedb/named.conf" ) { return ("/etc/namedb/named.conf"); }
    return ("/etc/named.conf");
}