| 1 |
<?php |
|---|
| 2 |
|
|---|
| 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 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
if ( !in_array('Snoopy', get_declared_classes() ) ) : |
|---|
| 39 |
class Snoopy |
|---|
| 40 |
{ |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
/* user definable vars */ |
|---|
| 44 |
|
|---|
| 45 |
var $host = "www.php.net"; |
|---|
| 46 |
var $port = 80; |
|---|
| 47 |
var $proxy_host = ""; |
|---|
| 48 |
var $proxy_port = ""; |
|---|
| 49 |
var $proxy_user = ""; |
|---|
| 50 |
var $proxy_pass = ""; |
|---|
| 51 |
|
|---|
| 52 |
var $agent = "Snoopy v1.2.3"; |
|---|
| 53 |
var $referer = ""; |
|---|
| 54 |
var $cookies = array(); |
|---|
| 55 |
// $cookies["username"]="joe"; |
|---|
| 56 |
var $rawheaders = array(); |
|---|
| 57 |
// $rawheaders["Content-type"]="text/html"; |
|---|
| 58 |
|
|---|
| 59 |
var $maxredirs = 5; |
|---|
| 60 |
var $lastredirectaddr = ""; |
|---|
| 61 |
var $offsiteok = true; |
|---|
| 62 |
var $maxframes = 0; |
|---|
| 63 |
var $expandlinks = true; |
|---|
| 64 |
// this only applies to fetchlinks() |
|---|
| 65 |
// submitlinks(), and submittext() |
|---|
| 66 |
var $passcookies = true; |
|---|
| 67 |
// NOTE: this currently does not respect |
|---|
| 68 |
// dates, domains or paths. |
|---|
| 69 |
|
|---|
| 70 |
var $user = ""; |
|---|
| 71 |
var $pass = ""; |
|---|
| 72 |
|
|---|
| 73 |
// http accept types |
|---|
| 74 |
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; |
|---|
| 75 |
|
|---|
| 76 |
var $results = ""; |
|---|
| 77 |
|
|---|
| 78 |
var $error = ""; |
|---|
| 79 |
var $response_code = ""; |
|---|
| 80 |
var $headers = array(); |
|---|
| 81 |
var $maxlength = 8192; |
|---|
| 82 |
var $read_timeout = 0; |
|---|
| 83 |
// supported only since PHP 4 Beta 4 |
|---|
| 84 |
// set to 0 to disallow timeouts |
|---|
| 85 |
var $timed_out = false; |
|---|
| 86 |
var $status = 0; |
|---|
| 87 |
|
|---|
| 88 |
var $temp_dir = "/tmp"; |
|---|
| 89 |
// has permission to write to. |
|---|
| 90 |
// under Windows, this should be C:\temp |
|---|
| 91 |
|
|---|
| 92 |
var $curl_path = "/usr/local/bin/curl"; |
|---|
| 93 |
|
|---|
| 94 |
// SSL content if a full system path to |
|---|
| 95 |
// the cURL binary is supplied here. |
|---|
| 96 |
// set to false if you do not have |
|---|
| 97 |
// cURL installed. See http://curl.haxx.se |
|---|
| 98 |
// for details on installing cURL. |
|---|
| 99 |
// Snoopy does *not* use the cURL |
|---|
| 100 |
// library functions built into php, |
|---|
| 101 |
// as these functions are not stable |
|---|
| 102 |
// as of this Snoopy release. |
|---|
| 103 |
|
|---|
| 104 |
/**** Private variables ****/ |
|---|
| 105 |
|
|---|
| 106 |
var $_maxlinelen = 4096; |
|---|
| 107 |
|
|---|
| 108 |
var $_httpmethod = "GET"; |
|---|
| 109 |
var $_httpversion = "HTTP/1.0"; |
|---|
| 110 |
var $_submit_method = "POST"; |
|---|
| 111 |
var $_submit_type = "application/x-www-form-urlencoded"; |
|---|
| 112 |
var $_mime_boundary = ""; |
|---|
| 113 |
var $_redirectaddr = false; |
|---|
| 114 |
var $_redirectdepth = 0; |
|---|
| 115 |
var $_frameurls = array(); |
|---|
| 116 |
var $_framedepth = 0; |
|---|
| 117 |
|
|---|
| 118 |
var $_isproxy = false; |
|---|
| 119 |
var $_fp_timeout = 30; |
|---|
| 120 |
|
|---|
| 121 |
/*======================================================================*\ |
|---|
| 122 |
Function: fetch |
|---|
| 123 |
Purpose: fetch the contents of a web page |
|---|
| 124 |
(and possibly other protocols in the |
|---|
| 125 |
future like ftp, nntp, gopher, etc.) |
|---|
| 126 |
Input: $URI the location of the page to fetch |
|---|
| 127 |
Output: $this->results the output text from the fetch |
|---|
| 128 |
\*======================================================================*/ |
|---|
| 129 |
|
|---|
| 130 |
function fetch($URI) |
|---|
| 131 |
{ |
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
$URI_PARTS = parse_url($URI); |
|---|
| 135 |
if (!empty($URI_PARTS["user"])) |
|---|
| 136 |
$this->user = $URI_PARTS["user"]; |
|---|
| 137 |
if (!empty($URI_PARTS["pass"])) |
|---|
| 138 |
$this->pass = $URI_PARTS["pass"]; |
|---|
| 139 |
if (empty($URI_PARTS["query"])) |
|---|
| 140 |
$URI_PARTS["query"] = ''; |
|---|
| 141 |
if (empty($URI_PARTS["path"])) |
|---|
| 142 |
$URI_PARTS["path"] = ''; |
|---|
| 143 |
|
|---|
| 144 |
switch(strtolower($URI_PARTS["scheme"])) |
|---|
| 145 |
{ |
|---|
| 146 |
case "http": |
|---|
| 147 |
$this->host = $URI_PARTS["host"]; |
|---|
| 148 |
if(!empty($URI_PARTS["port"])) |
|---|
| 149 |
$this->port = $URI_PARTS["port"]; |
|---|
| 150 |
if($this->_connect($fp)) |
|---|
| 151 |
{ |
|---|
| 152 |
if($this->_isproxy) |
|---|
| 153 |
{ |
|---|
| 154 |
|
|---|
| 155 |
$this->_httprequest($URI,$fp,$URI,$this->_httpmethod); |
|---|
| 156 |
} |
|---|
| 157 |
else |
|---|
| 158 |
{ |
|---|
| 159 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 160 |
|
|---|
| 161 |
$this->_httprequest($path, $fp, $URI, $this->_httpmethod); |
|---|
| 162 |
} |
|---|
| 163 |
|
|---|
| 164 |
$this->_disconnect($fp); |
|---|
| 165 |
|
|---|
| 166 |
if($this->_redirectaddr) |
|---|
| 167 |
{ |
|---|
| 168 |
|
|---|
| 169 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 170 |
{ |
|---|
| 171 |
|
|---|
| 172 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 173 |
{ |
|---|
| 174 |
|
|---|
| 175 |
$this->_redirectdepth++; |
|---|
| 176 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 177 |
$this->fetch($this->_redirectaddr); |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
} |
|---|
| 181 |
|
|---|
| 182 |
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 183 |
{ |
|---|
| 184 |
$frameurls = $this->_frameurls; |
|---|
| 185 |
$this->_frameurls = array(); |
|---|
| 186 |
|
|---|
| 187 |
while(list(,$frameurl) = each($frameurls)) |
|---|
| 188 |
{ |
|---|
| 189 |
if($this->_framedepth < $this->maxframes) |
|---|
| 190 |
{ |
|---|
| 191 |
$this->fetch($frameurl); |
|---|
| 192 |
$this->_framedepth++; |
|---|
| 193 |
} |
|---|
| 194 |
else |
|---|
| 195 |
break; |
|---|
| 196 |
} |
|---|
| 197 |
} |
|---|
| 198 |
} |
|---|
| 199 |
else |
|---|
| 200 |
{ |
|---|
| 201 |
return false; |
|---|
| 202 |
} |
|---|
| 203 |
return true; |
|---|
| 204 |
break; |
|---|
| 205 |
case "https": |
|---|
| 206 |
if(!$this->curl_path) |
|---|
| 207 |
return false; |
|---|
| 208 |
if(function_exists("is_executable")) |
|---|
| 209 |
if (!is_executable($this->curl_path)) |
|---|
| 210 |
return false; |
|---|
| 211 |
$this->host = $URI_PARTS["host"]; |
|---|
| 212 |
if(!empty($URI_PARTS["port"])) |
|---|
| 213 |
$this->port = $URI_PARTS["port"]; |
|---|
| 214 |
if($this->_isproxy) |
|---|
| 215 |
{ |
|---|
| 216 |
|
|---|
| 217 |
$this->_httpsrequest($URI,$URI,$this->_httpmethod); |
|---|
| 218 |
} |
|---|
| 219 |
else |
|---|
| 220 |
{ |
|---|
| 221 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 222 |
|
|---|
| 223 |
$this->_httpsrequest($path, $URI, $this->_httpmethod); |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
if($this->_redirectaddr) |
|---|
| 227 |
{ |
|---|
| 228 |
|
|---|
| 229 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 230 |
{ |
|---|
| 231 |
|
|---|
| 232 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 233 |
{ |
|---|
| 234 |
|
|---|
| 235 |
$this->_redirectdepth++; |
|---|
| 236 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 237 |
$this->fetch($this->_redirectaddr); |
|---|
| 238 |
} |
|---|
| 239 |
} |
|---|
| 240 |
} |
|---|
| 241 |
|
|---|
| 242 |
if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 243 |
{ |
|---|
| 244 |
$frameurls = $this->_frameurls; |
|---|
| 245 |
$this->_frameurls = array(); |
|---|
| 246 |
|
|---|
| 247 |
while(list(,$frameurl) = each($frameurls)) |
|---|
| 248 |
{ |
|---|
| 249 |
if($this->_framedepth < $this->maxframes) |
|---|
| 250 |
{ |
|---|
| 251 |
$this->fetch($frameurl); |
|---|
| 252 |
$this->_framedepth++; |
|---|
| 253 |
} |
|---|
| 254 |
else |
|---|
| 255 |
break; |
|---|
| 256 |
} |
|---|
| 257 |
} |
|---|
| 258 |
return true; |
|---|
| 259 |
break; |
|---|
| 260 |
default: |
|---|
| 261 |
|
|---|
| 262 |
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|---|
| 263 |
return false; |
|---|
| 264 |
break; |
|---|
| 265 |
} |
|---|
| 266 |
return true; |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
|
|---|
| 280 |
function submit($URI, $formvars="", $formfiles="") |
|---|
| 281 |
|
|---|
| 282 |
$postdata); |
|---|
| 283 |
|
|---|
| 284 |
$postdata = $this->_prepare_post_body($formvars, $formfiles); |
|---|
| 285 |
|
|---|
| 286 |
$URI_PARTS = parse_url($URI); |
|---|
| 287 |
$URI_PARTS["user"])) |
|---|
| 288 |
$this->user = $URI_PARTS["user"]; |
|---|
| 289 |
$URI_PARTS["pass"])) |
|---|
| 290 |
$this->pass = $URI_PARTS["pass"]; |
|---|
| 291 |
$URI_PARTS["query"])) |
|---|
| 292 |
$URI_PARTS["query"] = ''; |
|---|
| 293 |
$URI_PARTS["path"])) |
|---|
| 294 |
$URI_PARTS["path"] = ''; |
|---|
| 295 |
|
|---|
| 296 |
strtolower($URI_PARTS["scheme"])) |
|---|
| 297 |
|
|---|
| 298 |
"http": |
|---|
| 299 |
$this->host = $URI_PARTS["host"]; |
|---|
| 300 |
$URI_PARTS["port"])) |
|---|
| 301 |
$this->port = $URI_PARTS["port"]; |
|---|
| 302 |
$this->_connect($fp)) |
|---|
| 303 |
|
|---|
| 304 |
$this->_isproxy) |
|---|
| 305 |
|
|---|
| 306 |
|
|---|
| 307 |
$this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); |
|---|
| 308 |
|
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 312 |
|
|---|
| 313 |
$this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|---|
| 314 |
|
|---|
| 315 |
|
|---|
| 316 |
$this->_disconnect($fp); |
|---|
| 317 |
|
|---|
| 318 |
$this->_redirectaddr) |
|---|
| 319 |
|
|---|
| 320 |
|
|---|
| 321 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 322 |
|
|---|
| 323 |
preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|---|
| 324 |
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|---|
| 325 |
|
|---|
| 326 |
|
|---|
| 327 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
$this->_redirectdepth++; |
|---|
| 331 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 332 |
strpos( $this->_redirectaddr, "?" ) > 0 ) |
|---|
| 333 |
$this->fetch($this->_redirectaddr); |
|---|
| 334 |
else |
|---|
| 335 |
$this->submit($this->_redirectaddr,$formvars, $formfiles); |
|---|
| 336 |
|
|---|
| 337 |
|
|---|
| 338 |
|
|---|
| 339 |
|
|---|
| 340 |
$this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 341 |
|
|---|
| 342 |
$frameurls = $this->_frameurls; |
|---|
| 343 |
$this->_frameurls = array(); |
|---|
| 344 |
|
|---|
| 345 |
$frameurl) = each($frameurls)) |
|---|
| 346 |
|
|---|
| 347 |
$this->_framedepth < $this->maxframes) |
|---|
| 348 |
|
|---|
| 349 |
$this->fetch($frameurl); |
|---|
| 350 |
$this->_framedepth++; |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
|
|---|
| 355 |
|
|---|
| 356 |
|
|---|
| 357 |
|
|---|
| 358 |
|
|---|
| 359 |
|
|---|
| 360 |
false; |
|---|
| 361 |
|
|---|
| 362 |
true; |
|---|
| 363 |
|
|---|
| 364 |
"https": |
|---|
| 365 |
$this->curl_path) |
|---|
| 366 |
false; |
|---|
| 367 |
function_exists("is_executable")) |
|---|
| 368 |
is_executable($this->curl_path)) |
|---|
| 369 |
false; |
|---|
| 370 |
$this->host = $URI_PARTS["host"]; |
|---|
| 371 |
$URI_PARTS["port"])) |
|---|
| 372 |
$this->port = $URI_PARTS["port"]; |
|---|
| 373 |
$this->_isproxy) |
|---|
| 374 |
|
|---|
| 375 |
|
|---|
| 376 |
$this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|---|
| 377 |
|
|---|
| 378 |
|
|---|
| 379 |
|
|---|
| 380 |
$path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); |
|---|
| 381 |
|
|---|
| 382 |
$this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata); |
|---|
| 383 |
|
|---|
| 384 |
|
|---|
| 385 |
$this->_redirectaddr) |
|---|
| 386 |
|
|---|
| 387 |
|
|---|
| 388 |
if($this->maxredirs > $this->_redirectdepth) |
|---|
| 389 |
|
|---|
| 390 |
preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) |
|---|
| 391 |
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); |
|---|
| 392 |
|
|---|
| 393 |
|
|---|
| 394 |
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) |
|---|
| 395 |
|
|---|
| 396 |
|
|---|
| 397 |
$this->_redirectdepth++; |
|---|
| 398 |
$this->lastredirectaddr=$this->_redirectaddr; |
|---|
| 399 |
strpos( $this->_redirectaddr, "?" ) > 0 ) |
|---|
| 400 |
$this->fetch($this->_redirectaddr); |
|---|
| 401 |
else |
|---|
| 402 |
$this->submit($this->_redirectaddr,$formvars, $formfiles); |
|---|
| 403 |
|
|---|
| 404 |
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 |
$this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) |
|---|
| 408 |
|
|---|
| 409 |
$frameurls = $this->_frameurls; |
|---|
| 410 |
$this->_frameurls = array(); |
|---|
| 411 |
|
|---|
| 412 |
$frameurl) = each($frameurls)) |
|---|
| 413 |
|
|---|
| 414 |
$this->_framedepth < $this->maxframes) |
|---|
| 415 |
|
|---|
| 416 |
$this->fetch($frameurl); |
|---|
| 417 |
$this->_framedepth++; |
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 |
|
|---|
| 421 |
|
|---|
| 422 |
|
|---|
| 423 |
true; |
|---|
| 424 |
|
|---|
| 425 |
|
|---|
| 426 |
|
|---|
| 427 |
|
|---|
| 428 |
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; |
|---|
| 429 |
false |
|---|