Mercurial > hg > LGMap
comparison geotemco/php/proxy.php @ 0:57bde4830927
first commit
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Tue, 24 Mar 2015 11:37:17 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:57bde4830927 |
|---|---|
| 1 <?php | |
| 2 /* | |
| 3 * proxy.php | |
| 4 * | |
| 5 * Copyright (c) 2013, Sebastian Kruse. All rights reserved. | |
| 6 * | |
| 7 * This library is free software; you can redistribute it and/or | |
| 8 * modify it under the terms of the GNU Lesser General Public | |
| 9 * License as published by the Free Software Foundation; either | |
| 10 * version 3 of the License, or (at your option) any later version. | |
| 11 * | |
| 12 * This library is distributed in the hope that it will be useful, | |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 * Lesser General Public License for more details. | |
| 16 * | |
| 17 * You should have received a copy of the GNU Lesser General Public | |
| 18 * License along with this library; if not, write to the Free Software | |
| 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
| 20 * MA 02110-1301 USA | |
| 21 */ | |
| 22 | |
| 23 //Hosts that are allowed to download from in RegEx form. (e.g. "/.*dropbox\.com/") | |
| 24 //If this array is empty, all hosts are allowed. | |
| 25 $validHosts = array( | |
| 26 "/localhost/", | |
| 27 ); | |
| 28 | |
| 29 if (isset($_REQUEST['address'])){ | |
| 30 | |
| 31 $parsedAddress = parse_url($_REQUEST['address']); | |
| 32 | |
| 33 $found = 0; | |
| 34 | |
| 35 foreach ($validHosts as $host){ | |
| 36 if (preg_match($host, $parsedAddress["host"])){ | |
| 37 $found = 1; | |
| 38 break; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 if ((count($validHosts)==0) || ($found==1)){ | |
| 43 $address = $_REQUEST['address']; | |
| 44 $isFirst = 1; | |
| 45 foreach($_REQUEST as $key => $value){ | |
| 46 if ($key == 'address') | |
| 47 continue; | |
| 48 if ($isFirst == 1){ | |
| 49 $isFirst = 0; | |
| 50 $address .= "?"; | |
| 51 } else { | |
| 52 $address .= "&"; | |
| 53 } | |
| 54 $address .= $key . "=" . $value; | |
| 55 } | |
| 56 | |
| 57 $request_body = file_get_contents('php://input'); | |
| 58 | |
| 59 if (empty($request_body)){ | |
| 60 echo file_get_contents($address); | |
| 61 } else { | |
| 62 $opts = array('http' => | |
| 63 array( | |
| 64 'method' => 'POST', | |
| 65 'header' => 'Content-type: '.$_SERVER["CONTENT_TYPE"], | |
| 66 'content' => $request_body | |
| 67 ) | |
| 68 ); | |
| 69 | |
| 70 $context = stream_context_create($opts); | |
| 71 | |
| 72 echo file_get_contents($address, false, $context); | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 ?> |
