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