|
1 | 1 | <?php
|
2 | 2 |
|
3 |
| -require("vendor/autoload.php"); |
4 |
| - |
5 | 3 | 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).'/'); |
| 4 | + |
| 5 | +require("vendor/autoload.php"); |
8 | 6 |
|
9 | 7 | use Symfony\Component\HttpFoundation\Request;
|
10 | 8 | use Symfony\Component\HttpFoundation\Response;
|
|
15 | 13 | use Proxy\Config;
|
16 | 14 | use Proxy\Proxy;
|
17 | 15 |
|
| 16 | +// start the session |
| 17 | +session_start(); |
| 18 | + |
18 | 19 | // load config...
|
19 | 20 | Config::load('./config.php');
|
20 | 21 |
|
| 22 | +if(!Config::get('app_key')){ |
| 23 | + die("app_key inside config.php cannot be empty!"); |
| 24 | +} |
| 25 | + |
| 26 | +// how are our URLs be generated from this point? this must be set here so the proxify_url function below can make use of it |
| 27 | +if(Config::get('url_mode') == 1){ |
| 28 | + Config::set('encryption_key', md5(Config::get('app_key').$_SERVER['REMOTE_ADDR'])); |
| 29 | +} else if(Config::get('url_mode') == 2){ |
| 30 | + Config::set('encryption_key', md5(Config::get('app_key').session_id())); |
| 31 | +} |
| 32 | + |
21 | 33 | // form submit in progress...
|
22 | 34 | if(isset($_POST['url'])){
|
23 | 35 |
|
24 | 36 | $url = $_POST['url'];
|
25 | 37 | $url = add_http($url);
|
26 | 38 |
|
27 | 39 | header("HTTP/1.1 302 Found");
|
28 |
| - header('Location: '.SCRIPT_BASE.'?q='.encrypt_url($url)); |
| 40 | + header('Location: '.proxify_url($url)); |
29 | 41 | exit;
|
30 | 42 |
|
31 | 43 | } else if(!isset($_GET['q'])){
|
|
38 | 50 | header("Location: ".Config::get('index_redirect'));
|
39 | 51 |
|
40 | 52 | } else {
|
41 |
| - echo render_template("./templates/main.php", array('script_base' => SCRIPT_BASE, 'version' => Proxy::VERSION)); |
| 53 | + echo render_template("./templates/main.php", array('version' => Proxy::VERSION)); |
42 | 54 | }
|
43 | 55 |
|
44 | 56 | exit;
|
45 | 57 | }
|
46 | 58 |
|
47 |
| - |
48 |
| -// get real URL |
49 |
| -$url = decrypt_url($_GET['q']); |
50 |
| -define('URL', $url); |
51 |
| - |
| 59 | +// decode q parameter to get the real URL |
| 60 | +$url = base64_decrypt($_GET['q']); |
52 | 61 |
|
53 | 62 | $proxy = new Proxy();
|
54 | 63 |
|
55 |
| - |
56 | 64 | // load plugins
|
57 | 65 | foreach(Config::get('plugins', array()) as $plugin){
|
58 | 66 |
|
|
63 | 71 | // use user plugin from /plugins/
|
64 | 72 | require_once('./plugins/'.$plugin_class.'.php');
|
65 | 73 |
|
66 |
| - } else { |
| 74 | + } else if(class_exists('\\Proxy\\Plugin\\'.$plugin_class)){ |
67 | 75 |
|
68 |
| - // use native plugin from php-proxy - it was already loaded into namespace automatically through composer |
| 76 | + // does the native plugin from php-proxy package with such name exist? |
69 | 77 | $plugin_class = '\\Proxy\\Plugin\\'.$plugin_class;
|
70 | 78 | }
|
71 | 79 |
|
| 80 | + // otherwise plugin_class better be loaded already and match namespace exactly \\Vendor\\Plugin\\SuperPlugin |
72 | 81 | $proxy->getEventDispatcher()->addSubscriber(new $plugin_class());
|
73 | 82 | }
|
74 | 83 |
|
|
86 | 95 | }
|
87 | 96 |
|
88 | 97 | $url_form = render_template("./templates/url_form.php", array(
|
89 |
| - 'url' => $url, |
90 |
| - 'script_base' => SCRIPT_BASE |
| 98 | + 'url' => $url |
91 | 99 | ));
|
92 | 100 |
|
93 | 101 | $output = $response->getContent();
|
|
131 | 139 |
|
132 | 140 | echo render_template("./templates/main.php", array(
|
133 | 141 | 'url' => $url,
|
134 |
| - 'script_base' => SCRIPT_BASE, |
135 | 142 | 'error_msg' => $ex->getMessage(),
|
136 | 143 | 'version' => Proxy::VERSION
|
137 | 144 | ));
|
|
0 commit comments