| 1 |
<?php |
|---|
| 2 |
if ( !in_array('Snoopy', get_declared_classes() ) ) : |
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
class Snoopy |
|---|
| 33 |
{ |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
/* user definable vars */ |
|---|
| 37 |
|
|---|
| 38 |
var $host = "www.php.net"; |
|---|
| 39 |
var $port = 80; |
|---|
| 40 |
var $proxy_host = ""; |
|---|
| 41 |
var $proxy_port = ""; |
|---|
| 42 |
var $proxy_user = ""; |
|---|
| 43 |
var $proxy_pass = ""; |
|---|
| 44 |
|
|---|
| 45 |
var $agent = "Snoopy v1.2.4"; |
|---|
| 46 |
var $referer = ""; |
|---|
| 47 |
var $cookies = array(); |
|---|
| 48 |
// $cookies["username"]="joe"; |
|---|
| 49 |
var $rawheaders = array(); |
|---|
| 50 |
// $rawheaders["Content-type"]="text/html"; |
|---|
| 51 |
|
|---|
| 52 |
var $maxredirs = 5; |
|---|
| 53 |
var $lastredirectaddr = ""; |
|---|
| 54 |
var $offsiteok = true; |
|---|
| 55 |
var $maxframes = 0; |
|---|
| 56 |
var $expandlinks = true; |
|---|
| 57 |
// this only applies to fetchlinks() |
|---|
| 58 |
// submitlinks(), and submittext() |
|---|
| 59 |
var $passcookies = true; |
|---|
| 60 |
// NOTE: this currently does not respect |
|---|
| 61 |
// dates, domains or paths. |
|---|
| 62 |
|
|---|
| 63 |
var $user = ""; |
|---|
| 64 |
var $pass = ""; |
|---|
| 65 |
|
|---|
| 66 |
// http accept types |
|---|
| 67 |
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|---|
| 68 |
|
|---|
| 69 |
var $results = ""; |
|---|
| 70 |
|
|---|
| 71 |
var $error = ""; |
|---|
| 72 |
var $response_code = ""; |
|---|
| 73 |
var $headers = array(); |
|---|
| 74 |
var $maxlength = 500000; |
|---|
| 75 |
var $read_timeout = 0; |
|---|
| 76 |
// supported only since PHP 4 Beta 4 |
|---|
| 77 |
// set to 0 to disallow timeouts |
|---|
| 78 |
var $timed_out = false; |
|---|
| 79 |
var $status = 0; |
|---|
| 80 |
|
|---|
| 81 |
var $temp_dir = "/tmp"; |
|---|
| 82 |
// has permission to write to. |
|---|
| 83 |
// under Windows, this should be C:\temp |
|---|
| 84 |
|
|---|
| 85 |
var $curl_path = "/usr/local/bin/curl"; |
|---|
| 86 |
|
|---|
| 87 |
// SSL content if a full system path to |
|---|
| 88 |
// the cURL binary is supplied here. |
|---|
| 89 |
// set to false if you do not have |
|---|
| 90 |
// cURL installed. See http://curl.haxx.se |
|---|
| 91 |
// for details on installing cURL. |
|---|
| 92 |
// Snoopy does *not* use the cURL |
|---|
| 93 |
// library functions built into php, |
|---|
| 94 |
// as these functions are not stable |
|---|
| 95 |
// as of this Snoopy release. |
|---|
| 96 |
|
|---|
| 97 |
/**** Private variables ****/ |
|---|
| 98 |
|
|---|
| 99 |
var $_maxlinelen = 4096; |
|---|
| 100 |
|
|---|
| 101 |
var $_httpmethod = "GET"; |
|---|
| 102 |
var $_httpversion = "HTTP/1.0"; |
|---|
| 103 |
var $_submit_method = "POST"; |
|---|
| 104 |
var $_submit_type = "application/x-www-form-urlencoded"; |
|---|
| 105 |
var $_mime_boundary = ""; |
|---|
| 106 |
var $_redirectaddr = false; |
|---|
| 107 |
var $_redirectdepth = 0; |
|---|
| 108 |
var $_frameurls = array(); |
|---|
| 109 |
var $_framedepth = 0; |
|---|
| 110 |
|
|---|
| 111 |
var $_isproxy = false; |
|---|
| 112 |
var $_fp_timeout = 30; |
|---|
| 113 |
|
|---|
| 114 |
/*======================================================================*\ |
|---|
| 115 |
Function: fetch |
|---|
| 116 |
Purpose: fetch the contents of a web page |
|---|
| 117 |
(and possibly other protocols in the |
|---|
| 118 |
future like ftp, nntp, gopher, etc.) |
|---|
| 119 |
Input: $URI the location of the page to fetch |
|---|
| 120 |
Output: $this->results the output text from the fetch |
|---|
| 121 |
\*======================================================================*/ |
|---|
| 122 |
|
|---|
| 123 |
function fetch($URI) |
|---|
| 124 |
{ |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
$URI_PARTS = parse_url($URI); |
|---|
| 128 |
if (!empty($URI_PARTS["user"])) |
|---|
| 129 |
$this->user = $URI_PARTS["user"]; |
|---|
| 130 |
if (!empty($URI_PARTS["pass"])) |
|---|
| 131 |
$this->pass = $URI_PARTS["pass"]; |
|---|
| 132 |
if (empty($URI_PARTS["query"])) |
|---|
| 133 |
$URI_PARTS["query"] = ''; |
|---|
| 134 |
if (empty($URI_PARTS["path"])) |
|---|
| 135 |
$URI_PARTS["path"] = ''; |
|---|
| 136 |
|
|---|
| 137 |
switch(strtolower($URI_PARTS["scheme"])) |
|---|
| 138 |
{ |
|---|
| 139 |
case "http": |
|---|
| 140 |
$this->host = $URI_PARTS["host"]; |
|---|
| 141 |
if(!empty($URI_PARTS["port"])) |
|---|
| 142 |
$this->port = $URI_PARTS["port"]; |
|---|
| 143 |
if($this->_connect($fp)) |
|---|
| 144 |
{ |
|---|
| 145 |
if($this->_isproxy) |
|---|
| 146 |
{ |
|---|
| 147 |
|
|---|
| 148 |
$this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|---|
| 149 |
} |
|---|
| 150 |
else |
|---|
| 151 |
{ |
|---|
| 152 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 153 |
|
|---|
| 154 |
$this->_httprequest($path, $fp, $URI, $this->_httpmethod); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
$this->_disconnect($fp); |
|---|
| 158 |
|
|---|
| 159 |
if($this->_redirectaddr) |
|---|
| 160 |
{ |
|---|
| 161 |
|
|---|
| 162 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 163 |
{ |
|---|
| 164 |
|
|---|
| 165 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 166 |
{ |
|---|
| 167 |
|
|---|
| 168 |
$this->_redirectdepth++; |
|---|
| 169 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 170 |
$this->fetch($this->_redirectaddr); |
|---|
| 171 |
} |
|---|
| 172 |
} |
|---|
| 173 |
} |
|---|
| 174 |
|
|---|
| 175 |
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 176 |
{ |
|---|
| 177 |
$frameurls = $this->_frameurls; |
|---|
| 178 |
$this->_frameurls = array(); |
|---|
| 179 |
|
|---|
| 180 |
while(list(,$frameurl) = each($frameurls)) |
|---|
| 181 |
{ |
|---|
| 182 |
if($this->_framedepth < $this->maxframes) |
|---|
| 183 |
{ |
|---|
| 184 |
$this->fetch($frameurl); |
|---|
| 185 |
$this->_framedepth++; |
|---|
| 186 |
} |
|---|
| 187 |
else |
|---|
| 188 |
break; |
|---|
| 189 |
} |
|---|
| 190 |
} |
|---|
| 191 |
} |
|---|
| 192 |
else |
|---|
| 193 |
{ |
|---|
| 194 |
return false; |
|---|
| 195 |
} |
|---|
| 196 |
return true; |
|---|
| 197 |
break; |
|---|
| 198 |
case "https": |
|---|
| 199 |
if(!$this->curl_path) |
|---|
| 200 |
return false; |
|---|
| 201 |
if(function_exists("is_executable")) |
|---|
| 202 |
if (!is_executable($this->curl_path)) |
|---|
| 203 |
return false; |
|---|
| 204 |
$this->host = $URI_PARTS["host"]; |
|---|
| 205 |
if(!empty($URI_PARTS["port"])) |
|---|
| 206 |
$this->port = $URI_PARTS["port"]; |
|---|
| 207 |
if($this->_isproxy) |
|---|
| 208 |
{ |
|---|
| 209 |
|
|---|
| 210 |
$this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|---|
| 211 |
} |
|---|
| 212 |
else |
|---|
| 213 |
{ |
|---|
| 214 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 215 |
|
|---|
| 216 |
$this->_httpsrequest($path, $URI, $this->_httpmethod); |
|---|
| 217 |
} |
|---|
| 218 |
|
|---|
| 219 |
if($this->_redirectaddr) |
|---|
| 220 |
{ |
|---|
| 221 |
|
|---|
| 222 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 223 |
{ |
|---|
| 224 |
|
|---|
| 225 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 226 |
{ |
|---|
| 227 |
|
|---|
| 228 |
$this->_redirectdepth++; |
|---|
| 229 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 230 |
$this->fetch($this->_redirectaddr); |
|---|
| 231 |
} |
|---|
| 232 |
} |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 236 |
{ |
|---|
| 237 |
$frameurls = $this->_frameurls; |
|---|
| 238 |
$this->_frameurls = array(); |
|---|
| 239 |
|
|---|
| 240 |
while(list(,$frameurl) = each($frameurls)) |
|---|
| 241 |
{ |
|---|
| 242 |
if($this->_framedepth < $this->maxframes) |
|---|
| 243 |
{ |
|---|
| 244 |
$this->fetch($frameurl); |
|---|
| 245 |
$this->_framedepth++; |
|---|
| 246 |
} |
|---|
| 247 |
else |
|---|
| 248 |
break; |
|---|
| 249 |
} |
|---|
| 250 |
} |
|---|
| 251 |
return true; |
|---|
| 252 |
break; |
|---|
| 253 |
default: |
|---|
| 254 |
|
|---|
| 255 |
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|---|
| 256 |
return false; |
|---|
| 257 |
break; |
|---|
| 258 |
} |
|---|
| 259 |
return true; |
|---|
| 260 |
} |
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 |
|
|---|
| 264 |
|
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
function submit($URI, $formvars="", $formfiles="") |
|---|
| 274 |
|
|---|
| 275 |
$postdata); |
|---|
| 276 |
|
|---|
| 277 |
$postdata = $this->_prepare_post_body($formvars, $formfiles); |
|---|
| 278 |
|
|---|
| 279 |
$URI_PARTS = parse_url($URI); |
|---|
| 280 |
$URI_PARTS["user"])) |
|---|
| 281 |
$this->user = $URI_PARTS["user"]; |
|---|
| 282 |
$URI_PARTS["pass"])) |
|---|
| 283 |
$this->pass = $URI_PARTS["pass"]; |
|---|
| 284 |
$URI_PARTS["query"])) |
|---|
| 285 |
$URI_PARTS["query"] = ''; |
|---|
| 286 |
$URI_PARTS["path"])) |
|---|
| 287 |
$URI_PARTS["path"] = ''; |
|---|
| 288 |
|
|---|
| 289 |
strtolower($URI_PARTS["scheme"])) |
|---|
| 290 |
|
|---|
| 291 |
"http": |
|---|
| 292 |
$this->host = $URI_PARTS["host"]; |
|---|
| 293 |
$URI_PARTS["port"])) |
|---|
| 294 |
$this->port = $URI_PARTS["port"]; |
|---|
| 295 |
$this->_connect($fp)) |
|---|
| 296 |
|
|---|
| 297 |
$this->_isproxy) |
|---|
| 298 |
|
|---|
| 299 |
|
|---|
| 300 |
$this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); |
|---|
| 301 |
|
|---|
| 302 |
|
|---|
| 303 |
|
|---|
| 304 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 305 |
|
|---|
| 306 |
$this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|---|
| 307 |
|
|---|
| 308 |
|
|---|
| 309 |
$this->_disconnect($fp); |
|---|
| 310 |
|
|---|
| 311 |
$this->_redirectaddr) |
|---|
| 312 |
|
|---|
| 313 |
|
|---|
| 314 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 315 |
|
|---|
| 316 |
preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|---|
| 317 |
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|---|
| 318 |
|
|---|
| 319 |
|
|---|
| 320 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 321 |
|
|---|
| 322 |
|
|---|
| 323 |
$this->_redirectdepth++; |
|---|
| 324 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 325 |
strpos( $this->_redirectaddr, "?" ) > 0 ) |
|---|
| 326 |
$this->fetch($this->_redirectaddr); |
|---|
| 327 |
else |
|---|
| 328 |
$this->submit($this->_redirectaddr,$formvars, $formfiles); |
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
|
|---|
| 332 |
|
|---|
| 333 |
$this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 334 |
|
|---|
| 335 |
$frameurls = $this->_frameurls; |
|---|
| 336 |
$this->_frameurls = array(); |
|---|
| 337 |
|
|---|
| 338 |
$frameurl) = each($frameurls)) |
|---|
| 339 |
|
|---|
| 340 |
$this->_framedepth < $this->maxframes) |
|---|
| 341 |
|
|---|
| 342 |
$this->fetch($frameurl); |
|---|
| 343 |
$this->_framedepth++; |
|---|
| 344 |
|
|---|
| 345 |
|
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
|
|---|
| 349 |
|
|---|
| 350 |
|
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
false; |
|---|
| 354 |
|
|---|
| 355 |
true; |
|---|
| 356 |
|
|---|
| 357 |
"https": |
|---|
| 358 |
$this->curl_path) |
|---|
| 359 |
false; |
|---|
| 360 |
function_exists("is_executable")) |
|---|
| 361 |
is_executable($this->curl_path)) |
|---|
| 362 |
false; |
|---|
| 363 |
$this->host = $URI_PARTS["host"]; |
|---|
| 364 |
$URI_PARTS["port"])) |
|---|
| 365 |
$this->port = $URI_PARTS["port"]; |
|---|
| 366 |
$this->_isproxy) |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
$this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|---|
| 370 |
|
|---|
| 371 |
|
|---|
| 372 |
|
|---|
| 373 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 374 |
|
|---|
| 375 |
$this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|---|
| 376 |
|
|---|
| 377 |
|
|---|
| 378 |
$this->_redirectaddr) |
|---|
| 379 |
|
|---|
| 380 |
|
|---|
| 381 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 382 |
|
|---|
| 383 |
preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|---|
| 384 |
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|---|
| 385 |
|
|---|
| 386 |
|
|---|
| 387 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
$this->_redirectdepth++; |
|---|
| 391 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 392 |
strpos( $this->_redirectaddr, "?" ) > 0 ) |
|---|
| 393 |
$this->fetch($this->_redirectaddr); |
|---|
| 394 |
else |
|---|
| 395 |
$this->submit($this->_redirectaddr,$formvars, $formfiles); |
|---|
| 396 |
|
|---|
| 397 |
|
|---|
| 398 |
|
|---|
| 399 |
|
|---|
| 400 |
$this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 401 |
|
|---|
| 402 |
$frameurls = $this->_frameurls; |
|---|
| 403 |
$this->_frameurls = array(); |
|---|
| 404 |
|
|---|
| 405 |
$frameurl) = each($frameurls)) |
|---|
| 406 |
|
|---|
| 407 |
$this->_framedepth < $this->maxframes) |
|---|
| 408 |
|
|---|
| 409 |
$this->fetch($frameurl); |
|---|
| 410 |
$this->_framedepth++; |
|---|
| 411 |
|
|---|
| 412 |
|
|---|
| 413 |
|
|---|
| 414 |
|
|---|
| 415 |
|
|---|
| 416 |
true; |
|---|
| 417 |
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|---|
| 422 |
false; |
|---|
| 423 |
|
|---|
| 424 |
|
|---|
| 425 |
true; |
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 |
|
|---|
| 432 |
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 |
function fetchlinks($URI) |
|---|
| 436 |
|
|---|
| 437 |
$this->fetch($URI)) |
|---|
| 438 |
|
|---|
| 439 |
$this->lastredirectaddr) |
|---|
| 440 |
$URI = $this->lastredirectaddr; |
|---|
| 441 |
is_array($this->results)) |
|---|
| 442 |
|
|---|
| 443 |
$x=0;$x<count($this->results);$x++) |
|---|
| 444 |
$this->results[$x] = $this->_striplinks($this->results[$x]); |
|---|
| 445 |
|
|---|
| 446 |
|
|---|
| 447 |
$this->results = $this->_striplinks($this->results); |
|---|
| 448 |
|
|---|
| 449 |
$this->expandlinks) |
|---|
| 450 |
$this->results = $this->_expandlinks($this->results, $URI); |
|---|
| 451 |
true; |
|---|
| 452 |
|
|---|
| 453 |
|
|---|
| 454 |
false; |
|---|
| 455 |
|
|---|
| 456 |
|
|---|
| 457 |
|
|---|
| 458 |
|
|---|
| 459 |
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 |
|
|---|
| 463 |
|
|---|
| 464 |
function fetchform($URI) |
|---|
| 465 |
|
|---|
| 466 |
|
|---|
| 467 |
$this->fetch($URI)) |
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 |
is_array($this->results)) |
|---|
| 471 |
|
|---|
| 472 |
$x=0;$x<count($this->results);$x++) |
|---|
| 473 |
$this->results[$x] = $this->_stripform($this->results[$x]); |
|---|
| 474 |
|
|---|
| 475 |
|
|---|
| 476 |
$this->results = $this->_stripform($this->results); |
|---|
| 477 |
|
|---|
| 478 |
true; |
|---|
| 479 |
|
|---|
| 480 |
|
|---|
| 481 |
false; |
|---|
| 482 |
|
|---|
| 483 |
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 |
|
|---|
| 487 |
|
|---|
| 488 |
|
|---|
| 489 |
|
|---|
| 490 |
|
|---|
| 491 |
|
|---|
| 492 |
function fetchtext($URI) |
|---|
| 493 |
|
|---|
| 494 |
$this->fetch($URI)) |
|---|
| 495 |
|
|---|
| 496 |
is_array($this->results)) |
|---|
| 497 |
|
|---|
| 498 |
$x=0;$x<count($this->results);$x++) |
|---|
| 499 |
$this->results[$x] = $this->_striptext($this->results[$x]); |
|---|
| 500 |
|
|---|
| 501 |
|
|---|
| 502 |
$this->results = $this->_striptext($this->results); |
|---|
| 503 |
true; |
|---|
| 504 |
|
|---|
| 505 |
|
|---|
| 506 |
false; |
|---|
| 507 |
|
|---|
| 508 |
|
|---|
| 509 |
|
|---|
| 510 |
|
|---|
| 511 |
|
|---|
| 512 |
|
|---|
| 513 |
|
|---|
| 514 |
|
|---|
| 515 |
|
|---|
| 516 |
function submitlinks($URI, $formvars="", $formfiles="") |
|---|
| 517 |
|
|---|
| 518 |
$this->submit($URI,$formvars, $formfiles)) |
|---|
| 519 |
|
|---|
| 520 |
$this->lastredirectaddr) |
|---|
| 521 |
$URI = $this->lastredirectaddr; |
|---|
| 522 |
is_array($this->results)) |
|---|
| 523 |
|
|---|
| 524 |
$x=0;$x<count($this->results);$x++) |
|---|
| 525 |
|
|---|
| 526 |
$this->results[$x] = $this->_striplinks($this->results[$x]); |
|---|
| 527 |
$this->expandlinks) |
|---|
| 528 |
$this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
$this->results = $this->_striplinks($this->results); |
|---|
| 534 |
$this->expandlinks) |
|---|
| 535 |
$this->results = $this->_expandlinks($this->results,$URI); |
|---|
| 536 |
|
|---|
| 537 |
true; |
|---|
| 538 |
|
|---|
| 539 |
|
|---|
| 540 |
false; |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
function submittext($URI, $formvars = "", $formfiles = "") |
|---|
| 551 |
|
|---|
| 552 |
$this->submit($URI,$formvars, $formfiles)) |
|---|
| 553 |
|
|---|
| 554 |
$this->lastredirectaddr) |
|---|
| 555 |
$URI = $this->lastredirectaddr; |
|---|
| 556 |
is_array($this->results)) |
|---|
| 557 |
|
|---|
| 558 |
$x=0;$x<count($this->results);$x++) |
|---|
| 559 |
|
|---|
| 560 |
$this->results[$x] = $this->_striptext($this->results[$x]); |
|---|
| 561 |
$this->expandlinks) |
|---|
| 562 |
$this->results[$x] = $this->_expandlinks($this->results[$x],$URI); |
|---|
| 563 |
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 |
$this->results = $this->_striptext($this->results); |
|---|
| 568 |
$this->expandlinks) |
|---|
| 569 |
$this->results = $this->_expandlinks($this->results,$URI); |
|---|
| 570 |
|
|---|
| 571 |
true; |
|---|
| 572 |
|
|---|
| 573 |
|
|---|
| 574 |
false; |
|---|
| 575 |
|
|---|
| 576 |
|
|---|
| 577 |
|
|---|
| 578 |
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 |
|
|---|
| 582 |
|
|---|
| 583 |
|
|---|
| 584 |
function set_submit_multipart() |
|---|
| 585 |
|
|---|
| 586 |
$this->_submit_type = "multipart/form-data"; |
|---|
| 587 |
|
|---|
| 588 |
|
|---|
| 589 |
|
|---|
| 590 |
|
|---|
| 591 |
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 |
|
|---|
| 595 |
function set_submit_normal() |
|---|
| 596 |
|
|---|
| 597 |
$this->_submit_type = "application/x-www-form-urlencoded"; |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
|
|---|
| 601 |
|
|---|
| 602 |
|
|---|
| 603 |
|
|---|
| 604 |
|
|---|
| 605 |
|
|---|
| 606 |
|
|---|
| 607 |
|
|---|
| 608 |
|
|---|
| 609 |
|
|---|
| 610 |
|
|---|
| 611 |
|
|---|
| 612 |
|
|---|
| 613 |
|
|---|
| 614 |
|
|---|
| 615 |
function _striplinks($document) |
|---|
| 616 |
|
|---|
| 617 |
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href= |
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 |
|
|---|
| 621 |
,$document,$links); |
|---|
| 622 |
|
|---|
| 623 |
|
|---|
| 624 |
|
|---|
| 625 |
|
|---|
| 626 |
while(list($key,$val) = each($links[2])) |
|---|
| 627 |
|
|---|
| 628 |
$val)) |
|---|
| 629 |
$match[] = $val; |
|---|
| 630 |
|
|---|
| 631 |
|
|---|
| 632 |
$key,$val) = each($links[3])) |
|---|
| 633 |
|
|---|
| 634 |
$val)) |
|---|
| 635 |
$match[] = $val; |
|---|
| 636 |
|
|---|
| 637 |
|
|---|
| 638 |
|
|---|
| 639 |
return $match; |
|---|
| 640 |
|
|---|
| 641 |
|
|---|
| 642 |
|
|---|
| 643 |
|
|---|
| 644 |
|
|---|
| 645 |
|
|---|
| 646 |
|
|---|
| 647 |
|
|---|
| 648 |
|
|---|
| 649 |
function _stripform($document) |
|---|
| 650 |
|
|---|
| 651 |
preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements); |
|---|
| 652 |
|
|---|
| 653 |
|
|---|
| 654 |
$match = implode("\r\n",$elements[0]); |
|---|
| 655 |
|
|---|
| 656 |
|
|---|
| 657 |
return $match; |
|---|
| 658 |
|
|---|
| 659 |
|
|---|
| 660 |
|
|---|
| 661 |
|
|---|
| 662 |
|
|---|
| 663 |
|
|---|
| 664 |
|
|---|
| 665 |
|
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 |
|
|---|
| 669 |
function _striptext($document) |
|---|
| 670 |
|
|---|
| 671 |
|
|---|
| 672 |
|
|---|
| 673 |
|
|---|
| 674 |
|
|---|
| 675 |
|
|---|
| 676 |
$search = array("'<script[^>]*?>.*?</script>'si", |
|---|
| 677 |
"'<[\/\!]*?[^<>]*?>'si", |
|---|
| 678 |
"'([\r\n])[\s]+'", |
|---|
| 679 |
"'&(quot|#34|#034|#x22);'i", |
|---|
| 680 |
"'&(amp|#38|#038|#x26);'i", |
|---|
| 681 |
"'&(lt|#60|#060|#x3c);'i", |
|---|
| 682 |
"'&(gt|#62|#062|#x3e);'i", |
|---|
| 683 |
"'&(nbsp|#160|#xa0);'i", |
|---|
| 684 |
"'&(iexcl|#161);'i", |
|---|
| 685 |
"'&(cent|#162);'i", |
|---|
| 686 |
"'&(pound|#163);'i", |
|---|
| 687 |
"'&(copy|#169);'i", |
|---|
| 688 |
"'&(reg|#174);'i", |
|---|
| 689 |
"'&(deg|#176);'i", |
|---|
| 690 |
"'&(#39|#039|#x27);'", |
|---|
| 691 |
"'&(euro|#8364);'i", |
|---|
| 692 |
"'&a(uml|UML);'", |
|---|
| 693 |
"'&o(uml|UML);'", |
|---|
| 694 |
"'&u(uml|UML);'", |
|---|
| 695 |
"'&A(uml|UML);'", |
|---|
| 696 |
"'&O(uml|UML);'", |
|---|
| 697 |
"'&U(uml|UML);'", |
|---|
| 698 |
"'ß'i", |
|---|
| 699 |
|
|---|
| 700 |
$replace = array( "", |
|---|
| 701 |
"", |
|---|
| 702 |
"\\1", |
|---|
| 703 |
"\"", |
|---|
| 704 |
"&", |
|---|
| 705 |
"<", |
|---|
| 706 |
">", |
|---|
| 707 |
" ", |
|---|
| 708 |
chr(161), |
|---|
| 709 |
chr(162), |
|---|
| 710 |
chr(163), |
|---|
| 711 |
chr(169), |
|---|
| 712 |
chr(174), |
|---|
| 713 |
chr(176), |
|---|
| 714 |
chr(39), |
|---|
| 715 |
chr(128), |
|---|
| 716 |
"� |
|---|
| 717 |
� "� "�, |
|---|
| 718 |
"�, |
|---|
| 719 |
�, |
|---|
| 720 |
"�, |
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 |
|
|---|
| 724 |
|
|---|
| 725 |
|
|---|
| 726 |
|
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
|
|---|
| 730 |
|
|---|
| 731 |
|
|---|
| 732 |
|
|---|
| 733 |
|
|---|
| 734 |
|
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 |
|
|---|
| 739 |
/^[^Warning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0?]+/",$URI,$match); |
|---|
| 740 |
|
|---|
| 741 |
|/[^Warning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0/Warning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0.]+Warning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0.[^Warning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0/Warning: Unexpected character in input: '\' (ASCII=92) state=1 in Unknown on line 0.]+$|","",$match[0]); |
|---|
| 742 |
|/$|","",$match); |
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
scheme"].": |
|---|
| 746 |
|
|---|
| 747 |
$search = array( "|^http://".preg_quote($this->host)."|i", |
|---|
| 748 |
"|^(\/)|i", |
|---|
| 749 |
"|^(?!http://)(?!mailto:)|i", |
|---|
| 750 |
"|/\./|", |
|---|
| 751 |
"|/[^\/]+/\.\./|" |
|---|
| 752 |
); |
|---|
| 753 |
|
|---|
| 754 |
$replace = array( "", |
|---|
| 755 |
$match_root."/", |
|---|
| 756 |
$match."/", |
|---|
| 757 |
"/", |
|---|
| 758 |
"/" |
|---|
| 759 |
); |
|---|
| 760 |
|
|---|
| 761 |
$expandedLinks = preg_replace($search,$replace,$links); |
|---|
| 762 |
|
|---|
| 763 |
$expandedLinks; |
|---|
| 764 |
|
|---|
| 765 |
|
|---|
| 766 |
|
|---|
| 767 |
|
|---|
| 768 |
|
|---|
| 769 |
|
|---|
| 770 |
|
|---|
| 771 |
|
|---|
| 772 |
|
|---|
| 773 |
|
|---|
| 774 |
|
|---|
| 775 |
|
|---|
| 776 |
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="") |
|---|
| 777 |
|
|---|
| 778 |
$cookie_headers = ''; |
|---|
| 779 |
$this->passcookies && $this->_redirectaddr) |
|---|
| 780 |
$this->setcookies(); |
|---|
| 781 |
|
|---|
| 782 |
$URI_PARTS = parse_url($URI); |
|---|
| 783 |
$url)) |
|---|
| 784 |
$url = "/"; |
|---|
| 785 |
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n"; |
|---|
| 786 |
$this->agent)) |
|---|
| 787 |
$headers .= "User-Agent: ".$this->agent."\r\n"; |
|---|
| 788 |
$this->host) && !isset($this->rawheaders['Host'])) { |
|---|
| 789 |
$headers .= "Host: ".$this->host; |
|---|
| 790 |
$this->port) && $this->port != 80) |
|---|
| 791 |
$headers .= ":".$this->port; |
|---|
| 792 |
$headers .= "\r\n"; |
|---|
| 793 |
|
|---|
| 794 |
$this->accept)) |
|---|
| 795 |
$headers .= "Accept: ".$this->accept."\r\n"; |
|---|
| 796 |
$this->referer)) |
|---|
| 797 |
$headers .= "Referer: ".$this->referer."\r\n"; |
|---|
| 798 |
$this->cookies)) |
|---|
| 799 |
|
|---|
| 800 |
is_array($this->cookies)) |
|---|
| 801 |
$this->cookies = (array)$this->cookies; |
|---|
| 802 |
|
|---|
| 803 |
reset($this->cookies); |
|---|
| 804 |
count($this->cookies) > 0 ) { |
|---|
| 805 |
$cookie_headers .= 'Cookie: '; |
|---|
| 806 |
$this->cookies as $cookieKey => $cookieVal ) { |
|---|
| 807 |
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; "; |
|---|
| 808 |
|
|---|
| 809 |
$headers .= substr($cookie_headers,0,-2) . "\r\n"; |
|---|
| 810 |
|
|---|
| 811 |
|
|---|
| 812 |
$this->rawheaders)) |
|---|
| 813 |
|
|---|
| 814 |
is_array($this->rawheaders)) |
|---|
| 815 |
$this->rawheaders = (array)$this->rawheaders; |
|---|
| 816 |
$headerKey,$headerVal) = each($this->rawheaders)) |
|---|
| 817 |
$headers .= $headerKey.": ".$headerVal."\r\n"; |
|---|
| 818 |
|
|---|
| 819 |
$content_type)) { |
|---|
| 820 |
$headers .= "Content-type: $content_type"; |
|---|
| 821 |
$content_type == "multipart/form-data") |
|---|
| 822 |
$headers .= "; boundary=".$this->_mime_boundary; |
|---|
| 823 |
$headers .= "\r\n"; |
|---|
| 824 |
|
|---|
| 825 |
$body)) |
|---|
| 826 |
$headers .= "Content-length: ".strlen($body)."\r\n"; |
|---|
| 827 |
$this->user) || !empty($this->pass)) |
|---|
| 828 |
$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n"; |
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
if(!empty($this->proxy_user)) |
|---|
| 832 |
$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n"; |
|---|
| 833 |
|
|---|
| 834 |
|
|---|
| 835 |
$headers .= "\r\n"; |
|---|
| 836 |
|
|---|
| 837 |
|
|---|
| 838 |
if ($this->read_timeout > 0) |
|---|
| 839 |
socket_set_timeout($fp, $this->read_timeout); |
|---|
| 840 |
$this->timed_out = false; |
|---|
| 841 |
|
|---|
| 842 |
fwrite($fp,$headers.$body,strlen($headers.$body)); |
|---|
| 843 |
|
|---|
| 844 |
$this->_redirectaddr = false; |
|---|
| 845 |
$this->headers); |
|---|
| 846 |
|
|---|
| 847 |
$currentHeader = fgets($fp,$this->_maxlinelen)) |
|---|
| 848 |
|
|---|
| 849 |
$this->read_timeout > 0 && $this->_check_timeout($fp)) |
|---|
| 850 |
|
|---|
| 851 |
$this->status=-100; |
|---|
| 852 |
false; |
|---|
| 853 |
|
|---|
| 854 |
|
|---|
| 855 |
$currentHeader == "\r\n") |
|---|
| 856 |
|
|---|
| 857 |
|
|---|
| 858 |
|
|---|
| 859 |
if(preg_match("/^(Location:|URI:)/i",$currentHeader)) |
|---|
| 860 |
|
|---|
| 861 |
|
|---|
| 862 |
preg_match("/^(Location:|URI:)[ ]+(.*)/i",chop($currentHeader),$matches); |
|---|
| 863 |
|
|---|
| 864 |
if(!preg_match("|\:\/\/|",$matches[2])) |
|---|
| 865 |
|
|---|
| 866 |
|
|---|
| 867 |
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|---|
| 868 |
|
|---|
| 869 |
if(!preg_match("|^/|",$matches[2])) |
|---|
| 870 |
$this->_redirectaddr .= "/".$matches[2]; |
|---|
| 871 |
|
|---|
| 872 |
$this->_redirectaddr .= $matches[2]; |
|---|
| 873 |
|
|---|
| 874 |
|
|---|
| 875 |
$this->_redirectaddr = $matches[2]; |
|---|
| 876 |
|
|---|
| 877 |
|
|---|
| 878 |
preg_match("|^HTTP/|",$currentHeader)) |
|---|
| 879 |
|
|---|
| 880 |
preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status)) |
|---|
| 881 |
|
|---|
| 882 |
$this->status= $status[1]; |
|---|
| 883 |
|
|---|
| 884 |
$this->response_code = $currentHeader; |
|---|
| 885 |
|
|---|
| 886 |
|
|---|
| 887 |
$this->headers[] = $currentHeader; |
|---|
| 888 |
|
|---|
| 889 |
|
|---|
| 890 |
$results = ''; |
|---|
| 891 |
|
|---|
| 892 |
$_data = fread($fp, $this->maxlength); |
|---|
| 893 |
strlen($_data) == 0) { |
|---|
| 894 |
|
|---|
| 895 |
|
|---|
| 896 |
$results .= $_data; |
|---|
| 897 |
true); |
|---|
| 898 |
|
|---|
| 899 |
$this->read_timeout > 0 && $this->_check_timeout($fp)) |
|---|
| 900 |
|
|---|
| 901 |
$this->status=-100; |
|---|
| 902 |
false; |
|---|
| 903 |
|
|---|
| 904 |
|
|---|
| 905 |
|
|---|
| 906 |
|
|---|
| 907 |
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|---|
| 908 |
|
|---|
| 909 |
|
|---|
| 910 |
$this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|---|
| 911 |
|
|---|
| 912 |
|
|---|
| 913 |
|
|---|
| 914 |
if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|---|
| 915 |
|
|---|
| 916 |
$this->results[] = $results; |
|---|
| 917 |
$x=0; $x<count($match[1]); $x++) |
|---|
| 918 |
$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|---|
| 919 |
|
|---|
| 920 |
|
|---|
| 921 |
elseif(is_array($this->results)) |
|---|
| 922 |
$this->results[] = $results; |
|---|
| 923 |
|
|---|
| 924 |
else |
|---|
| 925 |
$this->results = $results; |
|---|
| 926 |
|
|---|
| 927 |
true; |
|---|
| 928 |
|
|---|
| 929 |
|
|---|
| 930 |
|
|---|
| 931 |
|
|---|
| 932 |
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 |
|
|---|
| 936 |
|
|---|
| 937 |
|
|---|
| 938 |
|
|---|
| 939 |
function _httpsrequest($url,$URI,$http_method,$content_type="",$body="") |
|---|
| 940 |
|
|---|
| 941 |
$this->passcookies && $this->_redirectaddr) |
|---|
| 942 |
$this->setcookies(); |
|---|
| 943 |
|
|---|
| 944 |
$headers = array(); |
|---|
| 945 |
|
|---|
| 946 |
$URI_PARTS = parse_url($URI); |
|---|
| 947 |
$url)) |
|---|
| 948 |
$url = "/"; |
|---|
| 949 |
|
|---|
| 950 |
|
|---|
| 951 |
if(!empty($this->agent)) |
|---|
| 952 |
$headers[] = "User-Agent: ".$this->agent; |
|---|
| 953 |
$this->host)) |
|---|
| 954 |
$this->port)) |
|---|
| 955 |
$headers[] = "Host: ".$this->host.":".$this->port; |
|---|
| 956 |
|
|---|
| 957 |
$headers[] = "Host: ".$this->host; |
|---|
| 958 |
$this->accept)) |
|---|
| 959 |
$headers[] = "Accept: ".$this->accept; |
|---|
| 960 |
$this->referer)) |
|---|
| 961 |
$headers[] = "Referer: ".$this->referer; |
|---|
| 962 |
$this->cookies)) |
|---|
| 963 |
|
|---|
| 964 |
is_array($this->cookies)) |
|---|
| 965 |
$this->cookies = (array)$this->cookies; |
|---|
| 966 |
|
|---|
| 967 |
reset($this->cookies); |
|---|
| 968 |
count($this->cookies) > 0 ) { |
|---|
| 969 |
$cookie_str = 'Cookie: '; |
|---|
| 970 |
$this->cookies as $cookieKey => $cookieVal ) { |
|---|
| 971 |
$cookie_str .= $cookieKey."=".urlencode($cookieVal)."; "; |
|---|
| 972 |
|
|---|
| 973 |
$headers[] = substr($cookie_str,0,-2); |
|---|
| 974 |
|
|---|
| 975 |
|
|---|
| 976 |
$this->rawheaders)) |
|---|
| 977 |
|
|---|
| 978 |
is_array($this->rawheaders)) |
|---|
| 979 |
$this->rawheaders = (array)$this->rawheaders; |
|---|
| 980 |
$headerKey,$headerVal) = each($this->rawheaders)) |
|---|
| 981 |
$headers[] = $headerKey.": ".$headerVal; |
|---|
| 982 |
|
|---|
| 983 |
$content_type)) { |
|---|
| 984 |
$content_type == "multipart/form-data") |
|---|
| 985 |
$headers[] = "Content-type: $content_type; boundary=".$this->_mime_boundary; |
|---|
| 986 |
|
|---|
| 987 |
$headers[] = "Content-type: $content_type"; |
|---|
| 988 |
|
|---|
| 989 |
$body)) |
|---|
| 990 |
$headers[] = "Content-length: ".strlen($body); |
|---|
| 991 |
$this->user) || !empty($this->pass)) |
|---|
| 992 |
$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass); |
|---|
| 993 |
|
|---|
| 994 |
$curr_header = 0; $curr_header < count($headers); $curr_header++) { |
|---|
| 995 |
$safer_header = strtr( $headers[$curr_header], "\"", " " ); |
|---|
| 996 |
$cmdline_params .= " -H \"".$safer_header."\""; |
|---|
| 997 |
|
|---|
| 998 |
|
|---|
| 999 |
$body)) |
|---|
| 1000 |
$cmdline_params .= " -d \"$body\""; |
|---|
| 1001 |
|
|---|
| 1002 |
$this->read_timeout > 0) |
|---|
| 1003 |
$cmdline_params .= " -m ".$this->read_timeout; |
|---|
| 1004 |
|
|---|
| 1005 |
$headerfile = tempnam($temp_dir, "sno"); |
|---|
| 1006 |
|
|---|
| 1007 |
exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return); |
|---|
| 1008 |
|
|---|
| 1009 |
$return) |
|---|
| 1010 |
|
|---|
| 1011 |
$this->error = "Error: cURL could not retrieve the document, error $return."; |
|---|
| 1012 |
false; |
|---|
| 1013 |
|
|---|
| 1014 |
|
|---|
| 1015 |
|
|---|
| 1016 |
$results = implode("\r\n",$results); |
|---|
| 1017 |
|
|---|
| 1018 |
$result_headers = file("$headerfile"); |
|---|
| 1019 |
|
|---|
| 1020 |
$this->_redirectaddr = false; |
|---|
| 1021 |
$this->headers); |
|---|
| 1022 |
|
|---|
| 1023 |
$currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++) |
|---|
| 1024 |
|
|---|
| 1025 |
|
|---|
| 1026 |
|
|---|
| 1027 |
if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader])) |
|---|
| 1028 |
|
|---|
| 1029 |
|
|---|
| 1030 |
preg_match("/^(Location: |URI:)\s+(.*)/",chop($result_headers[$currentHeader]),$matches); |
|---|
| 1031 |
|
|---|
| 1032 |
if(!preg_match("|\:\/\/|",$matches[2])) |
|---|
| 1033 |
|
|---|
| 1034 |
|
|---|
| 1035 |
$this->_redirectaddr = $URI_PARTS["scheme"]."://".$this->host.":".$this->port; |
|---|
| 1036 |
|
|---|
| 1037 |
if(!preg_match("|^/|",$matches[2])) |
|---|
| 1038 |
$this->_redirectaddr .= "/".$matches[2]; |
|---|
| 1039 |
|
|---|
| 1040 |
$this->_redirectaddr .= $matches[2]; |
|---|
| 1041 |
|
|---|
| 1042 |
|
|---|
| 1043 |
$this->_redirectaddr = $matches[2]; |
|---|
| 1044 |
|
|---|
| 1045 |
|
|---|
| 1046 |
preg_match("|^HTTP/|",$result_headers[$currentHeader])) |
|---|
| 1047 |
$this->response_code = $result_headers[$currentHeader]; |
|---|
| 1048 |
|
|---|
| 1049 |
$this->headers[] = $result_headers[$currentHeader]; |
|---|
| 1050 |
|
|---|
| 1051 |
|
|---|
| 1052 |
|
|---|
| 1053 |
|
|---|
| 1054 |
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match)) |
|---|
| 1055 |
|
|---|
| 1056 |
$this->_redirectaddr = $this->_expandlinks($match[1],$URI); |
|---|
| 1057 |
|
|---|
| 1058 |
|
|---|
| 1059 |
|
|---|
| 1060 |
if(($this->_framedepth < $this->maxframes) && preg_match_all("'<frame\s+.*src[\s]*=[\'\"]?([^\'\"\>]+)'i",$results,$match)) |
|---|
| 1061 |
|
|---|
| 1062 |
$this->results[] = $results; |
|---|
| 1063 |
$x=0; $x<count($match[1]); $x++) |
|---|
| 1064 |
$this->_frameurls[] = $this->_expandlinks($match[1][$x],$URI_PARTS["scheme"]."://".$this->host); |
|---|
| 1065 |
|
|---|
| 1066 |
|
|---|
| 1067 |
elseif(is_array($this->results)) |
|---|
| 1068 |
$this->results[] = $results; |
|---|
| 1069 |
|
|---|
| 1070 |
else |
|---|
| 1071 |
$this->results = $results; |
|---|
| 1072 |
|
|---|
| 1073 |
unlink("$headerfile"); |
|---|
| 1074 |
|
|---|
| 1075 |
true; |
|---|
| 1076 |
|
|---|
| 1077 |
|
|---|
| 1078 |
|
|---|
| 1079 |
|
|---|
| 1080 |
|
|---|
| 1081 |
|
|---|
| 1082 |
|
|---|
| 1083 |
function setcookies() |
|---|
| 1084 |
|
|---|
| 1085 |
$x=0; $x<count($this->headers); $x++) |
|---|
| 1086 |
|
|---|
| 1087 |
preg_match('/^set-cookie:[\s]+([^=]+)=([^;]+)/i', $this->headers[$x],$match)) |
|---|
| 1088 |
$this->cookies[$match[1]] = urldecode($match[2]); |
|---|
| 1089 |
|
|---|
| 1090 |
|
|---|
| 1091 |
|
|---|
| 1092 |
|
|---|
| 1093 |
|
|---|
| 1094 |
|
|---|
| 1095 |
|
|---|
| 1096 |
|
|---|
| 1097 |
|
|---|
| 1098 |
|
|---|
| 1099 |
function _check_timeout($fp) |
|---|
| 1100 |
|
|---|
| 1101 |
$this->read_timeout > 0) { |
|---|
| 1102 |
$fp_status = socket_get_status($fp); |
|---|
| 1103 |
$fp_status["timed_out"]) { |
|---|
| 1104 |
$this->timed_out = true; |
|---|
| 1105 |
true; |
|---|
| 1106 |
|
|---|
| 1107 |
|
|---|
| 1108 |
false; |
|---|
| 1109 |
|
|---|
| 1110 |
|
|---|
| 1111 |
|
|---|
| 1112 |
|
|---|
| 1113 |
|
|---|
| 1114 |
|
|---|
| 1115 |
|
|---|
| 1116 |
|
|---|
| 1117 |
function _connect(&$fp) |
|---|
| 1118 |
|
|---|
| 1119 |
$this->proxy_host) && !empty($this->proxy_port)) |
|---|
| 1120 |
|
|---|
| 1121 |
$this->_isproxy = true; |
|---|
| 1122 |
|
|---|
| 1123 |
$host = $this->proxy_host; |
|---|
| 1124 |
$port = $this->proxy_port; |
|---|
| 1125 |
|
|---|
| 1126 |
|
|---|
| 1127 |
|
|---|
| 1128 |
$host = $this->host; |
|---|
| 1129 |
$port = $this->port; |
|---|
| 1130 |
|
|---|
| 1131 |
|
|---|
| 1132 |
$this->status = 0; |
|---|
| 1133 |
|
|---|
| 1134 |
$fp = fsockopen( |
|---|
| 1135 |
$host, |
|---|
| 1136 |
$port, |
|---|
| 1137 |
$errno, |
|---|
| 1138 |
$errstr, |
|---|
| 1139 |
$this->_fp_timeout |
|---|
| 1140 |
)) |
|---|
| 1141 |
|
|---|
| 1142 |
|
|---|
| 1143 |
|
|---|
| 1144 |
return true; |
|---|
| 1145 |
|
|---|
| 1146 |
|
|---|
| 1147 |
|
|---|
| 1148 |
|
|---|
| 1149 |
$this->status = $errno; |
|---|
| 1150 |
$errno) |
|---|
| 1151 |
|
|---|
| 1152 |
3: |
|---|
| 1153 |
$this->error="socket creation failed (-3)"; |
|---|
| 1154 |
4: |
|---|
| 1155 |
$this->error="dns lookup failure (-4)"; |
|---|
| 1156 |
5: |
|---|
| 1157 |
$this->error="connection refused or timed out (-5)"; |
|---|
| 1158 |
|
|---|
| 1159 |
$this->error="connection failed (".$errno.")"; |
|---|
| 1160 |
|
|---|
| 1161 |
false; |
|---|
| 1162 |
|
|---|
| 1163 |
|
|---|
| 1164 |
|
|---|
| 1165 |
|
|---|
| 1166 |
|
|---|
| 1167 |
|
|---|
| 1168 |
|
|---|
| 1169 |
|
|---|
| 1170 |
function _disconnect($fp) |
|---|
| 1171 |
|
|---|
| 1172 |
fclose($fp)); |
|---|
| 1173 |
|
|---|
| 1174 |
|
|---|
| 1175 |
|
|---|
| 1176 |
|
|---|
| 1177 |
|
|---|
| 1178 |
|
|---|
| 1179 |
|
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 |
|
|---|
| 1183 |
|
|---|
| 1184 |
function _prepare_post_body($formvars, $formfiles) |
|---|
| 1185 |
|
|---|
| 1186 |
settype($formvars, "array"); |
|---|
| 1187 |
settype($formfiles, "array"); |
|---|
| 1188 |
$postdata = ''; |
|---|
| 1189 |
|
|---|
| 1190 |
count($formvars) == 0 && count($formfiles) == 0) |
|---|
| 1191 |
|
|---|
| 1192 |
|
|---|
| 1193 |
$this->_submit_type) { |
|---|
| 1194 |
"application/x-www-form-urlencoded": |
|---|
| 1195 |
reset($formvars); |
|---|
| 1196 |
$key,$val) = each($formvars)) { |
|---|
| 1197 |
is_array($val) || is_object($val)) { |
|---|
| 1198 |
$cur_key, $cur_val) = each($val)) { |
|---|
| 1199 |
$postdata .= urlencode($key)."[]=".urlencode($cur_val)."&"; |
|---|
| 1200 |
|
|---|
| 1201 |
|
|---|
| 1202 |
$postdata .= urlencode($key)."=".urlencode($val)."&"; |
|---|
| 1203 |
|
|---|
| 1204 |
|
|---|
| 1205 |
|
|---|
| 1206 |
"multipart/form-data": |
|---|
| 1207 |
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime())); |
|---|
| 1208 |
|
|---|
| 1209 |
reset($formvars); |
|---|
| 1210 |
$key,$val) = each($formvars)) { |
|---|
| 1211 |
is_array($val) || is_object($val)) { |
|---|
| 1212 |
$cur_key, $cur_val) = each($val)) { |
|---|
| 1213 |
$postdata .= "--".$this->_mime_boundary."\r\n"; |
|---|
| 1214 |
$postdata .= "Content-Disposition: form-data; name=\"$key\[\]\"\r\n\r\n"; |
|---|
| 1215 |
$postdata .= "$cur_val\r\n"; |
|---|
| 1216 |
|
|---|
| 1217 |
|
|---|
| 1218 |
$postdata .= "--".$this->_mime_boundary."\r\n"; |
|---|
| 1219 |
$postdata .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n"; |
|---|
| 1220 |
$postdata .= "$val\r\n"; |
|---|
| 1221 |
|
|---|
| 1222 |
|
|---|
| 1223 |
|
|---|
| 1224 |
reset($formfiles); |
|---|
| 1225 |
$field_name, $file_names) = each($formfiles)) { |
|---|
| 1226 |
settype($file_names, "array"); |
|---|
| 1227 |
$file_name) = each($file_names)) { |
|---|
| 1228 |
is_readable($file_name)) continue; |
|---|
| 1229 |
|
|---|
| 1230 |
$fp = fopen($file_name, "r"); |
|---|
| 1231 |
$file_content = fread($fp, filesize($file_name)); |
|---|
| 1232 |
fclose($fp); |
|---|
| 1233 |
$base_name = basename($file_name); |
|---|
| 1234 |
|
|---|
| 1235 |
$postdata .= "--".$this->_mime_boundary."\r\n"; |
|---|
| 1236 |
$postdata .= "Content-Disposition: form-data; name=\"$field_name\"; filename=\"$base_name\"\r\n\r\n"; |
|---|
| 1237 |
$postdata .= "$file_content\r\n"; |
|---|
| 1238 |
|
|---|
| 1239 |
|
|---|
| 1240 |
$postdata .= "--".$this->_mime_boundary."--\r\n"; |
|---|
| 1241 |
|
|---|
| 1242 |
|
|---|
| 1243 |
|
|---|
| 1244 |
$postdata; |
|---|
| 1245 |
|
|---|
| 1246 |
|
|---|
| 1247 |
|
|---|
| 1248 |
?> |
|---|
| 1249 |
|
|---|