From dfe9fad5afcc87afe0c3d04fe1be6528cd13c516 Mon Sep 17 00:00:00 2001 From: Desktop Date: Sun, 10 May 2015 22:37:09 +0000 Subject: [PATCH] first commit from php-proxy-script --- .gitignore | 3 + composer.json | 10 +++ config.php | 37 +++++++++++ index.php | 142 +++++++++++++++++++++++++++++++++++++++++ plugins/TestPlugin.php | 25 ++++++++ templates/main.php | 90 ++++++++++++++++++++++++++ templates/url_form.php | 62 ++++++++++++++++++ 7 files changed, 369 insertions(+) create mode 100644 .gitignore create mode 100644 composer.json create mode 100644 config.php create mode 100644 index.php create mode 100644 plugins/TestPlugin.php create mode 100644 templates/main.php create mode 100644 templates/url_form.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fd24be70 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/vendor/* +composer.lock +.htaccess \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..4336069d --- /dev/null +++ b/composer.json @@ -0,0 +1,10 @@ +{ + "name": "athlon1600/php-proxy-app", + "type": "project", + "version": "1.0.0", + "keywords": ["php proxy", "php proxy application", "php proxy web", "proxy script", "php web proxy", "web proxy"], + "homepage": "https://www.php-proxy.com/", + "require": { + "athlon1600/php-proxy": "@dev" + } +} \ No newline at end of file diff --git a/config.php b/config.php new file mode 100644 index 00000000..c1acadce --- /dev/null +++ b/config.php @@ -0,0 +1,37 @@ + '123.123.123.13', + //CURLOPT_USERAGENT => 'Firefox 5000' +); + +//$config['error_redirect'] = "https://unblockvideos.com/#error={error_msg}"; +//$config['index_redirect'] = 'https://unblockvideos.com/'; + +// this better be here other Config::load fails +return $config; + +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 00000000..cf59ab6e --- /dev/null +++ b/index.php @@ -0,0 +1,142 @@ + SCRIPT_BASE, 'version' => Proxy::VERSION)); + } + + exit; +} + + +// get real URL +$url = decrypt_url($_GET['q']); +define('URL', $url); + + +$proxy = new Proxy(); + + +// load plugins +foreach(Config::get('plugins', array()) as $plugin){ + + $plugin_class = $plugin.'Plugin'; + + if(file_exists('./plugins/'.$plugin_class.'.php')){ + + // use user plugin from /plugins/ + require_once('./plugins/'.$plugin_class.'.php'); + + } else { + + // use native plugin from php-proxy - it was already loaded into namespace automatically through composer + $plugin_class = '\\Proxy\\Plugin\\'.$plugin_class; + } + + $proxy->getEventDispatcher()->addSubscriber(new $plugin_class()); +} + +// provide URL form +$proxy->getEventDispatcher()->addListener('request.complete', function($event){ + + $request = $event['request']; + $response = $event['response']; + + $url = $request->getUri(); + + // we attach url_form only if this is a html response + if(!is_html($response->headers->get('content-type'))){ + return; + } + + $url_form = render_template("./templates/url_form.php", array( + 'url' => $url, + 'script_base' => SCRIPT_BASE + )); + + $output = $response->getContent(); + + // does the html page contain tag, if so insert our form right after tag starts + $output = preg_replace('@@is', '$0'.PHP_EOL.$url_form, $output, 1, $count); + + // tag was not found, just put the form at the top of the page + if($count == 0){ + $output = $url_form.$output; + } + + $response->setContent($output); +}); + + +try { + + // request sent to index.php + $request = Request::createFromGlobals(); + + // forward it to some other URL + $response = $proxy->forward($request, $url); + + // if that was a streaming response, then everything was already sent and script will be killed before it even reaches this line + $response->send(); + +} catch (Exception $ex){ + + // if the site is on server2.proxy.com then you may wish to redirect it back to proxy.com + if(Config::get("error_redirect")){ + + $url = render_string(Config::get("error_redirect"), array( + 'error_msg' => rawurlencode($ex->getMessage()) + )); + + header("HTTP/1.1 302 Found"); + header("Location: {$url}"); + + } else { + + echo render_template("./templates/main.php", array( + 'url' => $url, + 'script_base' => SCRIPT_BASE, + 'error_msg' => $ex->getMessage(), + 'version' => Proxy::VERSION + )); + + } +} + +?> \ No newline at end of file diff --git a/plugins/TestPlugin.php b/plugins/TestPlugin.php new file mode 100644 index 00000000..5259bf19 --- /dev/null +++ b/plugins/TestPlugin.php @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/templates/main.php b/templates/main.php new file mode 100644 index 00000000..40bc4735 --- /dev/null +++ b/templates/main.php @@ -0,0 +1,90 @@ + + + + +PHP-Proxy + + + + + + + + + + + +
+ +
+

PHP-Proxy

+
+ + + +
+

+
+ + + +
+ + + +
+ + +
+ + + + + +
+ +
+ + + + + + \ No newline at end of file diff --git a/templates/url_form.php b/templates/url_form.php new file mode 100644 index 00000000..c1ba378b --- /dev/null +++ b/templates/url_form.php @@ -0,0 +1,62 @@ + + + + + +
+ +
+ +
+ + + + +
+ +
+ +
+ +