forked from Gerst20051/Languages
/
URLproxyServer.php
executable file
·144 lines (130 loc) · 5.2 KB
/
URLproxyServer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
/************************************************\
* URL proxy v1.3 Pre-Alpha *
* a co-authored script *
* by Scott Atkins <atkinssc@engr.orst.edu> *
* Bob Matcuk <bmatcuk@users.sourceforge.net> *
* Copyright (C) 2002 All rights reserved *
* Released under the GPL, see the README *
* *
* Edit config.php instead of this file please *
* If you change this file and break your proxy *
* don't ask for help, as you were warned *
\************************************************/
// User should not have to edit this file
include("config.php");
include("classWebPage.php");
// Constants
$STATIC = 1;
$DYNAMIC = 2;
// Mode of the script
$proxyMode = ((isset($server) AND isset($redirectIP)) ? $STATIC : $DYNAMIC);
// Version Number
$phase = "pre-alpha";
$version = "1.3 " . $phase;
/*Flags******************************************\
* $isHTML; true if mimetype is html *
* $isImage; true if mimetype is an image *
* $isDown; true if specified mimetype is to be *
* downloaded *
* $isAuth; true if the page is protected by *
* .htaccess *
* $isForm; true if the page contains a form *
\************************************************/
$isHTML = false;
$isImage = false;
$isDown = false;
$isAuth = false;
$isForm = false;
$isError = false;
/*getContentType*********************************\
* Function for finding the mime type of the file *
* Returns the content type *
\************************************************/
function getContentType($headers){
foreach($headers as $h){
if(eregi("^Content-Type: (.*)$",$h,$A1))
return $A1[1];
}
}
/*processHeaders*********************************\
* Function for handling the headers that apache *
* sends out. *
* Returns an array with the headers that should *
* be sent out *
\************************************************/
function processHeaders($headers, $fileName, $mime_dl, &$type,
&$isDown, &$isHTML, &$isImage){
array_shift($headers);
$type = getContentType($headers);
$isDown = (isset($mime_dl[$type]) ? $mime_dl[$type] : true);
if(eregi("image",$type))
$isImage = true;
elseif(eregi("text/html",$type))
$isHTML = true;
/* if($isDown)
$headers[] = "Content-Disposition: attachment;" .
" filename=$fileName";*/
return $headers;
}
/************************************************\
* This block of code gets the directory we are *
* currently in, for rel links. *
\************************************************/
if(eregi("http://",$_GET[$fileVar])){
$relDir = eregi_replace("^http://[^/]*", "", $_GET[$fileVar]);
}else{
$relDir = $_GET[$fileVar];
}
$relDir = eregi_replace("/[^/]*$","/",$relDir);
/************************************************\
* We create a new object of type WebPage and *
* pass it the url we are being a proxy for and *
* other information about the current state. *
\************************************************/
$page = new WebPage($redirectIP."/".$_GET[$fileVar],true,$server,"URLproxyServer.php",$fileVar,$relDir);
// function WebPage($URL, $static, $currentServer, $scriptName, $varName, $relDir)
/************************************************\
* This tells the WebPage object to open up a *
* connection to the URL. *
* *
* Note: *
* This does not actually get the web page, just *
* opens the connection for the headers. *
\************************************************/
$page->openLink();
/************************************************\
* Process the headers so we know what kind of *
* data we have (html/other) *
\************************************************/
$head = processHeaders($page->getHeaders(),$file,$mime_dl,$type,$isDown,$isHtml,$isImage);
/************************************************\
* This code replicates the headers that were *
* sent when the class connected to the url. *
* *
* FIXME: extra headers need to be sent if we are *
* downloading the file. *
* *
* GOTCHA?: need to check if http 1.1 will work *
* correctly *
\************************************************/
foreach($head as $h) header($h);
/************************************************\
* This block of code displays the page to the *
* user. *
* *
* Note: Both processPageData and getRawPageData *
* close the connection to the URL when they *
* return. You must re-open a connection with *
* openLink to use them again. *
\************************************************/
if($isHtml){
$page->processPageData();
if($encryptPage)
$page->encryptPage();
echo $page->getPageData();
}else{
if($isImage)
$page->getRawPageData();
}
?>