source: vhosts/server.php @ 288

Last change on this file since 288 was 245, checked in by andersk, 17 years ago
Give 404s for unknown vhosts.
File size: 2.2 KB
Line 
1<?php
2if (isset($_SERVER['SERVER_NAME'])) $name = $_SERVER['SERVER_NAME']; else $name = '';
3if (isset($_SERVER['REQUEST_URI'])) $req = $_SERVER['REQUEST_URI']; else $req = '/';
4if (isset($_SERVER['PATH_INFO'])) $pi = explode('/',$_SERVER['PATH_INFO']);
5if (isset($_SERVER['SERVER_PORT'])) $port = $_SERVER['SERVER_PORT']; else $port = '80';
6
7if (array_shift(explode('.',$name)) == 'www') {
8        $name = explode('.',$name);
9        array_shift($name);
10        $name = implode('.',$name);
11}
12
13// catch a docroot from the DocumentRoot directive in an apacheconf
14$documentRoot = str_replace(__FILE__,'',$_SERVER['DOCUMENT_ROOT']);
15if (!empty($documentRoot) && substr($documentRoot,0,1) == '/')
16        $documentRoot = substr($documentRoot, 1);
17if (empty($documentRoot))
18        $documentRoot = array_shift(explode('.',$_SERVER['SERVER_NAME']));
19
20switch($port) {
21        case 443:
22                $myHTTP = 'https';
23                $mySSL = true;
24                break;
25        default:
26                $myHTTP = 'http';
27                $mySSL = false;
28                break;
29}
30
31$myTitle = $name;
32$baseHTTP = 'http://scripts.mit.edu/~'.$documentRoot;
33$baseHTTPS = 'https://scripts.mit.edu/~'.$documentRoot;
34
35$settingsFiles[] = '/afs/athena.mit.edu/contrib/scripts/vhosts/settings/'.$name;
36$settingsFiles[] = '/afs/athena.mit.edu/contrib/scripts/vhosts/settings/'.$name.'.mit.edu';
37$settingsFiles[] = '/afs/athena.mit.edu/contrib/scripts/vhosts/settings/www.'.$name;
38$settings = array();
39foreach($settingsFiles as $aFile) {
40        if (file_exists($aFile)) {
41                $settings = file($aFile);
42                break;
43        }
44}
45if (count($settings)) {
46        if (count($settings) >= 0 && '' != trim($settings[0])) $myTitle = trim($settings[0]);
47        if (count($settings) >= 1 && '' != trim($settings[1])) $baseHTTP = trim($settings[1]);
48        if (count($settings) >= 2 && '' != trim($settings[2])) $baseHTTPS = trim($settings[2]);
49} else {
50        header ("HTTP/1.0 404 Not Found");
51?>
52<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
53<html><head>
54<title>404 Not Found</title>
55</head><body>
56<h1>Not Found</h1>
57<p>The requested URL <?=htmlspecialchars($req)?> was not found on this server.</p>
58</body></html>
59<?
60        exit;
61}
62
63$baseURL = $mySSL?$baseHTTPS:$baseHTTP;
64?>
65<html>
66<head><title><?=htmlspecialchars($myTitle)?></title></head>
67
68<frameset rows="*">
69        <frame src="<?=htmlspecialchars($baseURL . $req)?>" />
70</frameset>
71
72</html>
Note: See TracBrowser for help on using the repository browser.