diff options
Diffstat (limited to 'include/network.php')
-rw-r--r-- | include/network.php | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/include/network.php b/include/network.php index 6961bf0ba..4c9813768 100644 --- a/include/network.php +++ b/include/network.php @@ -48,6 +48,10 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { if(($redirects > 8) || (! $ch)) return $ret; + if(! array_key_exists('request_target',$opts)) { + $opts['request_target'] = 'get ' . get_request_string($url); + } + @curl_setopt($ch, CURLOPT_HEADER, true); @curl_setopt($ch, CURLINFO_HEADER_OUT, true); @curl_setopt($ch, CURLOPT_CAINFO, get_capath()); @@ -157,7 +161,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { $matches = array(); - preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); + preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches); $newurl = trim(array_pop($matches)); if(strpos($newurl,'/') === 0) $newurl = $url . $newurl; @@ -179,6 +183,7 @@ function z_fetch_url($url, $binary = false, $redirects = 0, $opts = array()) { } $ret['body'] = substr($s,strlen($header)); $ret['header'] = $header; + $ret['request_target'] = $opts['request_target']; if(x($opts,'debug')) { $ret['debug'] = $curl_info; @@ -227,6 +232,10 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) { if(($redirects > 8) || (! $ch)) return $ret; + if(! array_key_exists('request_target',$opts)) { + $opts['request_target'] = 'get ' . get_request_string($url); + } + @curl_setopt($ch, CURLOPT_HEADER, true); @curl_setopt($ch, CURLINFO_HEADER_OUT, true); @curl_setopt($ch, CURLOPT_CAINFO, get_capath()); @@ -359,6 +368,7 @@ function z_post_url($url, $params, $redirects = 0, $opts = array()) { $ret['body'] = substr($s, strlen($header)); $ret['header'] = $header; + $ret['request_target'] = $opts['request_target']; if(x($opts,'debug')) { $ret['debug'] = $curl_info; @@ -2042,6 +2052,22 @@ function jsonld_document_loader($url) { require_once('library/jsonld/jsonld.php'); + $recursion = 0; + + $x = debug_backtrace(); + if($x) { + foreach($x as $n) { + if($n['function'] === __FUNCTION__) { + $recursion ++; + } + } + } + if($recursion > 5) { + logger('jsonld bomb detected at: ' . $url); + killme(); + } + + $cachepath = 'store/[data]/ldcache'; if(! is_dir($cachepath)) os_mkdir($cachepath, STORAGE_DEFAULT_PERMISSIONS, true); @@ -2064,3 +2090,17 @@ function jsonld_document_loader($url) { return []; } + +/** + * @brief Given a URL, return everything after the host portion. + * example https://foobar.com/gravy?g=5&y=6 + * returns /gravy?g=5&y=6 + * result always returns the leading slash + */ + +function get_request_string($url) { + + $a = explode('/',$url,4); + return '/' . ((count($a) > 3) ? $a[3] : EMPTY_STR); + +} |