Advertisement
Guest User

Untitled

a guest
Apr 17th, 2010
572
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. <?php
  2.  
  3. $version = '1.2';
  4.  
  5. if(isset($_GET['dbboon_version'])) {
  6. echo '{"version":"' . $version . '"}';
  7. exit;
  8. }
  9.  
  10. function dbboon_parseHeaders($subject) {
  11.  
  12. global $version;
  13.  
  14. $subject = trim($subject);
  15. $parsed = Array();
  16. $len = strlen($subject);
  17. $position = $field = 0;
  18. $position = strpos($subject, "\r\n") + 2;
  19.  
  20. while(isset($subject[$position])) {
  21.  
  22. $nextC = strpos($subject, ':', $position);
  23. $fieldName = substr($subject, $position, ($nextC-$position));
  24. $position += strlen($fieldName) + 1;
  25. $fieldValue = NULL;
  26.  
  27. while(1) {
  28. $nextCrlf = strpos($subject, "\r\n", $position - 1);
  29. if(FALSE === $nextCrlf) {
  30. $t = substr($subject, $position);
  31. $position = $len;
  32. } else {
  33. $t = substr($subject, $position, $nextCrlf-$position);
  34. $position += strlen($t) + 2;
  35. }
  36.  
  37. $fieldValue .= $t;
  38. if(!isset($subject[$position]) || (' ' != $subject[$position] && "\t" != $subject[$position])) {
  39. break;
  40. }
  41. }
  42.  
  43. $parsed[strtolower($fieldName)] = trim($fieldValue);
  44. if($position > $len) {
  45. echo '{"result":false,"error":{"code":4,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
  46. exit;
  47. }
  48. }
  49. return $parsed;
  50. }
  51.  
  52. if(!function_exists('http_build_query')) {
  53. function http_build_query($data, $prefix = '', $sep = '', $key = '') {
  54. $ret = Array();
  55. foreach((array) $data as $k => $v) {
  56. if(is_int($k) && NULL != $prefix) {
  57. $k = urlencode($prefix . $k);
  58. }
  59. if(!empty($key) || $key === 0) {
  60. $k = $key . '[' . urlencode($k) . ']';
  61. }
  62. if(is_array($v) || is_object($v)) {
  63. array_push($ret, http_build_query($v, '', $sep, $k));
  64. } else {
  65. array_push($ret, $k . '=' . urlencode($v));
  66. }
  67. }
  68. if(empty($sep)) {
  69. $sep = '&';
  70. }
  71. return implode($sep, $ret);
  72. }
  73. }
  74.  
  75. $host = 'dbexternalsubscriber.secureserver.net';
  76. $get = http_build_query($_GET);
  77. $post = http_build_query($_POST);
  78. $url = $get ? "?$get" : '';
  79. $fp = fsockopen($host, 80, $errno, $errstr);
  80.  
  81. if($fp) {
  82.  
  83. $payload = "POST /embed/$url HTTP/1.1\r\n";
  84. $payload .= "Host: $host\r\n";
  85. $payload .= "Content-Length: " . strlen($post) . "\r\n";
  86. $payload .= "Content-Type: application/x-www-form-urlencoded\r\n";
  87. $payload .= "Connection: Close\r\n\r\n";
  88. $payload .= $post;
  89.  
  90. fwrite($fp, $payload);
  91.  
  92. $httpCode = NULL;
  93. $response = NULL;
  94. $timeout = time() + 15;
  95.  
  96. do {
  97. while($line = fgets($fp)) {
  98. $response .= $line;
  99. if(!trim($line)) {
  100. break;
  101. }
  102. }
  103. } while($timeout > time() && NULL === $response);
  104.  
  105. $headers = dbboon_parseHeaders($response);
  106. if(isset($headers['transfer-encoding']) && 'chunked' === $headers['transfer-encoding']) {
  107. do {
  108. $cSize = $read = hexdec(trim(fgets($fp)));
  109. while($read > 0) {
  110. $buff = fread($fp, $read);
  111. $read -= strlen($buff);
  112. $response .= $buff;
  113. }
  114. $response .= fgets($fp);
  115. } while($cSize > 0);
  116. } else {
  117. preg_match('/Content-Length:\s([0-9]+)\r\n/msi', $response, $match);
  118. if(!isset($match[1])) {
  119. echo '{"result":false,"error":{"code":3,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
  120. exit;
  121. } else {
  122. while($match[1] > 0) {
  123. $buff = fread($fp, $match[1]);
  124. $match[1] -= strlen($buff);
  125. $response .= $buff;
  126. }
  127. }
  128. }
  129.  
  130. fclose($fp);
  131.  
  132. if(!$pos = strpos($response, "\r\n\r\n")) {
  133. echo '{"result":false,"error":{"code":2,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
  134. exit;
  135. }
  136.  
  137. echo substr($response, $pos + 4);
  138.  
  139. } else {
  140. echo '{"result":false,"error":{"code":1,"message":"Communication error, unable to contact proxy service.","version":"' . $version . '"}}';
  141. exit;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement