From 03d620341087e24137d3e31e57238c658d21922c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Dec 2019 08:13:12 +0000 Subject: [PATCH 1/6] We can now detect Hubzilla accounts --- src/Network/Probe.php | 209 +++++++++++++++++++++++++++++++++--------- 1 file changed, 165 insertions(+), 44 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 3f02ef011..514cd6989 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -17,6 +17,7 @@ use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; +use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Protocol\ActivityNamespace; use Friendica\Protocol\ActivityPub; @@ -142,11 +143,7 @@ class Probe return []; } - $lrdd = []; - // The following webfinger path is defined in RFC 7033 https://tools.ietf.org/html/rfc7033 - // Problem is that Hubzilla currently doesn't provide all data in the JSON webfinger - // compared to the XML webfinger. So this is commented out by now. - // $lrdd = array("application/jrd+json" => $host_url.'/.well-known/webfinger?resource={uri}'); + $lrdd = ['application/jrd+json' => $host_url . '/.well-known/webfinger?resource={uri}']; foreach ($links["xrd"]["link"] as $value => $link) { if (!empty($link["@attributes"])) { @@ -644,17 +641,20 @@ class Probe if (in_array($network, ["", Protocol::DFRN])) { $result = self::dfrn($webfinger); } - if ((!$result && ($network == "")) || ($network == Protocol::DIASPORA)) { - $result = self::diaspora($webfinger); + if ((empty($result['network']) && ($network == "")) || ($network == Protocol::DIASPORA)) { + $result = self::diaspora($webfinger, $result); } - if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) { - $result = self::ostatus($webfinger); + if ((empty($result['network']) && ($network == "")) || ($network == Protocol::OSTATUS)) { + $result = self::ostatus($webfinger, false, $result); } - if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) { - $result = self::pumpio($webfinger, $addr); + if ((empty($result['network']) && ($network == "")) || ($network == Protocol::PUMPIO)) { + $result = self::pumpio($webfinger, $addr, $result); } - if ((!$result && ($network == "")) || ($network == Protocol::FEED)) { - $result = self::feed($uri); + if ((empty($result['network']) && ($network == "")) || ($network == Protocol::ZOT)) { + $result = self::hubzilla($webfinger, $result); + } + if ((empty($result['network']) && ($network == "")) || ($network == Protocol::FEED)) { + $result = self::feed($uri, true, $result); } else { // We overwrite the detected nick with our try if the previois routines hadn't detected it. // Additionally it is overwritten when the nickname doesn't make sense (contains spaces). @@ -686,6 +686,127 @@ class Probe return $result; } + private static function hubzilla($webfinger, $data) + { + if (strstr($webfinger['properties']['http://purl.org/zot/federation'] ?? '', 'zot')) { + $data['network'] = Protocol::ZOT; + } + if (!empty($webfinger['properties']['http://webfinger.net/ns/name'])) { + $data['name'] = $webfinger['properties']['http://webfinger.net/ns/name']; + } + if (!empty($webfinger['properties']['https://w3id.org/security/v1#publicKeyPem'])) { + $data['pubkey'] = $webfinger['properties']['https://w3id.org/security/v1#publicKeyPem']; + } +//print_r($webfinger); + $hcard_url = ''; + $zot_url = ''; + foreach ($webfinger['links'] as $link) { + if (($link['rel'] == 'http://microformats.org/profile/hcard') && !empty($link['href'])) { + $hcard_url = $link['href']; + } elseif (($link['rel'] == 'http://purl.org/zot/protocol') && !empty($link['href'])) { + $zot_url = $link['href']; + } elseif (($link["rel"] == "http://purl.org/zot/protocol/6.0") && !empty($link["href"])) { + $data["url"] = $link["href"]; + } elseif (($link["rel"] == "http://webfinger.net/rel/blog") && !empty($link["href"]) && empty($data["url"])) { + $data["url"] = $link["href"]; + } + } + + if (empty($zot_url) && !empty($data['addr']) && !empty(self::$baseurl)) { + $zot_url = self::$baseurl . '/.well-known/zot-info?address=' . $data['addr']; + } + + if (!empty($hcard_url)) { + $data = self::pollHcard($hcard_url, $data, false); + } + + if (!empty($zot_url)) { + $data = self::pollZot($zot_url, $data); + } + + return $data; + } + + public static function pollZot($url, $data) + { + $curlResult = Network::curl($url); + if ($curlResult->isTimeout()) { + return $data; + } + $content = $curlResult->getBody(); + if (!$content) { + return $data; + } + + $json = json_decode($content, true); + if (!is_array($json)) { + return $data; + } + + if (!empty($json['protocols']) && in_array('zot', $json['protocols'])) { + $data['network'] = Protocol::ZOT; + } + + if (!empty($json['guid'])) { + $data['guid'] = $json['guid']; + } + if (!empty($json['key'])) { + $data['pubkey'] = $json['key']; + } + if (!empty($json['name'])) { + $data['name'] = $json['name']; + } + if (!empty($json['address'])) { + $data['addr'] = $json['address']; + } + if (!empty($json['url'])) { + $data['url'] = $json['url']; + } + if (!empty($json['connections_url'])) { + $data['poco'] = $json['connections_url']; + } + if (isset($json['searchable'])) { + $data['hide'] = !$json['searchable']; + } + if (!empty($json['public_forum'])) { + $data['community'] = $json['public_forum']; + $data['account-type'] = Contact::PAGE_COMMUNITY; + } + + if (!empty($json['profile'])) { + $profile = $json['profile']; + if (!empty($profile['description'])) { + $data['about'] = $profile['description']; + } + if (!empty($profile['gender'])) { + $data['gender'] = $profile['gender']; + } + if (!empty($profile['keywords'])) { + $keywords = implode(', ', $profile['keywords']); + if (!empty($keywords)) { + $data['keywords'] = $keywords; + } + } + + $loc = []; + if (!empty($profile['region'])) { + $loc['region'] = $profile['region']; + } + if (!empty($profile['country'])) { + $loc['country-name'] = $profile['country']; + } + if (!empty($profile['hometown'])) { + $loc['locality'] = $profile['hometown']; + } + $location = Profile::formatLocation($loc); + if (!empty($location)) { + $data['location'] = $location; + } + } + + return $data; + } + /** * @brief Perform a webfinger request. * @@ -998,7 +1119,7 @@ class Probe } if (!isset($data["network"]) || ($hcard_url == "")) { - return false; + return $data; } // Fetch data via noscrape - this is faster @@ -1156,10 +1277,13 @@ class Probe * @return array Diaspora data * @throws HTTPException\InternalServerErrorException */ - private static function diaspora($webfinger) + private static function diaspora($webfinger, $data) { $hcard_url = ""; - $data = []; + + unset($data["guid"]); + unset($data["pubkey"]); + // The array is reversed to take into account the order of preference for same-rel links // See: https://tools.ietf.org/html/rfc7033#section-4.4.4 foreach (array_reverse($webfinger["links"]) as $link) { @@ -1187,8 +1311,8 @@ class Probe } } - if (!isset($data["url"]) || ($hcard_url == "")) { - return false; + if (empty($data["url"]) || empty($hcard_url)) { + return $data; } if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { @@ -1208,15 +1332,11 @@ class Probe // Fetch further information from the hcard $data = self::pollHcard($hcard_url, $data); - if (!$data) { - return false; - } - - if (isset($data["url"]) - && isset($data["guid"]) - && isset($data["baseurl"]) - && isset($data["pubkey"]) - && ($hcard_url != "") + if (!empty($data["url"]) + && !empty($data["guid"]) + && !empty($data["baseurl"]) + && !empty($data["pubkey"]) + && !empty($hcard_url) ) { $data["network"] = Protocol::DIASPORA; @@ -1228,8 +1348,6 @@ class Probe // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"]; $data["batch"] = $data["baseurl"] . "/receive/public"; - } else { - return false; } return $data; @@ -1244,10 +1362,8 @@ class Probe * @return array|bool OStatus data or "false" on error or "true" on short mode * @throws HTTPException\InternalServerErrorException */ - private static function ostatus($webfinger, $short = false) + private static function ostatus($webfinger, $short = false, $data = []) { - $data = []; - if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { foreach ($webfinger["aliases"] as $alias) { if (strstr($alias, "@") && !strstr(Strings::normaliseLink($alias), "http://")) { @@ -1288,7 +1404,11 @@ class Probe $curlResult = Network::curl($pubkey); if ($curlResult->isTimeout()) { self::$istimeout = true; - return false; + if ($short) { + return false; + } else { + return $data; + } } $pubkey = $curlResult->getBody(); } @@ -1309,8 +1429,10 @@ class Probe && isset($data["url"]) ) { $data["network"] = Protocol::OSTATUS; - } else { + } elseif ($short) { return false; + } else { + return $data; } if ($short) { @@ -1321,7 +1443,7 @@ class Probe $curlResult = Network::curl($data["poll"]); if ($curlResult->isTimeout()) { self::$istimeout = true; - return false; + return $data; } $feed = $curlResult->getBody(); $dummy1 = null; @@ -1329,7 +1451,7 @@ class Probe $dummy2 = null; $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true); if (!$feed_data) { - return false; + return $data; } if (!empty($feed_data["header"]["author-name"])) { @@ -1429,9 +1551,8 @@ class Probe * @param $addr * @return array pump.io data */ - private static function pumpio($webfinger, $addr) + private static function pumpio($webfinger, $addr, $data) { - $data = []; // The array is reversed to take into account the order of preference for same-rel links // See: https://tools.ietf.org/html/rfc7033#section-4.4.4 foreach (array_reverse($webfinger["links"]) as $link) { @@ -1458,13 +1579,13 @@ class Probe $data["network"] = Protocol::PUMPIO; } else { - return false; + return $data; } $profile_data = self::pumpioProfileData($data["url"]); if (!$profile_data) { - return false; + return $data; } $data = array_merge($data, $profile_data); @@ -1591,12 +1712,12 @@ class Probe * @return array feed data * @throws HTTPException\InternalServerErrorException */ - private static function feed($url, $probe = true) + private static function feed($url, $probe = true, $data = []) { $curlResult = Network::curl($url); if ($curlResult->isTimeout()) { self::$istimeout = true; - return false; + return $data; } $feed = $curlResult->getBody(); $dummy1 = $dummy2 = $dummy3 = null; @@ -1604,13 +1725,13 @@ class Probe if (!$feed_data) { if (!$probe) { - return false; + return $data; } $feed_url = self::getFeedLink($url); if (!$feed_url) { - return false; + return $data; } return self::feed($feed_url, false); From 4653d7d3b0972de78130ebeca8c3217a1cd65fe4 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 22 Dec 2019 17:20:11 +0000 Subject: [PATCH 2/6] Renamed function, added documentation --- src/Network/Probe.php | 58 ++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 514cd6989..629453f18 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -359,9 +359,9 @@ class Probe $data['url'] = $uri; } - if (!empty($data['photo'])) { - $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink($data['baseurl'] ?? ''), Strings::normaliseLink($data['photo'])); - } else { + if (!empty($data['photo']) && !empty($data["baseurl"])) { + $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink($data['baseurl']), Strings::normaliseLink($data['photo'])); + } elseif (empty($data['photo'])) { $data['photo'] = System::baseUrl() . '/images/person-300.jpg'; } @@ -651,7 +651,7 @@ class Probe $result = self::pumpio($webfinger, $addr, $result); } if ((empty($result['network']) && ($network == "")) || ($network == Protocol::ZOT)) { - $result = self::hubzilla($webfinger, $result); + $result = self::zot($webfinger, $result); } if ((empty($result['network']) && ($network == "")) || ($network == Protocol::FEED)) { $result = self::feed($uri, true, $result); @@ -677,7 +677,7 @@ class Probe Logger::log($uri." is ".$result["network"], Logger::DEBUG); - if (empty($result["baseurl"])) { + if (empty($result["baseurl"]) && ($result["network"] != Protocol::PHANTOM)) { $pos = strpos($result["url"], $host); if ($pos) { $result["baseurl"] = substr($result["url"], 0, $pos).$host; @@ -686,29 +686,21 @@ class Probe return $result; } - private static function hubzilla($webfinger, $data) + /** + * Check for Zot contact + * + * @param array $webfinger Webfinger data + * @param array $data previously probed data + * + * @return array Zot data + * @throws HTTPException\InternalServerErrorException + */ + private static function zot($webfinger, $data) { - if (strstr($webfinger['properties']['http://purl.org/zot/federation'] ?? '', 'zot')) { - $data['network'] = Protocol::ZOT; - } - if (!empty($webfinger['properties']['http://webfinger.net/ns/name'])) { - $data['name'] = $webfinger['properties']['http://webfinger.net/ns/name']; - } - if (!empty($webfinger['properties']['https://w3id.org/security/v1#publicKeyPem'])) { - $data['pubkey'] = $webfinger['properties']['https://w3id.org/security/v1#publicKeyPem']; - } -//print_r($webfinger); - $hcard_url = ''; $zot_url = ''; foreach ($webfinger['links'] as $link) { - if (($link['rel'] == 'http://microformats.org/profile/hcard') && !empty($link['href'])) { - $hcard_url = $link['href']; - } elseif (($link['rel'] == 'http://purl.org/zot/protocol') && !empty($link['href'])) { + if (($link['rel'] == 'http://purl.org/zot/protocol') && !empty($link['href'])) { $zot_url = $link['href']; - } elseif (($link["rel"] == "http://purl.org/zot/protocol/6.0") && !empty($link["href"])) { - $data["url"] = $link["href"]; - } elseif (($link["rel"] == "http://webfinger.net/rel/blog") && !empty($link["href"]) && empty($data["url"])) { - $data["url"] = $link["href"]; } } @@ -716,10 +708,6 @@ class Probe $zot_url = self::$baseurl . '/.well-known/zot-info?address=' . $data['addr']; } - if (!empty($hcard_url)) { - $data = self::pollHcard($hcard_url, $data, false); - } - if (!empty($zot_url)) { $data = self::pollZot($zot_url, $data); } @@ -745,6 +733,8 @@ class Probe if (!empty($json['protocols']) && in_array('zot', $json['protocols'])) { $data['network'] = Protocol::ZOT; + } elseif (!isset($json['protocols'])) { + $data['network'] = Protocol::ZOT; } if (!empty($json['guid'])) { @@ -756,6 +746,9 @@ class Probe if (!empty($json['name'])) { $data['name'] = $json['name']; } + if (!empty($json['photo']) && empty($data['photo'])) { + $data['photo'] = $json['photo']; + } if (!empty($json['address'])) { $data['addr'] = $json['address']; } @@ -1273,6 +1266,7 @@ class Probe * @brief Check for Diaspora contact * * @param array $webfinger Webfinger data + * @param array $data previously probed data * * @return array Diaspora data * @throws HTTPException\InternalServerErrorException @@ -1358,6 +1352,7 @@ class Probe * * @param array $webfinger Webfinger data * @param bool $short Short detection mode + * @param array $data previously probed data * * @return array|bool OStatus data or "false" on error or "true" on short mode * @throws HTTPException\InternalServerErrorException @@ -1546,9 +1541,9 @@ class Probe /** * @brief Check for pump.io contact * - * @param array $webfinger Webfinger data - * - * @param $addr + * @param array $webfinger Webfinger data + * @param string $addr + * @param array $data previously probed data * @return array pump.io data */ private static function pumpio($webfinger, $addr, $data) @@ -1708,6 +1703,7 @@ class Probe * * @param string $url Profile link * @param boolean $probe Do a probe if the page contains a feed link + * @param array $data previously probed data * * @return array feed data * @throws HTTPException\InternalServerErrorException From 9cc2212b4b517e66d2b10bbe0c5a6d6770a5afd2 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 23 Dec 2019 14:26:06 +0000 Subject: [PATCH 3/6] Restructuring code --- src/Network/Probe.php | 91 ++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 36 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 629453f18..fe7a25a05 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -359,7 +359,7 @@ class Probe $data['url'] = $uri; } - if (!empty($data['photo']) && !empty($data["baseurl"])) { + if (!empty($data['photo']) && !empty($data['baseurl'])) { $data['baseurl'] = Network::getUrlMatch(Strings::normaliseLink($data['baseurl']), Strings::normaliseLink($data['photo'])); } elseif (empty($data['photo'])) { $data['photo'] = System::baseUrl() . '/images/person-300.jpg'; @@ -641,20 +641,20 @@ class Probe if (in_array($network, ["", Protocol::DFRN])) { $result = self::dfrn($webfinger); } - if ((empty($result['network']) && ($network == "")) || ($network == Protocol::DIASPORA)) { - $result = self::diaspora($webfinger, $result); + if ((!$result && ($network == "")) || ($network == Protocol::DIASPORA)) { + $result = self::diaspora($webfinger); } - if ((empty($result['network']) && ($network == "")) || ($network == Protocol::OSTATUS)) { - $result = self::ostatus($webfinger, false, $result); + if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) { + $result = self::ostatus($webfinger, false); } - if ((empty($result['network']) && ($network == "")) || ($network == Protocol::PUMPIO)) { - $result = self::pumpio($webfinger, $addr, $result); +// if (in_array($network, ['', Protocol::ZOT])) { +// $result = self::zot($webfinger, $result); +// } + if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) { + $result = self::pumpio($webfinger, $addr); } - if ((empty($result['network']) && ($network == "")) || ($network == Protocol::ZOT)) { - $result = self::zot($webfinger, $result); - } - if ((empty($result['network']) && ($network == "")) || ($network == Protocol::FEED)) { - $result = self::feed($uri, true, $result); + if ((!$result && ($network == "")) || ($network == Protocol::FEED)) { + $result = self::feed($uri, true); } else { // We overwrite the detected nick with our try if the previois routines hadn't detected it. // Additionally it is overwritten when the nickname doesn't make sense (contains spaces). @@ -697,6 +697,18 @@ class Probe */ private static function zot($webfinger, $data) { + if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { + foreach ($webfinger["aliases"] as $alias) { + if (substr($alias, 0, 5) == 'acct:') { + $data["addr"] = substr($alias, 5); + } + } + } + + if (!empty($webfinger["subject"]) && (substr($webfinger["subject"], 0, 5) == "acct:")) { + $data["addr"] = substr($webfinger["subject"], 5); + } + $zot_url = ''; foreach ($webfinger['links'] as $link) { if (($link['rel'] == 'http://purl.org/zot/protocol') && !empty($link['href'])) { @@ -705,6 +717,10 @@ class Probe } if (empty($zot_url) && !empty($data['addr']) && !empty(self::$baseurl)) { + $condition = ['nurl' => Strings::normaliseLink(self::$baseurl), 'platform' => ['hubzilla']]; + if (!DBA::exists('gserver', $condition)) { + exit; + } $zot_url = self::$baseurl . '/.well-known/zot-info?address=' . $data['addr']; } @@ -730,24 +746,29 @@ class Probe if (!is_array($json)) { return $data; } - - if (!empty($json['protocols']) && in_array('zot', $json['protocols'])) { - $data['network'] = Protocol::ZOT; - } elseif (!isset($json['protocols'])) { - $data['network'] = Protocol::ZOT; +//print_r($json); + if (empty($data['network'])) { + if (!empty($json['protocols']) && in_array('zot', $json['protocols'])) { + $data['network'] = Protocol::ZOT; + } elseif (!isset($json['protocols'])) { + $data['network'] = Protocol::ZOT; + } } - if (!empty($json['guid'])) { + if (!empty($json['guid']) && empty($data['guid'])) { $data['guid'] = $json['guid']; } - if (!empty($json['key'])) { + if (!empty($json['key']) && empty($data['pubkey'])) { $data['pubkey'] = $json['key']; } if (!empty($json['name'])) { $data['name'] = $json['name']; } - if (!empty($json['photo']) && empty($data['photo'])) { + if (!empty($json['photo'])) { $data['photo'] = $json['photo']; + if (!empty($json['photo_updated'])) { + $data['photo'] .= '?rev=' . urlencode($json['photo_updated']); + } } if (!empty($json['address'])) { $data['addr'] = $json['address']; @@ -1112,7 +1133,7 @@ class Probe } if (!isset($data["network"]) || ($hcard_url == "")) { - return $data; + return false; } // Fetch data via noscrape - this is faster @@ -1266,17 +1287,15 @@ class Probe * @brief Check for Diaspora contact * * @param array $webfinger Webfinger data - * @param array $data previously probed data * * @return array Diaspora data * @throws HTTPException\InternalServerErrorException */ - private static function diaspora($webfinger, $data) + private static function diaspora($webfinger) { $hcard_url = ""; - unset($data["guid"]); - unset($data["pubkey"]); + $data = []; // The array is reversed to take into account the order of preference for same-rel links // See: https://tools.ietf.org/html/rfc7033#section-4.4.4 @@ -1352,13 +1371,14 @@ class Probe * * @param array $webfinger Webfinger data * @param bool $short Short detection mode - * @param array $data previously probed data * * @return array|bool OStatus data or "false" on error or "true" on short mode * @throws HTTPException\InternalServerErrorException */ - private static function ostatus($webfinger, $short = false, $data = []) + private static function ostatus($webfinger, $short = false) { + $data = []; + if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { foreach ($webfinger["aliases"] as $alias) { if (strstr($alias, "@") && !strstr(Strings::normaliseLink($alias), "http://")) { @@ -1543,11 +1563,11 @@ class Probe * * @param array $webfinger Webfinger data * @param string $addr - * @param array $data previously probed data * @return array pump.io data */ - private static function pumpio($webfinger, $addr, $data) + private static function pumpio($webfinger, $addr) { + $data = []; // The array is reversed to take into account the order of preference for same-rel links // See: https://tools.ietf.org/html/rfc7033#section-4.4.4 foreach (array_reverse($webfinger["links"]) as $link) { @@ -1574,13 +1594,13 @@ class Probe $data["network"] = Protocol::PUMPIO; } else { - return $data; + return false; } $profile_data = self::pumpioProfileData($data["url"]); if (!$profile_data) { - return $data; + return false; } $data = array_merge($data, $profile_data); @@ -1703,17 +1723,16 @@ class Probe * * @param string $url Profile link * @param boolean $probe Do a probe if the page contains a feed link - * @param array $data previously probed data * * @return array feed data * @throws HTTPException\InternalServerErrorException */ - private static function feed($url, $probe = true, $data = []) + private static function feed($url, $probe = true) { $curlResult = Network::curl($url); if ($curlResult->isTimeout()) { self::$istimeout = true; - return $data; + return false; } $feed = $curlResult->getBody(); $dummy1 = $dummy2 = $dummy3 = null; @@ -1721,13 +1740,13 @@ class Probe if (!$feed_data) { if (!$probe) { - return $data; + return false; } $feed_url = self::getFeedLink($url); if (!$feed_url) { - return $data; + return false; } return self::feed($feed_url, false); From 2306b949f2aca993e33d70ff5a4cb219f016b8f5 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 23 Dec 2019 14:30:48 +0000 Subject: [PATCH 4/6] Partly reworked, part 2 --- src/Network/Probe.php | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index fe7a25a05..fdce42696 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -645,7 +645,7 @@ class Probe $result = self::diaspora($webfinger); } if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) { - $result = self::ostatus($webfinger, false); + $result = self::ostatus($webfinger); } // if (in_array($network, ['', Protocol::ZOT])) { // $result = self::zot($webfinger, $result); @@ -654,7 +654,7 @@ class Probe $result = self::pumpio($webfinger, $addr); } if ((!$result && ($network == "")) || ($network == Protocol::FEED)) { - $result = self::feed($uri, true); + $result = self::feed($uri); } else { // We overwrite the detected nick with our try if the previois routines hadn't detected it. // Additionally it is overwritten when the nickname doesn't make sense (contains spaces). @@ -1294,7 +1294,6 @@ class Probe private static function diaspora($webfinger) { $hcard_url = ""; - $data = []; // The array is reversed to take into account the order of preference for same-rel links @@ -1345,6 +1344,10 @@ class Probe // Fetch further information from the hcard $data = self::pollHcard($hcard_url, $data); + if (!$data) { + return false; + } + if (!empty($data["url"]) && !empty($data["guid"]) && !empty($data["baseurl"]) @@ -1361,6 +1364,8 @@ class Probe // We have to overwrite the detected value for "notify" since Hubzilla doesn't send it $data["notify"] = $data["baseurl"] . "/receive/users/" . $data["guid"]; $data["batch"] = $data["baseurl"] . "/receive/public"; + } else { + return false; } return $data; @@ -1419,11 +1424,7 @@ class Probe $curlResult = Network::curl($pubkey); if ($curlResult->isTimeout()) { self::$istimeout = true; - if ($short) { - return false; - } else { - return $data; - } + return false; } $pubkey = $curlResult->getBody(); } @@ -1444,10 +1445,8 @@ class Probe && isset($data["url"]) ) { $data["network"] = Protocol::OSTATUS; - } elseif ($short) { - return false; } else { - return $data; + return false; } if ($short) { @@ -1458,7 +1457,7 @@ class Probe $curlResult = Network::curl($data["poll"]); if ($curlResult->isTimeout()) { self::$istimeout = true; - return $data; + return false; } $feed = $curlResult->getBody(); $dummy1 = null; @@ -1466,7 +1465,7 @@ class Probe $dummy2 = null; $feed_data = Feed::import($feed, $dummy1, $dummy2, $dummy3, true); if (!$feed_data) { - return $data; + return false; } if (!empty($feed_data["header"]["author-name"])) { From 7fd1d674a96977fdf2ef2a76eb3c31c15715f23c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 23 Dec 2019 15:07:49 +0000 Subject: [PATCH 5/6] Zot seems to work now --- src/Network/Probe.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index fdce42696..c059fd3cd 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -647,9 +647,9 @@ class Probe if ((!$result && ($network == "")) || ($network == Protocol::OSTATUS)) { $result = self::ostatus($webfinger); } -// if (in_array($network, ['', Protocol::ZOT])) { -// $result = self::zot($webfinger, $result); -// } + if (in_array($network, ['', Protocol::ZOT])) { + $result = self::zot($webfinger, $result); + } if ((!$result && ($network == "")) || ($network == Protocol::PUMPIO)) { $result = self::pumpio($webfinger, $addr); } @@ -719,7 +719,7 @@ class Probe if (empty($zot_url) && !empty($data['addr']) && !empty(self::$baseurl)) { $condition = ['nurl' => Strings::normaliseLink(self::$baseurl), 'platform' => ['hubzilla']]; if (!DBA::exists('gserver', $condition)) { - exit; + return $data; } $zot_url = self::$baseurl . '/.well-known/zot-info?address=' . $data['addr']; } @@ -1324,7 +1324,7 @@ class Probe } if (empty($data["url"]) || empty($hcard_url)) { - return $data; + return false; } if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { From b442f41159c6bfa4f527b3f540d8d083c367023c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 23 Dec 2019 21:10:54 +0000 Subject: [PATCH 6/6] Remove test code --- src/Network/Probe.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Network/Probe.php b/src/Network/Probe.php index c059fd3cd..042e761e9 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -746,7 +746,7 @@ class Probe if (!is_array($json)) { return $data; } -//print_r($json); + if (empty($data['network'])) { if (!empty($json['protocols']) && in_array('zot', $json['protocols'])) { $data['network'] = Protocol::ZOT;