if (! isset($virtual)) { $virtual = 1; }
if ($virtual == 2) {
$virtual_file = "/usr/local/apache2/conf/virtual2.conf";
} else {
$virtual_file = "/usr/local/apache2/conf/virtual1.conf";
}
$servers = array();
$domains = array();
$documentroot = "";
?>
PCI By-Name Virtual Hosts
Some older web browsing clients are unable to use by-name virtual hosting. Yours appears to be one
of them. You are probably looking for one of the following web names.
if ( !($fp = fopen($virtual_file,"r")) ) {
echo "Error: Could not open $virtual_file
";
} else {
// build an array of domain names
//echo "looping through file
";
while ($buffer = fgets($fp,300)) {
if ( eregi("\";
reset($servers);
$found = 0;
while (list($key, $val) = each($servers)) {
//echo "$key = $server_name ?";
if ($key == $server_name) {
$found = 1;
//print "YES";
break;
}
}
if ( ! $found ) {
$servers[$server_name] = $documentroot;
}
}
}
unset($domains);
$domains = array();
$looking = 0;
$documentroot = "";
continue;
}
if ( eregi("^ServerName (.*)",$buffer,$regs) ) {
// ServerName
$server_name = trim($regs[1]);
if ( ereg("^www.(.*)$",$server_name,$regs) ) {
// strip off leading www
$server_name = $regs[1];
}
$domains[] = $server_name; // make a place-holder for this name
$looking = 1; // Look for a path
continue;
}
if ( eregi("^ServerAlias (.*) (.*)",$buffer,$regs) ) {
// ServerName
$server_name = trim($regs[1]);
if ( ereg("^www.(.*)$",$server_name,$regs) ) {
// strip off leading www
$server_name = $regs[1];
}
$domains[] = $server_name; // make a place-holder for this name
$looking = 1; // Look for a path
continue;
}
if ( $looking and eregi("^DocumentRoot (.*)",$buffer,$regs) ) {
// DocumentRoot
$documentroot = trim($regs[1]);
if ( ereg("^\/web\/(.*)\/webpage",$documentroot,$regs) ) {
// clean up
$documentroot = $regs[1];
}
continue;
}
}
fclose($fp);
// pick up the last one
if ($looking and ($documentroot != "") ) {
// we have something, so fill it in
// print_r($servers);
foreach ($domains as $server_name) {
// create an entry for it with documentroot
//echo "Creating $server_name current (" . $current . ")
";
reset($servers);
$found = 0;
while (list($key, $val) = each($servers)) {
//echo "$key = $server_name ?";
if ($key == $server_name) {
$found = 1;
//print "YES";
break;
}
}
if ( ! $found ) {
$servers[$server_name] = $documentroot;
}
}
}
}
//Now loop through the servers
ksort($servers);
reset($servers);
while (list($key, $val) = each($servers)) {
echo '' . $key . '
';
}
?>