source: vhosts/server.php @ 295

Last change on this file since 295 was 295, checked in by geofft, 14 years ago
I think I should just go sleep.
File size: 2.3 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 ($req == '/robots.txt') {
8        header('Content-Type: text/plain');
9        readfile('/afs/athena.mit.edu/contrib/scripts/web_scripts/robots.txt');
10        exit;
11}
12
13if (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']);
21if (!empty($documentRoot) && substr($documentRoot,0,1) == '/')
22        $documentRoot = substr($documentRoot, 1);
23if (empty($documentRoot))
24        $documentRoot = array_shift(explode('.',$_SERVER['SERVER_NAME']));
25
26switch($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();
45foreach($settingsFiles as $aFile) {
46        if (file_exists($aFile)) {
47                $settings = file($aFile);
48                break;
49        }
50}
51if (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]);
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;
67}
68
69$baseURL = $mySSL?$baseHTTPS:$baseHTTP;
70?>
71<html>
72<head><title><?=htmlspecialchars($myTitle)?></title></head>
73
74<frameset rows="*">
75        <frame src="<?=htmlspecialchars($baseURL . $req)?>" />
76</frameset>
77
78</html>
Note: See TracBrowser for help on using the repository browser.