Skip to content

Commit dfe9fad

Browse files
committed
first commit from php-proxy-script
1 parent 6ac6348 commit dfe9fad

File tree

7 files changed

+369
-0
lines changed

7 files changed

+369
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/*
2+
composer.lock
3+
.htaccess

composer.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "athlon1600/php-proxy-app",
3+
"type": "project",
4+
"version": "1.0.0",
5+
"keywords": ["php proxy", "php proxy application", "php proxy web", "proxy script", "php web proxy", "web proxy"],
6+
"homepage": "https://www.php-proxy.com/",
7+
"require": {
8+
"athlon1600/php-proxy": "@dev"
9+
}
10+
}

config.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
// all possible options will be stored
4+
$config = array();
5+
6+
// make it as long as possible for extra security... secret key is being used when encrypting urls
7+
$config['secret_key'] = '';
8+
9+
// plugins to load - plugins will be loaded in this exact order as in array
10+
$config['plugins'] = array(
11+
'Test',
12+
'Stream',
13+
'HeaderRewrite',
14+
'Cookie',
15+
'Proxify',
16+
// site specific plugins
17+
'Youtube',
18+
'DailyMotion',
19+
'RedTube',
20+
'XHamster',
21+
'XVideos',
22+
'Twitter'
23+
);
24+
25+
// additional curl options to go with each request
26+
$config['curl'] = array(
27+
//CURLOPT_INTERFACE => '123.123.123.13',
28+
//CURLOPT_USERAGENT => 'Firefox 5000'
29+
);
30+
31+
//$config['error_redirect'] = "https://unblockvideos.com/#error={error_msg}";
32+
//$config['index_redirect'] = 'https://unblockvideos.com/';
33+
34+
// this better be here other Config::load fails
35+
return $config;
36+
37+
?>

index.php

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
<?php
2+
3+
require("vendor/autoload.php");
4+
5+
define('PROXY_START', microtime(true));
6+
define('SCRIPT_BASE', (!empty($_SERVER['HTTPS']) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']);
7+
define('SCRIPT_DIR', pathinfo(SCRIPT_BASE, PATHINFO_DIRNAME).'/');
8+
9+
use Symfony\Component\HttpFoundation\Request;
10+
use Symfony\Component\HttpFoundation\Response;
11+
use Symfony\Component\HttpFoundation\ParameterBag;
12+
13+
use Proxy\Plugin\AbstractPlugin;
14+
use Proxy\Event\FilterEvent;
15+
use Proxy\Config;
16+
use Proxy\Proxy;
17+
18+
// load config...
19+
Config::load('./config.php');
20+
21+
// form submit in progress...
22+
if(isset($_POST['url'])){
23+
24+
$url = $_POST['url'];
25+
$url = add_http($url);
26+
27+
header("HTTP/1.1 302 Found");
28+
header('Location: '.SCRIPT_BASE.'?q='.encrypt_url($url));
29+
exit;
30+
31+
} else if(!isset($_GET['q'])){
32+
33+
// must be at homepage - should we redirect somewhere else?
34+
if(Config::get('index_redirect')){
35+
36+
// redirect to...
37+
header("HTTP/1.1 301 Moved Permanently");
38+
header("Location: ".Config::get('index_redirect'));
39+
40+
} else {
41+
echo render_template("./templates/main.php", array('script_base' => SCRIPT_BASE, 'version' => Proxy::VERSION));
42+
}
43+
44+
exit;
45+
}
46+
47+
48+
// get real URL
49+
$url = decrypt_url($_GET['q']);
50+
define('URL', $url);
51+
52+
53+
$proxy = new Proxy();
54+
55+
56+
// load plugins
57+
foreach(Config::get('plugins', array()) as $plugin){
58+
59+
$plugin_class = $plugin.'Plugin';
60+
61+
if(file_exists('./plugins/'.$plugin_class.'.php')){
62+
63+
// use user plugin from /plugins/
64+
require_once('./plugins/'.$plugin_class.'.php');
65+
66+
} else {
67+
68+
// use native plugin from php-proxy - it was already loaded into namespace automatically through composer
69+
$plugin_class = '\\Proxy\\Plugin\\'.$plugin_class;
70+
}
71+
72+
$proxy->getEventDispatcher()->addSubscriber(new $plugin_class());
73+
}
74+
75+
// provide URL form
76+
$proxy->getEventDispatcher()->addListener('request.complete', function($event){
77+
78+
$request = $event['request'];
79+
$response = $event['response'];
80+
81+
$url = $request->getUri();
82+
83+
// we attach url_form only if this is a html response
84+
if(!is_html($response->headers->get('content-type'))){
85+
return;
86+
}
87+
88+
$url_form = render_template("./templates/url_form.php", array(
89+
'url' => $url,
90+
'script_base' => SCRIPT_BASE
91+
));
92+
93+
$output = $response->getContent();
94+
95+
// does the html page contain <body> tag, if so insert our form right after <body> tag starts
96+
$output = preg_replace('@<body.*?>@is', '$0'.PHP_EOL.$url_form, $output, 1, $count);
97+
98+
// <body> tag was not found, just put the form at the top of the page
99+
if($count == 0){
100+
$output = $url_form.$output;
101+
}
102+
103+
$response->setContent($output);
104+
});
105+
106+
107+
try {
108+
109+
// request sent to index.php
110+
$request = Request::createFromGlobals();
111+
112+
// forward it to some other URL
113+
$response = $proxy->forward($request, $url);
114+
115+
// if that was a streaming response, then everything was already sent and script will be killed before it even reaches this line
116+
$response->send();
117+
118+
} catch (Exception $ex){
119+
120+
// if the site is on server2.proxy.com then you may wish to redirect it back to proxy.com
121+
if(Config::get("error_redirect")){
122+
123+
$url = render_string(Config::get("error_redirect"), array(
124+
'error_msg' => rawurlencode($ex->getMessage())
125+
));
126+
127+
header("HTTP/1.1 302 Found");
128+
header("Location: {$url}");
129+
130+
} else {
131+
132+
echo render_template("./templates/main.php", array(
133+
'url' => $url,
134+
'script_base' => SCRIPT_BASE,
135+
'error_msg' => $ex->getMessage(),
136+
'version' => Proxy::VERSION
137+
));
138+
139+
}
140+
}
141+
142+
?>

plugins/TestPlugin.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
use Proxy\Plugin\AbstractPlugin;
4+
use Proxy\Event\ProxyEvent;
5+
6+
class TestPlugin extends AbstractPlugin {
7+
8+
public function onBeforeRequest(ProxyEvent $event){
9+
// fired right before a request is being sent to a proxy
10+
}
11+
12+
public function onHeadersReceived(ProxyEvent $event){
13+
// fired right after response headers have been fully received - last chance to modify before sending it back to the user
14+
}
15+
16+
public function onCurlWrite(ProxyEvent $event){
17+
// fired as the data is being written piece by piece
18+
}
19+
20+
public function onCompleted(ProxyEvent $event){
21+
// fired after the full response=headers+body has been read - will only be called on "non-streaming" responses
22+
}
23+
}
24+
25+
?>

templates/main.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
5+
<title>PHP-Proxy</title>
6+
7+
<meta name="generator" content="php-proxy.com">
8+
<meta name="version" content="<?=$version;?>">
9+
10+
<style type="text/css">
11+
html body {
12+
font-family: Arial,Helvetica,sans-serif;
13+
font-size: 12px;
14+
}
15+
16+
#container {
17+
width:500px;
18+
margin:0 auto;
19+
margin-top:150px;
20+
}
21+
22+
#error {
23+
color:red;
24+
font-weight:bold;
25+
}
26+
27+
#frm {
28+
padding:10px 15px;
29+
background-color:#FFC8C8;
30+
31+
border:1px solid #818181;
32+
33+
-webkit-border-radius: 8px;
34+
-moz-border-radius: 8px;
35+
border-radius: 8px;
36+
}
37+
38+
#footer {
39+
text-align:center;
40+
font-size:10px;
41+
margin-top:35px;
42+
clear:both;
43+
}
44+
</style>
45+
46+
</head>
47+
48+
<body>
49+
50+
51+
<div id="container">
52+
53+
<div style="text-align:center;">
54+
<h1 style="color:blue;">PHP-Proxy</h1>
55+
</div>
56+
57+
<?php if(isset($error_msg)){ ?>
58+
59+
<div id="error">
60+
<p><?php echo $error_msg; ?></p>
61+
</div>
62+
63+
<?php } ?>
64+
65+
<div id="frm">
66+
67+
<!-- I wouldn't touch this part -->
68+
69+
<form action="index.php" method="post" style="margin-bottom:0;">
70+
<input name="url" type="text" style="width:400px;" autocomplete="off" placeholder="http://" />
71+
<input type="submit" value="Go" />
72+
</form>
73+
74+
<script type="text/javascript">
75+
document.getElementsByName("url")[0].focus();
76+
</script>
77+
78+
<!-- [END] -->
79+
80+
</div>
81+
82+
</div>
83+
84+
<div id="footer">
85+
Powered by <a href="//www.php-proxy.com/" target="_blank">PHP-Proxy</a> <?php echo $version; ?>
86+
</div>
87+
88+
89+
</body>
90+
</html>

templates/url_form.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2+
<style type="text/css">
3+
4+
html body {
5+
margin-top: 50px !important;
6+
}
7+
8+
#top_form {
9+
position: fixed;
10+
top:0;
11+
left:0;
12+
width: 100%;
13+
14+
margin:0;
15+
16+
z-index: 2100000000;
17+
-moz-user-select: none;
18+
-khtml-user-select: none;
19+
-webkit-user-select: none;
20+
-o-user-select: none;
21+
22+
border-bottom:1px solid #151515;
23+
24+
background:#FFC8C8;
25+
26+
height:45px;
27+
line-height:45px;
28+
}
29+
30+
#top_form input[name=url] {
31+
width: 550px;
32+
height: 20px;
33+
padding: 5px;
34+
font: 13px "Helvetica Neue",Helvetica,Arial,sans-serif;
35+
border: 0px none;
36+
background: none repeat scroll 0% 0% #FFF;
37+
}
38+
39+
40+
41+
</style>
42+
43+
<script src="//www.php-proxy.com/assets/url_form.js"></script>
44+
45+
<div id="top_form">
46+
47+
<div style="width:800px; margin:0 auto;">
48+
49+
<form method="post" action="index.php" target="_top" style="margin:0; padding:0;">
50+
<input type="button" value="Home" onclick="window.location.href='index.php'">
51+
<input type="text" name="url" value="<?php echo $url; ?>" autocomplete="off">
52+
<input type="hidden" name="form" value="1">
53+
<input type="submit" value="Go">
54+
</form>
55+
56+
</div>
57+
58+
</div>
59+
60+
<script type="text/javascript">
61+
smart_select(document.getElementsByName("url")[0]);
62+
</script>

0 commit comments

Comments
 (0)