From 1b51777825f2643295ac759791bbdd4829a6aba9 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 22:51:07 -0500 Subject: [PATCH 01/13] Create Network class Create Network class and copy methods --- include/network.php | 1014 +-------------------------------------- src/Util/Network.php | 1086 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1109 insertions(+), 991 deletions(-) create mode 100644 src/Util/Network.php diff --git a/include/network.php b/include/network.php index 73fa80f981..7798fd9cd8 100644 --- a/include/network.php +++ b/include/network.php @@ -9,1079 +9,111 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Network\Probe; use Friendica\Object\Image; +use Friendica\Util\Network; use Friendica\Util\XML; -/** - * @brief Curl wrapper - * - * If binary flag is true, return binary results. - * Set the cookiejar argument to a string (e.g. "/tmp/friendica-cookies.txt") - * to preserve cookies from one request to the next. - * - * @param string $url URL to fetch - * @param boolean $binary default false - * TRUE if asked to return binary results (file download) - * @param integer $redirects The recursion counter for internal use - default 0 - * @param integer $timeout Timeout in seconds, default system config value or 60 seconds - * @param string $accept_content supply Accept: header with 'accept_content' as the value - * @param string $cookiejar Path to cookie jar file - * - * @return string The fetched content - */ function fetch_url($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) { - $ret = z_fetch_url( - $url, - $binary, - $redirects, - ['timeout'=>$timeout, - 'accept_content'=>$accept_content, - 'cookiejar'=>$cookiejar - ] - ); - - return($ret['body']); + return Network::fetchURL($url, $binary, $redirects, $timeout, $accept_content, $cookiejar); } -/** - * @brief fetches an URL. - * - * @param string $url URL to fetch - * @param boolean $binary default false - * TRUE if asked to return binary results (file download) - * @param int $redirects The recursion counter for internal use - default 0 - * @param array $opts (optional parameters) assoziative array with: - * 'accept_content' => supply Accept: header with 'accept_content' as the value - * 'timeout' => int Timeout in seconds, default system config value or 60 seconds - * 'http_auth' => username:password - * 'novalidate' => do not validate SSL certs, default is to validate using our CA list - * 'nobody' => only return the header - * 'cookiejar' => path to cookie jar file - * - * @return array an assoziative array with: - * int 'return_code' => HTTP return code or 0 if timeout or failure - * boolean 'success' => boolean true (if HTTP 2xx result) or false - * string 'redirect_url' => in case of redirect, content was finally retrieved from this URL - * string 'header' => HTTP headers - * string 'body' => fetched content - */ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = []) { - $ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '']; - - $stamp1 = microtime(true); - - $a = get_app(); - - if (blocked_url($url)) { - logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA); - return $ret; - } - - $ch = @curl_init($url); - - if (($redirects > 8) || (!$ch)) { - return $ret; - } - - @curl_setopt($ch, CURLOPT_HEADER, true); - - if (x($opts, "cookiejar")) { - curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]); - curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]); - } - - // These settings aren't needed. We're following the location already. - // @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - // @curl_setopt($ch, CURLOPT_MAXREDIRS, 5); - - if (x($opts, 'accept_content')) { - curl_setopt( - $ch, - CURLOPT_HTTPHEADER, - ['Accept: ' . $opts['accept_content']] - ); - } - - @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - @curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - - $range = intval(Config::get('system', 'curl_range_bytes', 0)); - - if ($range > 0) { - @curl_setopt($ch, CURLOPT_RANGE, '0-' . $range); - } - - // Without this setting it seems as if some webservers send compressed content - // This seems to confuse curl so that it shows this uncompressed. - /// @todo We could possibly set this value to "gzip" or something similar - curl_setopt($ch, CURLOPT_ENCODING, ''); - - if (x($opts, 'headers')) { - @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); - } - - if (x($opts, 'nobody')) { - @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); - } - - if (x($opts, 'timeout')) { - @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); - } else { - $curl_time = Config::get('system', 'curl_timeout', 60); - @curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time)); - } - - // by default we will allow self-signed certs - // but you can override this - - $check_cert = Config::get('system', 'verifyssl'); - @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); - - if ($check_cert) { - @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - } - - $proxy = Config::get('system', 'proxy'); - - if (strlen($proxy)) { - @curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); - @curl_setopt($ch, CURLOPT_PROXY, $proxy); - $proxyuser = @Config::get('system', 'proxyuser'); - - if (strlen($proxyuser)) { - @curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser); - } - } - - if (Config::get('system', 'ipv4_resolve', false)) { - curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - } - - if ($binary) { - @curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); - } - - $a->set_curl_code(0); - - // don't let curl abort the entire application - // if it throws any errors. - - $s = @curl_exec($ch); - $curl_info = @curl_getinfo($ch); - - // Special treatment for HTTP Code 416 - // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416 - if (($curl_info['http_code'] == 416) && ($range > 0)) { - @curl_setopt($ch, CURLOPT_RANGE, ''); - $s = @curl_exec($ch); - $curl_info = @curl_getinfo($ch); - } - - if (curl_errno($ch) !== CURLE_OK) { - logger('fetch_url error fetching ' . $url . ': ' . curl_error($ch), LOGGER_NORMAL); - } - - $ret['errno'] = curl_errno($ch); - - $base = $s; - $ret['info'] = $curl_info; - - $http_code = $curl_info['http_code']; - - logger('fetch_url ' . $url . ': ' . $http_code . " " . $s, LOGGER_DATA); - $header = ''; - - // Pull out multiple headers, e.g. proxy and continuation headers - // allow for HTTP/2.x without fixing code - - while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) { - $chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4); - $header .= $chunk; - $base = substr($base, strlen($chunk)); - } - - $a->set_curl_code($http_code); - $a->set_curl_content_type($curl_info['content_type']); - $a->set_curl_headers($header); - - if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { - $new_location_info = @parse_url($curl_info['redirect_url']); - $old_location_info = @parse_url($curl_info['url']); - - $newurl = $curl_info['redirect_url']; - - if (($new_location_info['path'] == '') && ( $new_location_info['host'] != '')) { - $newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path']; - } - - $matches = []; - - if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) { - $newurl = trim(array_pop($matches)); - } - if (strpos($newurl, '/') === 0) { - $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl; - } - - if (filter_var($newurl, FILTER_VALIDATE_URL)) { - $redirects++; - @curl_close($ch); - return z_fetch_url($newurl, $binary, $redirects, $opts); - } - } - - $a->set_curl_code($http_code); - $a->set_curl_content_type($curl_info['content_type']); - - $rc = intval($http_code); - $ret['return_code'] = $rc; - $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); - $ret['redirect_url'] = $url; - - if (!$ret['success']) { - $ret['error'] = curl_error($ch); - $ret['debug'] = $curl_info; - logger('z_fetch_url: error: '.$url.': '.$ret['return_code'].' - '.$ret['error'], LOGGER_DEBUG); - logger('z_fetch_url: debug: '.print_r($curl_info, true), LOGGER_DATA); - } - - $ret['body'] = substr($s, strlen($header)); - $ret['header'] = $header; - - if (x($opts, 'debug')) { - $ret['debug'] = $curl_info; - } - - @curl_close($ch); - - $a->save_timestamp($stamp1, 'network'); - - return($ret); + return Network::zFetchURL($url, $binary, $redirects, $opts); } -/** - * @brief Send POST request to $url - * - * @param string $url URL to post - * @param mixed $params array of POST variables - * @param string $headers HTTP headers - * @param integer $redirects Recursion counter for internal use - default = 0 - * @param integer $timeout The timeout in seconds, default system config value or 60 seconds - * - * @return string The content - */ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) { - $stamp1 = microtime(true); - - if (blocked_url($url)) { - logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA); - return false; - } - - $a = get_app(); - $ch = curl_init($url); - - if (($redirects > 8) || (!$ch)) { - return false; - } - - logger('post_url: start ' . $url, LOGGER_DATA); - - curl_setopt($ch, CURLOPT_HEADER, true); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, $params); - curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - - if (Config::get('system', 'ipv4_resolve', false)) { - curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); - } - - if (intval($timeout)) { - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - } else { - $curl_time = Config::get('system', 'curl_timeout', 60); - curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time)); - } - - if (defined('LIGHTTPD')) { - if (!is_array($headers)) { - $headers = ['Expect:']; - } else { - if (!in_array('Expect:', $headers)) { - array_push($headers, 'Expect:'); - } - } - } - - if ($headers) { - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - } - - $check_cert = Config::get('system', 'verifyssl'); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); - - if ($check_cert) { - @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); - } - - $proxy = Config::get('system', 'proxy'); - - if (strlen($proxy)) { - curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); - curl_setopt($ch, CURLOPT_PROXY, $proxy); - $proxyuser = Config::get('system', 'proxyuser'); - if (strlen($proxyuser)) { - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser); - } - } - - $a->set_curl_code(0); - - // don't let curl abort the entire application - // if it throws any errors. - - $s = @curl_exec($ch); - - $base = $s; - $curl_info = curl_getinfo($ch); - $http_code = $curl_info['http_code']; - - logger('post_url: result ' . $http_code . ' - ' . $url, LOGGER_DATA); - - $header = ''; - - // Pull out multiple headers, e.g. proxy and continuation headers - // allow for HTTP/2.x without fixing code - - while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) { - $chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4); - $header .= $chunk; - $base = substr($base, strlen($chunk)); - } - - if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { - $matches = []; - preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); - $newurl = trim(array_pop($matches)); - - if (strpos($newurl, '/') === 0) { - $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl; - } - - if (filter_var($newurl, FILTER_VALIDATE_URL)) { - $redirects++; - logger('post_url: redirect ' . $url . ' to ' . $newurl); - return post_url($newurl, $params, $headers, $redirects, $timeout); - } - } - - $a->set_curl_code($http_code); - - $body = substr($s, strlen($header)); - - $a->set_curl_headers($header); - - curl_close($ch); - - $a->save_timestamp($stamp1, 'network'); - - logger('post_url: end ' . $url, LOGGER_DATA); - - return $body; + return Network::postURL($url, $params, $headers, $redirects, $timeout); } -// Generic XML return -// Outputs a basic dfrn XML status structure to STDOUT, with a variable -// of $st and an optional text of $message and terminates the current process. - function xml_status($st, $message = '') { - $result = ['status' => $st]; - - if ($message != '') { - $result['message'] = $message; - } - - if ($st) { - logger('xml_status returning non_zero: ' . $st . " message=" . $message); - } - - header("Content-type: text/xml"); - - $xmldata = ["result" => $result]; - - echo XML::fromArray($xmldata, $xml); - - killme(); + Network::xmlStatus($st, $message); } -/** - * @brief Send HTTP status header and exit. - * - * @param integer $val HTTP status result value - * @param array $description optional message - * 'title' => header title - * 'description' => optional message - */ - -/** - * @brief Send HTTP status header and exit. - * - * @param integer $val HTTP status result value - * @param array $description optional message - * 'title' => header title - * 'description' => optional message - */ function http_status_exit($val, $description = []) { - $err = ''; - if ($val >= 400) { - $err = 'Error'; - if (!isset($description["title"])) { - $description["title"] = $err." ".$val; - } - } - if ($val >= 200 && $val < 300) - $err = 'OK'; - - logger('http_status_exit ' . $val); - header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); - - if (isset($description["title"])) { - $tpl = get_markup_template('http_status.tpl'); - echo replace_macros( - $tpl, - [ - '$title' => $description["title"], - '$description' => $description["description"]] - ); - } - - killme(); + Network::httpStatusExit($val, $description); } -/** - * @brief Check URL to se if ts's real - * - * Take a URL from the wild, prepend http:// if necessary - * and check DNS to see if it's real (or check if is a valid IP address) - * - * @param string $url The URL to be validated - * @return string|boolean The actual working URL, false else - */ function validate_url($url) { - if (Config::get('system', 'disable_url_validation')) { - return $url; - } - - // no naked subdomains (allow localhost for tests) - if (strpos($url, '.') === false && strpos($url, '/localhost/') === false) { - return false; - } - - if (substr($url, 0, 4) != 'http') { - $url = 'http://' . $url; - } - - /// @TODO Really suppress function outcomes? Why not find them + debug them? - $h = @parse_url($url); - - if ((is_array($h)) && (@dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { - return $url; - } - - return false; + return Network::validateURL($url); } -/** - * @brief Checks that email is an actual resolvable internet address - * - * @param string $addr The email address - * @return boolean True if it's a valid email address, false if it's not - */ function validate_email($addr) { - if (Config::get('system', 'disable_email_validation')) { - return true; - } - - if (! strpos($addr, '@')) { - return false; - } - - $h = substr($addr, strpos($addr, '@') + 1); - - if (($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) { - return true; - } - return false; + return Network::validateEmail($addr); } -/** - * @brief Check if URL is allowed - * - * Check $url against our list of allowed sites, - * wildcards allowed. If allowed_sites is unset return true; - * - * @param string $url URL which get tested - * @return boolean True if url is allowed otherwise return false - */ function allowed_url($url) { - $h = @parse_url($url); - - if (! $h) { - return false; - } - - $str_allowed = Config::get('system', 'allowed_sites'); - if (! $str_allowed) { - return true; - } - - $found = false; - - $host = strtolower($h['host']); - - // always allow our own site - if ($host == strtolower($_SERVER['SERVER_NAME'])) { - return true; - } - - $fnmatch = function_exists('fnmatch'); - $allowed = explode(',', $str_allowed); - - if (count($allowed)) { - foreach ($allowed as $a) { - $pat = strtolower(trim($a)); - if (($fnmatch && fnmatch($pat, $host)) || ($pat == $host)) { - $found = true; - break; - } - } - } - return $found; + return Network::allowedURL($url); } -/** - * Checks if the provided url domain is on the domain blocklist. - * Returns true if it is or malformed URL, false if not. - * - * @param string $url The url to check the domain from - * - * @return boolean - */ function blocked_url($url) { - $h = @parse_url($url); - - if (! $h) { - return true; - } - - $domain_blocklist = Config::get('system', 'blocklist', []); - if (! $domain_blocklist) { - return false; - } - - $host = strtolower($h['host']); - - foreach ($domain_blocklist as $domain_block) { - if (strtolower($domain_block['domain']) == $host) { - return true; - } - } - - return false; + return Network::blockedURL($url); } -/** - * @brief Check if email address is allowed to register here. - * - * Compare against our list (wildcards allowed). - * - * @param string $email email address - * @return boolean False if not allowed, true if allowed - * or if allowed list is not configured - */ -function allowed_email($email) +function allowedEmail($email) { - $domain = strtolower(substr($email, strpos($email, '@') + 1)); - if (!$domain) { - return false; - } - - $str_allowed = Config::get('system', 'allowed_email', ''); - if (!x($str_allowed)) { - return true; - } - - $allowed = explode(',', $str_allowed); - - return allowed_domain($domain, $allowed); + return Network::allowedEmail($email); } -/** - * Checks for the existence of a domain in a domain list - * - * @brief Checks for the existence of a domain in a domain list - * @param string $domain - * @param array $domain_list - * @return boolean - */ function allowed_domain($domain, array $domain_list) { - $found = false; - - foreach ($domain_list as $item) { - $pat = strtolower(trim($item)); - if (fnmatch($pat, $domain) || ($pat == $domain)) { - $found = true; - break; - } - } - - return $found; + return Network::allowedDomain($domain, $domain_list); } function avatar_img($email) { - $avatar['size'] = 175; - $avatar['email'] = $email; - $avatar['url'] = ''; - $avatar['success'] = false; - - Addon::callHooks('avatar_lookup', $avatar); - - if (! $avatar['success']) { - $avatar['url'] = System::baseUrl() . '/images/person-175.jpg'; - } - - logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG); - return $avatar['url']; + return Network::avatarImg($email); } function parse_xml_string($s, $strict = true) { - // the "strict" parameter is deactivated - - /// @todo Move this function to the xml class - libxml_use_internal_errors(true); - - $x = @simplexml_load_string($s); - if (!$x) { - logger('libxml: parse: error: ' . $s, LOGGER_DATA); - foreach (libxml_get_errors() as $err) { - logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA); - } - libxml_clear_errors(); - } - return $x; + return Network::parseXmlString($s, $strict); } function scale_external_images($srctext, $include_link = true, $scale_replace = false) { - // Suppress "view full size" - if (intval(Config::get('system', 'no_view_full_size'))) { - $include_link = false; - } - - // Picture addresses can contain special characters - $s = htmlspecialchars_decode($srctext); - - $matches = null; - $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); - if ($c) { - foreach ($matches as $mtch) { - logger('scale_external_image: ' . $mtch[1]); - - $hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3)); - if (stristr($mtch[1], $hostname)) { - continue; - } - - // $scale_replace, if passed, is an array of two elements. The - // first is the name of the full-size image. The second is the - // name of a remote, scaled-down version of the full size image. - // This allows Friendica to display the smaller remote image if - // one exists, while still linking to the full-size image - if ($scale_replace) { - $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]); - } else { - $scaled = $mtch[1]; - } - $i = fetch_url($scaled); - if (! $i) { - return $srctext; - } - - // guess mimetype from headers or filename - $type = Image::guessType($mtch[1], true); - - if ($i) { - $Image = new Image($i, $type); - if ($Image->isValid()) { - $orig_width = $Image->getWidth(); - $orig_height = $Image->getHeight(); - - if ($orig_width > 640 || $orig_height > 640) { - $Image->scaleDown(640); - $new_width = $Image->getWidth(); - $new_height = $Image->getHeight(); - logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); - $s = str_replace( - $mtch[0], - '[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' - . "\n" . (($include_link) - ? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n" - : ''), - $s - ); - logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); - } - } - } - } - } - - // replace the special char encoding - $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); - return $s; + return Network::scaleExternalImages($srctext, $include_link, $scale_replace); } - function fix_contact_ssl_policy(&$contact, $new_policy) { - $ssl_changed = false; - if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) { - $ssl_changed = true; - $contact['url'] = str_replace('https:', 'http:', $contact['url']); - $contact['request'] = str_replace('https:', 'http:', $contact['request']); - $contact['notify'] = str_replace('https:', 'http:', $contact['notify']); - $contact['poll'] = str_replace('https:', 'http:', $contact['poll']); - $contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']); - $contact['poco'] = str_replace('https:', 'http:', $contact['poco']); - } - - if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) { - $ssl_changed = true; - $contact['url'] = str_replace('http:', 'https:', $contact['url']); - $contact['request'] = str_replace('http:', 'https:', $contact['request']); - $contact['notify'] = str_replace('http:', 'https:', $contact['notify']); - $contact['poll'] = str_replace('http:', 'https:', $contact['poll']); - $contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']); - $contact['poco'] = str_replace('http:', 'https:', $contact['poco']); - } - - if ($ssl_changed) { - $fields = ['url' => $contact['url'], 'request' => $contact['request'], - 'notify' => $contact['notify'], 'poll' => $contact['poll'], - 'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; - dba::update('contact', $fields, ['id' => $contact['id']]); - } + Network::fixContactSslPolicy($contact, $new_policy); } -/** - * @brief Remove Google Analytics and other tracking platforms params from URL - * - * @param string $url Any user-submitted URL that may contain tracking params - * @return string The same URL stripped of tracking parameters - */ function strip_tracking_query_params($url) { - $urldata = parse_url($url); - if (is_string($urldata["query"])) { - $query = $urldata["query"]; - parse_str($query, $querydata); - - if (is_array($querydata)) { - foreach ($querydata as $param => $value) { - if (in_array( - $param, - [ - "utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign", - "wt_mc", "pk_campaign", "pk_kwd", "mc_cid", "mc_eid", - "fb_action_ids", "fb_action_types", "fb_ref", - "awesm", "wtrid", - "woo_campaign", "woo_source", "woo_medium", "woo_content", "woo_term"] - ) - ) { - $pair = $param . "=" . urlencode($value); - $url = str_replace($pair, "", $url); - - // Second try: if the url isn't encoded completely - $pair = $param . "=" . str_replace(" ", "+", $value); - $url = str_replace($pair, "", $url); - - // Third try: Maybey the url isn't encoded at all - $pair = $param . "=" . $value; - $url = str_replace($pair, "", $url); - - $url = str_replace(["?&", "&&"], ["?", ""], $url); - } - } - } - - if (substr($url, -1, 1) == "?") { - $url = substr($url, 0, -1); - } - } - - return $url; + return Network::stripTrackingQueryParams($url); } -/** - * @brief Returns the original URL of the provided URL - * - * This function strips tracking query params and follows redirections, either - * through HTTP code or meta refresh tags. Stops after 10 redirections. - * - * @todo Remove the $fetchbody parameter that generates an extraneous HEAD request - * - * @see ParseUrl::getSiteinfo - * - * @param string $url A user-submitted URL - * @param int $depth The current redirection recursion level (internal) - * @param bool $fetchbody Wether to fetch the body or not after the HEAD requests - * @return string A canonical URL - */ function original_url($url, $depth = 1, $fetchbody = false) { - $a = get_app(); - - $url = strip_tracking_query_params($url); - - if ($depth > 10) { - return($url); - } - - $url = trim($url, "'"); - - $stamp1 = microtime(true); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HEADER, 1); - curl_setopt($ch, CURLOPT_NOBODY, 1); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - - curl_exec($ch); - $curl_info = @curl_getinfo($ch); - $http_code = $curl_info['http_code']; - curl_close($ch); - - $a->save_timestamp($stamp1, "network"); - - if ($http_code == 0) - return($url); - - if ((($curl_info['http_code'] == "301") || ($curl_info['http_code'] == "302")) - && (($curl_info['redirect_url'] != "") || ($curl_info['location'] != "")) - ) { - if ($curl_info['redirect_url'] != "") { - return(original_url($curl_info['redirect_url'], ++$depth, $fetchbody)); - } else { - return(original_url($curl_info['location'], ++$depth, $fetchbody)); - } - } - - // Check for redirects in the meta elements of the body if there are no redirects in the header. - if (!$fetchbody) { - return(original_url($url, ++$depth, true)); - } - - // if the file is too large then exit - if ($curl_info["download_content_length"] > 1000000) { - return($url); - } - - // if it isn't a HTML file then exit - if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]), "html")) { - return($url); - } - - $stamp1 = microtime(true); - - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_HEADER, 0); - curl_setopt($ch, CURLOPT_NOBODY, 0); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - - $body = curl_exec($ch); - curl_close($ch); - - $a->save_timestamp($stamp1, "network"); - - if (trim($body) == "") { - return($url); - } - - // Check for redirect in meta elements - $doc = new DOMDocument(); - @$doc->loadHTML($body); - - $xpath = new DomXPath($doc); - - $list = $xpath->query("//meta[@content]"); - foreach ($list as $node) { - $attr = []; - if ($node->attributes->length) { - foreach ($node->attributes as $attribute) { - $attr[$attribute->name] = $attribute->value; - } - } - - if (@$attr["http-equiv"] == 'refresh') { - $path = $attr["content"]; - $pathinfo = explode(";", $path); - foreach ($pathinfo as $value) { - if (substr(strtolower($value), 0, 4) == "url=") { - return(original_url(substr($value, 4), ++$depth)); - } - } - } - } - - return $url; + return Network::originalURL($url, $depth, $fetchbody); } function short_link($url) { - require_once 'library/slinky.php'; - $slinky = new Slinky($url); - $yourls_url = Config::get('yourls', 'url1'); - if ($yourls_url) { - $yourls_username = Config::get('yourls', 'username1'); - $yourls_password = Config::get('yourls', 'password1'); - $yourls_ssl = Config::get('yourls', 'ssl1'); - $yourls = new Slinky_YourLS(); - $yourls->set('username', $yourls_username); - $yourls->set('password', $yourls_password); - $yourls->set('ssl', $yourls_ssl); - $yourls->set('yourls-url', $yourls_url); - $slinky->set_cascade([$yourls, new Slinky_Ur1ca(), new Slinky_TinyURL()]); - } else { - // setup a cascade of shortening services - // try to get a short link from these services - // in the order ur1.ca, tinyurl - $slinky->set_cascade([new Slinky_Ur1ca(), new Slinky_TinyURL()]); - } - return $slinky->short(); + return Network::shortLink($url); } -/** - * @brief Encodes content to json - * - * This function encodes an array to json format - * and adds an application/json HTTP header to the output. - * After finishing the process is getting killed. - * - * @param array $x The input content - */ function json_return_and_die($x) { - header("content-type: application/json"); - echo json_encode($x); - killme(); + Network::jsonReturnAndDie($x); } -/** - * @brief Find the matching part between two url - * - * @param string $url1 - * @param string $url2 - * @return string The matching part - */ function matching_url($url1, $url2) { - if (($url1 == "") || ($url2 == "")) { - return ""; - } - - $url1 = normalise_link($url1); - $url2 = normalise_link($url2); - - $parts1 = parse_url($url1); - $parts2 = parse_url($url2); - - if (!isset($parts1["host"]) || !isset($parts2["host"])) { - return ""; - } - - if ($parts1["scheme"] != $parts2["scheme"]) { - return ""; - } - - if ($parts1["host"] != $parts2["host"]) { - return ""; - } - - if ($parts1["port"] != $parts2["port"]) { - return ""; - } - - $match = $parts1["scheme"]."://".$parts1["host"]; - - if ($parts1["port"]) { - $match .= ":".$parts1["port"]; - } - - $pathparts1 = explode("/", $parts1["path"]); - $pathparts2 = explode("/", $parts2["path"]); - - $i = 0; - $path = ""; - do { - $path1 = $pathparts1[$i]; - $path2 = $pathparts2[$i]; - - if ($path1 == $path2) { - $path .= $path1."/"; - } - } while (($path1 == $path2) && ($i++ <= count($pathparts1))); - - $match .= $path; - - return normalise_link($match); + return Network::matchingURL($url1, $url2); } -/** - * @brief Glue url parts together - * - * @param array $parsed URL parts - * - * @return string The glued URL - */ function unParseUrl($parsed) { - $get = function ($key) use ($parsed) { - return isset($parsed[$key]) ? $parsed[$key] : null; - }; - - $pass = $get('pass'); - $user = $get('user'); - $userinfo = $pass !== null ? "$user:$pass" : $user; - $port = $get('port'); - $scheme = $get('scheme'); - $query = $get('query'); - $fragment = $get('fragment'); - $authority = ($userinfo !== null ? $userinfo."@" : '') . - $get('host') . - ($port ? ":$port" : ''); - - return (strlen($scheme) ? $scheme.":" : '') . - (strlen($authority) ? "//".$authority : '') . - $get('path') . - (strlen($query) ? "?".$query : '') . - (strlen($fragment) ? "#".$fragment : ''); + return Network::unParseURL($parsed); } diff --git a/src/Util/Network.php b/src/Util/Network.php new file mode 100644 index 0000000000..f25d9c9a26 --- /dev/null +++ b/src/Util/Network.php @@ -0,0 +1,1086 @@ +$timeout, + 'accept_content'=>$accept_content, + 'cookiejar'=>$cookiejar + ] + ); + + return($ret['body']); + } + + /** + * @brief fetches an URL. + * + * @param string $url URL to fetch + * @param boolean $binary default false + * TRUE if asked to return binary results (file download) + * @param int $redirects The recursion counter for internal use - default 0 + * @param array $opts (optional parameters) assoziative array with: + * 'accept_content' => supply Accept: header with 'accept_content' as the value + * 'timeout' => int Timeout in seconds, default system config value or 60 seconds + * 'http_auth' => username:password + * 'novalidate' => do not validate SSL certs, default is to validate using our CA list + * 'nobody' => only return the header + * 'cookiejar' => path to cookie jar file + * + * @return array an assoziative array with: + * int 'return_code' => HTTP return code or 0 if timeout or failure + * boolean 'success' => boolean true (if HTTP 2xx result) or false + * string 'redirect_url' => in case of redirect, content was finally retrieved from this URL + * string 'header' => HTTP headers + * string 'body' => fetched content + */ + public static function zFetchURL($url, $binary = false, &$redirects = 0, $opts = []) + { + $ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '']; + + $stamp1 = microtime(true); + + $a = get_app(); + + if (blocked_url($url)) { + logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA); + return $ret; + } + + $ch = @curl_init($url); + + if (($redirects > 8) || (!$ch)) { + return $ret; + } + + @curl_setopt($ch, CURLOPT_HEADER, true); + + if (x($opts, "cookiejar")) { + curl_setopt($ch, CURLOPT_COOKIEJAR, $opts["cookiejar"]); + curl_setopt($ch, CURLOPT_COOKIEFILE, $opts["cookiejar"]); + } + + // These settings aren't needed. We're following the location already. + // @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + // @curl_setopt($ch, CURLOPT_MAXREDIRS, 5); + + if (x($opts, 'accept_content')) { + curl_setopt( + $ch, + CURLOPT_HTTPHEADER, + ['Accept: ' . $opts['accept_content']] + ); + } + + @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + @curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); + + $range = intval(Config::get('system', 'curl_range_bytes', 0)); + + if ($range > 0) { + @curl_setopt($ch, CURLOPT_RANGE, '0-' . $range); + } + + // Without this setting it seems as if some webservers send compressed content + // This seems to confuse curl so that it shows this uncompressed. + /// @todo We could possibly set this value to "gzip" or something similar + curl_setopt($ch, CURLOPT_ENCODING, ''); + + if (x($opts, 'headers')) { + @curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); + } + + if (x($opts, 'nobody')) { + @curl_setopt($ch, CURLOPT_NOBODY, $opts['nobody']); + } + + if (x($opts, 'timeout')) { + @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); + } else { + $curl_time = Config::get('system', 'curl_timeout', 60); + @curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time)); + } + + // by default we will allow self-signed certs + // but you can override this + + $check_cert = Config::get('system', 'verifyssl'); + @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); + + if ($check_cert) { + @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + } + + $proxy = Config::get('system', 'proxy'); + + if (strlen($proxy)) { + @curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); + @curl_setopt($ch, CURLOPT_PROXY, $proxy); + $proxyuser = @Config::get('system', 'proxyuser'); + + if (strlen($proxyuser)) { + @curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser); + } + } + + if (Config::get('system', 'ipv4_resolve', false)) { + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + } + + if ($binary) { + @curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); + } + + $a->set_curl_code(0); + + // don't let curl abort the entire application + // if it throws any errors. + + $s = @curl_exec($ch); + $curl_info = @curl_getinfo($ch); + + // Special treatment for HTTP Code 416 + // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416 + if (($curl_info['http_code'] == 416) && ($range > 0)) { + @curl_setopt($ch, CURLOPT_RANGE, ''); + $s = @curl_exec($ch); + $curl_info = @curl_getinfo($ch); + } + + if (curl_errno($ch) !== CURLE_OK) { + logger('fetch_url error fetching ' . $url . ': ' . curl_error($ch), LOGGER_NORMAL); + } + + $ret['errno'] = curl_errno($ch); + + $base = $s; + $ret['info'] = $curl_info; + + $http_code = $curl_info['http_code']; + + logger('fetch_url ' . $url . ': ' . $http_code . " " . $s, LOGGER_DATA); + $header = ''; + + // Pull out multiple headers, e.g. proxy and continuation headers + // allow for HTTP/2.x without fixing code + + while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) { + $chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4); + $header .= $chunk; + $base = substr($base, strlen($chunk)); + } + + $a->set_curl_code($http_code); + $a->set_curl_content_type($curl_info['content_type']); + $a->set_curl_headers($header); + + if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + $new_location_info = @parse_url($curl_info['redirect_url']); + $old_location_info = @parse_url($curl_info['url']); + + $newurl = $curl_info['redirect_url']; + + if (($new_location_info['path'] == '') && ( $new_location_info['host'] != '')) { + $newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path']; + } + + $matches = []; + + if (preg_match('/(Location:|URI:)(.*?)\n/i', $header, $matches)) { + $newurl = trim(array_pop($matches)); + } + if (strpos($newurl, '/') === 0) { + $newurl = $old_location_info["scheme"]."://".$old_location_info["host"].$newurl; + } + + if (filter_var($newurl, FILTER_VALIDATE_URL)) { + $redirects++; + @curl_close($ch); + return z_fetch_url($newurl, $binary, $redirects, $opts); + } + } + + $a->set_curl_code($http_code); + $a->set_curl_content_type($curl_info['content_type']); + + $rc = intval($http_code); + $ret['return_code'] = $rc; + $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); + $ret['redirect_url'] = $url; + + if (!$ret['success']) { + $ret['error'] = curl_error($ch); + $ret['debug'] = $curl_info; + logger('z_fetch_url: error: '.$url.': '.$ret['return_code'].' - '.$ret['error'], LOGGER_DEBUG); + logger('z_fetch_url: debug: '.print_r($curl_info, true), LOGGER_DATA); + } + + $ret['body'] = substr($s, strlen($header)); + $ret['header'] = $header; + + if (x($opts, 'debug')) { + $ret['debug'] = $curl_info; + } + + @curl_close($ch); + + $a->save_timestamp($stamp1, 'network'); + + return($ret); + } + + /** + * @brief Send POST request to $url + * + * @param string $url URL to post + * @param mixed $params array of POST variables + * @param string $headers HTTP headers + * @param integer $redirects Recursion counter for internal use - default = 0 + * @param integer $timeout The timeout in seconds, default system config value or 60 seconds + * + * @return string The content + */ + public static function postURL($url, $params, $headers = null, &$redirects = 0, $timeout = 0) + { + $stamp1 = microtime(true); + + if (blocked_url($url)) { + logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA); + return false; + } + + $a = get_app(); + $ch = curl_init($url); + + if (($redirects > 8) || (!$ch)) { + return false; + } + + logger('post_url: start ' . $url, LOGGER_DATA); + + curl_setopt($ch, CURLOPT_HEADER, true); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); + + if (Config::get('system', 'ipv4_resolve', false)) { + curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); + } + + if (intval($timeout)) { + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + } else { + $curl_time = Config::get('system', 'curl_timeout', 60); + curl_setopt($ch, CURLOPT_TIMEOUT, intval($curl_time)); + } + + if (defined('LIGHTTPD')) { + if (!is_array($headers)) { + $headers = ['Expect:']; + } else { + if (!in_array('Expect:', $headers)) { + array_push($headers, 'Expect:'); + } + } + } + + if ($headers) { + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + } + + $check_cert = Config::get('system', 'verifyssl'); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); + + if ($check_cert) { + @curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); + } + + $proxy = Config::get('system', 'proxy'); + + if (strlen($proxy)) { + curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); + curl_setopt($ch, CURLOPT_PROXY, $proxy); + $proxyuser = Config::get('system', 'proxyuser'); + if (strlen($proxyuser)) { + curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyuser); + } + } + + $a->set_curl_code(0); + + // don't let curl abort the entire application + // if it throws any errors. + + $s = @curl_exec($ch); + + $base = $s; + $curl_info = curl_getinfo($ch); + $http_code = $curl_info['http_code']; + + logger('post_url: result ' . $http_code . ' - ' . $url, LOGGER_DATA); + + $header = ''; + + // Pull out multiple headers, e.g. proxy and continuation headers + // allow for HTTP/2.x without fixing code + + while (preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/', $base)) { + $chunk = substr($base, 0, strpos($base, "\r\n\r\n") + 4); + $header .= $chunk; + $base = substr($base, strlen($chunk)); + } + + if ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307) { + $matches = []; + preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); + $newurl = trim(array_pop($matches)); + + if (strpos($newurl, '/') === 0) { + $newurl = $old_location_info["scheme"] . "://" . $old_location_info["host"] . $newurl; + } + + if (filter_var($newurl, FILTER_VALIDATE_URL)) { + $redirects++; + logger('post_url: redirect ' . $url . ' to ' . $newurl); + return post_url($newurl, $params, $headers, $redirects, $timeout); + } + } + + $a->set_curl_code($http_code); + + $body = substr($s, strlen($header)); + + $a->set_curl_headers($header); + + curl_close($ch); + + $a->save_timestamp($stamp1, 'network'); + + logger('post_url: end ' . $url, LOGGER_DATA); + + return $body; + } + + /** + * Generic XML return + * Outputs a basic dfrn XML status structure to STDOUT, with a variable + * of $st and an optional text of $message and terminates the current process. + */ + public static function xmlStatus($st, $message = '') + { + $result = ['status' => $st]; + + if ($message != '') { + $result['message'] = $message; + } + + if ($st) { + logger('xml_status returning non_zero: ' . $st . " message=" . $message); + } + + header("Content-type: text/xml"); + + $xmldata = ["result" => $result]; + + echo XML::fromArray($xmldata, $xml); + + killme(); + } + + /** + * @brief Send HTTP status header and exit. + * + * @param integer $val HTTP status result value + * @param array $description optional message + * 'title' => header title + * 'description' => optional message + */ + public static function httpStatusExit($val, $description = []) + { + $err = ''; + if ($val >= 400) { + $err = 'Error'; + if (!isset($description["title"])) { + $description["title"] = $err." ".$val; + } + } + + if ($val >= 200 && $val < 300) { + $err = 'OK'; + } + + logger('http_status_exit ' . $val); + header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); + + if (isset($description["title"])) { + $tpl = get_markup_template('http_status.tpl'); + echo replace_macros( + $tpl, + [ + '$title' => $description["title"], + '$description' => $description["description"]] + ); + } + + killme(); + } + + /** + * @brief Check URL to se if ts's real + * + * Take a URL from the wild, prepend http:// if necessary + * and check DNS to see if it's real (or check if is a valid IP address) + * + * @param string $url The URL to be validated + * @return string|boolean The actual working URL, false else + */ + public static function validateURL($url) + { + if (Config::get('system', 'disable_url_validation')) { + return $url; + } + + // no naked subdomains (allow localhost for tests) + if (strpos($url, '.') === false && strpos($url, '/localhost/') === false) { + return false; + } + + if (substr($url, 0, 4) != 'http') { + $url = 'http://' . $url; + } + + /// @TODO Really suppress function outcomes? Why not find them + debug them? + $h = @parse_url($url); + + if ((is_array($h)) && (@dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { + return $url; + } + + return false; + } + + /** + * @brief Checks that email is an actual resolvable internet address + * + * @param string $addr The email address + * @return boolean True if it's a valid email address, false if it's not + */ + public static function validateEmail($addr) + { + if (Config::get('system', 'disable_email_validation')) { + return true; + } + + if (! strpos($addr, '@')) { + return false; + } + + $h = substr($addr, strpos($addr, '@') + 1); + + if (($h) && (dns_get_record($h, DNS_A + DNS_CNAME + DNS_PTR + DNS_MX) || filter_var($h, FILTER_VALIDATE_IP) )) { + return true; + } + return false; + } + + /** + * @brief Check if URL is allowed + * + * Check $url against our list of allowed sites, + * wildcards allowed. If allowed_sites is unset return true; + * + * @param string $url URL which get tested + * @return boolean True if url is allowed otherwise return false + */ + public static function allowedURL($url) + { + $h = @parse_url($url); + + if (! $h) { + return false; + } + + $str_allowed = Config::get('system', 'allowed_sites'); + if (! $str_allowed) { + return true; + } + + $found = false; + + $host = strtolower($h['host']); + + // always allow our own site + if ($host == strtolower($_SERVER['SERVER_NAME'])) { + return true; + } + + $fnmatch = function_exists('fnmatch'); + $allowed = explode(',', $str_allowed); + + if (count($allowed)) { + foreach ($allowed as $a) { + $pat = strtolower(trim($a)); + if (($fnmatch && fnmatch($pat, $host)) || ($pat == $host)) { + $found = true; + break; + } + } + } + return $found; + } + + /** + * Checks if the provided url domain is on the domain blocklist. + * Returns true if it is or malformed URL, false if not. + * + * @param string $url The url to check the domain from + * + * @return boolean + */ + public static function blockedURL($url) + { + $h = @parse_url($url); + + if (! $h) { + return true; + } + + $domain_blocklist = Config::get('system', 'blocklist', []); + if (! $domain_blocklist) { + return false; + } + + $host = strtolower($h['host']); + + foreach ($domain_blocklist as $domain_block) { + if (strtolower($domain_block['domain']) == $host) { + return true; + } + } + + return false; + } + + /** + * @brief Check if email address is allowed to register here. + * + * Compare against our list (wildcards allowed). + * + * @param string $email email address + * @return boolean False if not allowed, true if allowed + * or if allowed list is not configured + */ + public static function allowedEmail($email) + { + $domain = strtolower(substr($email, strpos($email, '@') + 1)); + if (!$domain) { + return false; + } + + $str_allowed = Config::get('system', 'allowed_email', ''); + if (!x($str_allowed)) { + return true; + } + + $allowed = explode(',', $str_allowed); + + return allowed_domain($domain, $allowed); + } + + /** + * Checks for the existence of a domain in a domain list + * + * @brief Checks for the existence of a domain in a domain list + * @param string $domain + * @param array $domain_list + * @return boolean + */ + public static function allowedDomain($domain, array $domain_list) + { + $found = false; + + foreach ($domain_list as $item) { + $pat = strtolower(trim($item)); + if (fnmatch($pat, $domain) || ($pat == $domain)) { + $found = true; + break; + } + } + + return $found; + } + + public static function avatarImg($email) + { + $avatar['size'] = 175; + $avatar['email'] = $email; + $avatar['url'] = ''; + $avatar['success'] = false; + + Addon::callHooks('avatar_lookup', $avatar); + + if (! $avatar['success']) { + $avatar['url'] = System::baseUrl() . '/images/person-175.jpg'; + } + + logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG); + return $avatar['url']; + } + + public static function parseXmlString($s, $strict = true) + { + // the "strict" parameter is deactivated + + /// @todo Move this function to the xml class + libxml_use_internal_errors(true); + + $x = @simplexml_load_string($s); + if (!$x) { + logger('libxml: parse: error: ' . $s, LOGGER_DATA); + foreach (libxml_get_errors() as $err) { + logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA); + } + libxml_clear_errors(); + } + return $x; + } + + public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) + { + // Suppress "view full size" + if (intval(Config::get('system', 'no_view_full_size'))) { + $include_link = false; + } + + // Picture addresses can contain special characters + $s = htmlspecialchars_decode($srctext); + + $matches = null; + $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); + if ($c) { + foreach ($matches as $mtch) { + logger('scale_external_image: ' . $mtch[1]); + + $hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3)); + if (stristr($mtch[1], $hostname)) { + continue; + } + + // $scale_replace, if passed, is an array of two elements. The + // first is the name of the full-size image. The second is the + // name of a remote, scaled-down version of the full size image. + // This allows Friendica to display the smaller remote image if + // one exists, while still linking to the full-size image + if ($scale_replace) { + $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]); + } else { + $scaled = $mtch[1]; + } + $i = fetch_url($scaled); + if (! $i) { + return $srctext; + } + + // guess mimetype from headers or filename + $type = Image::guessType($mtch[1], true); + + if ($i) { + $Image = new Image($i, $type); + if ($Image->isValid()) { + $orig_width = $Image->getWidth(); + $orig_height = $Image->getHeight(); + + if ($orig_width > 640 || $orig_height > 640) { + $Image->scaleDown(640); + $new_width = $Image->getWidth(); + $new_height = $Image->getHeight(); + logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); + $s = str_replace( + $mtch[0], + '[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' + . "\n" . (($include_link) + ? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n" + : ''), + $s + ); + logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); + } + } + } + } + } + + // replace the special char encoding + $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); + return $s; + } + + public static function fixContactSslPolicy(&$contact, $new_policy) + { + $ssl_changed = false; + if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) { + $ssl_changed = true; + $contact['url'] = str_replace('https:', 'http:', $contact['url']); + $contact['request'] = str_replace('https:', 'http:', $contact['request']); + $contact['notify'] = str_replace('https:', 'http:', $contact['notify']); + $contact['poll'] = str_replace('https:', 'http:', $contact['poll']); + $contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']); + $contact['poco'] = str_replace('https:', 'http:', $contact['poco']); + } + + if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) { + $ssl_changed = true; + $contact['url'] = str_replace('http:', 'https:', $contact['url']); + $contact['request'] = str_replace('http:', 'https:', $contact['request']); + $contact['notify'] = str_replace('http:', 'https:', $contact['notify']); + $contact['poll'] = str_replace('http:', 'https:', $contact['poll']); + $contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']); + $contact['poco'] = str_replace('http:', 'https:', $contact['poco']); + } + + if ($ssl_changed) { + $fields = ['url' => $contact['url'], 'request' => $contact['request'], + 'notify' => $contact['notify'], 'poll' => $contact['poll'], + 'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; + dba::update('contact', $fields, ['id' => $contact['id']]); + } + } + + /** + * @brief Remove Google Analytics and other tracking platforms params from URL + * + * @param string $url Any user-submitted URL that may contain tracking params + * @return string The same URL stripped of tracking parameters + */ + public static function stripTrackingQueryParams($url) + { + $urldata = parse_url($url); + if (is_string($urldata["query"])) { + $query = $urldata["query"]; + parse_str($query, $querydata); + + if (is_array($querydata)) { + foreach ($querydata as $param => $value) { + if (in_array( + $param, + [ + "utm_source", "utm_medium", "utm_term", "utm_content", "utm_campaign", + "wt_mc", "pk_campaign", "pk_kwd", "mc_cid", "mc_eid", + "fb_action_ids", "fb_action_types", "fb_ref", + "awesm", "wtrid", + "woo_campaign", "woo_source", "woo_medium", "woo_content", "woo_term"] + ) + ) { + $pair = $param . "=" . urlencode($value); + $url = str_replace($pair, "", $url); + + // Second try: if the url isn't encoded completely + $pair = $param . "=" . str_replace(" ", "+", $value); + $url = str_replace($pair, "", $url); + + // Third try: Maybey the url isn't encoded at all + $pair = $param . "=" . $value; + $url = str_replace($pair, "", $url); + + $url = str_replace(["?&", "&&"], ["?", ""], $url); + } + } + } + + if (substr($url, -1, 1) == "?") { + $url = substr($url, 0, -1); + } + } + + return $url; + } + + /** + * @brief Returns the original URL of the provided URL + * + * This function strips tracking query params and follows redirections, either + * through HTTP code or meta refresh tags. Stops after 10 redirections. + * + * @todo Remove the $fetchbody parameter that generates an extraneous HEAD request + * + * @see ParseUrl::getSiteinfo + * + * @param string $url A user-submitted URL + * @param int $depth The current redirection recursion level (internal) + * @param bool $fetchbody Wether to fetch the body or not after the HEAD requests + * @return string A canonical URL + */ + public static function originalURL($url, $depth = 1, $fetchbody = false) + { + $a = get_app(); + + $url = strip_tracking_query_params($url); + + if ($depth > 10) { + return($url); + } + + $url = trim($url, "'"); + + $stamp1 = microtime(true); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_NOBODY, 1); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); + + curl_exec($ch); + $curl_info = @curl_getinfo($ch); + $http_code = $curl_info['http_code']; + curl_close($ch); + + $a->save_timestamp($stamp1, "network"); + + if ($http_code == 0) { + return($url); + } + + if ((($curl_info['http_code'] == "301") || ($curl_info['http_code'] == "302")) + && (($curl_info['redirect_url'] != "") || ($curl_info['location'] != "")) + ) { + if ($curl_info['redirect_url'] != "") { + return(original_url($curl_info['redirect_url'], ++$depth, $fetchbody)); + } else { + return(original_url($curl_info['location'], ++$depth, $fetchbody)); + } + } + + // Check for redirects in the meta elements of the body if there are no redirects in the header. + if (!$fetchbody) { + return(original_url($url, ++$depth, true)); + } + + // if the file is too large then exit + if ($curl_info["download_content_length"] > 1000000) { + return($url); + } + + // if it isn't a HTML file then exit + if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]), "html")) { + return($url); + } + + $stamp1 = microtime(true); + + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HEADER, 0); + curl_setopt($ch, CURLOPT_NOBODY, 0); + curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); + + $body = curl_exec($ch); + curl_close($ch); + + $a->save_timestamp($stamp1, "network"); + + if (trim($body) == "") { + return($url); + } + + // Check for redirect in meta elements + $doc = new DOMDocument(); + @$doc->loadHTML($body); + + $xpath = new DomXPath($doc); + + $list = $xpath->query("//meta[@content]"); + foreach ($list as $node) { + $attr = []; + if ($node->attributes->length) { + foreach ($node->attributes as $attribute) { + $attr[$attribute->name] = $attribute->value; + } + } + + if (@$attr["http-equiv"] == 'refresh') { + $path = $attr["content"]; + $pathinfo = explode(";", $path); + foreach ($pathinfo as $value) { + if (substr(strtolower($value), 0, 4) == "url=") { + return(original_url(substr($value, 4), ++$depth)); + } + } + } + } + + return $url; + } + + public static function shortLink($url) + { + $slinky = new Slinky($url); + $yourls_url = Config::get('yourls', 'url1'); + if ($yourls_url) { + $yourls_username = Config::get('yourls', 'username1'); + $yourls_password = Config::get('yourls', 'password1'); + $yourls_ssl = Config::get('yourls', 'ssl1'); + $yourls = new Slinky_YourLS(); + $yourls->set('username', $yourls_username); + $yourls->set('password', $yourls_password); + $yourls->set('ssl', $yourls_ssl); + $yourls->set('yourls-url', $yourls_url); + $slinky->set_cascade([$yourls, new Slinky_Ur1ca(), new Slinky_TinyURL()]); + } else { + // setup a cascade of shortening services + // try to get a short link from these services + // in the order ur1.ca, tinyurl + $slinky->set_cascade([new Slinky_Ur1ca(), new Slinky_TinyURL()]); + } + return $slinky->short(); + } + + /** + * @brief Encodes content to json + * + * This function encodes an array to json format + * and adds an application/json HTTP header to the output. + * After finishing the process is getting killed. + * + * @param array $x The input content + */ + public static function jsonReturnAndDie($x) + { + header("content-type: application/json"); + echo json_encode($x); + killme(); + } + + /** + * @brief Find the matching part between two url + * + * @param string $url1 + * @param string $url2 + * @return string The matching part + */ + public static function matchingURL($url1, $url2) + { + if (($url1 == "") || ($url2 == "")) { + return ""; + } + + $url1 = normalise_link($url1); + $url2 = normalise_link($url2); + + $parts1 = parse_url($url1); + $parts2 = parse_url($url2); + + if (!isset($parts1["host"]) || !isset($parts2["host"])) { + return ""; + } + + if ($parts1["scheme"] != $parts2["scheme"]) { + return ""; + } + + if ($parts1["host"] != $parts2["host"]) { + return ""; + } + + if ($parts1["port"] != $parts2["port"]) { + return ""; + } + + $match = $parts1["scheme"]."://".$parts1["host"]; + + if ($parts1["port"]) { + $match .= ":".$parts1["port"]; + } + + $pathparts1 = explode("/", $parts1["path"]); + $pathparts2 = explode("/", $parts2["path"]); + + $i = 0; + $path = ""; + do { + $path1 = $pathparts1[$i]; + $path2 = $pathparts2[$i]; + + if ($path1 == $path2) { + $path .= $path1."/"; + } + } while (($path1 == $path2) && ($i++ <= count($pathparts1))); + + $match .= $path; + + return normalise_link($match); + } + + /** + * @brief Glue url parts together + * + * @param array $parsed URL parts + * + * @return string The glued URL + */ + public static function unParseURL($parsed) + { + $get = function ($key) use ($parsed) { + return isset($parsed[$key]) ? $parsed[$key] : null; + }; + + $pass = $get('pass'); + $user = $get('user'); + $userinfo = $pass !== null ? "$user:$pass" : $user; + $port = $get('port'); + $scheme = $get('scheme'); + $query = $get('query'); + $fragment = $get('fragment'); + $authority = ($userinfo !== null ? $userinfo."@" : '') . + $get('host') . + ($port ? ":$port" : ''); + + return (strlen($scheme) ? $scheme.":" : '') . + (strlen($authority) ? "//".$authority : '') . + $get('path') . + (strlen($query) ? "?".$query : '') . + (strlen($fragment) ? "#".$fragment : ''); + } +} From c67452f72e34cfa94977dd8b6f4a8fdd09e79523 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:09:48 -0500 Subject: [PATCH 02/13] Move fetch_url move fetch_url function --- include/api.php | 3 ++- include/bbcode.php | 7 ++++--- include/network.php | 2 +- mod/dfrn_poll.php | 5 +++-- mod/dfrn_request.php | 3 ++- mod/dirfind.php | 3 ++- mod/install.php | 5 +++-- mod/nodeinfo.php | 3 ++- mod/oexchange.php | 3 ++- mod/proxy.php | 3 ++- mod/pubsubhubbub.php | 3 ++- spec/dfrn2_contact_request.svg | 4 ++-- src/Content/OEmbed.php | 7 ++++--- src/Core/Worker.php | 4 ++-- src/Model/GContact.php | 3 ++- src/Model/Photo.php | 3 ++- src/Model/User.php | 3 ++- src/Object/Image.php | 3 ++- src/Protocol/Diaspora.php | 6 +++--- src/Protocol/PortableContact.php | 3 ++- src/Protocol/Salmon.php | 3 ++- src/Util/Network.php | 2 +- src/Worker/CheckVersion.php | 3 ++- src/Worker/Directory.php | 3 ++- src/Worker/DiscoverPoCo.php | 3 ++- 25 files changed, 55 insertions(+), 35 deletions(-) diff --git a/include/api.php b/include/api.php index 8579d2d185..610cd26dda 100644 --- a/include/api.php +++ b/include/api.php @@ -35,6 +35,7 @@ use Friendica\Network\HTTPException\UnauthorizedException; use Friendica\Network\HTTPException\TooManyRequestsException; use Friendica\Object\Image; use Friendica\Protocol\Diaspora; +use Friendica\Util\Network; use Friendica\Util\XML; require_once 'include/bbcode.php'; @@ -5073,7 +5074,7 @@ function api_get_nick($profile) if ($StatusnetHost != $profile) { $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); if ($StatusnetUser != $profile) { - $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); + $UserData = Network::fetchURL("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); if ($user) { $nick = $user->screen_name; diff --git a/include/bbcode.php b/include/bbcode.php index dfaed8ef78..0544c4c616 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -13,6 +13,7 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Model\Contact; use Friendica\Util\Map; +use Friendica\Util\Network; require_once 'include/event.php'; require_once 'mod/proxy.php'; @@ -688,7 +689,7 @@ function GetProfileUsername($profile, $username, $compact = false, $getnetwork = $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); if ($StatusnetUser != $profile) { /// @TODO Some hosts run on https, not just http and sometimes http is disabled, let's support both here - $UserData = fetch_url("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); + $UserData = Network::fetchURL("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); if ($user) { if ($getnetwork) { @@ -749,7 +750,7 @@ function bb_RemovePictureLinks($match) { // if its not a picture then look if its a page that contains a picture link require_once("include/network.php"); - $body = fetch_url($match[1]); + $body = Network::fetchURL($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); @@ -806,7 +807,7 @@ function bb_CleanPictureLinksSub($match) { // if its not a picture then look if its a page that contains a picture link require_once("include/network.php"); - $body = fetch_url($match[1]); + $body = Network::fetchURL($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); diff --git a/include/network.php b/include/network.php index 7798fd9cd8..f6a864a635 100644 --- a/include/network.php +++ b/include/network.php @@ -57,7 +57,7 @@ function blocked_url($url) return Network::blockedURL($url); } -function allowedEmail($email) +function allowed_email($email) { return Network::allowedEmail($email); } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index e5ca96934a..7b0785b6f3 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -11,6 +11,7 @@ use Friendica\Database\DBM; use Friendica\Module\Login; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; +use Friendica\Util\Network; require_once 'include/items.php'; @@ -98,7 +99,7 @@ function dfrn_poll_init(App $a) ); if (DBM::is_result($r)) { - $s = fetch_url($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); + $s = Network::fetchURL($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); @@ -481,7 +482,7 @@ function dfrn_poll_content(App $a) if (($type === 'profile') && (strlen($sec))) { // URL reply if ($dfrn_version < 2.2) { - $s = fetch_url($r[0]['poll'] + $s = Network::fetchURL($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' . '&dfrn_version=' . DFRN_PROTOCOL_VERSION diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index aada465ad2..18a6eefaf2 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -23,6 +23,7 @@ use Friendica\Model\User; use Friendica\Model\Profile; use Friendica\Module\Login; use Friendica\Network\Probe; +use Friendica\Util\Network; require_once 'include/enotify.php'; @@ -182,7 +183,7 @@ function dfrn_request_post(App $a) } if (strlen($dfrn_request) && strlen($confirm_key)) { - $s = fetch_url($dfrn_request . '?confirm_key=' . $confirm_key); + $s = Network::fetchURL($dfrn_request . '?confirm_key=' . $confirm_key); } // (ignore reply, nothing we can do it failed) diff --git a/mod/dirfind.php b/mod/dirfind.php index f1119a2979..c010aaac92 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -14,6 +14,7 @@ use Friendica\Model\GContact; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; require_once 'mod/contacts.php'; @@ -177,7 +178,7 @@ function dirfind_content(App $a, $prefix = "") { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); if(strlen(Config::get('system','directory'))) - $x = fetch_url(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::fetchURL(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); $j = json_decode($x); } diff --git a/mod/install.php b/mod/install.php index cbad3b2548..ef9f023f52 100644 --- a/mod/install.php +++ b/mod/install.php @@ -8,6 +8,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Database\DBStructure; use Friendica\Object\Image; +use Friendica\Util\Network; $install_wizard_pass = 1; @@ -482,10 +483,10 @@ function check_htaccess(&$checks) { $status = true; $help = ""; if (function_exists('curl_init')) { - $test = fetch_url(System::baseUrl()."/install/testrewrite"); + $test = Network::fetchURL(System::baseUrl()."/install/testrewrite"); if ($test != "ok") { - $test = fetch_url(normalise_link(System::baseUrl()."/install/testrewrite")); + $test = Network::fetchURL(normalise_link(System::baseUrl()."/install/testrewrite")); } if ($test != "ok") { diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index bcaf8e7a93..d0c4acab02 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -9,6 +9,7 @@ use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\System; use Friendica\Core\Config; +use Friendica\Util\Network; function nodeinfo_wellknown(App $a) { $nodeinfo = ['links' => [['rel' => 'http://nodeinfo.diaspora.software/ns/schema/1.0', @@ -246,7 +247,7 @@ function nodeinfo_cron() { // Now trying to register $url = 'http://the-federation.info/register/'.$a->get_hostname(); logger('registering url: '.$url, LOGGER_DEBUG); - $ret = fetch_url($url); + $ret = Network::fetchURL($url); logger('registering answer: '.$ret, LOGGER_DEBUG); logger('cron_end'); diff --git a/mod/oexchange.php b/mod/oexchange.php index 902499c031..79414a7f6a 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -6,6 +6,7 @@ use Friendica\App; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Module\Login; +use Friendica\Util\Network; function oexchange_init(App $a) { @@ -39,7 +40,7 @@ function oexchange_content(App $a) { $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); - $s = fetch_url(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + $s = Network::fetchURL(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); if (! strlen($s)) { return; diff --git a/mod/proxy.php b/mod/proxy.php index 538275ef00..1497185917 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -10,6 +10,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Photo; use Friendica\Object\Image; +use Friendica\Util\Network; define('PROXY_DEFAULT_TIME', 86400); // 1 Day @@ -161,7 +162,7 @@ function proxy_init(App $a) { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $redirects = 0; - $img_str = fetch_url($_REQUEST['url'], true, $redirects, 10); + $img_str = Network::fetchURL($_REQUEST['url'], true, $redirects, 10); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index f3134308fb..c2091d4de8 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -3,6 +3,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Database\DBM; +use Friendica\Util\Network; function post_var($name) { return (x($_POST, $name)) ? notags(trim($_POST[$name])) : ''; @@ -109,7 +110,7 @@ function pubsubhubbub_init(App $a) { // we don't actually enforce the lease time because GNU // Social/StatusNet doesn't honour it (yet) - $body = fetch_url($hub_callback . "?" . $params); + $body = Network::fetchURL($hub_callback . "?" . $params); $ret = $a->get_curl_code(); // give up if the HTTP return code wasn't a success (2xx) diff --git a/spec/dfrn2_contact_request.svg b/spec/dfrn2_contact_request.svg index e85eaf20b5..23b040985f 100644 --- a/spec/dfrn2_contact_request.svg +++ b/spec/dfrn2_contact_request.svg @@ -93,9 +93,9 @@ text { font:12px Dialog; } - create a contact for Karen in the contact table with the scraped data with blocked = 1 and pending = 1 (Karens pubkey becomes the contact site-pubkey) -- fetch_url($dfrn_request . '?confirm_key=' . +- Network::fetchURL($dfrn_request . '?confirm_key=' . $confirm_key); -- fetch_url(http://karenhomepage.com/dfrn_request? +- Network::fetchURL(http://karenhomepage.com/dfrn_request? confirm_key=”ABC123”) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 9f1df51745..80fab8c647 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -10,6 +10,7 @@ use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Database\DBM; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; use dba; use DOMDocument; @@ -77,7 +78,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery $redirects = 0; - $html_text = fetch_url($embedurl, false, $redirects, 15, "text/*"); + $html_text = Network::fetchURL($embedurl, false, $redirects, 15, "text/*"); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { @@ -85,13 +86,13 @@ class OEmbed $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = fetch_url($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); break; } $entries = $xpath->query("//link[@type='text/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = fetch_url($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); break; } } diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 893b1bccc8..11146e4a21 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -10,7 +10,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Process; use Friendica\Util\Lock; - +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -888,7 +888,7 @@ class Worker } $url = System::baseUrl()."/worker"; - fetch_url($url, false, $redirects, 1); + Network::fetchURL($url, false, $redirects, 1); } /** diff --git a/src/Model/GContact.php b/src/Model/GContact.php index d125ff8fe2..28c872f32c 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -13,6 +13,7 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; use dba; use Exception; @@ -568,7 +569,7 @@ class GContact $done[] = System::baseUrl() . '/poco'; if (strlen(Config::get('system', 'directory'))) { - $x = fetch_url(get_server()."/pubsites"); + $x = Network::fetchURL(get_server()."/pubsites"); if ($x) { $j = json_decode($x); if ($j->entries) { diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 94d5581bf0..23d893c925 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -12,6 +12,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Object\Image; +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -101,7 +102,7 @@ class Photo $photo_failure = false; $filename = basename($image_url); - $img_str = fetch_url($image_url, true); + $img_str = Network::fetchURL($image_url, true); if ($quit_on_error && ($img_str == "")) { return false; diff --git a/src/Model/User.php b/src/Model/User.php index 07df7ca615..ecd1040b75 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -17,6 +17,7 @@ use Friendica\Model\Group; use Friendica\Model\Photo; use Friendica\Object\Image; use Friendica\Util\Crypto; +use Friendica\Util\Network; use dba; use Exception; @@ -468,7 +469,7 @@ class User $photo_failure = false; $filename = basename($photo); - $img_str = fetch_url($photo, true); + $img_str = Network::fetchURL($photo, true); // guess mimetype from headers or filename $type = Image::guessType($photo, true); diff --git a/src/Object/Image.php b/src/Object/Image.php index 2feb3b9241..84c462205e 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -12,6 +12,7 @@ use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Photo; +use Friendica\Util\Network; use Exception; use Imagick; use ImagickPixel; @@ -773,7 +774,7 @@ class Image $data = Cache::get($url); if (is_null($data) || !$data || !is_array($data)) { - $img_str = fetch_url($url, true, $redirects, 4); + $img_str = Network::fetchURL($url, true, $redirects, 4); $filesize = strlen($img_str); if (function_exists("getimagesizefromstring")) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 540f82cc63..14bad8e1d9 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -25,8 +25,8 @@ use Friendica\Model\Queue; use Friendica\Model\User; use Friendica\Network\Probe; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; - use dba; use SimpleXMLElement; @@ -1257,7 +1257,7 @@ class Diaspora logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $envelope = fetch_url($source_url); + $envelope = Network::fetchURL($source_url); if ($envelope) { logger("Envelope was fetched.", LOGGER_DEBUG); $x = self::verifyMagicEnvelope($envelope); @@ -1275,7 +1275,7 @@ class Diaspora $source_url = $server."/p/".urlencode($guid).".xml"; logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $x = fetch_url($source_url); + $x = Network::fetchURL($source_url); if (!$x) { return false; } diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 22615fee10..65e71d07a9 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -15,6 +15,7 @@ use Friendica\Database\DBM; use Friendica\Model\GContact; use Friendica\Model\Profile; use Friendica\Network\Probe; +use Friendica\Util\Network; use dba; use DOMDocument; use DOMXPath; @@ -85,7 +86,7 @@ class PortableContact logger('load: ' . $url, LOGGER_DEBUG); - $s = fetch_url($url); + $s = Network::fetchURL($url); logger('load: returns ' . $s, LOGGER_DATA); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 5b0c66fb9d..3e8d368169 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -6,6 +6,7 @@ namespace Friendica\Protocol; use Friendica\Network\Probe; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; /** @@ -50,7 +51,7 @@ class Salmon $ret[$x] = substr($ret[$x], 5); } } elseif (normalise_link($ret[$x]) == 'http://') { - $ret[$x] = fetch_url($ret[$x]); + $ret[$x] = Network::fetchURL($ret[$x]); } } } diff --git a/src/Util/Network.php b/src/Util/Network.php index f25d9c9a26..39f2e03511 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -714,7 +714,7 @@ class Network } else { $scaled = $mtch[1]; } - $i = fetch_url($scaled); + $i = self::fetchURL($scaled); if (! $i) { return $srctext; } diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index b7e99cb67e..2e089502f1 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -8,6 +8,7 @@ namespace Friendica\Worker; use Friendica\Core\Config; +use Friendica\Util\Network; /** * @brief check the git repository VERSION file and save the version to the DB @@ -37,7 +38,7 @@ class CheckVersion { logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG); // fetch the VERSION file - $gitversion = dbesc(trim(fetch_url($checked_url))); + $gitversion = dbesc(trim(Network::fetchURL($checked_url))); logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG); Config::set('system', 'git_friendica_version', $gitversion); diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index e38f9eeeee..634c5a5ec5 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -10,6 +10,7 @@ use Friendica\Core\Addon; use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; +use Friendica\Util\Network; class Directory { public static function execute($url = '') { @@ -32,7 +33,7 @@ class Directory { logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG); if (strlen($arr['url'])) { - fetch_url($dir . '?url=' . bin2hex($arr['url'])); + Network::fetchURL($dir . '?url=' . bin2hex($arr['url'])); } return; diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index c00db89ff5..d72579cfb5 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -11,6 +11,7 @@ use Friendica\Database\DBM; use Friendica\Model\GContact; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; require_once 'include/datetime.php'; @@ -217,7 +218,7 @@ class DiscoverPoCo { } } - $x = fetch_url(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); + $x = Network::fetchURL(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); $j = json_decode($x); if (count($j->results)) { From 2f9642392dcd40fd6d949d607c0cafa337d4637e Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:18:38 -0500 Subject: [PATCH 03/13] Move z_fetch_url move z_fetch_url method --- include/acl_selectors.php | 3 ++- include/network.php | 10 ------- mod/ostatus_subscribe.php | 3 ++- mod/parse_url.php | 3 ++- src/Model/GContact.php | 2 +- src/Network/Probe.php | 17 ++++++------ src/Protocol/DFRN.php | 3 ++- src/Protocol/OStatus.php | 15 ++++++----- src/Protocol/PortableContact.php | 46 ++++++++++++++++---------------- src/Util/ExAuth.php | 4 +-- src/Util/Network.php | 2 +- src/Util/ParseUrl.php | 3 ++- src/Worker/DiscoverPoCo.php | 2 +- src/Worker/OnePoll.php | 5 ++-- 14 files changed, 58 insertions(+), 60 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 599b543ad0..38a418dd1c 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -11,6 +11,7 @@ use Friendica\Core\L10n; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\GContact; +use Friendica\Util\Network; require_once "mod/proxy.php"; @@ -733,7 +734,7 @@ function navbar_complete(App $a) { if (! $localsearch) { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - $x = z_fetch_url(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::zFetchURL(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); if ($x['success']) { $j = json_decode($x['body'],true); if ($j && isset($j['results'])) { diff --git a/include/network.php b/include/network.php index f6a864a635..7f1bbb6d83 100644 --- a/include/network.php +++ b/include/network.php @@ -12,16 +12,6 @@ use Friendica\Object\Image; use Friendica\Util\Network; use Friendica\Util\XML; -function fetch_url($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) -{ - return Network::fetchURL($url, $binary, $redirects, $timeout, $accept_content, $cookiejar); -} - -function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = []) -{ - return Network::zFetchURL($url, $binary, $redirects, $opts); -} - function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) { return Network::postURL($url, $params, $headers, $redirects, $timeout); diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 295ccfee61..81eced22e7 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -8,6 +8,7 @@ use Friendica\Core\PConfig; use Friendica\Core\System; use Friendica\Model\Contact; use Friendica\Network\Probe; +use Friendica\Util\Network; function ostatus_subscribe_content(App $a) { @@ -40,7 +41,7 @@ function ostatus_subscribe_content(App $a) { $api = $contact["baseurl"]."/api/"; // Fetching friends - $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]); + $data = Network::zFetchURL($api."statuses/friends.json?screen_name=".$contact["nick"]); if (!$data["success"]) { return $o.L10n::t("Couldn't fetch friends for contact."); diff --git a/mod/parse_url.php b/mod/parse_url.php index 6fb404f1b0..f1214e160f 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -12,6 +12,7 @@ use Friendica\App; use Friendica\Core\Addon; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; require_once("include/items.php"); @@ -60,7 +61,7 @@ function parse_url_content(App $a) { // the URL with the corresponding BBCode media tag $redirects = 0; // Fetch the header of the URL - $result = z_fetch_url($url, false, $redirects, ["novalidate" => true, "nobody" => true]); + $result = Network::zFetchURL($url, false, $redirects, ["novalidate" => true, "nobody" => true]); if($result["success"]) { // Convert the header fields into an array $hdrs = []; diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 28c872f32c..231970820f 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -981,7 +981,7 @@ class GContact $url = $server."/main/statistics"; - $result = z_fetch_url($url); + $result = Network::zFetchURL($url); if (!$result["success"]) { return false; } diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 2cc855216b..94fd929e10 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -18,6 +18,7 @@ use Friendica\Model\Profile; use Friendica\Protocol\Email; use Friendica\Protocol\Feed; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; @@ -107,7 +108,7 @@ class Probe logger("Probing for ".$host, LOGGER_DEBUG); - $ret = z_fetch_url($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::zFetchURL($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['success']) { $xml = $ret['body']; $xrd = parse_xml_string($xml, false); @@ -115,7 +116,7 @@ class Probe } if (!is_object($xrd)) { - $ret = z_fetch_url($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { logger("Probing timeout for ".$url, LOGGER_DEBUG); return false; @@ -692,7 +693,7 @@ class Probe $xrd_timeout = Config::get('system', 'xrd_timeout', 20); $redirects = 0; - $ret = z_fetch_url($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); + $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -759,7 +760,7 @@ class Probe */ private static function pollNoscrape($noscrape_url, $data) { - $ret = z_fetch_url($noscrape_url); + $ret = Network::zFetchURL($noscrape_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -993,7 +994,7 @@ class Probe */ private static function pollHcard($hcard_url, $data, $dfrn = false) { - $ret = z_fetch_url($hcard_url); + $ret = Network::zFetchURL($hcard_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1232,7 +1233,7 @@ class Probe $pubkey = substr($pubkey, 5); } } elseif (normalise_link($pubkey) == 'http://') { - $ret = z_fetch_url($pubkey); + $ret = Network::zFetchURL($pubkey); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1264,7 +1265,7 @@ class Probe } // Fetch all additional data from the feed - $ret = z_fetch_url($data["poll"]); + $ret = Network::zFetchURL($data["poll"]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1448,7 +1449,7 @@ class Probe */ private static function feed($url, $probe = true) { - $ret = z_fetch_url($url); + $ret = Network::zFetchURL($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 808e8aaa2a..4289769e41 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -25,6 +25,7 @@ use Friendica\Model\User; use Friendica\Object\Image; use Friendica\Protocol\OStatus; use Friendica\Util\Crypto; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; @@ -1186,7 +1187,7 @@ class DFRN logger('dfrn_deliver: ' . $url); - $ret = z_fetch_url($url); + $ret = Network::zFetchURL($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return -2; // timed out diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 3b04a11d27..87b894a717 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -17,6 +17,7 @@ use Friendica\Model\Conversation; use Friendica\Network\Probe; use Friendica\Object\Image; use Friendica\Util\Lock; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; use DOMDocument; @@ -725,7 +726,7 @@ class OStatus self::$conv_list[$conversation] = true; - $conversation_data = z_fetch_url($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $conversation_data = Network::zFetchURL($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$conversation_data['success']) { return; @@ -753,7 +754,7 @@ class OStatus } } if ($file != '') { - $conversation_atom = z_fetch_url($attribute['href']); + $conversation_atom = Network::zFetchURL($attribute['href']); if ($conversation_atom['success']) { $xml = $conversation_atom['body']; @@ -869,7 +870,7 @@ class OStatus return; } - $self_data = z_fetch_url($self); + $self_data = Network::zFetchURL($self); if (!$self_data['success']) { return; @@ -914,7 +915,7 @@ class OStatus } $stored = false; - $related_data = z_fetch_url($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $related_data = Network::zFetchURL($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$related_data['success']) { return; @@ -945,7 +946,7 @@ class OStatus } } if ($atom_file != '') { - $related_atom = z_fetch_url($atom_file); + $related_atom = Network::zFetchURL($atom_file); if ($related_atom['success']) { logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG); @@ -957,7 +958,7 @@ class OStatus // Workaround for older GNU Social servers if (($xml == '') && strstr($related, '/notice/')) { - $related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); + $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG); @@ -968,7 +969,7 @@ class OStatus // Even more worse workaround for GNU Social ;-) if ($xml == '') { $related_guess = OStatus::convertHref($related_uri); - $related_atom = z_fetch_url(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); + $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG); diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 65e71d07a9..35ec7fe962 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -288,7 +288,7 @@ class PortableContact } // Fetch the host-meta to check if this really is a server - $serverret = z_fetch_url($server_url."/.well-known/host-meta"); + $serverret = Network::zFetchURL($server_url."/.well-known/host-meta"); if (!$serverret["success"]) { return ""; } @@ -367,7 +367,7 @@ class PortableContact $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url))); if ($server) { - $noscraperet = z_fetch_url($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); + $noscraperet = Network::zFetchURL($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); if ($noscraperet["success"] && ($noscraperet["body"] != "")) { $noscrape = json_decode($noscraperet["body"], true); @@ -481,7 +481,7 @@ class PortableContact GContact::update($contact); - $feedret = z_fetch_url($data["poll"]); + $feedret = Network::zFetchURL($data["poll"]); if (!$feedret["success"]) { $fields = ['last_failure' => datetime_convert()]; @@ -632,7 +632,7 @@ class PortableContact */ private static function fetchNodeinfo($server_url) { - $serverret = z_fetch_url($server_url."/.well-known/nodeinfo"); + $serverret = Network::zFetchURL($server_url."/.well-known/nodeinfo"); if (!$serverret["success"]) { return false; } @@ -664,7 +664,7 @@ class PortableContact return false; } - $serverret = z_fetch_url($nodeinfo_url); + $serverret = Network::zFetchURL($nodeinfo_url); if (!$serverret["success"]) { return false; } @@ -873,7 +873,7 @@ class PortableContact $server_url = str_replace("http://", "https://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout. // But we want to make sure to only quit if we are mostly sure that this server url fits. @@ -890,7 +890,7 @@ class PortableContact $server_url = str_replace("https://", "http://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = z_fetch_url($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { @@ -926,7 +926,7 @@ class PortableContact // Look for poco if (!$failure) { - $serverret = z_fetch_url($server_url."/poco"); + $serverret = Network::zFetchURL($server_url."/poco"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->totalResults)) { @@ -952,7 +952,7 @@ class PortableContact if (!$failure) { // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers - $serverret = z_fetch_url($server_url); + $serverret = Network::zFetchURL($server_url); if (!$serverret["success"] || ($serverret["body"] == "")) { $failure = true; @@ -991,7 +991,7 @@ class PortableContact // Test for Statusnet // Will also return data for Friendica and GNU Social - but it will be overwritten later // The "not implemented" is a special treatment for really, really old Friendica versions - $serverret = z_fetch_url($server_url."/api/statusnet/version.json"); + $serverret = Network::zFetchURL($server_url."/api/statusnet/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "StatusNet"; @@ -1002,7 +1002,7 @@ class PortableContact } // Test for GNU Social - $serverret = z_fetch_url($server_url."/api/gnusocial/version.json"); + $serverret = Network::zFetchURL($server_url."/api/gnusocial/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "GNU Social"; @@ -1014,7 +1014,7 @@ class PortableContact // Test for Mastodon $orig_version = $version; - $serverret = z_fetch_url($server_url."/api/v1/instance"); + $serverret = Network::zFetchURL($server_url."/api/v1/instance"); if ($serverret["success"] && ($serverret["body"] != '')) { $data = json_decode($serverret["body"]); @@ -1037,7 +1037,7 @@ class PortableContact if (!$failure) { // Test for Hubzilla and Red - $serverret = z_fetch_url($server_url."/siteinfo.json"); + $serverret = Network::zFetchURL($server_url."/siteinfo.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->url)) { @@ -1065,7 +1065,7 @@ class PortableContact } } else { // Test for Hubzilla, Redmatrix or Friendica - $serverret = z_fetch_url($server_url."/api/statusnet/config.json"); + $serverret = Network::zFetchURL($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->site->server)) { @@ -1120,7 +1120,7 @@ class PortableContact // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix if (!$failure) { - $serverret = z_fetch_url($server_url."/statistics.json"); + $serverret = Network::zFetchURL($server_url."/statistics.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); @@ -1182,10 +1182,10 @@ class PortableContact // Check for noscrape // Friendica servers could be detected as OStatus servers if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) { - $serverret = z_fetch_url($server_url."/friendica/json"); + $serverret = Network::zFetchURL($server_url."/friendica/json"); if (!$serverret["success"]) { - $serverret = z_fetch_url($server_url."/friendika/json"); + $serverret = Network::zFetchURL($server_url."/friendika/json"); } if ($serverret["success"]) { @@ -1295,7 +1295,7 @@ class PortableContact */ private static function fetchServerlist($poco) { - $serverret = z_fetch_url($poco."/@server"); + $serverret = Network::zFetchURL($poco."/@server"); if (!$serverret["success"]) { return; } @@ -1344,7 +1344,7 @@ class PortableContact if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $serverdata = z_fetch_url($api, false, $redirects, ['headers' => $header]); + $serverdata = Network::zFetchURL($api, false, $redirects, ['headers' => $header]); if ($serverdata['success']) { $servers = json_decode($serverdata['body']); foreach ($servers->instances as $server) { @@ -1361,7 +1361,7 @@ class PortableContact //if (!Config::get('system','ostatus_disabled')) { // $serverdata = "http://gstools.org/api/get_open_instances/"; - // $result = z_fetch_url($serverdata); + // $result = Network::zFetchURL($serverdata); // if ($result["success"]) { // $servers = json_decode($result["body"]); @@ -1390,7 +1390,7 @@ class PortableContact logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG); - $retdata = z_fetch_url($url); + $retdata = Network::zFetchURL($url); if ($retdata["success"]) { $data = json_decode($retdata["body"]); @@ -1409,7 +1409,7 @@ class PortableContact $success = false; - $retdata = z_fetch_url($url); + $retdata = Network::zFetchURL($url); if ($retdata["success"]) { logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); $success = self::discoverServer(json_decode($retdata["body"])); @@ -1494,7 +1494,7 @@ class PortableContact // Fetch all contacts from a given user from the other server $url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - $retdata = z_fetch_url($url); + $retdata = Network::zFetchURL($url); if ($retdata["success"]) { self::discoverServer(json_decode($retdata["body"]), 3); } diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 8940c02055..35e812a5c9 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -38,9 +38,9 @@ use Friendica\Core\Config; use Friendica\Core\PConfig; use Friendica\Database\DBM; use Friendica\Model\User; +use Friendica\Util\Network; use dba; -require_once 'include/dba.php'; require_once 'include/dba.php'; class ExAuth @@ -181,7 +181,7 @@ class ExAuth $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; - $data = z_fetch_url($url); + $data = Network::zFetchURL($url); if (!is_array($data)) { return false; diff --git a/src/Util/Network.php b/src/Util/Network.php index 39f2e03511..ebe6abda47 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -233,7 +233,7 @@ class Network if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @curl_close($ch); - return z_fetch_url($newurl, $binary, $redirects, $opts); + return self::zFetchURL($newurl, $binary, $redirects, $opts); } } diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index b03fcd9827..67aebb4c72 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -8,6 +8,7 @@ namespace Friendica\Util; use Friendica\Content\OEmbed; use Friendica\Core\Addon; use Friendica\Object\Image; +use Friendica\Util\Network; use Friendica\Util\XML; use dba; @@ -145,7 +146,7 @@ class ParseUrl $siteinfo["url"] = $url; $siteinfo["type"] = "link"; - $data = z_fetch_url($url); + $data = Network::zFetchURL($url); if (!$data['success']) { return($siteinfo); } diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index d72579cfb5..0172bcd342 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -281,7 +281,7 @@ class DiscoverPoCo { $url = "http://gstools.org/api/users_search/".urlencode($search); - $result = z_fetch_url($url); + $result = Network::zFetchURL($url); if (!$result["success"]) { return false; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 293cd265e2..98b5f77869 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -10,6 +10,7 @@ use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\Email; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -176,7 +177,7 @@ class OnePoll . '&type=data&last_update=' . $last_update . '&perm=' . $perm ; - $ret = z_fetch_url($url); + $ret = Network::zFetchURL($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { // set the last-update so we don't keep polling @@ -311,7 +312,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $ret = z_fetch_url($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); + $ret = Network::zFetchURL($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { From a32ba32ff468284641c55c4a08f8b6d949b33c0c Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:24:23 -0500 Subject: [PATCH 04/13] Move post_url move post_url function --- include/items.php | 3 ++- include/network.php | 5 ----- mod/dfrn_confirm.php | 3 ++- mod/dfrn_poll.php | 2 +- mod/match.php | 5 +++-- spec/dfrn2_contact_confirmation.svg | 2 +- src/Protocol/DFRN.php | 2 +- src/Protocol/Diaspora.php | 2 +- src/Protocol/Salmon.php | 9 ++++----- src/Util/Network.php | 2 +- src/Worker/OnePoll.php | 2 +- src/Worker/PubSubPublish.php | 3 ++- 12 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/items.php b/include/items.php index edc757dc2e..a1afbb3062 100644 --- a/include/items.php +++ b/include/items.php @@ -22,6 +22,7 @@ use Friendica\Object\Image; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; use Friendica\Protocol\Feed; +use Friendica\Util\Network; use Friendica\Util\ParseUrl; require_once 'include/bbcode.php'; @@ -1480,7 +1481,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { dba::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]); } - post_url($url, $params); + Network::postURL($url, $params); logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG); diff --git a/include/network.php b/include/network.php index 7f1bbb6d83..875597f764 100644 --- a/include/network.php +++ b/include/network.php @@ -12,11 +12,6 @@ use Friendica\Object\Image; use Friendica\Util\Network; use Friendica\Util\XML; -function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0) -{ - return Network::postURL($url, $params, $headers, $redirects, $timeout); -} - function xml_status($st, $message = '') { Network::xmlStatus($st, $message); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index a712e439f7..d3c84c54fa 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -30,6 +30,7 @@ use Friendica\Model\User; use Friendica\Network\Probe; use Friendica\Protocol\Diaspora; use Friendica\Util\Crypto; +use Friendica\Util\Network; require_once 'include/enotify.php'; require_once 'include/items.php'; @@ -220,7 +221,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) * */ - $res = post_url($dfrn_confirm, $params, null, $redirects, 120); + $res = Network::postURL($dfrn_confirm, $params, null, $redirects, 120); logger(' Confirm: received data: ' . $res, LOGGER_DATA); diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 7b0785b6f3..0392c2c920 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -490,7 +490,7 @@ function dfrn_poll_content(App $a) . '&sec=' . $sec ); } else { - $s = post_url($r[0]['poll'], [ + $s = Network::postURL($r[0]['poll'], [ 'dfrn_id' => $encrypted_id, 'type' => 'profile-check', 'dfrn_version' => DFRN_PROTOCOL_VERSION, diff --git a/mod/match.php b/mod/match.php index 47b24e9f7e..ad1e00101e 100644 --- a/mod/match.php +++ b/mod/match.php @@ -10,6 +10,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Profile; +use Friendica\Util\Network; require_once 'include/text.php'; require_once 'mod/proxy.php'; @@ -58,9 +59,9 @@ function match_content(App $a) } if (strlen(Config::get('system', 'directory'))) { - $x = post_url(get_server().'/msearch', $params); + $x = Network::postURL(get_server().'/msearch', $params); } else { - $x = post_url(System::baseUrl() . '/msearch', $params); + $x = Network::postURL(System::baseUrl() . '/msearch', $params); } $j = json_decode($x); diff --git a/spec/dfrn2_contact_confirmation.svg b/spec/dfrn2_contact_confirmation.svg index bb506a2328..53c2b6c19f 100644 --- a/spec/dfrn2_contact_confirmation.svg +++ b/spec/dfrn2_contact_confirmation.svg @@ -69,7 +69,7 @@ text { font:12px Dialog; } getting transmitted (if $aes_allow -> encrypt the the public key) -> add duplex state and page-flags to the params -> send params to Bobs dfrn_confirm page ($res = -post_url($dfrn_confirm,$params); +Network::postURL($dfrn_confirm,$params); dfrn_confirm_post() diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 4289769e41..aed68e704f 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1333,7 +1333,7 @@ class DFRN logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars, true), LOGGER_DATA); - $xml = post_url($contact['notify'], $postvars); + $xml = Network::postURL($contact['notify'], $postvars); logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 14bad8e1d9..2ad4fadb11 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3229,7 +3229,7 @@ class Diaspora if (!intval(Config::get("system", "diaspora_test"))) { $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); - post_url($dest_url."/", $envelope, ["Content-Type: ".$content_type]); + Network::postURL($dest_url."/", $envelope, ["Content-Type: ".$content_type]); $return_code = $a->get_curl_code(); } else { logger("test_mode"); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 3e8d368169..f49225021e 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -133,7 +133,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - post_url($url, $salmon, [ + Network::postURL($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) ]); @@ -159,7 +159,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - post_url($url, $salmon, [ + Network::postURL($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) ]); @@ -182,10 +182,9 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - post_url($url, $salmon, [ + Network::postURL($url, $salmon, [ 'Content-type: application/magic-envelope+xml', - 'Content-length: ' . strlen($salmon)] - ); + 'Content-length: ' . strlen($salmon)]); $return_code = $a->get_curl_code(); } diff --git a/src/Util/Network.php b/src/Util/Network.php index ebe6abda47..e0400c7f0a 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -380,7 +380,7 @@ class Network if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; logger('post_url: redirect ' . $url . ' to ' . $newurl); - return post_url($newurl, $params, $headers, $redirects, $timeout); + return self::postURL($newurl, $params, $headers, $redirects, $timeout); } } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index 98b5f77869..b4e7bc20c4 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -281,7 +281,7 @@ class OnePoll $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['perm'] = 'rw'; - $xml = post_url($contact['poll'], $postvars); + $xml = Network::postURL($contact['poll'], $postvars); } elseif (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index 2656cef24b..a287e89d33 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -11,6 +11,7 @@ use Friendica\Core\Config; use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Protocol\OStatus; +use Friendica\Util\Network; require_once 'include/items.php'; @@ -68,7 +69,7 @@ class PubSubPublish { logger('POST '.print_r($headers, true)."\n".$params, LOGGER_DEBUG); - post_url($rr['callback_url'], $params, $headers); + Network::postURL($rr['callback_url'], $params, $headers); $ret = $a->get_curl_code(); if ($ret >= 200 && $ret <= 299) { From cd3643d17485aa1000c41312f5b363788e755c49 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:37:55 -0500 Subject: [PATCH 05/13] Move xml_status and http_status_exit move functions --- include/network.php | 10 ---------- mod/_well_known.php | 9 +++++---- mod/dfrn_confirm.php | 18 +++++++++--------- mod/dfrn_notify.php | 15 ++++++++------- mod/dfrn_poll.php | 20 ++++++++++---------- mod/display.php | 3 ++- mod/hovercard.php | 3 ++- mod/nodeinfo.php | 4 ++-- mod/poco.php | 11 ++++++----- mod/probe.php | 3 ++- mod/pubsubhubbub.php | 20 ++++++++++---------- mod/receive.php | 13 +++++++------ mod/salmon.php | 15 ++++++++------- mod/search.php | 5 +++-- mod/statistics_json.php | 3 ++- mod/webfinger.php | 3 ++- src/Module/Feed.php | 3 ++- src/Protocol/Diaspora.php | 14 +++++++------- 18 files changed, 87 insertions(+), 85 deletions(-) diff --git a/include/network.php b/include/network.php index 875597f764..726eac7570 100644 --- a/include/network.php +++ b/include/network.php @@ -12,16 +12,6 @@ use Friendica\Object\Image; use Friendica\Util\Network; use Friendica\Util\XML; -function xml_status($st, $message = '') -{ - Network::xmlStatus($st, $message); -} - -function http_status_exit($val, $description = []) -{ - Network::httpStatusExit($val, $description); -} - function validate_url($url) { return Network::validateURL($url); diff --git a/mod/_well_known.php b/mod/_well_known.php index 4b37c0b97f..e7bc8c92bf 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -2,10 +2,11 @@ use Friendica\App; use Friendica\Core\Config; +use Friendica\Util\Network; -require_once("mod/hostxrd.php"); -require_once("mod/nodeinfo.php"); -require_once("mod/xrd.php"); +require_once 'mod/hostxrd.php'; +require_once 'mod/nodeinfo.php'; +require_once 'mod/xrd.php'; function _well_known_init(App $a) { @@ -25,7 +26,7 @@ function _well_known_init(App $a) break; } } - http_status_exit(404); + Network::httpStatusExit(404); killme(); } diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index d3c84c54fa..9e5f0f3d54 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -493,7 +493,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) $user = dba::selectFirst('user', [], ['nickname' => $node]); if (!DBM::is_result($user)) { $message = L10n::t('No user record found for \'%s\' ', $node); - xml_status(3, $message); // failure + Network::xmlStatus(3, $message); // failure // NOTREACHED } @@ -503,7 +503,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strstr($my_prvkey, 'PRIVATE KEY')) { $message = L10n::t('Our site encryption key is apparently messed up.'); - xml_status(3, $message); + Network::xmlStatus(3, $message); } // verify everything @@ -514,7 +514,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strlen($decrypted_source_url)) { $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.'); - xml_status(3, $message); + Network::xmlStatus(3, $message); // NOTREACHED } @@ -530,7 +530,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!DBM::is_result($contact)) { // this is either a bogus confirmation (?) or we deleted the original introduction. $message = L10n::t('Contact record was not found for you on our site.'); - xml_status(3, $message); + Network::xmlStatus(3, $message); return; // NOTREACHED } } @@ -544,7 +544,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!$foreign_pubkey) { $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url); - xml_status(3, $message); + Network::xmlStatus(3, $message); } $decrypted_dfrn_id = ""; @@ -560,7 +560,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (dba::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) { $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.'); - xml_status(1, $message); // Birthday paradox - duplicate dfrn-id + Network::xmlStatus(1, $message); // Birthday paradox - duplicate dfrn-id // NOTREACHED } @@ -571,7 +571,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { $message = L10n::t('Unable to set your contact credentials on our system.'); - xml_status(3, $message); + Network::xmlStatus(3, $message); } // It's possible that the other person also requested friendship. @@ -626,7 +626,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { // indicates schema is messed up or total db failure $message = L10n::t('Unable to update your contact profile details on our system'); - xml_status(3, $message); + Network::xmlStatus(3, $message); } // Otherwise everything seems to have worked and we are almost done. Yay! @@ -707,7 +707,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) } } } - xml_status(0); // Success + Network::xmlStatus(0); // Success return; // NOTREACHED ////////////////////// End of this scenario /////////////////////////////////////////////// } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 8903d66e35..142cafaa09 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -11,6 +11,7 @@ use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\DFRN; +use Friendica\Util\Network; require_once 'include/items.php'; require_once 'include/event.php'; @@ -48,7 +49,7 @@ function dfrn_notify_post(App $a) { ); if (! DBM::is_result($r)) { logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); - xml_status(3, 'Could not match challenge'); + Network::xmlStatus(3, 'Could not match challenge'); } $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'", @@ -70,7 +71,7 @@ function dfrn_notify_post(App $a) { $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id)); break; default: - xml_status(3, 'Invalid direction'); + Network::xmlStatus(3, 'Invalid direction'); break; // NOTREACHED } @@ -96,7 +97,7 @@ function dfrn_notify_post(App $a) { if (! DBM::is_result($r)) { logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); - xml_status(3, 'Contact not found'); + Network::xmlStatus(3, 'Contact not found'); //NOTREACHED } @@ -131,7 +132,7 @@ function dfrn_notify_post(App $a) { // Relationship is dissolved permanently Contact::remove($importer['id']); logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']); - xml_status(0, 'relationship dissolved'); + Network::xmlStatus(0, 'relationship dissolved'); } $rino = Config::get('system', 'rino_encrypt'); @@ -145,7 +146,7 @@ function dfrn_notify_post(App $a) { // but only for $remote_rino > 1, because old code did't send rino version if ($rino_remote > 1 && $rino < $rino_remote) { logger("rino version '$rino_remote' is lower than supported '$rino'"); - xml_status(0, "rino version '$rino_remote' is lower than supported '$rino'"); + Network::xmlStatus(0, "rino version '$rino_remote' is lower than supported '$rino'"); } $rawkey = hex2bin(trim($key)); @@ -175,14 +176,14 @@ function dfrn_notify_post(App $a) { break; default: logger("rino: invalid sent version '$rino_remote'"); - xml_status(0, "Invalid sent version '$rino_remote'"); + Network::xmlStatus(0, "Invalid sent version '$rino_remote'"); } logger('rino: decrypted data: ' . $data, LOGGER_DATA); } $ret = DFRN::import($data, $importer); - xml_status($ret, 'Processed'); + Network::xmlStatus($ret, 'Processed'); // NOTREACHED } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 0392c2c920..8841a7b5a6 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -48,7 +48,7 @@ function dfrn_poll_init(App $a) if (($dfrn_id === '') && (!x($_POST, 'dfrn_id'))) { if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { - http_status_exit(403); + Network::httpStatusExit(403); } $user = ''; @@ -57,7 +57,7 @@ function dfrn_poll_init(App $a) dbesc($a->argv[1]) ); if (!$r) { - http_status_exit(404); + Network::httpStatusExit(404); } $hidewall = ($r[0]['hidewall'] && !local_user()); @@ -144,7 +144,7 @@ function dfrn_poll_init(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - xml_status(3, 'No ticket'); + Network::xmlStatus(3, 'No ticket'); // NOTREACHED } @@ -157,7 +157,7 @@ function dfrn_poll_init(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - xml_status(3, 'No profile'); + Network::xmlStatus(3, 'No profile'); } $contact = $c[0]; @@ -184,7 +184,7 @@ function dfrn_poll_init(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - xml_status(3, 'Bad decryption'); + Network::xmlStatus(3, 'Bad decryption'); } header("Content-type: text/xml"); @@ -208,10 +208,10 @@ function dfrn_poll_init(App $a) $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC", dbesc($dfrn_id)); if (DBM::is_result($r)) { - xml_status(1); + Network::xmlStatus(1); return; // NOTREACHED } - xml_status(0); + Network::xmlStatus(0); return; // NOTREACHED } } @@ -236,7 +236,7 @@ function dfrn_poll_post(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - xml_status(3, 'No ticket'); + Network::xmlStatus(3, 'No ticket'); // NOTREACHED } @@ -249,7 +249,7 @@ function dfrn_poll_post(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - xml_status(3, 'No profile'); + Network::xmlStatus(3, 'No profile'); } $contact = $c[0]; @@ -276,7 +276,7 @@ function dfrn_poll_post(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - xml_status(3, 'Bad decryption'); + Network::xmlStatus(3, 'Bad decryption'); } header("Content-type: text/xml"); diff --git a/mod/display.php b/mod/display.php index d62b398a75..54a54be167 100644 --- a/mod/display.php +++ b/mod/display.php @@ -11,6 +11,7 @@ use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Profile; use Friendica\Protocol\DFRN; +use Friendica\Util\Network; function display_init(App $a) { @@ -423,7 +424,7 @@ function display_content(App $a, $update = false, $update_uid = 0) { function displayShowFeed($item_id, $conversation) { $xml = DFRN::itemFeed($item_id, $conversation); if ($xml == '') { - http_status_exit(500); + Network::httpStatusExit(500); } header("Content-type: application/atom+xml"); echo $xml; diff --git a/mod/hovercard.php b/mod/hovercard.php index 334bf228ab..29a23acdff 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -12,6 +12,7 @@ use Friendica\Core\Config; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\Profile; +use Friendica\Util\Network; function hovercard_init(App $a) { @@ -26,7 +27,7 @@ function hovercard_content() // Get out if the system doesn't have public access allowed if (intval(Config::get('system', 'block_public'))) { - http_status_exit(401); + Network::httpStatusExit(401); } // Return the raw content of the template. We use this to make templates usable for js functions. diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index d0c4acab02..b3d42ab52e 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -22,12 +22,12 @@ function nodeinfo_wellknown(App $a) { function nodeinfo_init(App $a) { if (!Config::get('system', 'nodeinfo')) { - http_status_exit(404); + Network::httpStatusExit(404); killme(); } if (($a->argc != 2) || ($a->argv[1] != '1.0')) { - http_status_exit(404); + Network::httpStatusExit(404); killme(); } diff --git a/mod/poco.php b/mod/poco.php index 761a9c2b80..348f76d1ce 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -8,12 +8,13 @@ use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Protocol\PortableContact; +use Friendica\Util\Network; function poco_init(App $a) { $system_mode = false; if (intval(Config::get('system', 'block_public')) || (Config::get('system', 'block_local_dir'))) { - http_status_exit(401); + Network::httpStatusExit(401); } if ($a->argc > 1) { @@ -22,7 +23,7 @@ function poco_init(App $a) { if (! x($user)) { $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); if (! DBM::is_result($c)) { - http_status_exit(401); + Network::httpStatusExit(401); } $system_mode = true; } @@ -63,7 +64,7 @@ function poco_init(App $a) { dbesc($user) ); if (! DBM::is_result($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) { - http_status_exit(404); + Network::httpStatusExit(404); } $user = $users[0]; @@ -357,7 +358,7 @@ function poco_init(App $a) { $ret['entry'][] = []; } } else { - http_status_exit(500); + Network::httpStatusExit(500); } logger("End of poco", LOGGER_DEBUG); @@ -371,6 +372,6 @@ function poco_init(App $a) { echo json_encode($ret); killme(); } else { - http_status_exit(500); + Network::httpStatusExit(500); } } diff --git a/mod/probe.php b/mod/probe.php index deb80c0de2..a7746d55bc 100644 --- a/mod/probe.php +++ b/mod/probe.php @@ -5,11 +5,12 @@ use Friendica\App; use Friendica\Core\L10n; use Friendica\Network\Probe; +use Friendica\Util\Network; function probe_content(App $a) { if (!local_user()) { - http_status_exit(403, ["title" => L10n::t("Public access denied."), + Network::httpStatusExit(403, ["title" => L10n::t("Public access denied."), "description" => L10n::t("Only logged in users are permitted to perform a probing.")]); killme(); } diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index c2091d4de8..af7172cee2 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -13,7 +13,7 @@ function pubsubhubbub_init(App $a) { // PuSH subscription must be considered "public" so just block it // if public access isn't enabled. if (Config::get('system', 'block_public')) { - http_status_exit(403); + Network::httpStatusExit(403); } // Subscription request from subscriber @@ -41,7 +41,7 @@ function pubsubhubbub_init(App $a) { $subscribe = 0; } else { logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring."); - http_status_exit(404); + Network::httpStatusExit(404); } logger("pubsubhubbub: $hub_mode request from " . @@ -57,7 +57,7 @@ function pubsubhubbub_init(App $a) { if (!$nick) { logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.'); - http_status_exit(404); + Network::httpStatusExit(404); } // fetch user from database given the nickname @@ -67,7 +67,7 @@ function pubsubhubbub_init(App $a) { if (!DBM::is_result($r)) { logger('pubsubhubbub: local account not found: ' . $nick); - http_status_exit(404); + Network::httpStatusExit(404); } $owner = $r[0]; @@ -76,7 +76,7 @@ function pubsubhubbub_init(App $a) { if ($r[0]['hidewall']) { logger('pubsubhubbub: local user ' . $nick . 'has chosen to hide wall, ignoring.'); - http_status_exit(403); + Network::httpStatusExit(403); } // get corresponding row from contact table @@ -85,7 +85,7 @@ function pubsubhubbub_init(App $a) { intval($owner['uid'])); if (!DBM::is_result($r)) { logger('pubsubhubbub: contact not found.'); - http_status_exit(404); + Network::httpStatusExit(404); } $contact = $r[0]; @@ -94,7 +94,7 @@ function pubsubhubbub_init(App $a) { if (!link_compare($hub_topic, $contact['poll'])) { logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' . $contact['poll']); - http_status_exit(404); + Network::httpStatusExit(404); } // do subscriber verification according to the PuSH protocol @@ -117,7 +117,7 @@ function pubsubhubbub_init(App $a) { if ($ret < 200 || $ret > 299) { logger("pubsubhubbub: subscriber verification at $hub_callback ". "returned $ret, ignoring."); - http_status_exit(404); + Network::httpStatusExit(404); } // check that the correct hub_challenge code was echoed back @@ -125,7 +125,7 @@ function pubsubhubbub_init(App $a) { logger("pubsubhubbub: subscriber did not echo back ". "hub.challenge, ignoring."); logger("\"$hub_challenge\" != \"".trim($body)."\""); - http_status_exit(404); + Network::httpStatusExit(404); } // fetch the old subscription if it exists @@ -163,7 +163,7 @@ function pubsubhubbub_init(App $a) { logger("pubsubhubbub: successfully unsubscribed [$hub_callback]."); // we do nothing here, since the row was already deleted } - http_status_exit(202); + Network::httpStatusExit(202); } killme(); diff --git a/mod/receive.php b/mod/receive.php index 0c7a7e0953..60b8ed7961 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -8,6 +8,7 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Database\DBM; use Friendica\Protocol\Diaspora; +use Friendica\Util\Network; /** * @param object $a App @@ -18,7 +19,7 @@ function receive_post(App $a) $enabled = intval(Config::get('system', 'diaspora_enabled')); if (!$enabled) { logger('mod-diaspora: disabled'); - http_status_exit(500); + Network::httpStatusExit(500); } if (($a->argc == 2) && ($a->argv[1] === 'public')) { @@ -28,13 +29,13 @@ function receive_post(App $a) $public = false; if ($a->argc != 3 || $a->argv[1] !== 'users') { - http_status_exit(500); + Network::httpStatusExit(500); } $guid = $a->argv[2]; $importer = dba::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]); if (!DBM::is_result($importer)) { - http_status_exit(500); + Network::httpStatusExit(500); } } @@ -47,7 +48,7 @@ function receive_post(App $a) if (!$xml) { $postdata = file_get_contents("php://input"); if ($postdata == '') { - http_status_exit(500); + Network::httpStatusExit(500); } logger('mod-diaspora: message is in the new format', LOGGER_DEBUG); @@ -67,7 +68,7 @@ function receive_post(App $a) logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA); if (!is_array($msg)) { - http_status_exit(500); + Network::httpStatusExit(500); } logger('mod-diaspora: dispatching', LOGGER_DEBUG); @@ -79,6 +80,6 @@ function receive_post(App $a) $ret = Diaspora::dispatch($importer, $msg); } - http_status_exit(($ret) ? 200 : 500); + Network::httpStatusExit(($ret) ? 200 : 500); // NOTREACHED } diff --git a/mod/salmon.php b/mod/salmon.php index d5b0fe2430..20806df559 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -9,6 +9,7 @@ use Friendica\Model\Contact; use Friendica\Protocol\OStatus; use Friendica\Protocol\Salmon; use Friendica\Util\Crypto; +use Friendica\Util\Network; require_once 'include/items.php'; @@ -38,7 +39,7 @@ function salmon_post(App $a) { dbesc($nick) ); if (! DBM::is_result($r)) { - http_status_exit(500); + Network::httpStatusExit(500); } $importer = $r[0]; @@ -58,7 +59,7 @@ function salmon_post(App $a) { if(! $base) { logger('mod-salmon: unable to locate salmon data in xml '); - http_status_exit(400); + Network::httpStatusExit(400); } // Stash the signature away for now. We have to find their key or it won't be good for anything. @@ -96,7 +97,7 @@ function salmon_post(App $a) { if(! $author_link) { logger('mod-salmon: Could not retrieve author URI.'); - http_status_exit(400); + Network::httpStatusExit(400); } // Once we have the author URI, go to the web and try to find their public key @@ -107,7 +108,7 @@ function salmon_post(App $a) { if(! $key) { logger('mod-salmon: Could not retrieve author key.'); - http_status_exit(400); + Network::httpStatusExit(400); } $key_info = explode('.',$key); @@ -139,7 +140,7 @@ function salmon_post(App $a) { if (! $verify) { logger('mod-salmon: Message did not verify. Discarding.'); - http_status_exit(400); + Network::httpStatusExit(400); } logger('mod-salmon: Message verified with mode '.$mode); @@ -183,7 +184,7 @@ function salmon_post(App $a) { //if((DBM::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { if (DBM::is_result($r) && $r[0]['blocked']) { logger('mod-salmon: Ignoring this author.'); - http_status_exit(202); + Network::httpStatusExit(202); // NOTREACHED } @@ -194,5 +195,5 @@ function salmon_post(App $a) { OStatus::import($data, $importer, $contact_rec, $hub); - http_status_exit(200); + Network::httpStatusExit(200); } diff --git a/mod/search.php b/mod/search.php index b48fafe785..681dbc9a52 100644 --- a/mod/search.php +++ b/mod/search.php @@ -9,6 +9,7 @@ use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Database\DBM; +use Friendica\Util\Network; require_once "include/bbcode.php"; require_once 'include/security.php'; @@ -99,7 +100,7 @@ function search_content(App $a) { } if (Config::get('system','local_search') && !local_user() && !remote_user()) { - http_status_exit(403, + Network::httpStatusExit(403, ["title" => L10n::t("Public access denied."), "description" => L10n::t("Only logged in users are permitted to perform a search.")]); killme(); @@ -124,7 +125,7 @@ function search_content(App $a) { if (!is_null($result)) { $resultdata = json_decode($result); if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) { - http_status_exit(429, + Network::httpStatusExit(429, ["title" => L10n::t("Too Many Requests"), "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]); killme(); diff --git a/mod/statistics_json.php b/mod/statistics_json.php index f2c6e074f9..75e89ba75e 100644 --- a/mod/statistics_json.php +++ b/mod/statistics_json.php @@ -7,11 +7,12 @@ use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; +use Friendica\Util\Network; function statistics_json_init(App $a) { if (!Config::get("system", "nodeinfo")) { - http_status_exit(404); + Network::httpStatusExit(404); killme(); } diff --git a/mod/webfinger.php b/mod/webfinger.php index 3e205ec030..f834e4ff36 100644 --- a/mod/webfinger.php +++ b/mod/webfinger.php @@ -5,11 +5,12 @@ use Friendica\App; use Friendica\Core\L10n; use Friendica\Network\Probe; +use Friendica\Util\Network; function webfinger_content(App $a) { if (!local_user()) { - http_status_exit( + Network::httpStatusExit( 403, [ "title" => L10n::t("Public access denied."), diff --git a/src/Module/Feed.php b/src/Module/Feed.php index 678e77e83a..efc5a097e8 100644 --- a/src/Module/Feed.php +++ b/src/Module/Feed.php @@ -4,6 +4,7 @@ namespace Friendica\Module; use Friendica\BaseModule; use Friendica\Protocol\OStatus; +use Friendica\Util\Network; /** * Provides public Atom feeds @@ -31,7 +32,7 @@ class Feed extends BaseModule $nocache = x($_GET, 'nocache') && local_user(); if ($a->argc < 2) { - http_status_exit(400); + Network::httpStatusExit(400); } $type = null; diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 2ad4fadb11..58e3f5aff6 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -285,7 +285,7 @@ class Diaspora if (!is_object($j_outer_key_bundle)) { logger('Outer Salmon did not verify. Discarding.'); - http_status_exit(400); + Network::httpStatusExit(400); } $outer_iv = base64_decode($j_outer_key_bundle->iv); @@ -300,7 +300,7 @@ class Diaspora if (!is_object($basedom)) { logger('Received data does not seem to be an XML. Discarding. '.$xml); - http_status_exit(400); + Network::httpStatusExit(400); } $base = $basedom->children(NAMESPACE_SALMON_ME); @@ -325,7 +325,7 @@ class Diaspora $verify = Crypto::rsaVerify($signed_data, $signature, $key); if (!$verify) { logger('Message did not verify. Discarding.'); - http_status_exit(400); + Network::httpStatusExit(400); } return ['message' => (string)base64url_decode($base->data), @@ -403,7 +403,7 @@ class Diaspora if (!$base) { logger('unable to locate salmon data in xml'); - http_status_exit(400); + Network::httpStatusExit(400); } @@ -441,7 +441,7 @@ class Diaspora if (!$author_link) { logger('Could not retrieve author URI.'); - http_status_exit(400); + Network::httpStatusExit(400); } // Once we have the author URI, go to the web and try to find their public key // (first this will look it up locally if it is in the fcontact cache) @@ -452,14 +452,14 @@ class Diaspora if (!$key) { logger('Could not retrieve author key.'); - http_status_exit(400); + Network::httpStatusExit(400); } $verify = Crypto::rsaVerify($signed_data, $signature, $key); if (!$verify) { logger('Message did not verify. Discarding.'); - http_status_exit(400); + Network::httpStatusExit(400); } logger('Message verified.'); From 1eb7c19c1e2018e183baa503a873d3a538a31758 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Fri, 26 Jan 2018 23:51:41 -0500 Subject: [PATCH 06/13] Move multiple functions move multiple smaller functions --- include/network.php | 36 ------------------------------------ mod/dfrn_request.php | 6 +++--- mod/dirfind.php | 2 +- mod/settings.php | 3 ++- src/Content/OEmbed.php | 2 +- src/Model/Contact.php | 5 +++-- src/Model/Profile.php | 3 ++- src/Model/User.php | 10 +++++----- src/Module/Login.php | 3 ++- src/Network/Probe.php | 4 ++-- src/Util/Network.php | 6 +++--- 11 files changed, 24 insertions(+), 56 deletions(-) diff --git a/include/network.php b/include/network.php index 726eac7570..840991aa52 100644 --- a/include/network.php +++ b/include/network.php @@ -12,42 +12,6 @@ use Friendica\Object\Image; use Friendica\Util\Network; use Friendica\Util\XML; -function validate_url($url) -{ - return Network::validateURL($url); -} - -function validate_email($addr) -{ - return Network::validateEmail($addr); -} - -function allowed_url($url) -{ - return Network::allowedURL($url); -} - -function blocked_url($url) -{ - return Network::blockedURL($url); -} - -function allowed_email($email) -{ - return Network::allowedEmail($email); -} - -function allowed_domain($domain, array $domain_list) -{ - return Network::allowedDomain($domain, $domain_list); -} - -function avatar_img($email) -{ - return Network::avatarImg($email); -} - - function parse_xml_string($s, $strict = true) { return Network::parseXmlString($s, $strict); diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 18a6eefaf2..1d3e4cd8f6 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -332,20 +332,20 @@ function dfrn_request_post(App $a) intval($contact_record['id']) ); } else { - $url = validate_url($url); + $url = Network::validateURL($url); if (!$url) { notice(L10n::t('Invalid profile URL.') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED } - if (!allowed_url($url)) { + if (!Network::allowedURL($url)) { notice(L10n::t('Disallowed profile URL.') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED } - if (blocked_url($url)) { + if (Network::blockedURL($url)) { notice(L10n::t('Blocked domain') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED diff --git a/mod/dirfind.php b/mod/dirfind.php index c010aaac92..f08e723bae 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -46,7 +46,7 @@ function dirfind_content(App $a, $prefix = "") { if (strpos($search,'@') === 0) { $search = substr($search,1); $header = L10n::t('People Search - %s', $search); - if ((valid_email($search) && validate_email($search)) || + if ((valid_email($search) && Network::validateEmail($search)) || (substr(normalise_link($search), 0, 7) == "http://")) { $user_data = Probe::uri($search); $discover_user = (in_array($user_data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])); diff --git a/mod/settings.php b/mod/settings.php index 5b4bd903ec..a6ffd99e99 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -17,6 +17,7 @@ use Friendica\Model\GContact; use Friendica\Model\Group; use Friendica\Model\User; use Friendica\Protocol\Email; +use Friendica\Util\Network; function get_theme_config_file($theme) { @@ -535,7 +536,7 @@ function settings_post(App $a) // If openid has changed or if there's an openid but no openidserver, try and discover it. if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) { - if (validate_url($openid)) { + if (Network::validateURL($openid)) { logger('updating openidserver'); require_once 'library/openid.php'; $open_id_obj = new LightOpenID; diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 80fab8c647..1ddd3e65c6 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -312,7 +312,7 @@ class OEmbed $allowed = explode(',', $str_allowed); - return allowed_domain($domain, $allowed); + return Network::allowedDomain($domain, $allowed); } public static function getHTML($url, $title = null) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index acdb4815e6..bda5a925f5 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -20,6 +20,7 @@ use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; use Friendica\Protocol\PortableContact; use Friendica\Protocol\Salmon; +use Friendica\Util\Network; use dba; require_once 'boot.php'; @@ -1131,12 +1132,12 @@ class Contact extends BaseObject // remove ajax junk, e.g. Twitter $url = str_replace('/#!/', '/', $url); - if (!allowed_url($url)) { + if (!Network::allowedURL($url)) { $result['message'] = L10n::t('Disallowed profile URL.'); return $result; } - if (blocked_url($url)) { + if (Network::blockedURL($url)) { $result['message'] = L10n::t('Blocked domain'); return $result; } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 8e32f60aec..c77b6bbe44 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -17,6 +17,7 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\Diaspora; +use Friendica\Util\Network; use dba; require_once 'include/dba.php'; @@ -963,7 +964,7 @@ class Profile public static function zrlInit(App $a) { $my_url = self::getMyURL(); - $my_url = validate_url($my_url); + $my_url = Network::validateURL($my_url); if ($my_url) { // Is it a DDoS attempt? // The check fetches the cached value from gprobe to reduce the load for this system diff --git a/src/Model/User.php b/src/Model/User.php index ecd1040b75..bc14098d40 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -282,7 +282,7 @@ class User if (!x($username) || !x($email) || !x($nickname)) { if ($openid_url) { - if (!validate_url($openid_url)) { + if (!Network::validateURL($openid_url)) { throw new Exception(L10n::t('Invalid OpenID url')); } $_SESSION['register'] = 1; @@ -305,7 +305,7 @@ class User throw new Exception(L10n::t('Please enter the required information.')); } - if (!validate_url($openid_url)) { + if (!Network::validateURL($openid_url)) { $openid_url = ''; } @@ -330,11 +330,11 @@ class User } } - if (!allowed_email($email)) { + if (!Network::allowedEmail($email)) { throw new Exception(L10n::t('Your email domain is not among those allowed on this site.')); } - if (!valid_email($email) || !validate_email($email)) { + if (!valid_email($email) || !Network::validateEmail($email)) { throw new Exception(L10n::t('Not a valid email address.')); } @@ -461,7 +461,7 @@ class User // if we have no OpenID photo try to look up an avatar if (!strlen($photo)) { - $photo = avatar_img($email); + $photo = Network::avatarImg($email); } // unless there is no avatar-addon loaded diff --git a/src/Module/Login.php b/src/Module/Login.php index fdfa6623fe..c6396a4148 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -10,6 +10,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Database\DBM; use Friendica\Model\User; +use Friendica\Util\Network; use dba; require_once 'boot.php'; @@ -59,7 +60,7 @@ class Login extends BaseModule $openid_url = trim($_POST['openid_url'] ? : $_POST['username']); // if it's an email address or doesn't resolve to a URL, fail. - if ($noid || strpos($openid_url, '@') || !validate_url($openid_url)) { + if ($noid || strpos($openid_url, '@') || !Network::validateURL($openid_url)) { notice(L10n::t('Login failed.') . EOL); goaway(self::getApp()->get_baseurl()); // NOTREACHED diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 94fd929e10..e3130a4d75 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -1510,7 +1510,7 @@ class Probe */ private static function mail($uri, $uid) { - if (!validate_email($uri)) { + if (!Network::validateEmail($uri)) { return false; } @@ -1544,7 +1544,7 @@ class Probe $data["network"] = NETWORK_MAIL; $data["name"] = substr($uri, 0, strpos($uri, '@')); $data["nick"] = $data["name"]; - $data["photo"] = avatar_img($uri); + $data["photo"] = Network::avatarImg($uri); $data["url"] = 'mailto:'.$uri; $data["notify"] = 'smtp '.random_string(); $data["poll"] = 'email '.random_string(); diff --git a/src/Util/Network.php b/src/Util/Network.php index e0400c7f0a..cc796c5f7a 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -79,7 +79,7 @@ class Network $a = get_app(); - if (blocked_url($url)) { + if (self::blockedURL($url)) { logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA); return $ret; } @@ -281,7 +281,7 @@ class Network { $stamp1 = microtime(true); - if (blocked_url($url)) { + if (self::blockedURL($url)) { logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA); return false; } @@ -622,7 +622,7 @@ class Network $allowed = explode(',', $str_allowed); - return allowed_domain($domain, $allowed); + return self::allowedDomain($domain, $allowed); } /** From ca76e49c230fce5fd6d86063f6fdfc3df05e78d4 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 08:25:54 -0500 Subject: [PATCH 07/13] Move remaining functions update remaining function calls --- include/bb2diaspora.php | 3 ++- include/conversation.php | 13 +++++++------ include/html2bbcode.php | 3 ++- mod/dfrn_confirm.php | 2 +- mod/dfrn_notify.php | 2 +- mod/dfrn_poll.php | 4 ++-- mod/hovercard.php | 2 +- mod/item.php | 3 ++- mod/notifications.php | 8 ++++---- mod/smilies.php | 4 ++-- src/Core/NotificationsManager.php | 3 ++- src/Network/Probe.php | 9 ++++----- src/Protocol/DFRN.php | 20 ++++++++++---------- src/Protocol/Diaspora.php | 12 ++++++------ src/Protocol/Feed.php | 3 ++- src/Util/Network.php | 11 ++++++----- src/Util/ParseUrl.php | 2 +- src/Worker/Delivery.php | 3 ++- src/Worker/OnePoll.php | 2 +- 19 files changed, 58 insertions(+), 51 deletions(-) diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 2673750eec..d5fa8642ad 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -5,6 +5,7 @@ use Friendica\Core\Addon; use Friendica\Core\System; use Friendica\Model\Contact; use Friendica\Network\Probe; +use Friendica\Util\Network; use League\HTMLToMarkdown\HtmlConverter; require_once 'include/event.php'; @@ -82,7 +83,7 @@ function diaspora2bb($s) { $s = preg_replace('/(\[code\])+(.*?)(\[\/code\])+/ism', '[code]$2[/code]', $s); // Don't show link to full picture (until it is fixed) - $s = scale_external_images($s, false); + $s = Network::scaleExternalImages($s, false); return $s; } diff --git a/include/conversation.php b/include/conversation.php index e0f9856bab..11d0a0d0dc 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -15,6 +15,7 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Object\Thread; use Friendica\Object\Post; +use Friendica\Util\Network; require_once "include/bbcode.php"; require_once "include/acl_selectors.php"; @@ -184,8 +185,8 @@ function localize_item(&$item) { $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$item['object']); - $links = parse_xml_string($xmlhead."".unxmlify($obj->link).""); + $obj = Network::parseXmlString($xmlhead.$item['object']); + $links = Network::parseXmlString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; $Bphoto = ""; @@ -220,8 +221,8 @@ function localize_item(&$item) { $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = parse_xml_string($xmlhead.$item['object']); - $links = parse_xml_string($xmlhead."".unxmlify($obj->link).""); + $obj = Network::parseXmlString($xmlhead.$item['object']); + $links = Network::parseXmlString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; @@ -295,7 +296,7 @@ function localize_item(&$item) { } $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; - $parsedobj = parse_xml_string($xmlhead.$item['object']); + $parsedobj = Network::parseXmlString($xmlhead.$item['object']); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); @@ -312,7 +313,7 @@ function localize_item(&$item) { $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = parse_xml_string($xmlhead.$item['object']); + $obj = Network::parseXmlString($xmlhead.$item['object']); if (strlen($obj->id)) { $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($obj->id), diff --git a/include/html2bbcode.php b/include/html2bbcode.php index 2404e42f6b..c8a05c1453 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -9,6 +9,7 @@ */ use Friendica\Core\Addon; +use Friendica\Util\Network; use Friendica\Util\XML; function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb) @@ -362,7 +363,7 @@ function addHostnameSub($matches, $basepath) $url = $matches[1]; $parts = array_merge($base, parse_url($url)); - $url2 = unParseUrl($parts); + $url2 = Network::unParseURL($parts); return str_replace($url, $url2, $link); } diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 9e5f0f3d54..8c50a05a16 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -252,7 +252,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) return; } - $xml = parse_xml_string($res); + $xml = Network::parseXmlString($res); $status = (int) $xml->status; $message = unxmlify($xml->message); // human readable text of what may have gone wrong. switch ($status) { diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 142cafaa09..b1af5b3ef7 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -123,7 +123,7 @@ function dfrn_notify_post(App $a) { // if contact's ssl policy changed, update our links - fix_contact_ssl_policy($importer,$ssl_policy); + Network::fixContactSslPolicy($importer, $ssl_policy); logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); logger('dfrn_notify: data: ' . $data, LOGGER_DATA); diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 8841a7b5a6..5042ed642d 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -104,7 +104,7 @@ function dfrn_poll_init(App $a) logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); if (strlen($s)) { - $xml = parse_xml_string($s); + $xml = Network::parseXmlString($s); if ((int) $xml->status === 1) { $_SESSION['authenticated'] = 1; @@ -521,7 +521,7 @@ function dfrn_poll_content(App $a) logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA); if (strlen($s) && strstr($s, 'pager['page']; // Json output - if(intval($json) === 1) - json_return_and_die($notifs); + if (intval($json) === 1) { + Network::jsonReturnAndDie($notifs); + } $notif_tpl = get_markup_template('notifications.tpl'); diff --git a/mod/smilies.php b/mod/smilies.php index d96a4bfc6d..232ef91d05 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -1,10 +1,10 @@ $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]]; } - json_return_and_die($results); + Network::jsonReturnAndDie($results); } else { return Smilies::replace('', true); } diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index e88b4218b5..654ed5cc48 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -13,6 +13,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Profile; +use Friendica\Util\Network; require_once 'include/dba.php'; require_once 'include/html2plain.php'; @@ -337,7 +338,7 @@ class NotificationsManager extends BaseObject case ACTIVITY_FRIEND: $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = parse_xml_string($xmlhead . $it['object']); + $obj = Network::parseXmlString($xmlhead . $it['object']); $it['fname'] = $obj->title; $notif = [ diff --git a/src/Network/Probe.php b/src/Network/Probe.php index e3130a4d75..db4f307b6b 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -26,7 +26,6 @@ use DOMXPath; use DOMDocument; require_once 'include/dba.php'; -require_once 'include/network.php'; /** * @brief This class contain functions for probing URL @@ -111,7 +110,7 @@ class Probe $ret = Network::zFetchURL($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['success']) { $xml = $ret['body']; - $xrd = parse_xml_string($xml, false); + $xrd = Network::parseXmlString($xml, false); $host_url = 'https://'.$host; } @@ -122,7 +121,7 @@ class Probe return false; } $xml = $ret['body']; - $xrd = parse_xml_string($xml, false); + $xrd = Network::parseXmlString($xml, false); $host_url = 'http://'.$host; } if (!is_object($xrd)) { @@ -332,7 +331,7 @@ class Probe } if (x($data, "photo")) { - $data["baseurl"] = matching_url(normalise_link($data["baseurl"]), normalise_link($data["photo"])); + $data["baseurl"] = Network::matchingURL(normalise_link($data["baseurl"]), normalise_link($data["photo"])); } else { $data["photo"] = System::baseUrl().'/images/person-175.jpg'; } @@ -709,7 +708,7 @@ class Probe } // If it is not JSON, maybe it is XML - $xrd = parse_xml_string($data, false); + $xrd = Network::parseXmlString($data, false); if (!is_object($xrd)) { logger("No webfinger data retrievable for ".$url, LOGGER_DEBUG); return false; diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index aed68e704f..2901796db4 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -793,7 +793,7 @@ class DFRN if ($activity) { $entry = $doc->createElement($element); - $r = parse_xml_string($activity, false); + $r = Network::parseXmlString($activity, false); if (!$r) { return false; } @@ -816,7 +816,7 @@ class DFRN $r->link = preg_replace('/\/', '', $r->link); // XML does need a single element as root element so we add a dummy element here - $data = parse_xml_string("" . $r->link . "", false); + $data = Network::parseXmlString("" . $r->link . "", false); if (is_object($data)) { foreach ($data->link as $link) { $attributes = []; @@ -1212,7 +1212,7 @@ class DFRN return 3; } - $res = parse_xml_string($xml); + $res = Network::parseXmlString($xml); if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { return (($res->status) ? $res->status : 3); @@ -1357,7 +1357,7 @@ class DFRN Contact::unmarkForArchival($contact); } - $res = parse_xml_string($xml); + $res = Network::parseXmlString($xml); if (!isset($res->status)) { return -11; @@ -2188,7 +2188,7 @@ class DFRN if (!$verb) { return; } - $xo = parse_xml_string($item["object"], false); + $xo = Network::parseXmlString($item["object"], false); if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? @@ -2310,8 +2310,8 @@ class DFRN } if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = parse_xml_string($item["object"], false); - $xt = parse_xml_string($item["target"], false); + $xo = Network::parseXmlString($item["object"], false); + $xt = Network::parseXmlString($item["target"], false); if ($xt->type == ACTIVITY_OBJ_NOTE) { $r = q( @@ -2518,7 +2518,7 @@ class DFRN $item["object"] = self::transformActivity($xpath, $object, "object"); if (trim($item["object"]) != "") { - $r = parse_xml_string($item["object"], false); + $r = Network::parseXmlString($item["object"], false); if (isset($r->type)) { $item["object-type"] = $r->type; } @@ -2787,8 +2787,8 @@ class DFRN } if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = parse_xml_string($item["object"], false); - $xt = parse_xml_string($item["target"], false); + $xo = Network::parseXmlString($item["object"], false); + $xt = Network::parseXmlString($item["target"], false); if ($xt->type == ACTIVITY_OBJ_NOTE) { $i = q( diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 58e3f5aff6..b87aabfb47 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -186,7 +186,7 @@ class Diaspora */ private static function verifyMagicEnvelope($envelope) { - $basedom = parse_xml_string($envelope); + $basedom = Network::parseXmlString($envelope); if (!is_object($basedom)) { logger("Envelope is no XML file"); @@ -296,7 +296,7 @@ class Diaspora $xml = $raw; } - $basedom = parse_xml_string($xml); + $basedom = Network::parseXmlString($xml); if (!is_object($basedom)) { logger('Received data does not seem to be an XML. Discarding. '.$xml); @@ -347,7 +347,7 @@ class Diaspora public static function decode($importer, $xml) { $public = false; - $basedom = parse_xml_string($xml); + $basedom = Network::parseXmlString($xml); if (!is_object($basedom)) { logger("XML is not parseable."); @@ -381,7 +381,7 @@ class Diaspora $decrypted = self::aesDecrypt($outer_key, $outer_iv, $ciphertext); logger('decrypted: '.$decrypted, LOGGER_DEBUG); - $idom = parse_xml_string($decrypted); + $idom = Network::parseXmlString($decrypted); $inner_iv = base64_decode($idom->iv); $inner_aes_key = base64_decode($idom->aes_key); @@ -631,7 +631,7 @@ class Diaspora */ private static function validPosting($msg) { - $data = parse_xml_string($msg["message"]); + $data = Network::parseXmlString($msg["message"]); if (!is_object($data)) { logger("No valid XML ".$msg["message"], LOGGER_DEBUG); @@ -1281,7 +1281,7 @@ class Diaspora } } - $source_xml = parse_xml_string($x); + $source_xml = Network::parseXmlString($x); if (!is_object($source_xml)) { return false; diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index c129c31b01..e728afa245 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -9,6 +9,7 @@ namespace Friendica\Protocol; use Friendica\Database\DBM; use Friendica\Core\System; use Friendica\Model\Item; +use Friendica\Util\Network; use dba; use DOMDocument; use DOMXPath; @@ -243,7 +244,7 @@ class Feed { $orig_plink = $item["plink"]; - $item["plink"] = original_url($item["plink"]); + $item["plink"] = Network::originalURL($item["plink"]); $item["parent-uri"] = $item["uri"]; diff --git a/src/Util/Network.php b/src/Util/Network.php index cc796c5f7a..9cd3cb7197 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -11,6 +11,7 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Network\Probe; use Friendica\Object\Image; +use Friendica\Util\Network; use Friendica\Util\XML; require_once 'library/slinky.php'; @@ -852,7 +853,7 @@ class Network { $a = get_app(); - $url = strip_tracking_query_params($url); + $url = self::stripTrackingQueryParams($url); if ($depth > 10) { return($url); @@ -885,15 +886,15 @@ class Network && (($curl_info['redirect_url'] != "") || ($curl_info['location'] != "")) ) { if ($curl_info['redirect_url'] != "") { - return(original_url($curl_info['redirect_url'], ++$depth, $fetchbody)); + return(Network::originalURL($curl_info['redirect_url'], ++$depth, $fetchbody)); } else { - return(original_url($curl_info['location'], ++$depth, $fetchbody)); + return(Network::originalURL($curl_info['location'], ++$depth, $fetchbody)); } } // Check for redirects in the meta elements of the body if there are no redirects in the header. if (!$fetchbody) { - return(original_url($url, ++$depth, true)); + return(Network::originalURL($url, ++$depth, true)); } // if the file is too large then exit @@ -945,7 +946,7 @@ class Network $pathinfo = explode(";", $path); foreach ($pathinfo as $value) { if (substr(strtolower($value), 0, 4) == "url=") { - return(original_url(substr($value, 4), ++$depth)); + return(Network::originalURL(substr($value, 4), ++$depth)); } } } diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 67aebb4c72..ba9b7ec146 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -141,7 +141,7 @@ class ParseUrl $url = trim($url, "'"); $url = trim($url, '"'); - $url = strip_tracking_query_params($url); + $url = Network::stripTrackingQueryParams($url); $siteinfo["url"] = $url; $siteinfo["type"] = "link"; diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index a5befb8449..cc704474e0 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -15,6 +15,7 @@ use Friendica\Model\User; use Friendica\Protocol\Diaspora; use Friendica\Protocol\DFRN; use Friendica\Protocol\Email; +use Friendica\Util\Network; use dba; require_once 'include/html2plain.php'; @@ -299,7 +300,7 @@ class Delivery { } $ssl_policy = Config::get('system','ssl_policy'); - fix_contact_ssl_policy($x[0],$ssl_policy); + Network::fixContactSslPolicy($x[0], $ssl_policy); // If we are setup as a soapbox we aren't accepting top level posts from this person diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index b4e7bc20c4..c06b8f5930 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -219,7 +219,7 @@ class OnePoll } - $res = parse_xml_string($handshake_xml); + $res = Network::parseXmlString($handshake_xml); if (intval($res->status) == 1) { logger("$url replied status 1 - marking for death "); From 0f1be372797c3911323c15b85a82ea47db0608f8 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 08:28:20 -0500 Subject: [PATCH 08/13] Remove old file remove network.php and all require_once statements --- boot.php | 1 - include/bbcode.php | 4 --- include/network.php | 58 -------------------------------- src/Content/Text/BBCode.php | 1 - src/Model/GContact.php | 1 - src/Model/User.php | 1 - src/Network/Probe.php | 2 +- src/Protocol/PortableContact.php | 1 - src/Util/ParseUrl.php | 1 - 9 files changed, 1 insertion(+), 69 deletions(-) delete mode 100644 include/network.php diff --git a/boot.php b/boot.php index ede6fc77b9..98db95227f 100644 --- a/boot.php +++ b/boot.php @@ -32,7 +32,6 @@ use Friendica\Model\Contact; use Friendica\Database\DBStructure; use Friendica\Module\Login; -require_once 'include/network.php'; require_once 'include/text.php'; require_once 'include/datetime.php'; diff --git a/include/bbcode.php b/include/bbcode.php index 0544c4c616..8f758ae616 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -748,8 +748,6 @@ function bb_RemovePictureLinks($match) { $text = "[url=".$match[2]."]".$match[2]."[/url]"; // if its not a picture then look if its a page that contains a picture link - require_once("include/network.php"); - $body = Network::fetchURL($match[1]); $doc = new DOMDocument(); @@ -805,8 +803,6 @@ function bb_CleanPictureLinksSub($match) { $text = "[img]".$match[2]."[/img]"; // if its not a picture then look if its a page that contains a picture link - require_once("include/network.php"); - $body = Network::fetchURL($match[1]); $doc = new DOMDocument(); diff --git a/include/network.php b/include/network.php deleted file mode 100644 index 840991aa52..0000000000 --- a/include/network.php +++ /dev/null @@ -1,58 +0,0 @@ - Date: Sat, 27 Jan 2018 11:13:41 -0500 Subject: [PATCH 09/13] Review update Rename function, move others --- include/acl_selectors.php | 2 +- include/api.php | 2 +- include/bb2diaspora.php | 4 +- include/bbcode.php | 6 +- include/conversation.php | 14 +-- include/html2bbcode.php | 2 +- include/items.php | 2 +- mod/dfrn_confirm.php | 23 ++-- mod/dfrn_notify.php | 16 +-- mod/dfrn_poll.php | 27 ++--- mod/dfrn_request.php | 8 +- mod/dirfind.php | 4 +- mod/hovercard.php | 2 +- mod/install.php | 4 +- mod/item.php | 3 +- mod/match.php | 4 +- mod/nodeinfo.php | 2 +- mod/notifications.php | 2 +- mod/oexchange.php | 2 +- mod/ostatus_subscribe.php | 2 +- mod/parse_url.php | 2 +- mod/proxy.php | 2 +- mod/pubsubhubbub.php | 2 +- mod/settings.php | 2 +- mod/smilies.php | 2 +- spec/dfrn2_contact_confirmation.svg | 2 +- spec/dfrn2_contact_request.svg | 4 +- src/Content/OEmbed.php | 8 +- src/Content/Text/BBCode.php | 73 ++++++++++++ src/Core/NotificationsManager.php | 4 +- src/Core/Worker.php | 2 +- src/Model/Contact.php | 37 +++++- src/Model/GContact.php | 4 +- src/Model/Photo.php | 2 +- src/Model/Profile.php | 2 +- src/Model/User.php | 12 +- src/Module/Login.php | 2 +- src/Network/Probe.php | 28 ++--- src/Object/Image.php | 2 +- src/Protocol/DFRN.php | 24 ++-- src/Protocol/Diaspora.php | 18 +-- src/Protocol/Feed.php | 2 +- src/Protocol/OStatus.php | 14 +-- src/Protocol/PortableContact.php | 48 ++++---- src/Protocol/Salmon.php | 8 +- src/Util/ExAuth.php | 2 +- src/Util/Network.php | 172 +++++----------------------- src/Util/ParseUrl.php | 2 +- src/Util/XML.php | 16 +++ src/Worker/CheckVersion.php | 2 +- src/Worker/Delivery.php | 3 +- src/Worker/Directory.php | 8 +- src/Worker/DiscoverPoCo.php | 4 +- src/Worker/OnePoll.php | 9 +- src/Worker/PubSubPublish.php | 2 +- 55 files changed, 331 insertions(+), 326 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 38a418dd1c..72f49a40ba 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -734,7 +734,7 @@ function navbar_complete(App $a) { if (! $localsearch) { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - $x = Network::zFetchURL(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); if ($x['success']) { $j = json_decode($x['body'],true); if ($j && isset($j['results'])) { diff --git a/include/api.php b/include/api.php index 610cd26dda..7164f85abf 100644 --- a/include/api.php +++ b/include/api.php @@ -5074,7 +5074,7 @@ function api_get_nick($profile) if ($StatusnetHost != $profile) { $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); if ($StatusnetUser != $profile) { - $UserData = Network::fetchURL("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); + $UserData = Network::fetchUrl("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); if ($user) { $nick = $user->screen_name; diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index d5fa8642ad..95047d61ae 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -1,11 +1,11 @@ loadHTML($body); @@ -803,7 +803,7 @@ function bb_CleanPictureLinksSub($match) { $text = "[img]".$match[2]."[/img]"; // if its not a picture then look if its a page that contains a picture link - $body = Network::fetchURL($match[1]); + $body = Network::fetchUrl($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); diff --git a/include/conversation.php b/include/conversation.php index 11d0a0d0dc..af4bb0559e 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -15,7 +15,7 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Object\Thread; use Friendica\Object\Post; -use Friendica\Util\Network; +use Friendica\Util\XML; require_once "include/bbcode.php"; require_once "include/acl_selectors.php"; @@ -185,8 +185,8 @@ function localize_item(&$item) { $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = Network::parseXmlString($xmlhead.$item['object']); - $links = Network::parseXmlString($xmlhead."".unxmlify($obj->link).""); + $obj = XML::parseString($xmlhead.$item['object']); + $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; $Bphoto = ""; @@ -221,8 +221,8 @@ function localize_item(&$item) { $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = Network::parseXmlString($xmlhead.$item['object']); - $links = Network::parseXmlString($xmlhead."".unxmlify($obj->link).""); + $obj = XML::parseString($xmlhead.$item['object']); + $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; @@ -296,7 +296,7 @@ function localize_item(&$item) { } $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; - $parsedobj = Network::parseXmlString($xmlhead.$item['object']); + $parsedobj = XML::parseString($xmlhead.$item['object']); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); @@ -313,7 +313,7 @@ function localize_item(&$item) { $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = Network::parseXmlString($xmlhead.$item['object']); + $obj = XML::parseString($xmlhead.$item['object']); if (strlen($obj->id)) { $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($obj->id), diff --git a/include/html2bbcode.php b/include/html2bbcode.php index c8a05c1453..a5967d2cb3 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -363,7 +363,7 @@ function addHostnameSub($matches, $basepath) $url = $matches[1]; $parts = array_merge($base, parse_url($url)); - $url2 = Network::unParseURL($parts); + $url2 = Network::unparseURL($parts); return str_replace($url, $url2, $link); } diff --git a/include/items.php b/include/items.php index a1afbb3062..1951b340cb 100644 --- a/include/items.php +++ b/include/items.php @@ -1481,7 +1481,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { dba::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]); } - Network::postURL($url, $params); + Network::post($url, $params); logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 8c50a05a16..85e896dcf5 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -31,6 +31,7 @@ use Friendica\Network\Probe; use Friendica\Protocol\Diaspora; use Friendica\Util\Crypto; use Friendica\Util\Network; +use Friendica\Util\XML; require_once 'include/enotify.php'; require_once 'include/items.php'; @@ -221,7 +222,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) * */ - $res = Network::postURL($dfrn_confirm, $params, null, $redirects, 120); + $res = Network::post($dfrn_confirm, $params, null, $redirects, 120); logger(' Confirm: received data: ' . $res, LOGGER_DATA); @@ -252,7 +253,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) return; } - $xml = Network::parseXmlString($res); + $xml = XML::parseString($res); $status = (int) $xml->status; $message = unxmlify($xml->message); // human readable text of what may have gone wrong. switch ($status) { @@ -493,7 +494,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) $user = dba::selectFirst('user', [], ['nickname' => $node]); if (!DBM::is_result($user)) { $message = L10n::t('No user record found for \'%s\' ', $node); - Network::xmlStatus(3, $message); // failure + Network::xmlExit(3, $message); // failure // NOTREACHED } @@ -503,7 +504,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strstr($my_prvkey, 'PRIVATE KEY')) { $message = L10n::t('Our site encryption key is apparently messed up.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } // verify everything @@ -514,7 +515,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strlen($decrypted_source_url)) { $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); // NOTREACHED } @@ -530,7 +531,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!DBM::is_result($contact)) { // this is either a bogus confirmation (?) or we deleted the original introduction. $message = L10n::t('Contact record was not found for you on our site.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); return; // NOTREACHED } } @@ -544,7 +545,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!$foreign_pubkey) { $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } $decrypted_dfrn_id = ""; @@ -560,7 +561,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (dba::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) { $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.'); - Network::xmlStatus(1, $message); // Birthday paradox - duplicate dfrn-id + Network::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id // NOTREACHED } @@ -571,7 +572,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { $message = L10n::t('Unable to set your contact credentials on our system.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } // It's possible that the other person also requested friendship. @@ -626,7 +627,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { // indicates schema is messed up or total db failure $message = L10n::t('Unable to update your contact profile details on our system'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } // Otherwise everything seems to have worked and we are almost done. Yay! @@ -707,7 +708,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) } } } - Network::xmlStatus(0); // Success + Network::xmlExit(0); // Success return; // NOTREACHED ////////////////////// End of this scenario /////////////////////////////////////////////// } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index b1af5b3ef7..8efb9328d5 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -49,7 +49,7 @@ function dfrn_notify_post(App $a) { ); if (! DBM::is_result($r)) { logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); - Network::xmlStatus(3, 'Could not match challenge'); + Network::xmlExit(3, 'Could not match challenge'); } $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'", @@ -71,7 +71,7 @@ function dfrn_notify_post(App $a) { $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id)); break; default: - Network::xmlStatus(3, 'Invalid direction'); + Network::xmlExit(3, 'Invalid direction'); break; // NOTREACHED } @@ -97,7 +97,7 @@ function dfrn_notify_post(App $a) { if (! DBM::is_result($r)) { logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); - Network::xmlStatus(3, 'Contact not found'); + Network::xmlExit(3, 'Contact not found'); //NOTREACHED } @@ -123,7 +123,7 @@ function dfrn_notify_post(App $a) { // if contact's ssl policy changed, update our links - Network::fixContactSslPolicy($importer, $ssl_policy); + $importer = Contact::updateSslPolicy($importer, $ssl_policy); logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); logger('dfrn_notify: data: ' . $data, LOGGER_DATA); @@ -132,7 +132,7 @@ function dfrn_notify_post(App $a) { // Relationship is dissolved permanently Contact::remove($importer['id']); logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']); - Network::xmlStatus(0, 'relationship dissolved'); + Network::xmlExit(0, 'relationship dissolved'); } $rino = Config::get('system', 'rino_encrypt'); @@ -146,7 +146,7 @@ function dfrn_notify_post(App $a) { // but only for $remote_rino > 1, because old code did't send rino version if ($rino_remote > 1 && $rino < $rino_remote) { logger("rino version '$rino_remote' is lower than supported '$rino'"); - Network::xmlStatus(0, "rino version '$rino_remote' is lower than supported '$rino'"); + Network::xmlExit(0, "rino version '$rino_remote' is lower than supported '$rino'"); } $rawkey = hex2bin(trim($key)); @@ -176,14 +176,14 @@ function dfrn_notify_post(App $a) { break; default: logger("rino: invalid sent version '$rino_remote'"); - Network::xmlStatus(0, "Invalid sent version '$rino_remote'"); + Network::xmlExit(0, "Invalid sent version '$rino_remote'"); } logger('rino: decrypted data: ' . $data, LOGGER_DATA); } $ret = DFRN::import($data, $importer); - Network::xmlStatus($ret, 'Processed'); + Network::xmlExit($ret, 'Processed'); // NOTREACHED } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 5042ed642d..3e5aa5b1c7 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -12,6 +12,7 @@ use Friendica\Module\Login; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; use Friendica\Util\Network; +use Friendica\Util\XML; require_once 'include/items.php'; @@ -99,12 +100,12 @@ function dfrn_poll_init(App $a) ); if (DBM::is_result($r)) { - $s = Network::fetchURL($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); + $s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); if (strlen($s)) { - $xml = Network::parseXmlString($s); + $xml = XML::parseString($s); if ((int) $xml->status === 1) { $_SESSION['authenticated'] = 1; @@ -144,7 +145,7 @@ function dfrn_poll_init(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - Network::xmlStatus(3, 'No ticket'); + Network::xmlExit(3, 'No ticket'); // NOTREACHED } @@ -157,7 +158,7 @@ function dfrn_poll_init(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - Network::xmlStatus(3, 'No profile'); + Network::xmlExit(3, 'No profile'); } $contact = $c[0]; @@ -184,7 +185,7 @@ function dfrn_poll_init(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - Network::xmlStatus(3, 'Bad decryption'); + Network::xmlExit(3, 'Bad decryption'); } header("Content-type: text/xml"); @@ -208,10 +209,10 @@ function dfrn_poll_init(App $a) $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC", dbesc($dfrn_id)); if (DBM::is_result($r)) { - Network::xmlStatus(1); + Network::xmlExit(1); return; // NOTREACHED } - Network::xmlStatus(0); + Network::xmlExit(0); return; // NOTREACHED } } @@ -236,7 +237,7 @@ function dfrn_poll_post(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - Network::xmlStatus(3, 'No ticket'); + Network::xmlExit(3, 'No ticket'); // NOTREACHED } @@ -249,7 +250,7 @@ function dfrn_poll_post(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - Network::xmlStatus(3, 'No profile'); + Network::xmlExit(3, 'No profile'); } $contact = $c[0]; @@ -276,7 +277,7 @@ function dfrn_poll_post(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - Network::xmlStatus(3, 'Bad decryption'); + Network::xmlExit(3, 'Bad decryption'); } header("Content-type: text/xml"); @@ -482,7 +483,7 @@ function dfrn_poll_content(App $a) if (($type === 'profile') && (strlen($sec))) { // URL reply if ($dfrn_version < 2.2) { - $s = Network::fetchURL($r[0]['poll'] + $s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' . '&dfrn_version=' . DFRN_PROTOCOL_VERSION @@ -490,7 +491,7 @@ function dfrn_poll_content(App $a) . '&sec=' . $sec ); } else { - $s = Network::postURL($r[0]['poll'], [ + $s = Network::post($r[0]['poll'], [ 'dfrn_id' => $encrypted_id, 'type' => 'profile-check', 'dfrn_version' => DFRN_PROTOCOL_VERSION, @@ -521,7 +522,7 @@ function dfrn_poll_content(App $a) logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA); if (strlen($s) && strstr($s, 'cmd); return; // NOTREACHED } - if (!Network::allowedURL($url)) { + if (!Network::isUrlAllowed($url)) { notice(L10n::t('Disallowed profile URL.') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED } - if (Network::blockedURL($url)) { + if (Network::isUrlBlocked($url)) { notice(L10n::t('Blocked domain') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED diff --git a/mod/dirfind.php b/mod/dirfind.php index f08e723bae..9db4eeb7b6 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -46,7 +46,7 @@ function dirfind_content(App $a, $prefix = "") { if (strpos($search,'@') === 0) { $search = substr($search,1); $header = L10n::t('People Search - %s', $search); - if ((valid_email($search) && Network::validateEmail($search)) || + if ((valid_email($search) && Network::isEmailDomainValid($search)) || (substr(normalise_link($search), 0, 7) == "http://")) { $user_data = Probe::uri($search); $discover_user = (in_array($user_data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])); @@ -178,7 +178,7 @@ function dirfind_content(App $a, $prefix = "") { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); if(strlen(Config::get('system','directory'))) - $x = Network::fetchURL(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::fetchUrl(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); $j = json_decode($x); } diff --git a/mod/hovercard.php b/mod/hovercard.php index fbe783a51b..0bd1d26178 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -91,7 +91,7 @@ function hovercard_content() return $o; } else { - Network::jsonReturnAndDie($profile); + Network::jsonExit($profile); } } diff --git a/mod/install.php b/mod/install.php index ef9f023f52..c5f2e985f9 100644 --- a/mod/install.php +++ b/mod/install.php @@ -483,10 +483,10 @@ function check_htaccess(&$checks) { $status = true; $help = ""; if (function_exists('curl_init')) { - $test = Network::fetchURL(System::baseUrl()."/install/testrewrite"); + $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite"); if ($test != "ok") { - $test = Network::fetchURL(normalise_link(System::baseUrl()."/install/testrewrite")); + $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite")); } if ($test != "ok") { diff --git a/mod/item.php b/mod/item.php index ad089adc0f..1a512acec8 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,7 +29,6 @@ use Friendica\Network\Probe; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; use Friendica\Util\Emailer; -use Friendica\Util\Network; require_once 'include/enotify.php'; require_once 'include/tags.php'; @@ -520,7 +519,7 @@ function item_post(App $a) { // Fold multi-line [code] sequences $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); - $body = Network::scaleExternalImages($body, false); + $body = BBCode::scaleExternalImages($body, false); // Setting the object type if not defined before if (!$objecttype) { diff --git a/mod/match.php b/mod/match.php index ad1e00101e..c5e35031f5 100644 --- a/mod/match.php +++ b/mod/match.php @@ -59,9 +59,9 @@ function match_content(App $a) } if (strlen(Config::get('system', 'directory'))) { - $x = Network::postURL(get_server().'/msearch', $params); + $x = Network::post(get_server().'/msearch', $params); } else { - $x = Network::postURL(System::baseUrl() . '/msearch', $params); + $x = Network::post(System::baseUrl() . '/msearch', $params); } $j = json_decode($x); diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index b3d42ab52e..026d3f03d9 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -247,7 +247,7 @@ function nodeinfo_cron() { // Now trying to register $url = 'http://the-federation.info/register/'.$a->get_hostname(); logger('registering url: '.$url, LOGGER_DEBUG); - $ret = Network::fetchURL($url); + $ret = Network::fetchUrl($url); logger('registering answer: '.$ret, LOGGER_DEBUG); logger('cron_end'); diff --git a/mod/notifications.php b/mod/notifications.php index 06624f3c00..067e954228 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -139,7 +139,7 @@ function notifications_content(App $a) { // Json output if (intval($json) === 1) { - Network::jsonReturnAndDie($notifs); + Network::jsonExit($notifs); } $notif_tpl = get_markup_template('notifications.tpl'); diff --git a/mod/oexchange.php b/mod/oexchange.php index 79414a7f6a..feca39d353 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -40,7 +40,7 @@ function oexchange_content(App $a) { $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); - $s = Network::fetchURL(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + $s = Network::fetchUrl(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); if (! strlen($s)) { return; diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 81eced22e7..07f4647e69 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -41,7 +41,7 @@ function ostatus_subscribe_content(App $a) { $api = $contact["baseurl"]."/api/"; // Fetching friends - $data = Network::zFetchURL($api."statuses/friends.json?screen_name=".$contact["nick"]); + $data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]); if (!$data["success"]) { return $o.L10n::t("Couldn't fetch friends for contact."); diff --git a/mod/parse_url.php b/mod/parse_url.php index f1214e160f..ea860f6d31 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -61,7 +61,7 @@ function parse_url_content(App $a) { // the URL with the corresponding BBCode media tag $redirects = 0; // Fetch the header of the URL - $result = Network::zFetchURL($url, false, $redirects, ["novalidate" => true, "nobody" => true]); + $result = Network::curl($url, false, $redirects, ["novalidate" => true, "nobody" => true]); if($result["success"]) { // Convert the header fields into an array $hdrs = []; diff --git a/mod/proxy.php b/mod/proxy.php index 1497185917..7efc0ffbaa 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -162,7 +162,7 @@ function proxy_init(App $a) { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $redirects = 0; - $img_str = Network::fetchURL($_REQUEST['url'], true, $redirects, 10); + $img_str = Network::fetchUrl($_REQUEST['url'], true, $redirects, 10); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index af7172cee2..210bc6efbc 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -110,7 +110,7 @@ function pubsubhubbub_init(App $a) { // we don't actually enforce the lease time because GNU // Social/StatusNet doesn't honour it (yet) - $body = Network::fetchURL($hub_callback . "?" . $params); + $body = Network::fetchUrl($hub_callback . "?" . $params); $ret = $a->get_curl_code(); // give up if the HTTP return code wasn't a success (2xx) diff --git a/mod/settings.php b/mod/settings.php index a6ffd99e99..2ea6d53343 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -536,7 +536,7 @@ function settings_post(App $a) // If openid has changed or if there's an openid but no openidserver, try and discover it. if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) { - if (Network::validateURL($openid)) { + if (Network::isUrlValid($openid)) { logger('updating openidserver'); require_once 'library/openid.php'; $open_id_obj = new LightOpenID; diff --git a/mod/smilies.php b/mod/smilies.php index 232ef91d05..19f0152ef8 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -18,7 +18,7 @@ function smilies_content(App $a) for ($i = 0; $i < count($tmp['texts']); $i++) { $results[] = ['text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]]; } - Network::jsonReturnAndDie($results); + Network::jsonExit($results); } else { return Smilies::replace('', true); } diff --git a/spec/dfrn2_contact_confirmation.svg b/spec/dfrn2_contact_confirmation.svg index 53c2b6c19f..fc5b331625 100644 --- a/spec/dfrn2_contact_confirmation.svg +++ b/spec/dfrn2_contact_confirmation.svg @@ -69,7 +69,7 @@ text { font:12px Dialog; } getting transmitted (if $aes_allow -> encrypt the the public key) -> add duplex state and page-flags to the params -> send params to Bobs dfrn_confirm page ($res = -Network::postURL($dfrn_confirm,$params); +Network::post($dfrn_confirm,$params); dfrn_confirm_post() diff --git a/spec/dfrn2_contact_request.svg b/spec/dfrn2_contact_request.svg index 23b040985f..cc78be55c8 100644 --- a/spec/dfrn2_contact_request.svg +++ b/spec/dfrn2_contact_request.svg @@ -93,9 +93,9 @@ text { font:12px Dialog; } - create a contact for Karen in the contact table with the scraped data with blocked = 1 and pending = 1 (Karens pubkey becomes the contact site-pubkey) -- Network::fetchURL($dfrn_request . '?confirm_key=' . +- Network::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key); -- Network::fetchURL(http://karenhomepage.com/dfrn_request? +- Network::fetchUrl(http://karenhomepage.com/dfrn_request? confirm_key=”ABC123”) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 1ddd3e65c6..170ee7ba26 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -78,7 +78,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery $redirects = 0; - $html_text = Network::fetchURL($embedurl, false, $redirects, 15, "text/*"); + $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, "text/*"); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { @@ -86,13 +86,13 @@ class OEmbed $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } $entries = $xpath->query("//link[@type='text/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } } @@ -312,7 +312,7 @@ class OEmbed $allowed = explode(',', $str_allowed); - return Network::allowedDomain($domain, $allowed); + return Network::isDomainAllowed($domain, $allowed); } public static function getHTML($url, $title = null) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 664be933ae..5760533d37 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -6,7 +6,10 @@ namespace Friendica\Content\Text; use Friendica\App; use Friendica\Content\Text\Plaintext; +use Friencica\Core\Config; +use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Core\System; use Friendica\Object\Image; use Friendica\Util\ParseUrl; @@ -475,4 +478,74 @@ class BBCode return($post); } + + public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) + { + // Suppress "view full size" + if (intval(Config::get('system', 'no_view_full_size'))) { + $include_link = false; + } + + // Picture addresses can contain special characters + $s = htmlspecialchars_decode($srctext); + + $matches = null; + $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); + if ($c) { + foreach ($matches as $mtch) { + logger('scale_external_image: ' . $mtch[1]); + + $hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3)); + if (stristr($mtch[1], $hostname)) { + continue; + } + + // $scale_replace, if passed, is an array of two elements. The + // first is the name of the full-size image. The second is the + // name of a remote, scaled-down version of the full size image. + // This allows Friendica to display the smaller remote image if + // one exists, while still linking to the full-size image + if ($scale_replace) { + $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]); + } else { + $scaled = $mtch[1]; + } + $i = self::fetchURL($scaled); + if (! $i) { + return $srctext; + } + + // guess mimetype from headers or filename + $type = Image::guessType($mtch[1], true); + + if ($i) { + $Image = new Image($i, $type); + if ($Image->isValid()) { + $orig_width = $Image->getWidth(); + $orig_height = $Image->getHeight(); + + if ($orig_width > 640 || $orig_height > 640) { + $Image->scaleDown(640); + $new_width = $Image->getWidth(); + $new_height = $Image->getHeight(); + logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); + $s = str_replace( + $mtch[0], + '[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' + . "\n" . (($include_link) + ? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n" + : ''), + $s + ); + logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); + } + } + } + } + } + + // replace the special char encoding + $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); + return $s; + } } diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index 654ed5cc48..7c2760a85b 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -13,7 +13,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Profile; -use Friendica\Util\Network; +use Friendica\Util\XML; require_once 'include/dba.php'; require_once 'include/html2plain.php'; @@ -338,7 +338,7 @@ class NotificationsManager extends BaseObject case ACTIVITY_FRIEND: $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = Network::parseXmlString($xmlhead . $it['object']); + $obj = XML::parseString($xmlhead . $it['object']); $it['fname'] = $obj->title; $notif = [ diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 11146e4a21..ee313bef01 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -888,7 +888,7 @@ class Worker } $url = System::baseUrl()."/worker"; - Network::fetchURL($url, false, $redirects, 1); + Network::fetchUrl($url, false, $redirects, 1); } /** diff --git a/src/Model/Contact.php b/src/Model/Contact.php index bda5a925f5..ba9536b391 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1132,12 +1132,12 @@ class Contact extends BaseObject // remove ajax junk, e.g. Twitter $url = str_replace('/#!/', '/', $url); - if (!Network::allowedURL($url)) { + if (!Network::isUrlAllowed($url)) { $result['message'] = L10n::t('Disallowed profile URL.'); return $result; } - if (Network::blockedURL($url)) { + if (Network::isUrlBlocked($url)) { $result['message'] = L10n::t('Blocked domain'); return $result; } @@ -1321,4 +1321,37 @@ class Contact extends BaseObject $result['success'] = true; return $result; } + + public static function updateSslPolicy($contact, $new_policy) + { + $ssl_changed = false; + if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) { + $ssl_changed = true; + $contact['url'] = str_replace('https:', 'http:', $contact['url']); + $contact['request'] = str_replace('https:', 'http:', $contact['request']); + $contact['notify'] = str_replace('https:', 'http:', $contact['notify']); + $contact['poll'] = str_replace('https:', 'http:', $contact['poll']); + $contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']); + $contact['poco'] = str_replace('https:', 'http:', $contact['poco']); + } + + if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) { + $ssl_changed = true; + $contact['url'] = str_replace('http:', 'https:', $contact['url']); + $contact['request'] = str_replace('http:', 'https:', $contact['request']); + $contact['notify'] = str_replace('http:', 'https:', $contact['notify']); + $contact['poll'] = str_replace('http:', 'https:', $contact['poll']); + $contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']); + $contact['poco'] = str_replace('http:', 'https:', $contact['poco']); + } + + if ($ssl_changed) { + $fields = ['url' => $contact['url'], 'request' => $contact['request'], + 'notify' => $contact['notify'], 'poll' => $contact['poll'], + 'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; + dba::update('contact', $fields, ['id' => $contact['id']]); + } + + return $contact; + } } diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 0991110316..0d0969ca0c 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -568,7 +568,7 @@ class GContact $done[] = System::baseUrl() . '/poco'; if (strlen(Config::get('system', 'directory'))) { - $x = Network::fetchURL(get_server()."/pubsites"); + $x = Network::fetchUrl(get_server()."/pubsites"); if ($x) { $j = json_decode($x); if ($j->entries) { @@ -980,7 +980,7 @@ class GContact $url = $server."/main/statistics"; - $result = Network::zFetchURL($url); + $result = Network::curl($url); if (!$result["success"]) { return false; } diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 23d893c925..fc6e60a9ce 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -102,7 +102,7 @@ class Photo $photo_failure = false; $filename = basename($image_url); - $img_str = Network::fetchURL($image_url, true); + $img_str = Network::fetchUrl($image_url, true); if ($quit_on_error && ($img_str == "")) { return false; diff --git a/src/Model/Profile.php b/src/Model/Profile.php index c77b6bbe44..df53b5d80a 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -964,7 +964,7 @@ class Profile public static function zrlInit(App $a) { $my_url = self::getMyURL(); - $my_url = Network::validateURL($my_url); + $my_url = Network::isUrlValid($my_url); if ($my_url) { // Is it a DDoS attempt? // The check fetches the cached value from gprobe to reduce the load for this system diff --git a/src/Model/User.php b/src/Model/User.php index c767ec1b62..4eba5112ad 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -281,7 +281,7 @@ class User if (!x($username) || !x($email) || !x($nickname)) { if ($openid_url) { - if (!Network::validateURL($openid_url)) { + if (!Network::isUrlValid($openid_url)) { throw new Exception(L10n::t('Invalid OpenID url')); } $_SESSION['register'] = 1; @@ -304,7 +304,7 @@ class User throw new Exception(L10n::t('Please enter the required information.')); } - if (!Network::validateURL($openid_url)) { + if (!Network::isUrlValid($openid_url)) { $openid_url = ''; } @@ -329,11 +329,11 @@ class User } } - if (!Network::allowedEmail($email)) { + if (!Network::isEmailDomainAllowed($email)) { throw new Exception(L10n::t('Your email domain is not among those allowed on this site.')); } - if (!valid_email($email) || !Network::validateEmail($email)) { + if (!valid_email($email) || !Network::isEmailDomainValid($email)) { throw new Exception(L10n::t('Not a valid email address.')); } @@ -460,7 +460,7 @@ class User // if we have no OpenID photo try to look up an avatar if (!strlen($photo)) { - $photo = Network::avatarImg($email); + $photo = Network::lookupAvatarByEmail($email); } // unless there is no avatar-addon loaded @@ -468,7 +468,7 @@ class User $photo_failure = false; $filename = basename($photo); - $img_str = Network::fetchURL($photo, true); + $img_str = Network::fetchUrl($photo, true); // guess mimetype from headers or filename $type = Image::guessType($photo, true); diff --git a/src/Module/Login.php b/src/Module/Login.php index c6396a4148..e080663d7f 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -60,7 +60,7 @@ class Login extends BaseModule $openid_url = trim($_POST['openid_url'] ? : $_POST['username']); // if it's an email address or doesn't resolve to a URL, fail. - if ($noid || strpos($openid_url, '@') || !Network::validateURL($openid_url)) { + if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) { notice(L10n::t('Login failed.') . EOL); goaway(self::getApp()->get_baseurl()); // NOTREACHED diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 79b3840034..f7c3b84fdd 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -107,21 +107,21 @@ class Probe logger("Probing for ".$host, LOGGER_DEBUG); - $ret = Network::zFetchURL($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['success']) { $xml = $ret['body']; - $xrd = Network::parseXmlString($xml, false); + $xrd = XML::parseString($xml, false); $host_url = 'https://'.$host; } if (!is_object($xrd)) { - $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { logger("Probing timeout for ".$url, LOGGER_DEBUG); return false; } $xml = $ret['body']; - $xrd = Network::parseXmlString($xml, false); + $xrd = XML::parseString($xml, false); $host_url = 'http://'.$host; } if (!is_object($xrd)) { @@ -331,7 +331,7 @@ class Probe } if (x($data, "photo")) { - $data["baseurl"] = Network::matchingURL(normalise_link($data["baseurl"]), normalise_link($data["photo"])); + $data["baseurl"] = Network::getUrlMatch(normalise_link($data["baseurl"]), normalise_link($data["photo"])); } else { $data["photo"] = System::baseUrl().'/images/person-175.jpg'; } @@ -692,7 +692,7 @@ class Probe $xrd_timeout = Config::get('system', 'xrd_timeout', 20); $redirects = 0; - $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); + $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -708,7 +708,7 @@ class Probe } // If it is not JSON, maybe it is XML - $xrd = Network::parseXmlString($data, false); + $xrd = XML::parseString($data, false); if (!is_object($xrd)) { logger("No webfinger data retrievable for ".$url, LOGGER_DEBUG); return false; @@ -759,7 +759,7 @@ class Probe */ private static function pollNoscrape($noscrape_url, $data) { - $ret = Network::zFetchURL($noscrape_url); + $ret = Network::curl($noscrape_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -993,7 +993,7 @@ class Probe */ private static function pollHcard($hcard_url, $data, $dfrn = false) { - $ret = Network::zFetchURL($hcard_url); + $ret = Network::curl($hcard_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1232,7 +1232,7 @@ class Probe $pubkey = substr($pubkey, 5); } } elseif (normalise_link($pubkey) == 'http://') { - $ret = Network::zFetchURL($pubkey); + $ret = Network::curl($pubkey); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1264,7 +1264,7 @@ class Probe } // Fetch all additional data from the feed - $ret = Network::zFetchURL($data["poll"]); + $ret = Network::curl($data["poll"]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1448,7 +1448,7 @@ class Probe */ private static function feed($url, $probe = true) { - $ret = Network::zFetchURL($url); + $ret = Network::curl($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1509,7 +1509,7 @@ class Probe */ private static function mail($uri, $uid) { - if (!Network::validateEmail($uri)) { + if (!Network::isEmailDomainValid($uri)) { return false; } @@ -1543,7 +1543,7 @@ class Probe $data["network"] = NETWORK_MAIL; $data["name"] = substr($uri, 0, strpos($uri, '@')); $data["nick"] = $data["name"]; - $data["photo"] = Network::avatarImg($uri); + $data["photo"] = Network::lookupAvatarByEmail($uri); $data["url"] = 'mailto:'.$uri; $data["notify"] = 'smtp '.random_string(); $data["poll"] = 'email '.random_string(); diff --git a/src/Object/Image.php b/src/Object/Image.php index 84c462205e..d8d6dafc3c 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -774,7 +774,7 @@ class Image $data = Cache::get($url); if (is_null($data) || !$data || !is_array($data)) { - $img_str = Network::fetchURL($url, true, $redirects, 4); + $img_str = Network::fetchUrl($url, true, $redirects, 4); $filesize = strlen($img_str); if (function_exists("getimagesizefromstring")) { diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 2901796db4..59141576b3 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -793,7 +793,7 @@ class DFRN if ($activity) { $entry = $doc->createElement($element); - $r = Network::parseXmlString($activity, false); + $r = XML::parseString($activity, false); if (!$r) { return false; } @@ -816,7 +816,7 @@ class DFRN $r->link = preg_replace('/\/', '', $r->link); // XML does need a single element as root element so we add a dummy element here - $data = Network::parseXmlString("" . $r->link . "", false); + $data = XML::parseString("" . $r->link . "", false); if (is_object($data)) { foreach ($data->link as $link) { $attributes = []; @@ -1187,7 +1187,7 @@ class DFRN logger('dfrn_deliver: ' . $url); - $ret = Network::zFetchURL($url); + $ret = Network::curl($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return -2; // timed out @@ -1212,7 +1212,7 @@ class DFRN return 3; } - $res = Network::parseXmlString($xml); + $res = XML::parseString($xml); if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { return (($res->status) ? $res->status : 3); @@ -1333,7 +1333,7 @@ class DFRN logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars, true), LOGGER_DATA); - $xml = Network::postURL($contact['notify'], $postvars); + $xml = Network::post($contact['notify'], $postvars); logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA); @@ -1357,7 +1357,7 @@ class DFRN Contact::unmarkForArchival($contact); } - $res = Network::parseXmlString($xml); + $res = XML::parseString($xml); if (!isset($res->status)) { return -11; @@ -2188,7 +2188,7 @@ class DFRN if (!$verb) { return; } - $xo = Network::parseXmlString($item["object"], false); + $xo = XML::parseString($item["object"], false); if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? @@ -2310,8 +2310,8 @@ class DFRN } if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = Network::parseXmlString($item["object"], false); - $xt = Network::parseXmlString($item["target"], false); + $xo = XML::parseString($item["object"], false); + $xt = XML::parseString($item["target"], false); if ($xt->type == ACTIVITY_OBJ_NOTE) { $r = q( @@ -2518,7 +2518,7 @@ class DFRN $item["object"] = self::transformActivity($xpath, $object, "object"); if (trim($item["object"]) != "") { - $r = Network::parseXmlString($item["object"], false); + $r = XML::parseString($item["object"], false); if (isset($r->type)) { $item["object-type"] = $r->type; } @@ -2787,8 +2787,8 @@ class DFRN } if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = Network::parseXmlString($item["object"], false); - $xt = Network::parseXmlString($item["target"], false); + $xo = XML::parseString($item["object"], false); + $xt = XML::parseString($item["target"], false); if ($xt->type == ACTIVITY_OBJ_NOTE) { $i = q( diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index b87aabfb47..a6c74537d2 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -186,7 +186,7 @@ class Diaspora */ private static function verifyMagicEnvelope($envelope) { - $basedom = Network::parseXmlString($envelope); + $basedom = XML::parseString($envelope); if (!is_object($basedom)) { logger("Envelope is no XML file"); @@ -296,7 +296,7 @@ class Diaspora $xml = $raw; } - $basedom = Network::parseXmlString($xml); + $basedom = XML::parseString($xml); if (!is_object($basedom)) { logger('Received data does not seem to be an XML. Discarding. '.$xml); @@ -347,7 +347,7 @@ class Diaspora public static function decode($importer, $xml) { $public = false; - $basedom = Network::parseXmlString($xml); + $basedom = XML::parseString($xml); if (!is_object($basedom)) { logger("XML is not parseable."); @@ -381,7 +381,7 @@ class Diaspora $decrypted = self::aesDecrypt($outer_key, $outer_iv, $ciphertext); logger('decrypted: '.$decrypted, LOGGER_DEBUG); - $idom = Network::parseXmlString($decrypted); + $idom = XML::parseString($decrypted); $inner_iv = base64_decode($idom->iv); $inner_aes_key = base64_decode($idom->aes_key); @@ -631,7 +631,7 @@ class Diaspora */ private static function validPosting($msg) { - $data = Network::parseXmlString($msg["message"]); + $data = XML::parseString($msg["message"]); if (!is_object($data)) { logger("No valid XML ".$msg["message"], LOGGER_DEBUG); @@ -1257,7 +1257,7 @@ class Diaspora logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $envelope = Network::fetchURL($source_url); + $envelope = Network::fetchUrl($source_url); if ($envelope) { logger("Envelope was fetched.", LOGGER_DEBUG); $x = self::verifyMagicEnvelope($envelope); @@ -1275,13 +1275,13 @@ class Diaspora $source_url = $server."/p/".urlencode($guid).".xml"; logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $x = Network::fetchURL($source_url); + $x = Network::fetchUrl($source_url); if (!$x) { return false; } } - $source_xml = Network::parseXmlString($x); + $source_xml = XML::parseString($x); if (!is_object($source_xml)) { return false; @@ -3229,7 +3229,7 @@ class Diaspora if (!intval(Config::get("system", "diaspora_test"))) { $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); - Network::postURL($dest_url."/", $envelope, ["Content-Type: ".$content_type]); + Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]); $return_code = $a->get_curl_code(); } else { logger("test_mode"); diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index e728afa245..cc0915472d 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -244,7 +244,7 @@ class Feed { $orig_plink = $item["plink"]; - $item["plink"] = Network::originalURL($item["plink"]); + $item["plink"] = Network::finalUrl($item["plink"]); $item["parent-uri"] = $item["uri"]; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 87b894a717..e41f3addc1 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -726,7 +726,7 @@ class OStatus self::$conv_list[$conversation] = true; - $conversation_data = Network::zFetchURL($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $conversation_data = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$conversation_data['success']) { return; @@ -754,7 +754,7 @@ class OStatus } } if ($file != '') { - $conversation_atom = Network::zFetchURL($attribute['href']); + $conversation_atom = Network::curl($attribute['href']); if ($conversation_atom['success']) { $xml = $conversation_atom['body']; @@ -870,7 +870,7 @@ class OStatus return; } - $self_data = Network::zFetchURL($self); + $self_data = Network::curl($self); if (!$self_data['success']) { return; @@ -915,7 +915,7 @@ class OStatus } $stored = false; - $related_data = Network::zFetchURL($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $related_data = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$related_data['success']) { return; @@ -946,7 +946,7 @@ class OStatus } } if ($atom_file != '') { - $related_atom = Network::zFetchURL($atom_file); + $related_atom = Network::curl($atom_file); if ($related_atom['success']) { logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG); @@ -958,7 +958,7 @@ class OStatus // Workaround for older GNU Social servers if (($xml == '') && strstr($related, '/notice/')) { - $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); + $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG); @@ -969,7 +969,7 @@ class OStatus // Even more worse workaround for GNU Social ;-) if ($xml == '') { $related_guess = OStatus::convertHref($related_uri); - $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); + $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG); diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 9ed48b1cf4..f2def21ec1 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -85,7 +85,7 @@ class PortableContact logger('load: ' . $url, LOGGER_DEBUG); - $s = Network::fetchURL($url); + $s = Network::fetchUrl($url); logger('load: returns ' . $s, LOGGER_DATA); @@ -287,7 +287,7 @@ class PortableContact } // Fetch the host-meta to check if this really is a server - $serverret = Network::zFetchURL($server_url."/.well-known/host-meta"); + $serverret = Network::curl($server_url."/.well-known/host-meta"); if (!$serverret["success"]) { return ""; } @@ -366,7 +366,7 @@ class PortableContact $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url))); if ($server) { - $noscraperet = Network::zFetchURL($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); + $noscraperet = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); if ($noscraperet["success"] && ($noscraperet["body"] != "")) { $noscrape = json_decode($noscraperet["body"], true); @@ -480,7 +480,7 @@ class PortableContact GContact::update($contact); - $feedret = Network::zFetchURL($data["poll"]); + $feedret = Network::curl($data["poll"]); if (!$feedret["success"]) { $fields = ['last_failure' => datetime_convert()]; @@ -631,7 +631,7 @@ class PortableContact */ private static function fetchNodeinfo($server_url) { - $serverret = Network::zFetchURL($server_url."/.well-known/nodeinfo"); + $serverret = Network::curl($server_url."/.well-known/nodeinfo"); if (!$serverret["success"]) { return false; } @@ -663,7 +663,7 @@ class PortableContact return false; } - $serverret = Network::zFetchURL($nodeinfo_url); + $serverret = Network::curl($nodeinfo_url); if (!$serverret["success"]) { return false; } @@ -872,7 +872,7 @@ class PortableContact $server_url = str_replace("http://", "https://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout. // But we want to make sure to only quit if we are mostly sure that this server url fits. @@ -889,7 +889,7 @@ class PortableContact $server_url = str_replace("https://", "http://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { @@ -925,7 +925,7 @@ class PortableContact // Look for poco if (!$failure) { - $serverret = Network::zFetchURL($server_url."/poco"); + $serverret = Network::curl($server_url."/poco"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->totalResults)) { @@ -951,7 +951,7 @@ class PortableContact if (!$failure) { // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers - $serverret = Network::zFetchURL($server_url); + $serverret = Network::curl($server_url); if (!$serverret["success"] || ($serverret["body"] == "")) { $failure = true; @@ -990,7 +990,7 @@ class PortableContact // Test for Statusnet // Will also return data for Friendica and GNU Social - but it will be overwritten later // The "not implemented" is a special treatment for really, really old Friendica versions - $serverret = Network::zFetchURL($server_url."/api/statusnet/version.json"); + $serverret = Network::curl($server_url."/api/statusnet/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "StatusNet"; @@ -1001,7 +1001,7 @@ class PortableContact } // Test for GNU Social - $serverret = Network::zFetchURL($server_url."/api/gnusocial/version.json"); + $serverret = Network::curl($server_url."/api/gnusocial/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "GNU Social"; @@ -1013,7 +1013,7 @@ class PortableContact // Test for Mastodon $orig_version = $version; - $serverret = Network::zFetchURL($server_url."/api/v1/instance"); + $serverret = Network::curl($server_url."/api/v1/instance"); if ($serverret["success"] && ($serverret["body"] != '')) { $data = json_decode($serverret["body"]); @@ -1036,7 +1036,7 @@ class PortableContact if (!$failure) { // Test for Hubzilla and Red - $serverret = Network::zFetchURL($server_url."/siteinfo.json"); + $serverret = Network::curl($server_url."/siteinfo.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->url)) { @@ -1064,7 +1064,7 @@ class PortableContact } } else { // Test for Hubzilla, Redmatrix or Friendica - $serverret = Network::zFetchURL($server_url."/api/statusnet/config.json"); + $serverret = Network::curl($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->site->server)) { @@ -1119,7 +1119,7 @@ class PortableContact // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix if (!$failure) { - $serverret = Network::zFetchURL($server_url."/statistics.json"); + $serverret = Network::curl($server_url."/statistics.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); @@ -1181,10 +1181,10 @@ class PortableContact // Check for noscrape // Friendica servers could be detected as OStatus servers if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) { - $serverret = Network::zFetchURL($server_url."/friendica/json"); + $serverret = Network::curl($server_url."/friendica/json"); if (!$serverret["success"]) { - $serverret = Network::zFetchURL($server_url."/friendika/json"); + $serverret = Network::curl($server_url."/friendika/json"); } if ($serverret["success"]) { @@ -1294,7 +1294,7 @@ class PortableContact */ private static function fetchServerlist($poco) { - $serverret = Network::zFetchURL($poco."/@server"); + $serverret = Network::curl($poco."/@server"); if (!$serverret["success"]) { return; } @@ -1343,7 +1343,7 @@ class PortableContact if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $serverdata = Network::zFetchURL($api, false, $redirects, ['headers' => $header]); + $serverdata = Network::curl($api, false, $redirects, ['headers' => $header]); if ($serverdata['success']) { $servers = json_decode($serverdata['body']); foreach ($servers->instances as $server) { @@ -1360,7 +1360,7 @@ class PortableContact //if (!Config::get('system','ostatus_disabled')) { // $serverdata = "http://gstools.org/api/get_open_instances/"; - // $result = Network::zFetchURL($serverdata); + // $result = Network::curl($serverdata); // if ($result["success"]) { // $servers = json_decode($result["body"]); @@ -1389,7 +1389,7 @@ class PortableContact logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG); - $retdata = Network::zFetchURL($url); + $retdata = Network::curl($url); if ($retdata["success"]) { $data = json_decode($retdata["body"]); @@ -1408,7 +1408,7 @@ class PortableContact $success = false; - $retdata = Network::zFetchURL($url); + $retdata = Network::curl($url); if ($retdata["success"]) { logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); $success = self::discoverServer(json_decode($retdata["body"])); @@ -1493,7 +1493,7 @@ class PortableContact // Fetch all contacts from a given user from the other server $url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - $retdata = Network::zFetchURL($url); + $retdata = Network::curl($url); if ($retdata["success"]) { self::discoverServer(json_decode($retdata["body"]), 3); } diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index f49225021e..f30488ce14 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -51,7 +51,7 @@ class Salmon $ret[$x] = substr($ret[$x], 5); } } elseif (normalise_link($ret[$x]) == 'http://') { - $ret[$x] = Network::fetchURL($ret[$x]); + $ret[$x] = Network::fetchUrl($ret[$x]); } } } @@ -133,7 +133,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - Network::postURL($url, $salmon, [ + Network::post($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) ]); @@ -159,7 +159,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - Network::postURL($url, $salmon, [ + Network::post($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) ]); @@ -182,7 +182,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - Network::postURL($url, $salmon, [ + Network::post($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon)]); $return_code = $a->get_curl_code(); diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 35e812a5c9..a6851c3852 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -181,7 +181,7 @@ class ExAuth $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; - $data = Network::zFetchURL($url); + $data = Network::curl($url); if (!is_array($data)) { return false; diff --git a/src/Util/Network.php b/src/Util/Network.php index 9cd3cb7197..b013f65a3d 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -11,7 +11,6 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Network\Probe; use Friendica\Object\Image; -use Friendica\Util\Network; use Friendica\Util\XML; require_once 'library/slinky.php'; @@ -35,9 +34,9 @@ class Network * * @return string The fetched content */ - public static function fetchURL($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) + public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) { - $ret = self::zFetchURL( + $ret = self::curl( $url, $binary, $redirects, @@ -72,7 +71,7 @@ class Network * string 'header' => HTTP headers * string 'body' => fetched content */ - public static function zFetchURL($url, $binary = false, &$redirects = 0, $opts = []) + public static function curl($url, $binary = false, &$redirects = 0, $opts = []) { $ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '']; @@ -80,7 +79,7 @@ class Network $a = get_app(); - if (self::blockedURL($url)) { + if (self::isUrlBlocked($url)) { logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA); return $ret; } @@ -278,11 +277,11 @@ class Network * * @return string The content */ - public static function postURL($url, $params, $headers = null, &$redirects = 0, $timeout = 0) + public static function post($url, $params, $headers = null, &$redirects = 0, $timeout = 0) { $stamp1 = microtime(true); - if (self::blockedURL($url)) { + if (self::isUrlBlocked($url)) { logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA); return false; } @@ -381,7 +380,7 @@ class Network if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; logger('post_url: redirect ' . $url . ' to ' . $newurl); - return self::postURL($newurl, $params, $headers, $redirects, $timeout); + return self::post($newurl, $params, $headers, $redirects, $timeout); } } @@ -405,7 +404,7 @@ class Network * Outputs a basic dfrn XML status structure to STDOUT, with a variable * of $st and an optional text of $message and terminates the current process. */ - public static function xmlStatus($st, $message = '') + public static function xmlExit($st, $message = '') { $result = ['status' => $st]; @@ -465,7 +464,7 @@ class Network } /** - * @brief Check URL to se if ts's real + * @brief Check URL to see if it's real * * Take a URL from the wild, prepend http:// if necessary * and check DNS to see if it's real (or check if is a valid IP address) @@ -473,7 +472,7 @@ class Network * @param string $url The URL to be validated * @return string|boolean The actual working URL, false else */ - public static function validateURL($url) + public static function isUrlValid($url) { if (Config::get('system', 'disable_url_validation')) { return $url; @@ -504,7 +503,7 @@ class Network * @param string $addr The email address * @return boolean True if it's a valid email address, false if it's not */ - public static function validateEmail($addr) + public static function isEmailDomainValid($addr) { if (Config::get('system', 'disable_email_validation')) { return true; @@ -531,7 +530,7 @@ class Network * @param string $url URL which get tested * @return boolean True if url is allowed otherwise return false */ - public static function allowedURL($url) + public static function isUrlAllowed($url) { $h = @parse_url($url); @@ -576,7 +575,7 @@ class Network * * @return boolean */ - public static function blockedURL($url) + public static function isUrlBlocked($url) { $h = @parse_url($url); @@ -609,7 +608,7 @@ class Network * @return boolean False if not allowed, true if allowed * or if allowed list is not configured */ - public static function allowedEmail($email) + public static function isEmailDomainAllowed($email) { $domain = strtolower(substr($email, strpos($email, '@') + 1)); if (!$domain) { @@ -623,7 +622,7 @@ class Network $allowed = explode(',', $str_allowed); - return self::allowedDomain($domain, $allowed); + return self::isDomainAllowed($domain, $allowed); } /** @@ -634,7 +633,7 @@ class Network * @param array $domain_list * @return boolean */ - public static function allowedDomain($domain, array $domain_list) + public static function isDomainAllowed($domain, array $domain_list) { $found = false; @@ -649,7 +648,7 @@ class Network return $found; } - public static function avatarImg($email) + public static function lookupAvatarByEmail($email) { $avatar['size'] = 175; $avatar['email'] = $email; @@ -666,125 +665,6 @@ class Network return $avatar['url']; } - public static function parseXmlString($s, $strict = true) - { - // the "strict" parameter is deactivated - - /// @todo Move this function to the xml class - libxml_use_internal_errors(true); - - $x = @simplexml_load_string($s); - if (!$x) { - logger('libxml: parse: error: ' . $s, LOGGER_DATA); - foreach (libxml_get_errors() as $err) { - logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA); - } - libxml_clear_errors(); - } - return $x; - } - - public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) - { - // Suppress "view full size" - if (intval(Config::get('system', 'no_view_full_size'))) { - $include_link = false; - } - - // Picture addresses can contain special characters - $s = htmlspecialchars_decode($srctext); - - $matches = null; - $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); - if ($c) { - foreach ($matches as $mtch) { - logger('scale_external_image: ' . $mtch[1]); - - $hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3)); - if (stristr($mtch[1], $hostname)) { - continue; - } - - // $scale_replace, if passed, is an array of two elements. The - // first is the name of the full-size image. The second is the - // name of a remote, scaled-down version of the full size image. - // This allows Friendica to display the smaller remote image if - // one exists, while still linking to the full-size image - if ($scale_replace) { - $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]); - } else { - $scaled = $mtch[1]; - } - $i = self::fetchURL($scaled); - if (! $i) { - return $srctext; - } - - // guess mimetype from headers or filename - $type = Image::guessType($mtch[1], true); - - if ($i) { - $Image = new Image($i, $type); - if ($Image->isValid()) { - $orig_width = $Image->getWidth(); - $orig_height = $Image->getHeight(); - - if ($orig_width > 640 || $orig_height > 640) { - $Image->scaleDown(640); - $new_width = $Image->getWidth(); - $new_height = $Image->getHeight(); - logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); - $s = str_replace( - $mtch[0], - '[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' - . "\n" . (($include_link) - ? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n" - : ''), - $s - ); - logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); - } - } - } - } - } - - // replace the special char encoding - $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); - return $s; - } - - public static function fixContactSslPolicy(&$contact, $new_policy) - { - $ssl_changed = false; - if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) { - $ssl_changed = true; - $contact['url'] = str_replace('https:', 'http:', $contact['url']); - $contact['request'] = str_replace('https:', 'http:', $contact['request']); - $contact['notify'] = str_replace('https:', 'http:', $contact['notify']); - $contact['poll'] = str_replace('https:', 'http:', $contact['poll']); - $contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']); - $contact['poco'] = str_replace('https:', 'http:', $contact['poco']); - } - - if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) { - $ssl_changed = true; - $contact['url'] = str_replace('http:', 'https:', $contact['url']); - $contact['request'] = str_replace('http:', 'https:', $contact['request']); - $contact['notify'] = str_replace('http:', 'https:', $contact['notify']); - $contact['poll'] = str_replace('http:', 'https:', $contact['poll']); - $contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']); - $contact['poco'] = str_replace('http:', 'https:', $contact['poco']); - } - - if ($ssl_changed) { - $fields = ['url' => $contact['url'], 'request' => $contact['request'], - 'notify' => $contact['notify'], 'poll' => $contact['poll'], - 'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; - dba::update('contact', $fields, ['id' => $contact['id']]); - } - } - /** * @brief Remove Google Analytics and other tracking platforms params from URL * @@ -849,7 +729,7 @@ class Network * @param bool $fetchbody Wether to fetch the body or not after the HEAD requests * @return string A canonical URL */ - public static function originalURL($url, $depth = 1, $fetchbody = false) + public static function finalUrl($url, $depth = 1, $fetchbody = false) { $a = get_app(); @@ -886,15 +766,15 @@ class Network && (($curl_info['redirect_url'] != "") || ($curl_info['location'] != "")) ) { if ($curl_info['redirect_url'] != "") { - return(Network::originalURL($curl_info['redirect_url'], ++$depth, $fetchbody)); + return(self::finalUrl($curl_info['redirect_url'], ++$depth, $fetchbody)); } else { - return(Network::originalURL($curl_info['location'], ++$depth, $fetchbody)); + return(self::finalUrl($curl_info['location'], ++$depth, $fetchbody)); } } // Check for redirects in the meta elements of the body if there are no redirects in the header. if (!$fetchbody) { - return(Network::originalURL($url, ++$depth, true)); + return(self::finalUrl($url, ++$depth, true)); } // if the file is too large then exit @@ -946,7 +826,7 @@ class Network $pathinfo = explode(";", $path); foreach ($pathinfo as $value) { if (substr(strtolower($value), 0, 4) == "url=") { - return(Network::originalURL(substr($value, 4), ++$depth)); + return(self::finalUrl(substr($value, 4), ++$depth)); } } } @@ -955,7 +835,7 @@ class Network return $url; } - public static function shortLink($url) + public static function shortenUrl($url) { $slinky = new Slinky($url); $yourls_url = Config::get('yourls', 'url1'); @@ -987,7 +867,7 @@ class Network * * @param array $x The input content */ - public static function jsonReturnAndDie($x) + public static function jsonExit($x) { header("content-type: application/json"); echo json_encode($x); @@ -1001,7 +881,7 @@ class Network * @param string $url2 * @return string The matching part */ - public static function matchingURL($url1, $url2) + public static function getUrlMatch($url1, $url2) { if (($url1 == "") || ($url2 == "")) { return ""; @@ -1061,7 +941,7 @@ class Network * * @return string The glued URL */ - public static function unParseURL($parsed) + public static function unparseURL($parsed) { $get = function ($key) use ($parsed) { return isset($parsed[$key]) ? $parsed[$key] : null; diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 1c5676aced..868bd7ede8 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -145,7 +145,7 @@ class ParseUrl $siteinfo["url"] = $url; $siteinfo["type"] = "link"; - $data = Network::zFetchURL($url); + $data = Network::curl($url); if (!$data['success']) { return($siteinfo); } diff --git a/src/Util/XML.php b/src/Util/XML.php index c866475c1b..d8c5e03239 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -413,4 +413,20 @@ class XML $child->parentNode->removeChild($child); } } + + public static function parseString($s, $strict = true) + { + // the "strict" parameter is deactivated + libxml_use_internal_errors(true); + + $x = @simplexml_load_string($s); + if (!$x) { + logger('libxml: parse: error: ' . $s, LOGGER_DATA); + foreach (libxml_get_errors() as $err) { + logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA); + } + libxml_clear_errors(); + } + return $x; + } } diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index 2e089502f1..a6056ccbc4 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -38,7 +38,7 @@ class CheckVersion { logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG); // fetch the VERSION file - $gitversion = dbesc(trim(Network::fetchURL($checked_url))); + $gitversion = dbesc(trim(Network::fetchUrl($checked_url))); logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG); Config::set('system', 'git_friendica_version', $gitversion); diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index cc704474e0..e17d68f885 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -15,7 +15,6 @@ use Friendica\Model\User; use Friendica\Protocol\Diaspora; use Friendica\Protocol\DFRN; use Friendica\Protocol\Email; -use Friendica\Util\Network; use dba; require_once 'include/html2plain.php'; @@ -300,7 +299,7 @@ class Delivery { } $ssl_policy = Config::get('system','ssl_policy'); - Network::fixContactSslPolicy($x[0], $ssl_policy); + $x[0] = Contact::updateSslPolicy($x[0], $ssl_policy); // If we are setup as a soapbox we aren't accepting top level posts from this person diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index 634c5a5ec5..a59461037d 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -12,8 +12,10 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Util\Network; -class Directory { - public static function execute($url = '') { +class Directory +{ + public static function execute($url = '') + { $dir = Config::get('system', 'directory'); if (!strlen($dir)) { @@ -33,7 +35,7 @@ class Directory { logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG); if (strlen($arr['url'])) { - Network::fetchURL($dir . '?url=' . bin2hex($arr['url'])); + Network::fetchUrl($dir . '?url=' . bin2hex($arr['url'])); } return; diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index 0172bcd342..0657b0e1b2 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -218,7 +218,7 @@ class DiscoverPoCo { } } - $x = Network::fetchURL(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); + $x = Network::fetchUrl(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); $j = json_decode($x); if (count($j->results)) { @@ -281,7 +281,7 @@ class DiscoverPoCo { $url = "http://gstools.org/api/users_search/".urlencode($search); - $result = Network::zFetchURL($url); + $result = Network::curl($url); if (!$result["success"]) { return false; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index c06b8f5930..3a5fa5575b 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -11,6 +11,7 @@ use Friendica\Model\Contact; use Friendica\Protocol\Email; use Friendica\Protocol\PortableContact; use Friendica\Util\Network; +use Friendica\Util\XML; use dba; require_once 'include/dba.php'; @@ -177,7 +178,7 @@ class OnePoll . '&type=data&last_update=' . $last_update . '&perm=' . $perm ; - $ret = Network::zFetchURL($url); + $ret = Network::curl($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { // set the last-update so we don't keep polling @@ -219,7 +220,7 @@ class OnePoll } - $res = Network::parseXmlString($handshake_xml); + $res = XML::parseString($handshake_xml); if (intval($res->status) == 1) { logger("$url replied status 1 - marking for death "); @@ -281,7 +282,7 @@ class OnePoll $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['perm'] = 'rw'; - $xml = Network::postURL($contact['poll'], $postvars); + $xml = Network::post($contact['poll'], $postvars); } elseif (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) @@ -312,7 +313,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $ret = Network::zFetchURL($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); + $ret = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index a287e89d33..03608bea66 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -69,7 +69,7 @@ class PubSubPublish { logger('POST '.print_r($headers, true)."\n".$params, LOGGER_DEBUG); - Network::postURL($rr['callback_url'], $params, $headers); + Network::post($rr['callback_url'], $params, $headers); $ret = $a->get_curl_code(); if ($ret >= 200 && $ret <= 299) { From 9b8599b6198972538685fcc9723861e96b5112d0 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 11:59:10 -0500 Subject: [PATCH 10/13] Move functions to system move some functions to system --- mod/_well_known.php | 4 +- mod/dfrn_confirm.php | 18 ++++----- mod/dfrn_notify.php | 16 ++++---- mod/dfrn_poll.php | 20 +++++----- mod/display.php | 3 +- mod/hovercard.php | 6 +-- mod/nodeinfo.php | 4 +- mod/notifications.php | 3 +- mod/poco.php | 12 +++--- mod/probe.php | 4 +- mod/pubsubhubbub.php | 21 +++++----- mod/receive.php | 14 +++---- mod/salmon.php | 16 ++++---- mod/search.php | 6 +-- mod/smilies.php | 4 +- mod/statistics_json.php | 4 +- mod/webfinger.php | 4 +- src/Core/System.php | 81 +++++++++++++++++++++++++++++++++++++++ src/Module/Feed.php | 4 +- src/Protocol/Diaspora.php | 14 +++---- src/Util/Network.php | 80 -------------------------------------- 21 files changed, 169 insertions(+), 169 deletions(-) diff --git a/mod/_well_known.php b/mod/_well_known.php index e7bc8c92bf..25289171f6 100644 --- a/mod/_well_known.php +++ b/mod/_well_known.php @@ -2,7 +2,7 @@ use Friendica\App; use Friendica\Core\Config; -use Friendica\Util\Network; +use Friendica\Core\System; require_once 'mod/hostxrd.php'; require_once 'mod/nodeinfo.php'; @@ -26,7 +26,7 @@ function _well_known_init(App $a) break; } } - Network::httpStatusExit(404); + System::httpExit(404); killme(); } diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 85e896dcf5..3066a871fc 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -494,7 +494,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) $user = dba::selectFirst('user', [], ['nickname' => $node]); if (!DBM::is_result($user)) { $message = L10n::t('No user record found for \'%s\' ', $node); - Network::xmlExit(3, $message); // failure + System::xmlExit(3, $message); // failure // NOTREACHED } @@ -504,7 +504,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strstr($my_prvkey, 'PRIVATE KEY')) { $message = L10n::t('Our site encryption key is apparently messed up.'); - Network::xmlExit(3, $message); + System::xmlExit(3, $message); } // verify everything @@ -515,7 +515,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strlen($decrypted_source_url)) { $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.'); - Network::xmlExit(3, $message); + System::xmlExit(3, $message); // NOTREACHED } @@ -531,7 +531,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!DBM::is_result($contact)) { // this is either a bogus confirmation (?) or we deleted the original introduction. $message = L10n::t('Contact record was not found for you on our site.'); - Network::xmlExit(3, $message); + System::xmlExit(3, $message); return; // NOTREACHED } } @@ -545,7 +545,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!$foreign_pubkey) { $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url); - Network::xmlExit(3, $message); + System::xmlExit(3, $message); } $decrypted_dfrn_id = ""; @@ -561,7 +561,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (dba::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) { $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.'); - Network::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id + System::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id // NOTREACHED } @@ -572,7 +572,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { $message = L10n::t('Unable to set your contact credentials on our system.'); - Network::xmlExit(3, $message); + System::xmlExit(3, $message); } // It's possible that the other person also requested friendship. @@ -627,7 +627,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { // indicates schema is messed up or total db failure $message = L10n::t('Unable to update your contact profile details on our system'); - Network::xmlExit(3, $message); + System::xmlExit(3, $message); } // Otherwise everything seems to have worked and we are almost done. Yay! @@ -708,7 +708,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) } } } - Network::xmlExit(0); // Success + System::xmlExit(0); // Success return; // NOTREACHED ////////////////////// End of this scenario /////////////////////////////////////////////// } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index 8efb9328d5..2f4edafc5d 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -8,10 +8,10 @@ use Friendica\App; use Friendica\Core\Config; +use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\DFRN; -use Friendica\Util\Network; require_once 'include/items.php'; require_once 'include/event.php'; @@ -49,7 +49,7 @@ function dfrn_notify_post(App $a) { ); if (! DBM::is_result($r)) { logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); - Network::xmlExit(3, 'Could not match challenge'); + System::xmlExit(3, 'Could not match challenge'); } $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'", @@ -71,7 +71,7 @@ function dfrn_notify_post(App $a) { $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id)); break; default: - Network::xmlExit(3, 'Invalid direction'); + System::xmlExit(3, 'Invalid direction'); break; // NOTREACHED } @@ -97,7 +97,7 @@ function dfrn_notify_post(App $a) { if (! DBM::is_result($r)) { logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); - Network::xmlExit(3, 'Contact not found'); + System::xmlExit(3, 'Contact not found'); //NOTREACHED } @@ -132,7 +132,7 @@ function dfrn_notify_post(App $a) { // Relationship is dissolved permanently Contact::remove($importer['id']); logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']); - Network::xmlExit(0, 'relationship dissolved'); + System::xmlExit(0, 'relationship dissolved'); } $rino = Config::get('system', 'rino_encrypt'); @@ -146,7 +146,7 @@ function dfrn_notify_post(App $a) { // but only for $remote_rino > 1, because old code did't send rino version if ($rino_remote > 1 && $rino < $rino_remote) { logger("rino version '$rino_remote' is lower than supported '$rino'"); - Network::xmlExit(0, "rino version '$rino_remote' is lower than supported '$rino'"); + System::xmlExit(0, "rino version '$rino_remote' is lower than supported '$rino'"); } $rawkey = hex2bin(trim($key)); @@ -176,14 +176,14 @@ function dfrn_notify_post(App $a) { break; default: logger("rino: invalid sent version '$rino_remote'"); - Network::xmlExit(0, "Invalid sent version '$rino_remote'"); + System::xmlExit(0, "Invalid sent version '$rino_remote'"); } logger('rino: decrypted data: ' . $data, LOGGER_DATA); } $ret = DFRN::import($data, $importer); - Network::xmlExit($ret, 'Processed'); + System::xmlExit($ret, 'Processed'); // NOTREACHED } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 3e5aa5b1c7..7d5418c364 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -49,7 +49,7 @@ function dfrn_poll_init(App $a) if (($dfrn_id === '') && (!x($_POST, 'dfrn_id'))) { if (Config::get('system', 'block_public') && !local_user() && !remote_user()) { - Network::httpStatusExit(403); + System::httpExit(403); } $user = ''; @@ -58,7 +58,7 @@ function dfrn_poll_init(App $a) dbesc($a->argv[1]) ); if (!$r) { - Network::httpStatusExit(404); + System::httpExit(404); } $hidewall = ($r[0]['hidewall'] && !local_user()); @@ -145,7 +145,7 @@ function dfrn_poll_init(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - Network::xmlExit(3, 'No ticket'); + System::xmlExit(3, 'No ticket'); // NOTREACHED } @@ -158,7 +158,7 @@ function dfrn_poll_init(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - Network::xmlExit(3, 'No profile'); + System::xmlExit(3, 'No profile'); } $contact = $c[0]; @@ -185,7 +185,7 @@ function dfrn_poll_init(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - Network::xmlExit(3, 'Bad decryption'); + System::xmlExit(3, 'Bad decryption'); } header("Content-type: text/xml"); @@ -209,10 +209,10 @@ function dfrn_poll_init(App $a) $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC", dbesc($dfrn_id)); if (DBM::is_result($r)) { - Network::xmlExit(1); + System::xmlExit(1); return; // NOTREACHED } - Network::xmlExit(0); + System::xmlExit(0); return; // NOTREACHED } } @@ -237,7 +237,7 @@ function dfrn_poll_post(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - Network::xmlExit(3, 'No ticket'); + System::xmlExit(3, 'No ticket'); // NOTREACHED } @@ -250,7 +250,7 @@ function dfrn_poll_post(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - Network::xmlExit(3, 'No profile'); + System::xmlExit(3, 'No profile'); } $contact = $c[0]; @@ -277,7 +277,7 @@ function dfrn_poll_post(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - Network::xmlExit(3, 'Bad decryption'); + System::xmlExit(3, 'Bad decryption'); } header("Content-type: text/xml"); diff --git a/mod/display.php b/mod/display.php index 54a54be167..8d991d4768 100644 --- a/mod/display.php +++ b/mod/display.php @@ -11,7 +11,6 @@ use Friendica\Model\Contact; use Friendica\Model\Group; use Friendica\Model\Profile; use Friendica\Protocol\DFRN; -use Friendica\Util\Network; function display_init(App $a) { @@ -424,7 +423,7 @@ function display_content(App $a, $update = false, $update_uid = 0) { function displayShowFeed($item_id, $conversation) { $xml = DFRN::itemFeed($item_id, $conversation); if ($xml == '') { - Network::httpStatusExit(500); + System::httpExit(500); } header("Content-type: application/atom+xml"); echo $xml; diff --git a/mod/hovercard.php b/mod/hovercard.php index 0bd1d26178..01d9feb1e4 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -9,10 +9,10 @@ */ use Friendica\App; use Friendica\Core\Config; +use Friendica\Core\System; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Model\Profile; -use Friendica\Util\Network; function hovercard_init(App $a) { @@ -27,7 +27,7 @@ function hovercard_content() // Get out if the system doesn't have public access allowed if (intval(Config::get('system', 'block_public'))) { - Network::httpStatusExit(401); + System::httpExit(401); } // Return the raw content of the template. We use this to make templates usable for js functions. @@ -91,7 +91,7 @@ function hovercard_content() return $o; } else { - Network::jsonExit($profile); + System::jsonExit($profile); } } diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index 026d3f03d9..5cadc41c49 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -22,12 +22,12 @@ function nodeinfo_wellknown(App $a) { function nodeinfo_init(App $a) { if (!Config::get('system', 'nodeinfo')) { - Network::httpStatusExit(404); + System::httpExit(404); killme(); } if (($a->argc != 2) || ($a->argv[1] != '1.0')) { - Network::httpStatusExit(404); + System::httpExit(404); killme(); } diff --git a/mod/notifications.php b/mod/notifications.php index 067e954228..46519075b4 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -10,7 +10,6 @@ use Friendica\Core\L10n; use Friendica\Core\NotificationsManager; use Friendica\Core\System; use Friendica\Database\DBM; -use Friendica\Util\Network; function notifications_post(App $a) { @@ -139,7 +138,7 @@ function notifications_content(App $a) { // Json output if (intval($json) === 1) { - Network::jsonExit($notifs); + System::jsonExit($notifs); } $notif_tpl = get_markup_template('notifications.tpl'); diff --git a/mod/poco.php b/mod/poco.php index 348f76d1ce..c27cd7c49c 100644 --- a/mod/poco.php +++ b/mod/poco.php @@ -6,15 +6,15 @@ use Friendica\App; use Friendica\Core\Cache; use Friendica\Core\Config; +use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Protocol\PortableContact; -use Friendica\Util\Network; function poco_init(App $a) { $system_mode = false; if (intval(Config::get('system', 'block_public')) || (Config::get('system', 'block_local_dir'))) { - Network::httpStatusExit(401); + System::httpExit(401); } if ($a->argc > 1) { @@ -23,7 +23,7 @@ function poco_init(App $a) { if (! x($user)) { $c = q("SELECT * FROM `pconfig` WHERE `cat` = 'system' AND `k` = 'suggestme' AND `v` = 1"); if (! DBM::is_result($c)) { - Network::httpStatusExit(401); + System::httpExit(401); } $system_mode = true; } @@ -64,7 +64,7 @@ function poco_init(App $a) { dbesc($user) ); if (! DBM::is_result($users) || $users[0]['hidewall'] || $users[0]['hide-friends']) { - Network::httpStatusExit(404); + System::httpExit(404); } $user = $users[0]; @@ -358,7 +358,7 @@ function poco_init(App $a) { $ret['entry'][] = []; } } else { - Network::httpStatusExit(500); + System::httpExit(500); } logger("End of poco", LOGGER_DEBUG); @@ -372,6 +372,6 @@ function poco_init(App $a) { echo json_encode($ret); killme(); } else { - Network::httpStatusExit(500); + System::httpExit(500); } } diff --git a/mod/probe.php b/mod/probe.php index a7746d55bc..b4f6ff3a4d 100644 --- a/mod/probe.php +++ b/mod/probe.php @@ -4,13 +4,13 @@ */ use Friendica\App; use Friendica\Core\L10n; +use Friendica\Core\System; use Friendica\Network\Probe; -use Friendica\Util\Network; function probe_content(App $a) { if (!local_user()) { - Network::httpStatusExit(403, ["title" => L10n::t("Public access denied."), + System::httpExit(403, ["title" => L10n::t("Public access denied."), "description" => L10n::t("Only logged in users are permitted to perform a probing.")]); killme(); } diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index 210bc6efbc..ac85657ddf 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -2,6 +2,7 @@ use Friendica\App; use Friendica\Core\Config; +use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Util\Network; @@ -13,7 +14,7 @@ function pubsubhubbub_init(App $a) { // PuSH subscription must be considered "public" so just block it // if public access isn't enabled. if (Config::get('system', 'block_public')) { - Network::httpStatusExit(403); + System::httpExit(403); } // Subscription request from subscriber @@ -41,7 +42,7 @@ function pubsubhubbub_init(App $a) { $subscribe = 0; } else { logger("pubsubhubbub: invalid hub_mode=$hub_mode, ignoring."); - Network::httpStatusExit(404); + System::httpExit(404); } logger("pubsubhubbub: $hub_mode request from " . @@ -57,7 +58,7 @@ function pubsubhubbub_init(App $a) { if (!$nick) { logger('pubsubhubbub: bad hub_topic=$hub_topic, ignoring.'); - Network::httpStatusExit(404); + System::httpExit(404); } // fetch user from database given the nickname @@ -67,7 +68,7 @@ function pubsubhubbub_init(App $a) { if (!DBM::is_result($r)) { logger('pubsubhubbub: local account not found: ' . $nick); - Network::httpStatusExit(404); + System::httpExit(404); } $owner = $r[0]; @@ -76,7 +77,7 @@ function pubsubhubbub_init(App $a) { if ($r[0]['hidewall']) { logger('pubsubhubbub: local user ' . $nick . 'has chosen to hide wall, ignoring.'); - Network::httpStatusExit(403); + System::httpExit(403); } // get corresponding row from contact table @@ -85,7 +86,7 @@ function pubsubhubbub_init(App $a) { intval($owner['uid'])); if (!DBM::is_result($r)) { logger('pubsubhubbub: contact not found.'); - Network::httpStatusExit(404); + System::httpExit(404); } $contact = $r[0]; @@ -94,7 +95,7 @@ function pubsubhubbub_init(App $a) { if (!link_compare($hub_topic, $contact['poll'])) { logger('pubsubhubbub: hub topic ' . $hub_topic . ' != ' . $contact['poll']); - Network::httpStatusExit(404); + System::httpExit(404); } // do subscriber verification according to the PuSH protocol @@ -117,7 +118,7 @@ function pubsubhubbub_init(App $a) { if ($ret < 200 || $ret > 299) { logger("pubsubhubbub: subscriber verification at $hub_callback ". "returned $ret, ignoring."); - Network::httpStatusExit(404); + System::httpExit(404); } // check that the correct hub_challenge code was echoed back @@ -125,7 +126,7 @@ function pubsubhubbub_init(App $a) { logger("pubsubhubbub: subscriber did not echo back ". "hub.challenge, ignoring."); logger("\"$hub_challenge\" != \"".trim($body)."\""); - Network::httpStatusExit(404); + System::httpExit(404); } // fetch the old subscription if it exists @@ -163,7 +164,7 @@ function pubsubhubbub_init(App $a) { logger("pubsubhubbub: successfully unsubscribed [$hub_callback]."); // we do nothing here, since the row was already deleted } - Network::httpStatusExit(202); + System::httpExit(202); } killme(); diff --git a/mod/receive.php b/mod/receive.php index 60b8ed7961..41f2225cb4 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -6,9 +6,9 @@ use Friendica\App; use Friendica\Core\Config; +use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Protocol\Diaspora; -use Friendica\Util\Network; /** * @param object $a App @@ -19,7 +19,7 @@ function receive_post(App $a) $enabled = intval(Config::get('system', 'diaspora_enabled')); if (!$enabled) { logger('mod-diaspora: disabled'); - Network::httpStatusExit(500); + System::httpExit(500); } if (($a->argc == 2) && ($a->argv[1] === 'public')) { @@ -29,13 +29,13 @@ function receive_post(App $a) $public = false; if ($a->argc != 3 || $a->argv[1] !== 'users') { - Network::httpStatusExit(500); + System::httpExit(500); } $guid = $a->argv[2]; $importer = dba::selectFirst('user', [], ['guid' => $guid, 'account_expired' => false, 'account_removed' => false]); if (!DBM::is_result($importer)) { - Network::httpStatusExit(500); + System::httpExit(500); } } @@ -48,7 +48,7 @@ function receive_post(App $a) if (!$xml) { $postdata = file_get_contents("php://input"); if ($postdata == '') { - Network::httpStatusExit(500); + System::httpExit(500); } logger('mod-diaspora: message is in the new format', LOGGER_DEBUG); @@ -68,7 +68,7 @@ function receive_post(App $a) logger('mod-diaspora: decoded msg: ' . print_r($msg, true), LOGGER_DATA); if (!is_array($msg)) { - Network::httpStatusExit(500); + System::httpExit(500); } logger('mod-diaspora: dispatching', LOGGER_DEBUG); @@ -80,6 +80,6 @@ function receive_post(App $a) $ret = Diaspora::dispatch($importer, $msg); } - Network::httpStatusExit(($ret) ? 200 : 500); + System::httpExit(($ret) ? 200 : 500); // NOTREACHED } diff --git a/mod/salmon.php b/mod/salmon.php index 20806df559..af8f5fa55b 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -4,12 +4,12 @@ */ use Friendica\App; use Friendica\Core\PConfig; +use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\OStatus; use Friendica\Protocol\Salmon; use Friendica\Util\Crypto; -use Friendica\Util\Network; require_once 'include/items.php'; @@ -39,7 +39,7 @@ function salmon_post(App $a) { dbesc($nick) ); if (! DBM::is_result($r)) { - Network::httpStatusExit(500); + System::httpExit(500); } $importer = $r[0]; @@ -59,7 +59,7 @@ function salmon_post(App $a) { if(! $base) { logger('mod-salmon: unable to locate salmon data in xml '); - Network::httpStatusExit(400); + System::httpExit(400); } // Stash the signature away for now. We have to find their key or it won't be good for anything. @@ -97,7 +97,7 @@ function salmon_post(App $a) { if(! $author_link) { logger('mod-salmon: Could not retrieve author URI.'); - Network::httpStatusExit(400); + System::httpExit(400); } // Once we have the author URI, go to the web and try to find their public key @@ -108,7 +108,7 @@ function salmon_post(App $a) { if(! $key) { logger('mod-salmon: Could not retrieve author key.'); - Network::httpStatusExit(400); + System::httpExit(400); } $key_info = explode('.',$key); @@ -140,7 +140,7 @@ function salmon_post(App $a) { if (! $verify) { logger('mod-salmon: Message did not verify. Discarding.'); - Network::httpStatusExit(400); + System::httpExit(400); } logger('mod-salmon: Message verified with mode '.$mode); @@ -184,7 +184,7 @@ function salmon_post(App $a) { //if((DBM::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) { if (DBM::is_result($r) && $r[0]['blocked']) { logger('mod-salmon: Ignoring this author.'); - Network::httpStatusExit(202); + System::httpExit(202); // NOTREACHED } @@ -195,5 +195,5 @@ function salmon_post(App $a) { OStatus::import($data, $importer, $contact_rec, $hub); - Network::httpStatusExit(200); + System::httpExit(200); } diff --git a/mod/search.php b/mod/search.php index 681dbc9a52..c1990bf870 100644 --- a/mod/search.php +++ b/mod/search.php @@ -8,8 +8,8 @@ use Friendica\Content\Nav; use Friendica\Core\Cache; use Friendica\Core\Config; use Friendica\Core\L10n; +use Friendica\Core\System; use Friendica\Database\DBM; -use Friendica\Util\Network; require_once "include/bbcode.php"; require_once 'include/security.php'; @@ -100,7 +100,7 @@ function search_content(App $a) { } if (Config::get('system','local_search') && !local_user() && !remote_user()) { - Network::httpStatusExit(403, + System::httpExit(403, ["title" => L10n::t("Public access denied."), "description" => L10n::t("Only logged in users are permitted to perform a search.")]); killme(); @@ -125,7 +125,7 @@ function search_content(App $a) { if (!is_null($result)) { $resultdata = json_decode($result); if (($resultdata->time > (time() - $crawl_permit_period)) && ($resultdata->accesses > $free_crawls)) { - Network::httpStatusExit(429, + System::httpExit(429, ["title" => L10n::t("Too Many Requests"), "description" => L10n::t("Only one search per minute is permitted for not logged in users.")]); killme(); diff --git a/mod/smilies.php b/mod/smilies.php index 19f0152ef8..a33cbf6ad5 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -4,7 +4,7 @@ */ use Friendica\App; use Friendica\Content\Smilies; -use Friendica\Util\Network; +use Friendica\Core\System; /** * @param object $a App @@ -18,7 +18,7 @@ function smilies_content(App $a) for ($i = 0; $i < count($tmp['texts']); $i++) { $results[] = ['text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]]; } - Network::jsonExit($results); + System::jsonExit($results); } else { return Smilies::replace('', true); } diff --git a/mod/statistics_json.php b/mod/statistics_json.php index 75e89ba75e..c035c1c05a 100644 --- a/mod/statistics_json.php +++ b/mod/statistics_json.php @@ -7,12 +7,12 @@ use Friendica\App; use Friendica\Core\Addon; use Friendica\Core\Config; -use Friendica\Util\Network; +use Friendica\Core\System; function statistics_json_init(App $a) { if (!Config::get("system", "nodeinfo")) { - Network::httpStatusExit(404); + System::httpExit(404); killme(); } diff --git a/mod/webfinger.php b/mod/webfinger.php index f834e4ff36..c886793527 100644 --- a/mod/webfinger.php +++ b/mod/webfinger.php @@ -4,13 +4,13 @@ */ use Friendica\App; use Friendica\Core\L10n; +use Friendica\Core\System; use Friendica\Network\Probe; -use Friendica\Util\Network; function webfinger_content(App $a) { if (!local_user()) { - Network::httpStatusExit( + System::httpExit( 403, [ "title" => L10n::t("Public access denied."), diff --git a/src/Core/System.php b/src/Core/System.php index 469016770c..d0eb651e93 100644 --- a/src/Core/System.php +++ b/src/Core/System.php @@ -5,6 +5,7 @@ namespace Friendica\Core; use Friendica\BaseObject; +use Friendica\Util\XML; /** * @file include/Core/System.php @@ -97,6 +98,86 @@ EOT; killme(); } + /** + * Generic XML return + * Outputs a basic dfrn XML status structure to STDOUT, with a variable + * of $st and an optional text of $message and terminates the current process. + */ + public static function xmlExit($st, $message = '') + { + $result = ['status' => $st]; + + if ($message != '') { + $result['message'] = $message; + } + + if ($st) { + logger('xml_status returning non_zero: ' . $st . " message=" . $message); + } + + header("Content-type: text/xml"); + + $xmldata = ["result" => $result]; + + echo XML::fromArray($xmldata, $xml); + + killme(); + } + + /** + * @brief Send HTTP status header and exit. + * + * @param integer $val HTTP status result value + * @param array $description optional message + * 'title' => header title + * 'description' => optional message + */ + public static function httpExit($val, $description = []) + { + $err = ''; + if ($val >= 400) { + $err = 'Error'; + if (!isset($description["title"])) { + $description["title"] = $err." ".$val; + } + } + + if ($val >= 200 && $val < 300) { + $err = 'OK'; + } + + logger('http_status_exit ' . $val); + header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); + + if (isset($description["title"])) { + $tpl = get_markup_template('http_status.tpl'); + echo replace_macros( + $tpl, + [ + '$title' => $description["title"], + '$description' => $description["description"]] + ); + } + + killme(); + } + + /** + * @brief Encodes content to json + * + * This function encodes an array to json format + * and adds an application/json HTTP header to the output. + * After finishing the process is getting killed. + * + * @param array $x The input content + */ + public static function jsonExit($x) + { + header("content-type: application/json"); + echo json_encode($x); + killme(); + } + /// @todo Move the following functions from boot.php /* function get_guid($size = 16, $prefix = "") diff --git a/src/Module/Feed.php b/src/Module/Feed.php index efc5a097e8..485d070e30 100644 --- a/src/Module/Feed.php +++ b/src/Module/Feed.php @@ -3,8 +3,8 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\Core\System; use Friendica\Protocol\OStatus; -use Friendica\Util\Network; /** * Provides public Atom feeds @@ -32,7 +32,7 @@ class Feed extends BaseModule $nocache = x($_GET, 'nocache') && local_user(); if ($a->argc < 2) { - Network::httpStatusExit(400); + System::httpExit(400); } $type = null; diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index a6c74537d2..86fdb2374c 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -285,7 +285,7 @@ class Diaspora if (!is_object($j_outer_key_bundle)) { logger('Outer Salmon did not verify. Discarding.'); - Network::httpStatusExit(400); + System::httpExit(400); } $outer_iv = base64_decode($j_outer_key_bundle->iv); @@ -300,7 +300,7 @@ class Diaspora if (!is_object($basedom)) { logger('Received data does not seem to be an XML. Discarding. '.$xml); - Network::httpStatusExit(400); + System::httpExit(400); } $base = $basedom->children(NAMESPACE_SALMON_ME); @@ -325,7 +325,7 @@ class Diaspora $verify = Crypto::rsaVerify($signed_data, $signature, $key); if (!$verify) { logger('Message did not verify. Discarding.'); - Network::httpStatusExit(400); + System::httpExit(400); } return ['message' => (string)base64url_decode($base->data), @@ -403,7 +403,7 @@ class Diaspora if (!$base) { logger('unable to locate salmon data in xml'); - Network::httpStatusExit(400); + System::httpExit(400); } @@ -441,7 +441,7 @@ class Diaspora if (!$author_link) { logger('Could not retrieve author URI.'); - Network::httpStatusExit(400); + System::httpExit(400); } // Once we have the author URI, go to the web and try to find their public key // (first this will look it up locally if it is in the fcontact cache) @@ -452,14 +452,14 @@ class Diaspora if (!$key) { logger('Could not retrieve author key.'); - Network::httpStatusExit(400); + System::httpExit(400); } $verify = Crypto::rsaVerify($signed_data, $signature, $key); if (!$verify) { logger('Message did not verify. Discarding.'); - Network::httpStatusExit(400); + System::httpExit(400); } logger('Message verified.'); diff --git a/src/Util/Network.php b/src/Util/Network.php index b013f65a3d..ab1d44625c 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -399,70 +399,6 @@ class Network return $body; } - /** - * Generic XML return - * Outputs a basic dfrn XML status structure to STDOUT, with a variable - * of $st and an optional text of $message and terminates the current process. - */ - public static function xmlExit($st, $message = '') - { - $result = ['status' => $st]; - - if ($message != '') { - $result['message'] = $message; - } - - if ($st) { - logger('xml_status returning non_zero: ' . $st . " message=" . $message); - } - - header("Content-type: text/xml"); - - $xmldata = ["result" => $result]; - - echo XML::fromArray($xmldata, $xml); - - killme(); - } - - /** - * @brief Send HTTP status header and exit. - * - * @param integer $val HTTP status result value - * @param array $description optional message - * 'title' => header title - * 'description' => optional message - */ - public static function httpStatusExit($val, $description = []) - { - $err = ''; - if ($val >= 400) { - $err = 'Error'; - if (!isset($description["title"])) { - $description["title"] = $err." ".$val; - } - } - - if ($val >= 200 && $val < 300) { - $err = 'OK'; - } - - logger('http_status_exit ' . $val); - header($_SERVER["SERVER_PROTOCOL"] . ' ' . $val . ' ' . $err); - - if (isset($description["title"])) { - $tpl = get_markup_template('http_status.tpl'); - echo replace_macros( - $tpl, - [ - '$title' => $description["title"], - '$description' => $description["description"]] - ); - } - - killme(); - } - /** * @brief Check URL to see if it's real * @@ -858,22 +794,6 @@ class Network return $slinky->short(); } - /** - * @brief Encodes content to json - * - * This function encodes an array to json format - * and adds an application/json HTTP header to the output. - * After finishing the process is getting killed. - * - * @param array $x The input content - */ - public static function jsonExit($x) - { - header("content-type: application/json"); - echo json_encode($x); - killme(); - } - /** * @brief Find the matching part between two url * From 275a0aa1408fd0fae1b9146fc020aeaddc6be259 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 12:05:05 -0500 Subject: [PATCH 11/13] missed function rename missed rename zfetchurl --- src/Util/Network.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Util/Network.php b/src/Util/Network.php index ab1d44625c..b04cc068dc 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -233,7 +233,7 @@ class Network if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; @curl_close($ch); - return self::zFetchURL($newurl, $binary, $redirects, $opts); + return self::curl($newurl, $binary, $redirects, $opts); } } From 3220c78d70c76cd10b38ec364cb3d58d26e9309b Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 12:13:46 -0500 Subject: [PATCH 12/13] Missing uses missing uses for dom --- src/Util/Network.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Util/Network.php b/src/Util/Network.php index b04cc068dc..1f9184ae96 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -12,6 +12,8 @@ use Friendica\Core\Config; use Friendica\Network\Probe; use Friendica\Object\Image; use Friendica\Util\XML; +use DOMDocument; +use DomXPath; require_once 'library/slinky.php'; From 6c80a359530f37b7694e80f07b156cd45a970345 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 12:15:42 -0500 Subject: [PATCH 13/13] type friendica typo --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 5760533d37..8493e41b69 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -6,7 +6,7 @@ namespace Friendica\Content\Text; use Friendica\App; use Friendica\Content\Text\Plaintext; -use Friencica\Core\Config; +use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\PConfig; use Friendica\Core\System;