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/rebuildparkeddomains
#!/usr/bin/perl

my(%PDLIST);
opendir(CPU,"/var/cpanel/users");
@CPUS=readdir(CPU);
closedir(CPU);
foreach my $user (@CPUS) {
	my $dns;
	my @PD;
	if (-f "/var/cpanel/users/$user") {
			open(CP,"/var/cpanel/users/$user");
		while(<CP>) {
			if (/^DNS=(\S+)/) { $dns=$1; }
			elsif (/^DNS\d+=(\S+)/) { push(@PD,$1); }
		}
		close(CP);
		foreach my $pd (@PD) {
			my $issub = 0;
			if ($pd =~ /\.${dns}$/) {$issub=1;}
			foreach my $pdtest (@PD) {
				next if ($pdtest eq $pd);
				if ($pd =~ /\.${pdtest}$/) { $issub=1; }
			}
			if (!$issub) {
				$PDLIST{$dns}{$pd} = 1;
			 }

		}

	}

}

$httpc = find_httpconf();

open(HTTPD,$httpc);
open(HTTPDP,">$httpc.rebuiltparks");
while(<HTTPD>) {
	print HTTPDP;
	if (/servername[\s\t]+(\S+)/i) {
		my $sn = $1;
		$sn =~ s/^www\.//g;
		next if ($sn !~ /\./);
		print "processing server $sn....";
		my %PDS = %{$PDLIST{$sn}};
		my $haspd = 0;
		foreach my $pd (keys %PDS) {
			if ($haspd == 0) { $haspd = 1; print "\n"; }
			print HTTPDP "ServerAlias www.${pd} $pd\n";
			print "\t${pd}\n";
		}
		print "done\n";
	}
}
close(HTTPD);
close(HTTPDP);

print "Wrote: $httpc.rebuiltparks\n";

sub find_httpconf {
   my(@LOC,$loc);
@LOC = ("/usr/local/apache/conf/httpd.conf",
         "/etc/httpd/conf/httpd.conf");
   foreach $loc (@LOC) {
      if (-e $loc) { return $loc; }
   }
   return "";
}