* Replace htmlspecialchars to htmlSpecialString for compatibility.
This commit is contained in:
+166
-164
@@ -17,8 +17,8 @@ class ztclient
|
||||
public $session;
|
||||
|
||||
/**
|
||||
* The construce function.
|
||||
*
|
||||
* The construce function.
|
||||
*
|
||||
* @param string $zentaoRoot the zentao root url
|
||||
* @param string $account the login account
|
||||
* @param string $password the passwod
|
||||
@@ -43,8 +43,8 @@ class ztclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the settings through getconfig api from remote.
|
||||
*
|
||||
* Get the settings through getconfig api from remote.
|
||||
*
|
||||
* @access private
|
||||
* @return object
|
||||
*/
|
||||
@@ -58,7 +58,7 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Set the session api.
|
||||
*
|
||||
*
|
||||
* @access private
|
||||
* @return string the session api url.
|
||||
*/
|
||||
@@ -69,7 +69,7 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Set the login api.
|
||||
*
|
||||
*
|
||||
* @access private
|
||||
* @return string the login api url.
|
||||
*/
|
||||
@@ -80,8 +80,8 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Set the method api.
|
||||
*
|
||||
* @param string $module the module name
|
||||
*
|
||||
* @param string $module the module name
|
||||
* @param string $method the methhod name
|
||||
* @param string $vars the vars to passwd
|
||||
* @access private
|
||||
@@ -110,8 +110,8 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Set the method api.
|
||||
*
|
||||
* @param string $module the module name
|
||||
*
|
||||
* @param string $module the module name
|
||||
* @param string $method the methhod name
|
||||
* @param string $vars the vars to passed
|
||||
* @access private
|
||||
@@ -138,8 +138,8 @@ class ztclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Start session
|
||||
*
|
||||
* Start session
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -151,7 +151,7 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Login.
|
||||
*
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
@@ -164,9 +164,9 @@ class ztclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch one method of a module's control.
|
||||
*
|
||||
* @param string $module the module name
|
||||
* Fetch one method of a module's control.
|
||||
*
|
||||
* @param string $module the module name
|
||||
* @param string $method the methhod name
|
||||
* @param string $vars the vars to passwd
|
||||
* @access public
|
||||
@@ -178,9 +178,9 @@ class ztclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch one method of a module's model.
|
||||
*
|
||||
* @param string $module the module name
|
||||
* Fetch one method of a module's model.
|
||||
*
|
||||
* @param string $module the module name
|
||||
* @param string $method the methhod name
|
||||
* @param string $vars the vars to passwd
|
||||
* @access public
|
||||
@@ -192,9 +192,9 @@ class ztclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a api and check it.
|
||||
*
|
||||
* @param string $url
|
||||
* Get a api and check it.
|
||||
*
|
||||
* @param string $url
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
@@ -209,9 +209,9 @@ class ztclient
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch one method of a module's control.
|
||||
*
|
||||
* @param string $module the module name
|
||||
* Fetch one method of a module's control.
|
||||
*
|
||||
* @param string $module the module name
|
||||
* @param string $method the methhod name
|
||||
* @param array $vars the vars to passwd
|
||||
* @access public
|
||||
@@ -224,8 +224,8 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Post.
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @param string $url
|
||||
* @access private
|
||||
* @return bool
|
||||
*/
|
||||
@@ -241,8 +241,8 @@ class ztclient
|
||||
|
||||
/**
|
||||
* Append session param to the url.
|
||||
*
|
||||
* @param string $url
|
||||
*
|
||||
* @param string $url
|
||||
* @access private
|
||||
* @return string
|
||||
*/
|
||||
@@ -288,7 +288,7 @@ http://snoopy.sourceforge.net/
|
||||
class Snoopy
|
||||
{
|
||||
/**** Public variables ****/
|
||||
|
||||
|
||||
/* user definable vars */
|
||||
|
||||
var $host = "www.php.net"; // host name we are connecting to
|
||||
@@ -297,7 +297,7 @@ class Snoopy
|
||||
var $proxy_port = ""; // proxy port to use
|
||||
var $proxy_user = ""; // proxy user to use
|
||||
var $proxy_pass = ""; // proxy password to use
|
||||
|
||||
|
||||
var $agent = "Snoopy v1.2.4"; // agent we masquerade as
|
||||
var $referer = ""; // referer info to pass
|
||||
var $cookies = array(); // array of cookies to pass
|
||||
@@ -315,15 +315,15 @@ class Snoopy
|
||||
var $passcookies = true; // pass set cookies back through redirects
|
||||
// NOTE: this currently does not respect
|
||||
// dates, domains or paths.
|
||||
|
||||
|
||||
var $user = ""; // user for http authentication
|
||||
var $pass = ""; // password for http authentication
|
||||
|
||||
|
||||
// http accept types
|
||||
var $accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*";
|
||||
|
||||
|
||||
var $results = ""; // where the content is put
|
||||
|
||||
|
||||
var $error = ""; // error messages sent here
|
||||
var $response_code = ""; // response code returned from server
|
||||
var $headers = array(); // headers returned from server sent here
|
||||
@@ -349,11 +349,11 @@ class Snoopy
|
||||
// library functions built into php,
|
||||
// as these functions are not stable
|
||||
// as of this Snoopy release.
|
||||
|
||||
/**** Private variables ****/
|
||||
|
||||
|
||||
/**** Private variables ****/
|
||||
|
||||
var $_maxlinelen = 4096; // max line length (headers)
|
||||
|
||||
|
||||
var $_httpmethod = "GET"; // default http request method
|
||||
var $_httpversion = "HTTP/1.0"; // default http request version
|
||||
var $_submit_method = "POST"; // default submit method
|
||||
@@ -363,7 +363,7 @@ class Snoopy
|
||||
var $_redirectdepth = 0; // increments on an http redirect
|
||||
var $_frameurls = array(); // frame src urls
|
||||
var $_framedepth = 0; // increments on frame depth
|
||||
|
||||
|
||||
var $_isproxy = false; // set if using a proxy server
|
||||
var $_fp_timeout = 30; // timeout for socket connection
|
||||
|
||||
@@ -378,7 +378,7 @@ class Snoopy
|
||||
|
||||
function fetch($URI)
|
||||
{
|
||||
|
||||
|
||||
//preg_match("|^([^:]+)://([^:/]+)(:[\d]+)*(.*)|",$URI,$URI_PARTS);
|
||||
$URI_PARTS = parse_url($URI);
|
||||
if (!empty($URI_PARTS["user"]))
|
||||
@@ -389,7 +389,7 @@ class Snoopy
|
||||
$URI_PARTS["query"] = '';
|
||||
if (empty($URI_PARTS["path"]))
|
||||
$URI_PARTS["path"] = '';
|
||||
|
||||
|
||||
switch(strtolower($URI_PARTS["scheme"]))
|
||||
{
|
||||
case "http":
|
||||
@@ -409,7 +409,7 @@ class Snoopy
|
||||
// no proxy, send only the path
|
||||
$this->_httprequest($path, $fp, $URI, $this->_httpmethod);
|
||||
}
|
||||
|
||||
|
||||
$this->_disconnect($fp);
|
||||
|
||||
if($this->_redirectaddr)
|
||||
@@ -432,8 +432,8 @@ class Snoopy
|
||||
{
|
||||
$frameurls = $this->_frameurls;
|
||||
$this->_frameurls = array();
|
||||
|
||||
while(list(,$frameurl) = each($frameurls))
|
||||
|
||||
foreach($frameurls as $frameurl))
|
||||
{
|
||||
if($this->_framedepth < $this->maxframes)
|
||||
{
|
||||
@@ -441,15 +441,17 @@ class Snoopy
|
||||
$this->_framedepth++;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
break;
|
||||
case "https":
|
||||
if(!$this->curl_path)
|
||||
@@ -503,15 +505,15 @@ class Snoopy
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
// not a valid protocol
|
||||
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -529,9 +531,9 @@ class Snoopy
|
||||
function submit($URI, $formvars="", $formfiles="")
|
||||
{
|
||||
unset($postdata);
|
||||
|
||||
|
||||
$postdata = $this->_prepare_post_body($formvars, $formfiles);
|
||||
|
||||
|
||||
$URI_PARTS = parse_url($URI);
|
||||
if (!empty($URI_PARTS["user"]))
|
||||
$this->user = $URI_PARTS["user"];
|
||||
@@ -561,17 +563,17 @@ class Snoopy
|
||||
// no proxy, send only the path
|
||||
$this->_httprequest($path, $fp, $URI, $this->_submit_method, $this->_submit_type, $postdata);
|
||||
}
|
||||
|
||||
|
||||
$this->_disconnect($fp);
|
||||
|
||||
if($this->_redirectaddr)
|
||||
{
|
||||
/* url was redirected, check if we've hit the max depth */
|
||||
if($this->maxredirs > $this->_redirectdepth)
|
||||
{
|
||||
{
|
||||
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
|
||||
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
|
||||
{
|
||||
@@ -590,9 +592,9 @@ class Snoopy
|
||||
{
|
||||
$frameurls = $this->_frameurls;
|
||||
$this->_frameurls = array();
|
||||
|
||||
|
||||
while(list(,$frameurl) = each($frameurls))
|
||||
{
|
||||
{
|
||||
if($this->_framedepth < $this->maxframes)
|
||||
{
|
||||
$this->fetch($frameurl);
|
||||
@@ -601,14 +603,14 @@ class Snoopy
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return true;
|
||||
break;
|
||||
case "https":
|
||||
if(!$this->curl_path)
|
||||
@@ -635,9 +637,9 @@ class Snoopy
|
||||
{
|
||||
/* url was redirected, check if we've hit the max depth */
|
||||
if($this->maxredirs > $this->_redirectdepth)
|
||||
{
|
||||
{
|
||||
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
|
||||
if(preg_match("|^http://".preg_quote($this->host)."|i",$this->_redirectaddr) || $this->offsiteok)
|
||||
@@ -659,7 +661,7 @@ class Snoopy
|
||||
$this->_frameurls = array();
|
||||
|
||||
while(list(,$frameurl) = each($frameurls))
|
||||
{
|
||||
{
|
||||
if($this->_framedepth < $this->maxframes)
|
||||
{
|
||||
$this->fetch($frameurl);
|
||||
@@ -668,16 +670,16 @@ class Snoopy
|
||||
else
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
// not a valid protocol
|
||||
$this->error = 'Invalid protocol "'.$URI_PARTS["scheme"].'"\n';
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -691,7 +693,7 @@ class Snoopy
|
||||
function fetchlinks($URI)
|
||||
{
|
||||
if ($this->fetch($URI))
|
||||
{
|
||||
{
|
||||
if($this->lastredirectaddr)
|
||||
$URI = $this->lastredirectaddr;
|
||||
if(is_array($this->results))
|
||||
@@ -719,9 +721,9 @@ class Snoopy
|
||||
|
||||
function fetchform($URI)
|
||||
{
|
||||
|
||||
|
||||
if ($this->fetch($URI))
|
||||
{
|
||||
{
|
||||
|
||||
if(is_array($this->results))
|
||||
{
|
||||
@@ -730,14 +732,14 @@ class Snoopy
|
||||
}
|
||||
else
|
||||
$this->results = $this->_stripform($this->results);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: fetchtext
|
||||
Purpose: fetch the text from a web page, stripping the links
|
||||
@@ -748,7 +750,7 @@ class Snoopy
|
||||
function fetchtext($URI)
|
||||
{
|
||||
if($this->fetch($URI))
|
||||
{
|
||||
{
|
||||
if(is_array($this->results))
|
||||
{
|
||||
for($x=0;$x<count($this->results);$x++)
|
||||
@@ -772,7 +774,7 @@ class Snoopy
|
||||
function submitlinks($URI, $formvars="", $formfiles="")
|
||||
{
|
||||
if($this->submit($URI,$formvars, $formfiles))
|
||||
{
|
||||
{
|
||||
if($this->lastredirectaddr)
|
||||
$URI = $this->lastredirectaddr;
|
||||
if(is_array($this->results))
|
||||
@@ -806,7 +808,7 @@ class Snoopy
|
||||
function submittext($URI, $formvars = "", $formfiles = "")
|
||||
{
|
||||
if($this->submit($URI,$formvars, $formfiles))
|
||||
{
|
||||
{
|
||||
if($this->lastredirectaddr)
|
||||
$URI = $this->lastredirectaddr;
|
||||
if(is_array($this->results))
|
||||
@@ -830,7 +832,7 @@ class Snoopy
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: set_submit_multipart
|
||||
@@ -842,7 +844,7 @@ class Snoopy
|
||||
$this->_submit_type = "multipart/form-data";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: set_submit_normal
|
||||
Purpose: Set the form submission content type to
|
||||
@@ -853,14 +855,14 @@ class Snoopy
|
||||
$this->_submit_type = "application/x-www-form-urlencoded";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Private functions
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _striplinks
|
||||
Purpose: strip the hyperlinks from an html document
|
||||
@@ -869,13 +871,13 @@ class Snoopy
|
||||
\*======================================================================*/
|
||||
|
||||
function _striplinks($document)
|
||||
{
|
||||
{
|
||||
preg_match_all("'<\s*a\s.*?href\s*=\s* # find <a href=
|
||||
([\"\'])? # find single or double quote
|
||||
(?(1) (.*?)\\1 | ([^\s\>]+)) # if quote found, match up to next matching
|
||||
# quote, otherwise match up to next space
|
||||
'isx",$document,$links);
|
||||
|
||||
|
||||
|
||||
// catenate the non-empty matches from the conditional subpattern
|
||||
|
||||
@@ -883,14 +885,14 @@ class Snoopy
|
||||
{
|
||||
if(!empty($val))
|
||||
$match[] = $val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while(list($key,$val) = each($links[3]))
|
||||
{
|
||||
if(!empty($val))
|
||||
$match[] = $val;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// return the links
|
||||
return $match;
|
||||
}
|
||||
@@ -903,18 +905,18 @@ class Snoopy
|
||||
\*======================================================================*/
|
||||
|
||||
function _stripform($document)
|
||||
{
|
||||
{
|
||||
preg_match_all("'<\/?(FORM|INPUT|SELECT|TEXTAREA|(OPTION))[^<>]*>(?(2)(.*(?=<\/?(option|select)[^<>]*>[\r\n]*)|(?=[\r\n]*))|(?=[\r\n]*))'Usi",$document,$elements);
|
||||
|
||||
|
||||
// catenate the matches
|
||||
$match = implode("\r\n",$elements[0]);
|
||||
|
||||
|
||||
// return the links
|
||||
return $match;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _striptext
|
||||
Purpose: strip the text from an html document
|
||||
@@ -924,11 +926,11 @@ class Snoopy
|
||||
|
||||
function _striptext($document)
|
||||
{
|
||||
|
||||
|
||||
// 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
|
||||
// more common ones.
|
||||
|
||||
|
||||
$search = array("'<script[^>]*?>.*?</script>'si", // strip out javascript
|
||||
"'<[\/\!]*?[^<>]*?>'si", // strip out html tags
|
||||
"'([\r\n])[\s]+'", // strip out white space
|
||||
@@ -977,9 +979,9 @@ class Snoopy
|
||||
"?",
|
||||
"?",
|
||||
);
|
||||
|
||||
|
||||
$text = preg_replace($search,$replace,$document);
|
||||
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
@@ -993,7 +995,7 @@ class Snoopy
|
||||
|
||||
function _expandlinks($links,$URI)
|
||||
{
|
||||
|
||||
|
||||
preg_match("/^[^\?]+/",$URI,$match);
|
||||
|
||||
$match = preg_replace("|/[^\/\.]+\.[^\/\.]+$|","",$match[0]);
|
||||
@@ -1001,21 +1003,21 @@ class Snoopy
|
||||
$match_part = parse_url($match);
|
||||
$match_root =
|
||||
$match_part["scheme"]."://".$match_part["host"];
|
||||
|
||||
|
||||
$search = array( "|^http://".preg_quote($this->host)."|i",
|
||||
"|^(\/)|i",
|
||||
"|^(?!http://)(?!mailto:)|i",
|
||||
"|/\./|",
|
||||
"|/[^\/]+/\.\./|"
|
||||
);
|
||||
|
||||
|
||||
$replace = array( "",
|
||||
$match_root."/",
|
||||
$match."/",
|
||||
"/",
|
||||
"/"
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
$expandedLinks = preg_replace($search,$replace,$links);
|
||||
|
||||
return $expandedLinks;
|
||||
@@ -1028,19 +1030,19 @@ class Snoopy
|
||||
$fp the current open file pointer
|
||||
$URI the full URI
|
||||
$body body contents to send if any (POST)
|
||||
Output:
|
||||
Output:
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
function _httprequest($url,$fp,$URI,$http_method,$content_type="",$body="")
|
||||
{
|
||||
$cookie_headers = '';
|
||||
if($this->passcookies && $this->_redirectaddr)
|
||||
$this->setcookies();
|
||||
|
||||
|
||||
$URI_PARTS = parse_url($URI);
|
||||
if(empty($url))
|
||||
$url = "/";
|
||||
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
|
||||
$headers = $http_method." ".$url." ".$this->_httpversion."\r\n";
|
||||
if(!empty($this->agent))
|
||||
$headers .= "User-Agent: ".$this->agent."\r\n";
|
||||
if(!empty($this->host) && !isset($this->rawheaders['Host'])) {
|
||||
@@ -1054,10 +1056,10 @@ class Snoopy
|
||||
if(!empty($this->referer))
|
||||
$headers .= "Referer: ".$this->referer."\r\n";
|
||||
if(!empty($this->cookies))
|
||||
{
|
||||
{
|
||||
if(!is_array($this->cookies))
|
||||
$this->cookies = (array)$this->cookies;
|
||||
|
||||
|
||||
reset($this->cookies);
|
||||
if ( count($this->cookies) > 0 ) {
|
||||
$cookie_headers .= 'Cookie: ';
|
||||
@@ -1065,7 +1067,7 @@ class Snoopy
|
||||
$cookie_headers .= $cookieKey."=".urlencode($cookieVal)."; ";
|
||||
}
|
||||
$headers .= substr($cookie_headers,0,-2) . "\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!empty($this->rawheaders))
|
||||
{
|
||||
@@ -1080,28 +1082,28 @@ class Snoopy
|
||||
$headers .= "; boundary=".$this->_mime_boundary;
|
||||
$headers .= "\r\n";
|
||||
}
|
||||
if(!empty($body))
|
||||
if(!empty($body))
|
||||
$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";
|
||||
|
||||
|
||||
//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 .= "\r\n";
|
||||
|
||||
|
||||
// set the read timeout if needed
|
||||
if ($this->read_timeout > 0)
|
||||
socket_set_timeout($fp, $this->read_timeout);
|
||||
$this->timed_out = false;
|
||||
|
||||
|
||||
fwrite($fp,$headers.$body,strlen($headers.$body));
|
||||
|
||||
|
||||
$this->_redirectaddr = false;
|
||||
unset($this->headers);
|
||||
|
||||
|
||||
while($currentHeader = fgets($fp,$this->_maxlinelen))
|
||||
{
|
||||
if ($this->read_timeout > 0 && $this->_check_timeout($fp))
|
||||
@@ -1109,10 +1111,10 @@ class Snoopy
|
||||
$this->status=-100;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if($currentHeader == "\r\n")
|
||||
break;
|
||||
|
||||
|
||||
// if a header begins with Location: or URI:, set the redirect
|
||||
if(preg_match("/^(Location:|URI:)/i",$currentHeader))
|
||||
{
|
||||
@@ -1132,16 +1134,16 @@ class Snoopy
|
||||
else
|
||||
$this->_redirectaddr = $matches[2];
|
||||
}
|
||||
|
||||
|
||||
if(preg_match("|^HTTP/|",$currentHeader))
|
||||
{
|
||||
if(preg_match("|^HTTP/[^\s]*\s(.*?)\s|",$currentHeader, $status))
|
||||
{
|
||||
$this->status= $status[1];
|
||||
}
|
||||
}
|
||||
$this->response_code = $currentHeader;
|
||||
}
|
||||
|
||||
|
||||
$this->headers[] = $currentHeader;
|
||||
}
|
||||
|
||||
@@ -1159,13 +1161,13 @@ class Snoopy
|
||||
$this->status=-100;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// 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))
|
||||
|
||||
{
|
||||
$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?
|
||||
@@ -1181,7 +1183,7 @@ class Snoopy
|
||||
// no framed content
|
||||
else
|
||||
$this->results = $results;
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1191,21 +1193,21 @@ class Snoopy
|
||||
Input: $url the url to fetch
|
||||
$URI the full URI
|
||||
$body body contents to send if any (POST)
|
||||
Output:
|
||||
Output:
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
function _httpsrequest($url,$URI,$http_method,$content_type="",$body="")
|
||||
{
|
||||
{
|
||||
if($this->passcookies && $this->_redirectaddr)
|
||||
$this->setcookies();
|
||||
|
||||
$headers = array();
|
||||
|
||||
$headers = array();
|
||||
|
||||
$URI_PARTS = parse_url($URI);
|
||||
if(empty($url))
|
||||
$url = "/";
|
||||
// GET ... header not needed for curl
|
||||
//$headers[] = $http_method." ".$url." ".$this->_httpversion;
|
||||
//$headers[] = $http_method." ".$url." ".$this->_httpversion;
|
||||
if(!empty($this->agent))
|
||||
$headers[] = "User-Agent: ".$this->agent;
|
||||
if(!empty($this->host))
|
||||
@@ -1218,10 +1220,10 @@ class Snoopy
|
||||
if(!empty($this->referer))
|
||||
$headers[] = "Referer: ".$this->referer;
|
||||
if(!empty($this->cookies))
|
||||
{
|
||||
{
|
||||
if(!is_array($this->cookies))
|
||||
$this->cookies = (array)$this->cookies;
|
||||
|
||||
|
||||
reset($this->cookies);
|
||||
if ( count($this->cookies) > 0 ) {
|
||||
$cookie_str = 'Cookie: ';
|
||||
@@ -1244,43 +1246,43 @@ class Snoopy
|
||||
else
|
||||
$headers[] = "Content-type: $content_type";
|
||||
}
|
||||
if(!empty($body))
|
||||
if(!empty($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);
|
||||
|
||||
|
||||
for($curr_header = 0; $curr_header < count($headers); $curr_header++) {
|
||||
$safer_header = strtr( $headers[$curr_header], "\"", " " );
|
||||
$cmdline_params .= " -H \"".$safer_header."\"";
|
||||
}
|
||||
|
||||
|
||||
if(!empty($body))
|
||||
$cmdline_params .= " -d \"$body\"";
|
||||
|
||||
|
||||
if($this->read_timeout > 0)
|
||||
$cmdline_params .= " -m ".$this->read_timeout;
|
||||
|
||||
|
||||
$headerfile = tempnam($temp_dir, "sno");
|
||||
|
||||
exec($this->curl_path." -k -D \"$headerfile\"".$cmdline_params." \"".escapeshellcmd($URI)."\"",$results,$return);
|
||||
|
||||
|
||||
if($return)
|
||||
{
|
||||
$this->error = "Error: cURL could not retrieve the document, error $return.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$results = implode("\r\n",$results);
|
||||
|
||||
|
||||
$result_headers = file("$headerfile");
|
||||
|
||||
|
||||
$this->_redirectaddr = false;
|
||||
unset($this->headers);
|
||||
|
||||
|
||||
for($currentHeader = 0; $currentHeader < count($result_headers); $currentHeader++)
|
||||
{
|
||||
|
||||
|
||||
// if a header begins with Location: or URI:, set the redirect
|
||||
if(preg_match("/^(Location: |URI: )/i",$result_headers[$currentHeader]))
|
||||
{
|
||||
@@ -1300,7 +1302,7 @@ class Snoopy
|
||||
else
|
||||
$this->_redirectaddr = $matches[2];
|
||||
}
|
||||
|
||||
|
||||
if(preg_match("|^HTTP/|",$result_headers[$currentHeader]))
|
||||
$this->response_code = $result_headers[$currentHeader];
|
||||
|
||||
@@ -1308,10 +1310,10 @@ class Snoopy
|
||||
}
|
||||
|
||||
// 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))
|
||||
{
|
||||
$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?
|
||||
@@ -1329,7 +1331,7 @@ class Snoopy
|
||||
$this->results = $results;
|
||||
|
||||
unlink("$headerfile");
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1337,7 +1339,7 @@ class Snoopy
|
||||
Function: setcookies()
|
||||
Purpose: set cookies for a redirection
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
function setcookies()
|
||||
{
|
||||
for($x=0; $x<count($this->headers); $x++)
|
||||
@@ -1347,7 +1349,7 @@ class Snoopy
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _check_timeout
|
||||
Purpose: checks whether timeout has occurred
|
||||
@@ -1371,13 +1373,13 @@ class Snoopy
|
||||
Purpose: make a socket connection
|
||||
Input: $fp file pointer
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
function _connect(&$fp)
|
||||
{
|
||||
if(!empty($this->proxy_host) && !empty($this->proxy_port))
|
||||
{
|
||||
$this->_isproxy = true;
|
||||
|
||||
|
||||
$host = $this->proxy_host;
|
||||
$port = $this->proxy_port;
|
||||
}
|
||||
@@ -1386,9 +1388,9 @@ class Snoopy
|
||||
$host = $this->host;
|
||||
$port = $this->port;
|
||||
}
|
||||
|
||||
|
||||
$this->status = 0;
|
||||
|
||||
|
||||
if($fp = fsockopen(
|
||||
$host,
|
||||
$port,
|
||||
@@ -1424,13 +1426,13 @@ class Snoopy
|
||||
Purpose: disconnect a socket connection
|
||||
Input: $fp file pointer
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
function _disconnect($fp)
|
||||
{
|
||||
return(fclose($fp));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*======================================================================*\
|
||||
Function: _prepare_post_body
|
||||
Purpose: Prepare post body according to encoding type
|
||||
@@ -1438,7 +1440,7 @@ class Snoopy
|
||||
$formfiles - form upload files
|
||||
Output: post body
|
||||
\*======================================================================*/
|
||||
|
||||
|
||||
function _prepare_post_body($formvars, $formfiles)
|
||||
{
|
||||
settype($formvars, "array");
|
||||
@@ -1447,7 +1449,7 @@ class Snoopy
|
||||
|
||||
if (count($formvars) == 0 && count($formfiles) == 0)
|
||||
return;
|
||||
|
||||
|
||||
switch ($this->_submit_type) {
|
||||
case "application/x-www-form-urlencoded":
|
||||
reset($formvars);
|
||||
@@ -1463,7 +1465,7 @@ class Snoopy
|
||||
|
||||
case "multipart/form-data":
|
||||
$this->_mime_boundary = "Snoopy".md5(uniqid(microtime()));
|
||||
|
||||
|
||||
reset($formvars);
|
||||
while(list($key,$val) = each($formvars)) {
|
||||
if (is_array($val) || is_object($val)) {
|
||||
@@ -1478,7 +1480,7 @@ class Snoopy
|
||||
$postdata .= "$val\r\n";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
reset($formfiles);
|
||||
while (list($field_name, $file_names) = each($formfiles)) {
|
||||
settype($file_names, "array");
|
||||
|
||||
Reference in New Issue
Block a user