MOON
Server: Apache
System: Linux vps.thepromohut.com 2.6.18-398.el5 #1 SMP Tue Sep 16 20:51:48 EDT 2014 i686
User: caretrak (507)
PHP: 5.2.10
Disabled: NONE
Upload Files
File: //scripts.20110601.041516.15411/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 "";
}