topical media & game development
server-proxy-class.php
<?php
/*
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// -----------------------------------------------------------------
// Class: PHProxy
// Author: ultimategamer00 (Abdullah A.)
// Last Modified: 6:28 PM 6/22/2004
*/
util(s)
function __stripslashes(str) : str)
{
static str, alpha[1]);
}
}
class
class PHProxy
{
var version;
var url;
var flags = array('include_form' => 0, 'remove_scripts' => 1, 'accept_cookies' => 1, 'show_images' => 1, 'show_referer' => 0);
var content_type;
var post_body;
var response_body;
constructor
function PHProxy(this->version = '0.2';
_SERVER['HTTPS']) && _SERVER['HTTP_HOST']}{this->set_flags(
transfer(s)
function start_transfer(url)
{
url);
this->set_request_headers();
this->follow_location() === false)
{
if (this->set_cookies();
}
this->start_transfer(
socket
function open_socket()
{
this->socket = @fsockopen(this->url_segments['port'], &errstr, 5);
if (this->trigger_error("this->url_segments['host']})");
}
}
response
function set_response()
{
fwrite(this->request_headers);
data = fread(response .= data) != 0);
fclose(response, this->response_headers = this->response_body =
content type
function set_content_type()
{
preg_match("#content-type:([^\r\n]*)#i", this->response_headers, matches[1]) != '')
{
matches[1]);
content_type_array[0]));
}
}
url(s)
function set_url(this->url = url);
if (strpos(this->url = '' . url_segments = @parse_url(url_segments))
{
url_segments['port']) ? url_segments['path'] = isset(url_segments['path'] : '/';
url_segments['path'], 0, strrpos(url_segments['base'] = url_segments['host'] . url_segments['prev_dir'] = url_segments['base'], 0, strrpos(url_segments['base'] . '/';
url_segments;
/*
URL: username:password@www.example.com:80/dir/dir/page.php?foo=bar&foo2=bar2#bookmark
scheme // http
host // www.example.com
port // 80
user // username
pass // password
path // /dir/dir/page.php
query // ? 'foo=bar&foo2=bar2'
fragment // # 'bookmark'
dir // /dir/dir
base // www.example.com/dir/dir
prev_dir // www.example.com/dir/
*/
if (!empty(this->url_segments['host'], this->trigger_error('You are only allowed to browse these websites: ' . implode(', ', this->trigger_error('Please supply a valid URL');
}
}
de/en-code
function encode_url(url = str_rot13(urlencode(preg_replace('#^([\w+.-]+)://#i', "$1/",
return url;
}
function decode_url(url = preg_replace('#^([\w+.-]+)/#i', "$1://", urldecode(str_rot13(url;
}
modify
function modify_urls()
{
preg_match_all("#\s(href|src|action|codebase|url)=([\"\'])?(.*?)([\"\'])?([\s\>])#i", matches, PREG_SET_ORDER);
foreach (match)
{
match[3]);
hash_pos = strpos(uri, uri))
{
switch (substr(uri = this->url_segments['host'] . uri = uri;
break;
}
}
this->encode_url(replace = ' ' . match[2] . uri . match[4] . this->response_body = str_replace(replace,
flag(s)
function set_flags(flags)
{
if (is_numeric(flags, time()+(4*7*24*60*60), '', this->flags['include_form'] = this->flags['remove_scripts'] = this->flags['accept_cookies'] = this->flags['show_images'] = this->flags['show_referer'] = _COOKIE['flags']))
{
_COOKIE['flags']);
}
}
header
function set_request_headers()
{
_SERVER['REQUEST_METHOD']} {this->url_segments['query']) ? "?{headers .= "Host: {this->url_segments['port']}\r\n";
headers .= "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n";
this->flags['show_referer'] == 1)
{
this->url_segments['base']}\r\n";
}
this->get_cookies();
cookies != '' ? "Cookie: _SERVER['REQUEST_METHOD'] == 'POST')
{
_POST);
headers .= "Content-Length: " . strlen(headers .= headers .= "\r\n";
headers;
}
body
function set_post_body(parent_key = null)
{
foreach (key => value))
{
value, isset(parent_key, urlencode(key));
}
else
{
this->post_body != '' ? '&' : '';
parent_key) ? sprintf('\%s[\%s]', key)) : urlencode(this->post_body .= value));
}
}
}
location(s)
function follow_location()
{
if (preg_match("#(location|uri):([^\r\n]*)#i", matches))
{
this->decode_url(trim(uri))
{
if (substr(uri = this->url_segments['host'] . uri = uri;
}
}
uri;
return true;
}
return false;
}
set cookie(s)
function set_cookies()
{
if (preg_match_all("#set-cookie:([^\r\n]*)#i", matches))
{
foreach (match)
{
preg_match('#^\s*([^=;,\s]*)=?([^;,\s]*)#', cookie) ? list(, value) = match, expires) = match, path) = match, domain) = match, secure) = expires = isset(expires) : 0;
path) ? this->url_segments['dir'];
domain) ? this->url_segments['host'];
domain, '.');
if (!preg_match("#domain#i", #i', domain, '.') < 2)
{
continue;
}
}
else if (substr_count(name;path"), expires, '',
get cookie(s)
function get_cookies(restrict = true)
{
if (!empty(cookies = '';
foreach (cookie_name => cookie_args = explode(';', urldecode(cookie_args[0] != 'PHProxy')
{
continue;
}
if (name, path) = domain = str_replace('_', '.', this->url_segments['host']) && preg_match("#^this->url_segments['path']))
{
cookies != '' ? '; ' : '';
name=cookie_args);
cookie_args[1]);
cookie_value;
cookie_args;
}
}
return
delete cookie(s)
function delete_cookies(hash)
{
this->get_cookies(false);
foreach (args)
{
if (hash == md5(args[1].args[3]))
{
setcookie(urlencode("PHProxy;args[1];
response
function return_response(send_headers = true)
{
if (strpos(this->content_type, 'xhtml') !== false)
{
if (this->remove_scripts();
}
if (this->remove_images();
}
this->flags['include_form'] == 1)
{
headers = explode("\r\n", trim(headers[] = 'Content-Disposition: '. (strpos(this->url_segments['path'], strrpos(headers[] = 'Content-Length: '. strlen(send_headers)
{
foreach (header)
{
header(this->response_body;
}
script(s)?
function remove_scripts()
{
this->response_body); // Remove any scripts enclosed between <script />
this->response_body); // Remove javascript event handlers
this->response_body); //expose any html between <noscript />
}
image(s)?
function remove_images()
{
this->response_body);
}
form?
function include_form()
{
ob_start();
include_once 'url_form.inc';
this->response_body = preg_replace("#\<body(.*?)\>#si", "$0\nthis->response_body, 1);
}
error(s)
function trigger_error(this->script_url?error=
option(s)
function options_list(tabulate = false, output = '';
comments['include_form'] = 'Includes a mini URL-form on every HTML page';
comments['accept_cookies'] = 'Accept HTTP cookies';
comments['show_referer'] = 'Show referring website in HTTP headers';
foreach (flag_code => interface = array(ucwords(str_replace('_', ' ', flag_status == 1 ? ' checked="checked"' : '') . ' /> '
);
interface = array_reverse(output .= (interface[0]
. (interface[1]
. (comments[tabulate ? '</td></tr>' : '');
}
return
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.