Advertisement
shinobininja

ninjutsu proxy

Jun 26th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2.  
  3. $method = $_SERVER['REQUEST_METHOD'];
  4.  
  5.  
  6. if ($_GET && $_GET['url']) {
  7. $headers = getallheaders();
  8. $headers_str = [];
  9. $url = $_GET['url'];
  10.  
  11. foreach ( $headers as $key => $value){
  12. if($key == 'Host')
  13. continue;
  14. $headers_str[]=$key.":".$value;
  15. }
  16.  
  17. $ch = curl_init($url);
  18.  
  19. curl_setopt($ch,CURLOPT_URL, $url);
  20. if( $method !== 'GET') {
  21. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  22. }
  23.  
  24. if($method == "PUT" || $method == "PATCH" || ($method == "POST" && empty($_FILES))) {
  25. $data_str = file_get_contents('php://input');
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str);
  27. //error_log($method.': '.$data_str.serialize($_POST).'\n',3, 'err.log');
  28. }
  29. elseif($method == "POST") {
  30. $data_str = array();
  31. if(!empty($_FILES)) {
  32. foreach ($_FILES as $key => $value) {
  33. $full_path = realpath( $_FILES[$key]['tmp_name']);
  34. $data_str[$key] = '@'.$full_path;
  35. }
  36. }
  37. //error_log($method.': '.serialize($data_str+$_POST).'\n',3, 'err.log');
  38.  
  39. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_str+$_POST);
  40. }
  41.  
  42. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  43. curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers_str );
  44.  
  45. $result = curl_exec($ch);
  46. curl_close($ch);
  47.  
  48. header('Content-Type: application/json');
  49. echo $result;
  50. }
  51. else {
  52. echo $method;
  53. var_dump($_POST);
  54. var_dump($_GET);
  55. $data_str = file_get_contents('php://input');
  56. echo $data_str;
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement