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: //scripts.20110531.215904.25158/updatedomainips
#!/usr/bin/perl
# cpanel - updatedomainips                        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'; }

# ignore our parent if it dies as this could result in
# a blank domainips files
$SIG{'HUP'} = 'IGNORE';
$SIG{'INT'} = 'IGNORE';

use strict;
use Cpanel::Config::Httpd           ();
use Cpanel::Config::userdata::Cache ();
use Cpanel::SafeFile                ();

my( $main_ip, $ssl_port ) = split( ':', Cpanel::Config::Httpd::get_ssl_httpd_port(0) );
my %DOMAINIPS;

my %USERDOMAINS;
my $trueuserdomainslock = Cpanel::SafeFile::safeopen( \*TRUEUD_FH, '<', '/etc/trueuserdomains' ) || die "Unable to open: $!";
while (<TRUEUD_FH>) {
    chomp;
    my ( $ndomain, $nname ) = split( /\:\s*/, $_, 2 );
    $ndomain =~ s/\s//g;
    $nname   =~ s/\s//g;
    $USERDOMAINS{$ndomain} = $nname;
}
Cpanel::SafeFile::safeclose( \*TRUEUD_FH, $trueuserdomainslock );

#   Compile a list of IPs that have been assigned to resellers;
#   these are to be excluded from /etc/domainips, as they are by definition not dedicated to a single site
my %reseller_ips;
if (opendir my $rip_files, '/var/cpanel/mainips') {
    my @rip_files = grep { !/^\./ } ( readdir $rip_files );
    closedir $rip_files;
    for my $rip_file (map { "/var/cpanel/mainips/$_" } @rip_files) {
        if (open my $fh, '<', $rip_file) {
            my @ips = grep { /^\d+\.\d+\.\d+\.\d+/ } map { chomp; $_ } <$fh>;
            close $fh;
            $reseller_ips{$_} = 1 foreach @ips;
        }
    }
}

my %seen_ip;
my $userdata = Cpanel::Config::userdata::Cache::load_cache();
for my $dns_name ( keys %{ $userdata } ) {
    next if !exists $USERDOMAINS{$dns_name};
    my $ip = $userdata->{$dns_name}->[5];
    $ip =~ s/:.*//;  # Strip port number
    next if ( $ip eq $main_ip );
    next if $reseller_ips{$ip};
    push @{ $seen_ip{$ip} }, $dns_name;
}

for my $ip ( keys %seen_ip ) {
    next if ( @{ $seen_ip{$ip} } > 1 );
    $DOMAINIPS{$ip} = $seen_ip{$ip}[0];
}

my $domainipslock = Cpanel::SafeFile::safeopen( \*DOMAINIPSFH, '>', '/etc/domainips' ) || die "Unable to write: $!";
foreach my $domainip ( sort keys %DOMAINIPS ) {
    print DOMAINIPSFH "$domainip: $DOMAINIPS{$domainip}\n";
}
Cpanel::SafeFile::safeclose( \*DOMAINIPSFH, $domainipslock );

system '/scripts/buildpureftproot';