|
|
|
|
|
|
| |
It fetches remote pages and translates all HTML tags of links and images, background image attributes and external style sheet references to use the URLs based on the current script URL.
gonxproxy.class.php
|
<?php
/**
* gonxproxy class : Just a HTTP Proxy
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id$ - 07/04/2004 13:48:08 - gonxproxy.class.php
* @access public
**/
class gonxproxy{
/**
* Constructor
* @access protected
*/
function gonxproxy(){
}
/**
*
* @access public
* @return void
**/
function version(){
return "1.0.1";
}
/**
* Return html form of GonxProxy
*
* @access public
* @return void
**/
function form(){
global $url;
if (!ereg("http",$url) and $url!="") {
$url = base64_decode($url);
}
return "\n\n<!-- GonxProxy Form -->
<style><!--
.gonxproxy {
background-color: #F6F6F6;
margin: 4px;
padding: 4px;
border: 1px solid #CCCCCC;
}
input.gonxproxy {
background-color: white;
border: 1px solid #CCCCCC;
}
//-->
</style>
<form method=get action=\"?\">
<table class=gonxproxy width=600 cellpadding=4 cellspacing=10>
<tr><td>
<input name=url value=\"$url\" size=70 class=gonxproxy>
<input type=submit class=gonxproxy value=Submit><br/><br/>
<input type=hidden name=proxy value=1>
<font size=1>GonxProxy version ".gonxproxy::version()." - Author : Ben Yacoub Hatem - Copyright © <a href=\"http://www.dynamix-tn.com/v2/home/\" target=_blank>Dynamix SARL</a> 2004-2005 </font>
</td></tr></table>
</form>
<!-- /GonxProxy Form -->\n\n";
}
/**
* Retreive a url
*
* @access public
* @return void
**/
function connect($_url){
$file = @fopen( $_url, "rb" );
if (!$file) {
return "<font size=2 color=red>Error while opening URL</font>";
}
$line = fread( $file, 1024 );
if( eregi( "html", $line ) ){
fclose( $file );
$html = implode('',@file($_url) );
return gonxproxy::parse_html($html,$_url);
} else {
echo $line;
fpassthru( $file );
@fclose( $file );
exit;
}
}
/**
* Parse a HTML Page, remove JScript, convert Urls and return it.
*
* @access public
* @return void
**/
function parse_html($_data,$_url){
$matches = preg_match_all( "/(href|src|background|@import) *=? *\"(.*)\"/Ui", $_data, $regs );
foreach($regs[2] as $k=>$v){
$_data = str_replace($v,gonxproxy::chg_url($v,$_url), $_data);
}
return $_data;
}
/**
* Convert an URL to a GONX formatted url
*
* Original function code is taken from GURL v2.1 BETA
* by Bob Matcuk (BMatcuk@Users.SourceForge.Net)
* http://gurl.sourceforge.net
*
* @access public
* @return void
**/
function chg_url($piece,$url){
$url_elements = explode("/",$url );
$url_file = ( preg_match( "/\/$/i", $url ) ) ? 0 : 1;
if( preg_match( "/(.*)\#(.*)/", $piece, $regs ) ){ // Links to an anchor (#)
return ( ( $regs[1] == "" ) ? "" : gonxproxy::chg_url( $regs[1],$url ) ) . "#" . $regs[2];
} else if( preg_match( "/http:\/\/(.*)/i", $piece, $regs ) ){ // http:// form
$piece = $regs[1];
} else if( preg_match( "/^\//i", $piece ) ){ // starts with / form
$piece = $url_elements[0] . $piece;
} else if( preg_match( "/^\.\/(.*)/i", $piece, $regs ) ){ // single dots
$piece = $regs[1];
if( $url_file ){
for( $i = sizeof( $url_elements ) - 2; $i >= 0; $i-- ){
$piece = $url_elements[$i] . "/" . $piece;
}
} else {
$piece = $url . $piece;
}
} else if( preg_match( "/^(\.\.\/)+(.*)/i", $piece, $regs ) ){ // double dots
$tok = explode( "/", $piece );
$i = 1 + sizeof( $tok ) - 2;
if( $url_file ){
$i++;
}
$piece = $regs[2];
if( sizeof( $url_elements ) <= $i ){
$piece = $url_elements[0] . "/" . $piece;
} else {
for( $j = sizeof( $url_elements ) - $i; $j >= 0; $j-- ){
$piece = $url_elements[$j] . "/" . $piece;
}
}
} else {
if( $url_file ){
for( $i = sizeof( $url_elements ) - 2; $i >= 0; $i-- ){
$piece = $url_elements[$i] . "/" . $piece;
}
} else {
$piece = $url . $piece;
}
}
if( !( preg_match( "/(\/$|\..+$)/i", $piece ) && preg_match( "/\//i", $piece ) ) ){ // must end in / or file extension
$piece .= "/";
}
if (substr($piece,strlen($piece)-1,1 )=="/") {
$piece = substr($piece,0,strlen($piece)-1 );
}
return "?url=".base64_encode($piece);
}
}
?> | |
Usage Example
| <?php
/**
* gonxproxy Index
*
* @package
* @author Ben Yacoub Hatem <hatem@php.net>
* @copyright Copyright (c) 2004
* @version $Id$ - 09/04/2004 14:45:36 - index.php
* @access public
**/
require_once("gonxproxy.class.php");
@error_reporting(0); // Don't report error
@extract($_GET); // if register globals if off
if (isset($url) and $url!="" and $proxy==1) {
$res = gonxproxy::connect($url);
} elseif(isset($url) and $url!="" and !isset($proxy)){
$res = gonxproxy::connect(base64_decode($url));
}
$res .= gonxproxy::form(); // Add GonxProxy form
echo $res;
?> | | |
|
| Class that allows the PHP developer to create and manage UNIX like password files suitable for use as Apache authentication password files.
Categories : HTTP, PHP, PHP Classes, Filesystem | | | Easy upload class Categories : PHP Classes, Filesystem, HTTP, PHP | | | Request Method Class - seful for situations like form processing or API development. Requires PHP5 for the magic __call() method.
Categories : PHP, PHP Classes, HTTP, Headers | | | IP Blocking Categories : PHP, Security, HTTP | | | Produces browser-safe strings while preserving HTML tags. Categories : Strings, HTTP, PHP, HTML and PHP | | | Identify and log search engine access (spiders, robots, etc.) to a page. Categories : HTTP, Environment Variables, PHP, MySQL, Databases | | | Filter - A simple class that lets you use multiple functions to create custom filters. Categories : PHP, PHP Classes, Strings | | | PHP5 SQLite Abstraction class Categories : PHP, PHP Classes, SQLite, Databases | | | A simple script to count and report hits and the last
modification time of an HTML page. Requires MySQL support
(other DBs should work too, except possibly mSQL). Categories : HTTP, MySQL, PHP, Databases | | | DbObject - A PHP wrapper for working with various databases Categories : Databases, PHP, PHP Classes | | | The Ajax Tree view class fetches data from a db for the requested parent category id. The data is then stored in an array and converted into JSON (Javascript Object Notation) format. This format is then used by JavaScript for populating tree view. Categories : PHP, PHP Classes, Java Script, AJAX, Databases | | | Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs | | | Browser Detecor Class Categories : PHP Classes, PHP, HTML | | | Building a basic error handler with custom error types Categories : PHP, PHP Classes, Errors and Logging | | | Bs_IniHandler is a class that can read and write ini-style files (and strings) Categories : PHP, Filesystem, PHP Classes | |
|
|