mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-27 14:53:08 +02:00
Add conditional load back to snoopy and strip trailing whites
git-svn-id: http://svn.automattic.com/wordpress/trunk@9307 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
076763cfff
commit
b7ca9bd521
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
if ( !in_array('Snoopy', get_declared_classes() ) ) :
|
||||||
/*************************************************
|
/*************************************************
|
||||||
|
|
||||||
Snoopy - the PHP net client
|
Snoopy - the PHP net client
|
||||||
@ -32,7 +32,7 @@ http://snoopy.sourceforge.net/
|
|||||||
class Snoopy
|
class Snoopy
|
||||||
{
|
{
|
||||||
/**** Public variables ****/
|
/**** Public variables ****/
|
||||||
|
|
||||||
/* user definable vars */
|
/* user definable vars */
|
||||||
|
|
||||||
var $host = "www.php.net"; // host name we are connecting to
|
var $host = "www.php.net"; // host name we are connecting to
|
||||||
@ -41,7 +41,7 @@ class Snoopy
|
|||||||
var $proxy_port = ""; // proxy port to use
|
var $proxy_port = ""; // proxy port to use
|
||||||
var $proxy_user = ""; // proxy user to use
|
var $proxy_user = ""; // proxy user to use
|
||||||
var $proxy_pass = ""; // proxy password to use
|
var $proxy_pass = ""; // proxy password to use
|
||||||
|
|
||||||
var $agent = "Snoopy v1.2.4"; // agent we masquerade as
|
var $agent = "Snoopy v1.2.4"; // agent we masquerade as
|
||||||
var $referer = ""; // referer info to pass
|
var $referer = ""; // referer info to pass
|
||||||
var $cookies = array(); // array of cookies to pass
|
var $cookies = array(); // array of cookies to pass
|
||||||
@ -59,15 +59,15 @@ class Snoopy
|
|||||||
var $passcookies = true; // pass set cookies back through redirects
|
var $passcookies = true; // pass set cookies back through redirects
|
||||||
// NOTE: this currently does not respect
|
// NOTE: this currently does not respect
|
||||||
// dates, domains or paths.
|
// dates, domains or paths.
|
||||||
|
|
||||||
var $user = ""; // user for http authentication
|
var $user = ""; // user for http authentication
|
||||||
var $pass = ""; // password for http authentication
|
var $pass = ""; // password for http authentication
|
||||||
|
|
||||||
// http accept types
|
// http accept types
|
||||||
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
|
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
|
||||||
|
|
||||||
var $results = ""; // where the content is put
|
var $results = ""; // where the content is put
|
||||||
|
|
||||||
var $error = ""; // error messages sent here
|
var $error = ""; // error messages sent here
|
||||||
var $response_code = ""; // response code returned from server
|
var $response_code = ""; // response code returned from server
|
||||||
var $headers = array(); // headers returned from server sent here
|
var $headers = array(); // headers returned from server sent here
|
||||||
@ -93,11 +93,11 @@ class Snoopy
|
|||||||
// library functions built into php,
|
// library functions built into php,
|
||||||
// as these functions are not stable
|
// as these functions are not stable
|
||||||
// as of this Snoopy release.
|
// as of this Snoopy release.
|
||||||
|
|
||||||
/**** Private variables ****/
|
/**** Private variables ****/
|
||||||
|
|
||||||
var $_maxlinelen = 4096; // max line length (headers)
|
var $_maxlinelen = 4096; // max line length (headers)
|
||||||
|
|
||||||
var $_httpmethod = "GET"; // default http request method
|
var $_httpmethod = "GET"; // default http request method
|
||||||
var $_httpversion = "HTTP/1.0"; // default http request version
|
var $_httpversion = "HTTP/1.0"; // default http request version
|
||||||
var $_submit_method = "POST"; // default submit method
|
var $_submit_method = "POST"; // default submit method
|
||||||
@ -107,7 +107,7 @@ class Snoopy
|
|||||||
var $_redirectdepth = 0; // increments on an http redirect
|
var $_redirectdepth = 0; // increments on an http redirect
|
||||||
var $_frameurls = array(); // frame src urls
|
var $_frameurls = array(); // frame src urls
|
||||||
var $_framedepth = 0; // increments on frame depth
|
var $_framedepth = 0; // increments on frame depth
|
||||||
|
|
||||||
var $_isproxy = false; // set if using a proxy server
|
var $_isproxy = false; // set if using a proxy server
|
||||||
var $_fp_timeout = 30; // timeout for socket connection
|
var $_fp_timeout = 30; // timeout for socket connection
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ class Snoopy
|
|||||||
|
|
||||||
function fetch($URI)
|
function fetch($URI)
|
||||||
{
|
{
|
||||||
|
|
||||||
//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
|
//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
|
||||||
$URI_PARTS = parse_url($URI);
|
$URI_PARTS = parse_url($URI);
|
||||||
if (!empty($URI_PARTS["user"]))
|
if (!empty($URI_PARTS["user"]))
|
||||||
@ -133,7 +133,7 @@ class Snoopy
|
|||||||
$URI_PARTS["query"] = '';
|
$URI_PARTS["query"] = '';
|
||||||
if (empty($URI_PARTS["path"]))
|
if (empty($URI_PARTS["path"]))
|
||||||
$URI_PARTS["path"] = '';
|
$URI_PARTS["path"] = '';
|
||||||
|
|
||||||
switch(strtolower($URI_PARTS["scheme"]))
|
switch(strtolower($URI_PARTS["scheme"]))
|
||||||
{
|
{
|
||||||
case "http":
|
case "http":
|
||||||
@ -153,7 +153,7 @@ class Snoopy
|
|||||||
// no proxy, send only the path
|
// no proxy, send only the path
|
||||||
$this->_httprequest($path, $fp, $URI, $this->_httpmethod);
|
$this->_httprequest($path, $fp, $URI, $this->_httpmethod);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_disconnect($fp);
|
$this->_disconnect($fp);
|
||||||
|
|
||||||
if($this->_redirectaddr)
|
if($this->_redirectaddr)
|
||||||
@ -176,7 +176,7 @@ class Snoopy
|
|||||||
{
|
{
|
||||||
$frameurls = $this->_frameurls;
|
$frameurls = $this->_frameurls;
|
||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
while(list(,$frameurl) = each($frameurls))
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
@ -187,13 +187,13 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case "https":
|
case "https":
|
||||||
if(!$this->curl_path)
|
if(!$this->curl_path)
|
||||||
@ -247,15 +247,15 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// not a valid protocol
|
// not a valid protocol
|
||||||
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
|
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,9 +273,9 @@ class Snoopy
|
|||||||
function submit($URI, $formvars="", $formfiles="")
|
function submit($URI, $formvars="", $formfiles="")
|
||||||
{
|
{
|
||||||
unset($postdata);
|
unset($postdata);
|
||||||
|
|
||||||
$postdata = $this->_prepare_post_body($formvars, $formfiles);
|
$postdata = $this->_prepare_post_body($formvars, $formfiles);
|
||||||
|
|
||||||
$URI_PARTS = parse_url($URI);
|
$URI_PARTS = parse_url($URI);
|
||||||
if (!empty($URI_PARTS["user"]))
|
if (!empty($URI_PARTS["user"]))
|
||||||
$this->user = $URI_PARTS["user"];
|
$this->user = $URI_PARTS["user"];
|
||||||
@ -305,17 +305,17 @@ class Snoopy
|
|||||||
// no proxy, send only the path
|
// no proxy, send only the path
|
||||||
$this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
|
$this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->_disconnect($fp);
|
$this->_disconnect($fp);
|
||||||
|
|
||||||
if($this->_redirectaddr)
|
if($this->_redirectaddr)
|
||||||
{
|
{
|
||||||
/* url was redirected, check if we've hit the max depth */
|
/* url was redirected, check if we've hit the max depth */
|
||||||
if($this->maxredirs > $this->_redirectdepth)
|
if($this->maxredirs > $this->_redirectdepth)
|
||||||
{
|
{
|
||||||
if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
|
if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
|
||||||
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
|
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
|
||||||
|
|
||||||
// only follow redirect if it's on this site, or offsiteok is true
|
// only follow redirect if it's on this site, or offsiteok is true
|
||||||
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
|
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
|
||||||
{
|
{
|
||||||
@ -334,9 +334,9 @@ class Snoopy
|
|||||||
{
|
{
|
||||||
$frameurls = $this->_frameurls;
|
$frameurls = $this->_frameurls;
|
||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
while(list(,$frameurl) = each($frameurls))
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
{
|
{
|
||||||
$this->fetch($frameurl);
|
$this->fetch($frameurl);
|
||||||
@ -345,14 +345,14 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
case "https":
|
case "https":
|
||||||
if(!$this->curl_path)
|
if(!$this->curl_path)
|
||||||
@ -379,9 +379,9 @@ class Snoopy
|
|||||||
{
|
{
|
||||||
/* url was redirected, check if we've hit the max depth */
|
/* url was redirected, check if we've hit the max depth */
|
||||||
if($this->maxredirs > $this->_redirectdepth)
|
if($this->maxredirs > $this->_redirectdepth)
|
||||||
{
|
{
|
||||||
if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
|
if(!preg_match("|^".$URI_PARTS["scheme"]."://|", $this->_redirectaddr))
|
||||||
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
|
$this->_redirectaddr = $this->_expandlinks($this->_redirectaddr,$URI_PARTS["scheme"]."://".$URI_PARTS["host"]);
|
||||||
|
|
||||||
// only follow redirect if it's on this site, or offsiteok is true
|
// only follow redirect if it's on this site, or offsiteok is true
|
||||||
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
|
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
|
||||||
@ -403,7 +403,7 @@ class Snoopy
|
|||||||
$this->_frameurls = array();
|
$this->_frameurls = array();
|
||||||
|
|
||||||
while(list(,$frameurl) = each($frameurls))
|
while(list(,$frameurl) = each($frameurls))
|
||||||
{
|
{
|
||||||
if($this->_framedepth < $this->maxframes)
|
if($this->_framedepth < $this->maxframes)
|
||||||
{
|
{
|
||||||
$this->fetch($frameurl);
|
$this->fetch($frameurl);
|
||||||
@ -412,16 +412,16 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// not a valid protocol
|
// not a valid protocol
|
||||||
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
|
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
|
||||||
return false;
|
return false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -435,7 +435,7 @@ class Snoopy
|
|||||||
function fetchlinks($URI)
|
function fetchlinks($URI)
|
||||||
{
|
{
|
||||||
if ($this->fetch($URI))
|
if ($this->fetch($URI))
|
||||||
{
|
{
|
||||||
if($this->lastredirectaddr)
|
if($this->lastredirectaddr)
|
||||||
$URI = $this->lastredirectaddr;
|
$URI = $this->lastredirectaddr;
|
||||||
if(is_array($this->results))
|
if(is_array($this->results))
|
||||||
@ -463,9 +463,9 @@ class Snoopy
|
|||||||
|
|
||||||
function fetchform($URI)
|
function fetchform($URI)
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->fetch($URI))
|
if ($this->fetch($URI))
|
||||||
{
|
{
|
||||||
|
|
||||||
if(is_array($this->results))
|
if(is_array($this->results))
|
||||||
{
|
{
|
||||||
@ -474,14 +474,14 @@ class Snoopy
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->results = $this->_stripform($this->results);
|
$this->results = $this->_stripform($this->results);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: fetchtext
|
Function: fetchtext
|
||||||
Purpose: fetch the text from a web page, stripping the links
|
Purpose: fetch the text from a web page, stripping the links
|
||||||
@ -492,7 +492,7 @@ class Snoopy
|
|||||||
function fetchtext($URI)
|
function fetchtext($URI)
|
||||||
{
|
{
|
||||||
if($this->fetch($URI))
|
if($this->fetch($URI))
|
||||||
{
|
{
|
||||||
if(is_array($this->results))
|
if(is_array($this->results))
|
||||||
{
|
{
|
||||||
for($x=0;$x<count($this->results);$x++)
|
for($x=0;$x<count($this->results);$x++)
|
||||||
@ -516,7 +516,7 @@ class Snoopy
|
|||||||
function submitlinks($URI, $formvars="", $formfiles="")
|
function submitlinks($URI, $formvars="", $formfiles="")
|
||||||
{
|
{
|
||||||
if($this->submit($URI,$formvars, $formfiles))
|
if($this->submit($URI,$formvars, $formfiles))
|
||||||
{
|
{
|
||||||
if($this->lastredirectaddr)
|
if($this->lastredirectaddr)
|
||||||
$URI = $this->lastredirectaddr;
|
$URI = $this->lastredirectaddr;
|
||||||
if(is_array($this->results))
|
if(is_array($this->results))
|
||||||
@ -550,7 +550,7 @@ class Snoopy
|
|||||||
function submittext($URI, $formvars = "", $formfiles = "")
|
function submittext($URI, $formvars = "", $formfiles = "")
|
||||||
{
|
{
|
||||||
if($this->submit($URI,$formvars, $formfiles))
|
if($this->submit($URI,$formvars, $formfiles))
|
||||||
{
|
{
|
||||||
if($this->lastredirectaddr)
|
if($this->lastredirectaddr)
|
||||||
$URI = $this->lastredirectaddr;
|
$URI = $this->lastredirectaddr;
|
||||||
if(is_array($this->results))
|
if(is_array($this->results))
|
||||||
@ -574,7 +574,7 @@ class Snoopy
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: set_submit_multipart
|
Function: set_submit_multipart
|
||||||
@ -586,7 +586,7 @@ class Snoopy
|
|||||||
$this->_submit_type = "multipart/form-data";
|
$this->_submit_type = "multipart/form-data";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: set_submit_normal
|
Function: set_submit_normal
|
||||||
Purpose: Set the form submission content type to
|
Purpose: Set the form submission content type to
|
||||||
@ -597,14 +597,14 @@ class Snoopy
|
|||||||
$this->_submit_type = "application/x-www-form-urlencoded";
|
$this->_submit_type = "application/x-www-form-urlencoded";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Private functions
|
Private functions
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _striplinks
|
Function: _striplinks
|
||||||
Purpose: strip the hyperlinks from an html document
|
Purpose: strip the hyperlinks from an html document
|
||||||
@ -613,13 +613,13 @@ class Snoopy
|
|||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _striplinks($document)
|
function _striplinks($document)
|
||||||
{
|
{
|
||||||
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href=
|
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href=
|
||||||
([\"\'])? # find single or double quote
|
([\"\'])? # find single or double quote
|
||||||
(?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching
|
(?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching
|
||||||
# quote, otherwise match up to next space
|
# quote, otherwise match up to next space
|
||||||
'isx",$document,$links);
|
'isx",$document,$links);
|
||||||
|
|
||||||
|
|
||||||
// catenate the non-empty matches from the conditional subpattern
|
// catenate the non-empty matches from the conditional subpattern
|
||||||
|
|
||||||
@ -627,14 +627,14 @@ class Snoopy
|
|||||||
{
|
{
|
||||||
if(!empty($val))
|
if(!empty($val))
|
||||||
$match[] = $val;
|
$match[] = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(list($key,$val) = each($links[3]))
|
while(list($key,$val) = each($links[3]))
|
||||||
{
|
{
|
||||||
if(!empty($val))
|
if(!empty($val))
|
||||||
$match[] = $val;
|
$match[] = $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the links
|
// return the links
|
||||||
return $match;
|
return $match;
|
||||||
}
|
}
|
||||||
@ -647,18 +647,18 @@ class Snoopy
|
|||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _stripform($document)
|
function _stripform($document)
|
||||||
{
|
{
|
||||||
preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
|
preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
|
||||||
|
|
||||||
// catenate the matches
|
// catenate the matches
|
||||||
$match = implode("\r\n",$elements[0]);
|
$match = implode("\r\n",$elements[0]);
|
||||||
|
|
||||||
// return the links
|
// return the links
|
||||||
return $match;
|
return $match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _striptext
|
Function: _striptext
|
||||||
Purpose: strip the text from an html document
|
Purpose: strip the text from an html document
|
||||||
@ -668,11 +668,11 @@ class Snoopy
|
|||||||
|
|
||||||
function _striptext($document)
|
function _striptext($document)
|
||||||
{
|
{
|
||||||
|
|
||||||
// I didn't use preg eval (//e) since that is only available in PHP 4.0.
|
// I didn't use preg eval (//e) since that is only available in PHP 4.0.
|
||||||
// so, list your entities one by one here. I included some of the
|
// so, list your entities one by one here. I included some of the
|
||||||
// more common ones.
|
// more common ones.
|
||||||
|
|
||||||
$search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
|
$search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
|
||||||
"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
|
"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
|
||||||
"'([\r\n])[\s]+'", // strip out white space
|
"'([\r\n])[\s]+'", // strip out white space
|
||||||
@ -721,9 +721,9 @@ class Snoopy
|
|||||||
"Ü",
|
"Ü",
|
||||||
"ß",
|
"ß",
|
||||||
);
|
);
|
||||||
|
|
||||||
$text = preg_replace($search,$replace,$document);
|
$text = preg_replace($search,$replace,$document);
|
||||||
|
|
||||||
return $text;
|
return $text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,7 +737,7 @@ class Snoopy
|
|||||||
|
|
||||||
function _expandlinks($links,$URI)
|
function _expandlinks($links,$URI)
|
||||||
{
|
{
|
||||||
|
|
||||||
preg_match("/^[^\?]+/",$URI,$match);
|
preg_match("/^[^\?]+/",$URI,$match);
|
||||||
|
|
||||||
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
|
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
|
||||||
@ -745,21 +745,21 @@ class Snoopy
|
|||||||
$match_part = parse_url($match);
|
$match_part = parse_url($match);
|
||||||
$match_root =
|
$match_root =
|
||||||
$match_part["scheme"]."://".$match_part["host"];
|
$match_part["scheme"]."://".$match_part["host"];
|
||||||
|
|
||||||
$search = array( "|^http://".preg_quote($this->host)."|i",
|
$search = array( "|^http://".preg_quote($this->host)."|i",
|
||||||
"|^(\/)|i",
|
"|^(\/)|i",
|
||||||
"|^(?!http://)(?!mailto:)|i",
|
"|^(?!http://)(?!mailto:)|i",
|
||||||
"|/\./|",
|
"|/\./|",
|
||||||
"|/[^\/]+/\.\./|"
|
"|/[^\/]+/\.\./|"
|
||||||
);
|
);
|
||||||
|
|
||||||
$replace = array( "",
|
$replace = array( "",
|
||||||
$match_root."/",
|
$match_root."/",
|
||||||
$match."/",
|
$match."/",
|
||||||
"/",
|
"/",
|
||||||
"/"
|
"/"
|
||||||
);
|
);
|
||||||
|
|
||||||
$expandedLinks = preg_replace($search,$replace,$links);
|
$expandedLinks = preg_replace($search,$replace,$links);
|
||||||
|
|
||||||
return $expandedLinks;
|
return $expandedLinks;
|
||||||
@ -772,19 +772,19 @@ class Snoopy
|
|||||||
$fp the current open file pointer
|
$fp the current open file pointer
|
||||||
$URI the full URI
|
$URI the full URI
|
||||||
$body body contents to send if any (POST)
|
$body body contents to send if any (POST)
|
||||||
Output:
|
Output:
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
|
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
|
||||||
{
|
{
|
||||||
$cookie_headers = '';
|
$cookie_headers = '';
|
||||||
if($this->passcookies && $this->_redirectaddr)
|
if($this->passcookies && $this->_redirectaddr)
|
||||||
$this->setcookies();
|
$this->setcookies();
|
||||||
|
|
||||||
$URI_PARTS = parse_url($URI);
|
$URI_PARTS = parse_url($URI);
|
||||||
if(empty($url))
|
if(empty($url))
|
||||||
$url = "/";
|
$url = "/";
|
||||||
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
|
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
|
||||||
if(!empty($this->agent))
|
if(!empty($this->agent))
|
||||||
$headers .= "User-Agent: ".$this->agent."\r\n";
|
$headers .= "User-Agent: ".$this->agent."\r\n";
|
||||||
if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
|
if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
|
||||||
@ -798,10 +798,10 @@ class Snoopy
|
|||||||
if(!empty($this->referer))
|
if(!empty($this->referer))
|
||||||
$headers .= "Referer: ".$this->referer."\r\n";
|
$headers .= "Referer: ".$this->referer."\r\n";
|
||||||
if(!empty($this->cookies))
|
if(!empty($this->cookies))
|
||||||
{
|
{
|
||||||
if(!is_array($this->cookies))
|
if(!is_array($this->cookies))
|
||||||
$this->cookies = (array)$this->cookies;
|
$this->cookies = (array)$this->cookies;
|
||||||
|
|
||||||
reset($this->cookies);
|
reset($this->cookies);
|
||||||
if ( count($this->cookies) > 0 ) {
|
if ( count($this->cookies) > 0 ) {
|
||||||
$cookie_headers .= 'Cookie: ';
|
$cookie_headers .= 'Cookie: ';
|
||||||
@ -809,7 +809,7 @@ class Snoopy
|
|||||||
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
|
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
|
||||||
}
|
}
|
||||||
$headers .= substr($cookie_headers,0,-2) . "\r\n";
|
$headers .= substr($cookie_headers,0,-2) . "\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!empty($this->rawheaders))
|
if(!empty($this->rawheaders))
|
||||||
{
|
{
|
||||||
@ -824,28 +824,28 @@ class Snoopy
|
|||||||
$headers .= "; boundary=".$this->_mime_boundary;
|
$headers .= "; boundary=".$this->_mime_boundary;
|
||||||
$headers .= "\r\n";
|
$headers .= "\r\n";
|
||||||
}
|
}
|
||||||
if(!empty($body))
|
if(!empty($body))
|
||||||
$headers .= "Content-length: ".strlen($body)."\r\n";
|
$headers .= "Content-length: ".strlen($body)."\r\n";
|
||||||
if(!empty($this->user) || !empty($this->pass))
|
if(!empty($this->user) || !empty($this->pass))
|
||||||
$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
|
$headers .= "Authorization: Basic ".base64_encode($this->user.":".$this->pass)."\r\n";
|
||||||
|
|
||||||
//add proxy auth headers
|
//add proxy auth headers
|
||||||
if(!empty($this->proxy_user))
|
if(!empty($this->proxy_user))
|
||||||
$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
|
$headers .= 'Proxy-Authorization: ' . 'Basic ' . base64_encode($this->proxy_user . ':' . $this->proxy_pass)."\r\n";
|
||||||
|
|
||||||
|
|
||||||
$headers .= "\r\n";
|
$headers .= "\r\n";
|
||||||
|
|
||||||
// set the read timeout if needed
|
// set the read timeout if needed
|
||||||
if ($this->read_timeout > 0)
|
if ($this->read_timeout > 0)
|
||||||
socket_set_timeout($fp, $this->read_timeout);
|
socket_set_timeout($fp, $this->read_timeout);
|
||||||
$this->timed_out = false;
|
$this->timed_out = false;
|
||||||
|
|
||||||
fwrite($fp,$headers.$body,strlen($headers.$body));
|
fwrite($fp,$headers.$body,strlen($headers.$body));
|
||||||
|
|
||||||
$this->_redirectaddr = false;
|
$this->_redirectaddr = false;
|
||||||
unset($this->headers);
|
unset($this->headers);
|
||||||
|
|
||||||
while($currentHeader = fgets($fp,$this->_maxlinelen))
|
while($currentHeader = fgets($fp,$this->_maxlinelen))
|
||||||
{
|
{
|
||||||
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
|
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
|
||||||
@ -853,10 +853,10 @@ class Snoopy
|
|||||||
$this->status=-100;
|
$this->status=-100;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($currentHeader == "\r\n")
|
if($currentHeader == "\r\n")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// if a header begins with Location: or URI:, set the redirect
|
// if a header begins with Location: or URI:, set the redirect
|
||||||
if(preg_match("/^(Location:|URI:)/i",$currentHeader))
|
if(preg_match("/^(Location:|URI:)/i",$currentHeader))
|
||||||
{
|
{
|
||||||
@ -876,16 +876,16 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
$this->_redirectaddr = $matches[2];
|
$this->_redirectaddr = $matches[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match("|^HTTP/|",$currentHeader))
|
if(preg_match("|^HTTP/|",$currentHeader))
|
||||||
{
|
{
|
||||||
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
|
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
|
||||||
{
|
{
|
||||||
$this->status= $status[1];
|
$this->status= $status[1];
|
||||||
}
|
}
|
||||||
$this->response_code = $currentHeader;
|
$this->response_code = $currentHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->headers[] = $currentHeader;
|
$this->headers[] = $currentHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -903,13 +903,13 @@ class Snoopy
|
|||||||
$this->status=-100;
|
$this->status=-100;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if there is a a redirect meta tag
|
// check if there is a a redirect meta tag
|
||||||
|
|
||||||
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
|
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
|
||||||
|
|
||||||
{
|
{
|
||||||
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
|
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// have we hit our frame depth and is there frame src to fetch?
|
// have we hit our frame depth and is there frame src to fetch?
|
||||||
@ -925,7 +925,7 @@ class Snoopy
|
|||||||
// no framed content
|
// no framed content
|
||||||
else
|
else
|
||||||
$this->results = $results;
|
$this->results = $results;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -935,21 +935,21 @@ class Snoopy
|
|||||||
Input: $url the url to fetch
|
Input: $url the url to fetch
|
||||||
$URI the full URI
|
$URI the full URI
|
||||||
$body body contents to send if any (POST)
|
$body body contents to send if any (POST)
|
||||||
Output:
|
Output:
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
|
function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
|
||||||
{
|
{
|
||||||
if($this->passcookies && $this->_redirectaddr)
|
if($this->passcookies && $this->_redirectaddr)
|
||||||
$this->setcookies();
|
$this->setcookies();
|
||||||
|
|
||||||
$headers = array();
|
$headers = array();
|
||||||
|
|
||||||
$URI_PARTS = parse_url($URI);
|
$URI_PARTS = parse_url($URI);
|
||||||
if(empty($url))
|
if(empty($url))
|
||||||
$url = "/";
|
$url = "/";
|
||||||
// GET ... header not needed for curl
|
// GET ... header not needed for curl
|
||||||
//$headers[] = $http_method." ".$url." ".$this->_httpversion;
|
//$headers[] = $http_method." ".$url." ".$this->_httpversion;
|
||||||
if(!empty($this->agent))
|
if(!empty($this->agent))
|
||||||
$headers[] = "User-Agent: ".$this->agent;
|
$headers[] = "User-Agent: ".$this->agent;
|
||||||
if(!empty($this->host))
|
if(!empty($this->host))
|
||||||
@ -962,10 +962,10 @@ class Snoopy
|
|||||||
if(!empty($this->referer))
|
if(!empty($this->referer))
|
||||||
$headers[] = "Referer: ".$this->referer;
|
$headers[] = "Referer: ".$this->referer;
|
||||||
if(!empty($this->cookies))
|
if(!empty($this->cookies))
|
||||||
{
|
{
|
||||||
if(!is_array($this->cookies))
|
if(!is_array($this->cookies))
|
||||||
$this->cookies = (array)$this->cookies;
|
$this->cookies = (array)$this->cookies;
|
||||||
|
|
||||||
reset($this->cookies);
|
reset($this->cookies);
|
||||||
if ( count($this->cookies) > 0 ) {
|
if ( count($this->cookies) > 0 ) {
|
||||||
$cookie_str = 'Cookie: ';
|
$cookie_str = 'Cookie: ';
|
||||||
@ -988,43 +988,43 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
$headers[] = "Content-type: $content_type";
|
$headers[] = "Content-type: $content_type";
|
||||||
}
|
}
|
||||||
if(!empty($body))
|
if(!empty($body))
|
||||||
$headers[] = "Content-length: ".strlen($body);
|
$headers[] = "Content-length: ".strlen($body);
|
||||||
if(!empty($this->user) || !empty($this->pass))
|
if(!empty($this->user) || !empty($this->pass))
|
||||||
$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
|
$headers[] = "Authorization: BASIC ".base64_encode($this->user.":".$this->pass);
|
||||||
|
|
||||||
for($curr_header = 0; $curr_header < count($headers); $curr_header++) {
|
for($curr_header = 0; $curr_header < count($headers); $curr_header++) {
|
||||||
$safer_header = strtr( $headers[$curr_header], "\"", " " );
|
$safer_header = strtr( $headers[$curr_header], "\"", " " );
|
||||||
$cmdline_params .= " -H \"".$safer_header."\"";
|
$cmdline_params .= " -H \"".$safer_header."\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($body))
|
if(!empty($body))
|
||||||
$cmdline_params .= " -d \"$body\"";
|
$cmdline_params .= " -d \"$body\"";
|
||||||
|
|
||||||
if($this->read_timeout > 0)
|
if($this->read_timeout > 0)
|
||||||
$cmdline_params .= " -m ".$this->read_timeout;
|
$cmdline_params .= " -m ".$this->read_timeout;
|
||||||
|
|
||||||
$headerfile = tempnam($temp_dir, "sno");
|
$headerfile = tempnam($temp_dir, "sno");
|
||||||
|
|
||||||
exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return);
|
exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return);
|
||||||
|
|
||||||
if($return)
|
if($return)
|
||||||
{
|
{
|
||||||
$this->error = "Error: cURL could not retrieve the document, error $return.";
|
$this->error = "Error: cURL could not retrieve the document, error $return.";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$results = implode("\r\n",$results);
|
$results = implode("\r\n",$results);
|
||||||
|
|
||||||
$result_headers = file("$headerfile");
|
$result_headers = file("$headerfile");
|
||||||
|
|
||||||
$this->_redirectaddr = false;
|
$this->_redirectaddr = false;
|
||||||
unset($this->headers);
|
unset($this->headers);
|
||||||
|
|
||||||
for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
|
for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
|
||||||
{
|
{
|
||||||
|
|
||||||
// if a header begins with Location: or URI:, set the redirect
|
// if a header begins with Location: or URI:, set the redirect
|
||||||
if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
|
if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
|
||||||
{
|
{
|
||||||
@ -1044,7 +1044,7 @@ class Snoopy
|
|||||||
else
|
else
|
||||||
$this->_redirectaddr = $matches[2];
|
$this->_redirectaddr = $matches[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
|
if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
|
||||||
$this->response_code = $result_headers[$currentHeader];
|
$this->response_code = $result_headers[$currentHeader];
|
||||||
|
|
||||||
@ -1052,10 +1052,10 @@ class Snoopy
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if there is a a redirect meta tag
|
// check if there is a a redirect meta tag
|
||||||
|
|
||||||
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
|
if(preg_match("'<meta[\s]*http-equiv[^>]*?content[\s]*=[\s]*[\"\']?\d+;[\s]*URL[\s]*=[\s]*([^\"\']*?)[\"\']?>'i",$results,$match))
|
||||||
{
|
{
|
||||||
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
|
$this->_redirectaddr = $this->_expandlinks($match[1],$URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
// have we hit our frame depth and is there frame src to fetch?
|
// have we hit our frame depth and is there frame src to fetch?
|
||||||
@ -1073,7 +1073,7 @@ class Snoopy
|
|||||||
$this->results = $results;
|
$this->results = $results;
|
||||||
|
|
||||||
unlink("$headerfile");
|
unlink("$headerfile");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1081,7 +1081,7 @@ class Snoopy
|
|||||||
Function: setcookies()
|
Function: setcookies()
|
||||||
Purpose: set cookies for a redirection
|
Purpose: set cookies for a redirection
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function setcookies()
|
function setcookies()
|
||||||
{
|
{
|
||||||
for($x=0; $x<count($this->headers); $x++)
|
for($x=0; $x<count($this->headers); $x++)
|
||||||
@ -1091,7 +1091,7 @@ class Snoopy
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _check_timeout
|
Function: _check_timeout
|
||||||
Purpose: checks whether timeout has occurred
|
Purpose: checks whether timeout has occurred
|
||||||
@ -1115,13 +1115,13 @@ class Snoopy
|
|||||||
Purpose: make a socket connection
|
Purpose: make a socket connection
|
||||||
Input: $fp file pointer
|
Input: $fp file pointer
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _connect(&$fp)
|
function _connect(&$fp)
|
||||||
{
|
{
|
||||||
if(!empty($this->proxy_host) && !empty($this->proxy_port))
|
if(!empty($this->proxy_host) && !empty($this->proxy_port))
|
||||||
{
|
{
|
||||||
$this->_isproxy = true;
|
$this->_isproxy = true;
|
||||||
|
|
||||||
$host = $this->proxy_host;
|
$host = $this->proxy_host;
|
||||||
$port = $this->proxy_port;
|
$port = $this->proxy_port;
|
||||||
}
|
}
|
||||||
@ -1130,9 +1130,9 @@ class Snoopy
|
|||||||
$host = $this->host;
|
$host = $this->host;
|
||||||
$port = $this->port;
|
$port = $this->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->status = 0;
|
$this->status = 0;
|
||||||
|
|
||||||
if($fp = fsockopen(
|
if($fp = fsockopen(
|
||||||
$host,
|
$host,
|
||||||
$port,
|
$port,
|
||||||
@ -1168,13 +1168,13 @@ class Snoopy
|
|||||||
Purpose: disconnect a socket connection
|
Purpose: disconnect a socket connection
|
||||||
Input: $fp file pointer
|
Input: $fp file pointer
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _disconnect($fp)
|
function _disconnect($fp)
|
||||||
{
|
{
|
||||||
return(fclose($fp));
|
return(fclose($fp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*======================================================================*\
|
/*======================================================================*\
|
||||||
Function: _prepare_post_body
|
Function: _prepare_post_body
|
||||||
Purpose: Prepare post body according to encoding type
|
Purpose: Prepare post body according to encoding type
|
||||||
@ -1182,7 +1182,7 @@ class Snoopy
|
|||||||
$formfiles - form upload files
|
$formfiles - form upload files
|
||||||
Output: post body
|
Output: post body
|
||||||
\*======================================================================*/
|
\*======================================================================*/
|
||||||
|
|
||||||
function _prepare_post_body($formvars, $formfiles)
|
function _prepare_post_body($formvars, $formfiles)
|
||||||
{
|
{
|
||||||
settype($formvars, "array");
|
settype($formvars, "array");
|
||||||
@ -1191,7 +1191,7 @@ class Snoopy
|
|||||||
|
|
||||||
if (count($formvars) == 0 && count($formfiles) == 0)
|
if (count($formvars) == 0 && count($formfiles) == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch ($this->_submit_type) {
|
switch ($this->_submit_type) {
|
||||||
case "application/x-www-form-urlencoded":
|
case "application/x-www-form-urlencoded":
|
||||||
reset($formvars);
|
reset($formvars);
|
||||||
@ -1207,7 +1207,7 @@ class Snoopy
|
|||||||
|
|
||||||
case "multipart/form-data":
|
case "multipart/form-data":
|
||||||
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
|
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
|
||||||
|
|
||||||
reset($formvars);
|
reset($formvars);
|
||||||
while(list($key,$val) = each($formvars)) {
|
while(list($key,$val) = each($formvars)) {
|
||||||
if (is_array($val) || is_object($val)) {
|
if (is_array($val) || is_object($val)) {
|
||||||
@ -1222,7 +1222,7 @@ class Snoopy
|
|||||||
$postdata .= "$val\r\n";
|
$postdata .= "$val\r\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset($formfiles);
|
reset($formfiles);
|
||||||
while (list($field_name, $file_names) = each($formfiles)) {
|
while (list($field_name, $file_names) = each($formfiles)) {
|
||||||
settype($file_names, "array");
|
settype($file_names, "array");
|
||||||
@ -1246,5 +1246,5 @@ class Snoopy
|
|||||||
return $postdata;
|
return $postdata;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
endif;
|
||||||
?>
|
?>
|
||||||
|
Loading…
Reference in New Issue
Block a user