| [ PHPXref.com ] | [ Generated: Sun Jul 20 18:53:27 2008 ] | [ myPHPNuke 1.8.8_8 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 3 @( (bool)FALSE === strpos( $_SERVER['REQUEST_URI'], basename( __FILE__ ) ) ) OR exit( '!! ACCESS DENIED !!' ); 4 error_reporting( _E_VALUE ); 5 6 /* vim: set expandtab tabstop=4 shiftwidth=4: */ 7 // +----------------------------------------------------------------------+ 8 // | myPHPNuke Version 188_8 RC2 | 9 // +----------------------------------------------------------------------+ 10 // | License: GNU/GPL - http://www.gnu.org/copyleft/gpl.html | 11 // +----------------------------------------------------------------------+ 12 // | Support: http://myphpnuke.com/ | 13 // +----------------------------------------------------------------------+ 14 // | Author: myPHPNuke Dev Team | 15 // +----------------------------------------------------------------------+ 16 // | Copyright: © 2001-2004 myPHPNuke Dev Team | 17 // +----------------------------------------------------------------------+ 18 // $Id: core_Snoopy.class.php,v 1.5.2.4 2004/08/15 12:58:24 kirilt Exp $ 19 /************************************************* 20 21 Snoopy - the PHP net client 22 Author: Monte Ohrt <monte@ispi.net> 23 Copyright (c): 1999-2000 ispi, all rights reserved 24 Version: 1.01a ( Modified for Nested Page Project ) 25 26 * This library is free software; you can redistribute it and/or 27 * modify it under the terms of the GNU Lesser General Public 28 * License as published by the Free Software Foundation; either 29 * version 2.1 of the License, or (at your option) any later version. 30 * 31 * This library is distributed in the hope that it will be useful, 32 * but WITHOUT ANY WARRANTY; without even the implied warranty of 33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 34 * Lesser General Public License for more details. 35 * 36 * You should have received a copy of the GNU Lesser General Public 37 * License along with this library; if not, write to the Free Software 38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 39 40 You may contact the author of Snoopy by e-mail at: 41 monte@ispi.net 42 43 Or, write to: 44 Monte Ohrt 45 CTO, ispi 46 237 S. 70th suite 220 47 Lincoln, NE 68510 48 49 The latest version of Snoopy can be obtained from: 50 http://snoopy.sourceforge.com 51 52 *************************************************/ 53 54 class Snoopy 55 { 56 /**** Public variables ****/ 57 58 /* user definable vars */ 59 60 var $host = "www.php.net"; // host name we are connecting to 61 var $port = 80; // port we are connecting to 62 var $proxy_host = ""; // proxy host to use 63 var $proxy_port = ""; // proxy port to use 64 var $agent = "Snoopy v1.01"; // agent we masquerade as 65 var $referer = ""; // referer info to pass 66 var $cookies = array(); // array of cookies to pass 67 // $cookies["username"]="joe"; 68 var $rawheaders = array(); // array of raw headers to send 69 // $rawheaders["Content-type"]="text/html"; 70 71 var $maxredirs = 5; // http redirection depth maximum. 0 = disallow 72 var $lastredirectaddr = ""; // contains address of last redirected address 73 var $offsiteok = true; // allows redirection off-site 74 var $maxframes = 0; // frame content depth maximum. 0 = disallow 75 var $expandlinks = true; // expand links to fully qualified URLs. 76 // this only applies to fetchlinks() 77 // or submitlinks() 78 var $passcookies = true; // pass set cookies back through redirects 79 // NOTE: this currently does not respect 80 // dates, domains or paths. 81 82 var $user = ""; // user for http authentication 83 var $pass = ""; // password for http authentication 84 85 // http accept types 86 var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*"; 87 88 var $results = ""; // where the content is put 89 var $result_body = NULL; // stores body content in helpers and allows for 90 // body content processing without multiple 91 // queries to remote site 92 93 var $error = ""; // error messages sent here 94 var $response_code = ""; // response code returned from server 95 var $headers = array(); // headers returned from server sent here 96 var $maxlength = 500000; // max return data length (body) 97 var $read_timeout = 0; // timeout on read operations, in seconds 98 // supported only since PHP 4 Beta 4 99 // set to 0 to disallow timeouts 100 var $timed_out = false; // if a read operation timed out 101 var $status = 0; // http request status 102 103 var $curl_path = "/usr/local/bin/curl"; 104 // Snoopy will use cURL for fetching 105 // SSL content if a full system path to 106 // the cURL binary is supplied here. 107 // set to false if you do not have 108 // cURL installed. See http://curl.haxx.se 109 // for details on installing cURL. 110 // Snoopy does *not* use the cURL 111 // library functions built into php, 112 // as these functions are not stable 113 // as of this Snoopy release. 114 115 /**** Private variables ****/ 116 117 var $_maxlinelen = 4096; // max line length (headers) 118 119 var $_httpmethod = "GET"; // default http request method 120 var $_httpversion = "HTTP/1.0"; // default http request version 121 var $_submit_method = "POST"; // default submit method 122 var $_submit_type = "application/x-www-form-urlencoded"; // default submit type 123 var $_mime_boundary = ""; // MIME boundary for multipart/form-data submit type 124 var $_redirectaddr = false; // will be set if page fetched is a redirect 125 var $_redirectdepth = 0; // increments on an http redirect 126 var $_frameurls = array(); // frame src urls 127 var $_framedepth = 0; // increments on frame depth 128 129 var $_isproxy = false; // set if using a proxy server 130 var $_fp_timeout = 15; // timeout for socket connection 131 132 /*======================================================================*\ 133 Function: fetch 134 Purpose: fetch the contents of a web page 135 (and possibly other protocols in the 136 future like ftp, nntp, gopher, etc.) 137 Input: $URI the location of the page to fetch 138 $reset resets the result_body variable and fetchs a new copy 139 Output: $this->results the output text from the fetch 140 \*======================================================================*/ 141 142 function fetch( $URI, $reset = FALSE ) 143 { 144 //preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS); 145 146 if ( $reset ) { $this -> result_body = NULL; } 147 148 if ( ! empty( $this -> result_body ) && $this -> result_body != '' ) 149 { 150 $this -> results = $this -> result_body; 151 return (bool)TRUE; 152 } 153 154 $URI_PARTS = @parse_url($URI); 155 156 if ( (bool)FALSE === $URI_PARTS ) 157 { 158 return (bool)FALSE; 159 } 160 161 if (!empty($URI_PARTS["user"])) 162 $this->user = $URI_PARTS["user"]; 163 if (!empty($URI_PARTS["pass"])) 164 $this->pass = $URI_PARTS["pass"]; 165 if ( !empty($URI_PARTS["path"]) && 0 === strpos( $URI_PARTS["path"], '//' ) ) 166 { 167 $URI_PARTS["path"] = substr( $URI_PARTS["path"], 1 ); 168 } 169 170 switch($URI_PARTS["scheme"]) 171 { 172 case "http": 173 $this->host = $URI_PARTS["host"]; 174 if(!empty($URI_PARTS["port"])) 175 $this->port = $URI_PARTS["port"]; 176 177 if($this->_connect($fp)) 178 { 179 if($this->_isproxy) 180 { 181 // using proxy, send entire URI 182 $this->_httprequest($URI,$fp,$URI,$this->_httpmethod); 183 } 184 else 185 { 186 $path = ( isset( $URI_PARTS['path'] ) ? $URI_PARTS['path'] : '/') . ( isset( $URI_PARTS["query"] ) ? "?".$URI_PARTS["query"] : ""); 187 188 // no proxy, send only the path 189 190 $this->_httprequest($path, $fp, $URI, $this->_httpmethod); 191 } 192 193 $this->_disconnect($fp); 194 195 if($this->_redirectaddr) 196 { 197 /* url was redirected, check if we've hit the max depth */ 198 if($this->maxredirs > $this->_redirectdepth) 199 { 200 // only follow redirect if it's on this site, or offsiteok is true 201 if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) 202 { 203 /* follow the redirect */ 204 $this->_redirectdepth++; 205 $this->lastredirectaddr=$this->_redirectaddr; 206 $this->fetch($this->_redirectaddr); 207 } 208 } 209 } 210 211 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) 212 { 213 $frameurls = $this->_frameurls; 214 $this->_frameurls = array(); 215 216 while(list(,$frameurl) = each($frameurls)) 217 { 218 if($this->_framedepth< $this->maxframes) 219 { 220 $this->fetch($frameurl); 221 $this->_framedepth++; 222 } 223 else 224 break; 225 } 226 } 227 } 228 else 229 { 230 return false; 231 } 232 return true; 233 break; 234 case "https": 235 if(!$this->curl_path || (!is_executable($this->curl_path))) 236 return false; 237 $this->host = $URI_PARTS["host"]; 238 if(!empty($URI_PARTS["port"])) 239 $this->port = $URI_PARTS["port"]; 240 if($this->_isproxy) 241 { 242 // using proxy, send entire URI 243 $this->_httpsrequest($URI,$URI,$this->_httpmethod); 244 } 245 else 246 { 247 $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); 248 // no proxy, send only the path 249 $this->_httpsrequest($path, $URI, $this->_httpmethod); 250 } 251 252 if($this->_redirectaddr) 253 { 254 /* url was redirected, check if we've hit the max depth */ 255 if($this->maxredirs > $this->_redirectdepth) 256 { 257 // only follow redirect if it's on this site, or offsiteok is true 258 if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) 259 { 260 /* follow the redirect */ 261 $this->_redirectdepth++; 262 $this->lastredirectaddr=$this->_redirectaddr; 263 $this->fetch($this->_redirectaddr); 264 } 265 } 266 } 267 268 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) 269 { 270 $frameurls = $this->_frameurls; 271 $this->_frameurls = array(); 272 273 while(list(,$frameurl) = each($frameurls)) 274 { 275 if($this->_framedepth < $this->maxframes) 276 { 277 $this->fetch($frameurl); 278 $this->_framedepth++; 279 } 280 else 281 break; 282 } 283 } 284 return true; 285 break; 286 default: 287 // not a valid protocol 288 $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; 289 return false; 290 break; 291 } 292 return true; 293 } 294 295 /*======================================================================*\ 296 Function: submit 297 Purpose: submit an http form 298 Input: $URI the location to post the data 299 $formvars the formvars to use. 300 format: $formvars["var"] = "val"; 301 Output: $this->results the text output from the post 302 \*======================================================================*/ 303 304 function submit($URI, $formvars="", $formfiles="", $reset = TRUE ) 305 { 306 unset($postdata); 307 308 if ( $reset ) { $this -> result_body = NULL; } 309 310 $URI_PARTS = @parse_url($URI); 311 312 if ( (bool)FALSE === $URI_PARTS ) 313 { 314 return (bool)FALSE; 315 } 316 317 $postdata = $this->_prepare_post_body($formvars, $formfiles); 318 319 $URI_PARTS = parse_url($URI); 320 321 if (!empty($URI_PARTS["user"])) 322 $this->user = $URI_PARTS["user"]; 323 if (!empty($URI_PARTS["pass"])) 324 $this->pass = $URI_PARTS["pass"]; 325 326 switch($URI_PARTS["scheme"]) 327 { 328 case "http": 329 $this->host = $URI_PARTS["host"]; 330 if(!empty($URI_PARTS["port"])) 331 $this->port = $URI_PARTS["port"]; 332 if($this->_connect($fp)) 333 { 334 if($this->_isproxy) 335 { 336 // using proxy, send entire URI 337 $this->_httprequest($URI,$fp,$URI,$this->_submit_method,$this->_submit_type,$postdata); 338 } 339 else 340 { 341 $path = $URI_PARTS["path"].(!empty( $URI_PARTS["query"] ) ? "?".$URI_PARTS["query"] : ""); 342 // no proxy, send only the path 343 $this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata); 344 } 345 346 $this->_disconnect($fp); 347 348 if($this->_redirectaddr) 349 { 350 /* url was redirected, check if we've hit the max depth */ 351 if($this->maxredirs > $this->_redirectdepth) 352 { 353 if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) 354 $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); 355 356 // only follow redirect if it's on this site, or offsiteok is true 357 if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) 358 { 359 /* follow the redirect */ 360 $this->_redirectdepth++; 361 $this->lastredirectaddr=$this->_redirectaddr; 362 $this->submit($this->_redirectaddr,$formvars, $formfiles); 363 } 364 } 365 } 366 367 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) 368 { 369 $frameurls = $this->_frameurls; 370 $this->_frameurls = array(); 371 372 while(list(,$frameurl) = each($frameurls)) 373 { 374 if($this->_framedepth < $this->maxframes) 375 { 376 $this->fetch($frameurl); 377 $this->_framedepth++; 378 } 379 else 380 break; 381 } 382 } 383 } 384 else 385 { 386 return false; 387 } 388 return true; 389 break; 390 case "https": 391 if(!$this->curl_path || (!is_executable($this->curl_path))) 392 return false; 393 $this->host = $URI_PARTS["host"]; 394 if(!empty($URI_PARTS["port"])) 395 $this->port = $URI_PARTS["port"]; 396 if($this->_isproxy) 397 { 398 // using proxy, send entire URI 399 $this->_httpsrequest($URI, $URI, $this->_submit_method, $this->_submit_type, $postdata); 400 } 401 else 402 { 403 $path = $URI_PARTS["path"].($URI_PARTS["query"] ? "?".$URI_PARTS["query"] : ""); 404 // no proxy, send only the path 405 $this->_httpsrequest($path, $URI, $this->_submit_method, $this->_submit_type, $postdata); 406 } 407 408 if($this->_redirectaddr) 409 { 410 /* url was redirected, check if we've hit the max depth */ 411 if($this->maxredirs > $this->_redirectdepth) 412 { 413 if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr)) 414 $this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]); 415 416 // only follow redirect if it's on this site, or offsiteok is true 417 if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok) 418 { 419 /* follow the redirect */ 420 $this->_redirectdepth++; 421 $this->lastredirectaddr=$this->_redirectaddr; 422 $this->submit($this->_redirectaddr,$formvars, $formfiles); 423 } 424 } 425 } 426 427 if($this->_framedepth < $this->maxframes && count($this->_frameurls) > 0) 428 { 429 $frameurls = $this->_frameurls; 430 $this->_frameurls = array(); 431 432 while(list(,$frameurl) = each($frameurls)) 433 { 434 if($this->_framedepth < $this->maxframes) 435 { 436 $this->fetch($frameurl); 437 $this->_framedepth++; 438 } 439 else 440 break; 441 } 442 } 443 return true; 444 break; 445 446 default: 447 // not a valid protocol 448 $this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n'; 449 return false; 450 break; 451 } 452 return true; 453 } 454 455 /*======================================================================*\ 456 Function: fetchlinks 457 Purpose: fetch the links from a web page 458 Input: $URI where you are fetching from 459 Output: $this->results an array of the URLs 460 \*======================================================================*/ 461 462 function fetchlinks($URI) 463 { 464 if ($this->fetch($URI)) 465 { 466 $this -> result_body = $this -> results; 467 468 if(is_array($this->results)) 469 { 470 for($x=0;$x<count($this->results);$x++) 471 $this->results[$x] = $this->_striplinks($this->results[$x]); 472 } 473 else 474 $this->results = $this->_striplinks($this->results); 475 476 if($this->expandlinks) 477 $this->results = $this->_expandlinks($this->results, $URI); 478 return true; 479 } 480 else 481 return false; 482 } 483 484 /*======================================================================*\ 485 Function: fetchform 486 Purpose: fetch the form elements from a web page 487 Input: $URI where you are fetching from 488 Output: $this->results the resulting html form 489 \*======================================================================*/ 490 491 function fetchform($URI) 492 { 493 494 if ($this->fetch($URI)) 495 { 496 $this -> result_body = $this -> results; 497 498 if(is_array($this->results)) 499 { 500 for($x=0;$x<count($this->results);$x++) 501 $this->