use Friendica\Module\Register;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
+use Friendica\Network\HTTPClient\Client\HttpClient;
use Friendica\Protocol\Relay;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network;
// When a nodeinfo is present, we don't need to dig further
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = DI::httpClient()->get($url . '/.well-known/nodeinfo', [HttpClientOptions::TIMEOUT => $xrd_timeout]);
+ $curlResult = DI::httpClient()->get($url . '/.well-known/nodeinfo', [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isTimeout()) {
self::setFailure($url);
return false;
// On a redirect follow the new host but mark the old one as failure
if ($curlResult->isSuccess() && !empty($curlResult->getRedirectUrl()) && (parse_url($url, PHP_URL_HOST) != parse_url($curlResult->getRedirectUrl(), PHP_URL_HOST))) {
- $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
+ $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if (!empty($curlResult->getRedirectUrl()) && parse_url($url, PHP_URL_HOST) != parse_url($curlResult->getRedirectUrl(), PHP_URL_HOST)) {
Logger::info('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $curlResult->getRedirectUrl()]);
self::setFailure($url);
$basedata = ['detection-method' => self::DETECT_MANUAL];
}
- $curlResult = DI::httpClient()->get($baseurl, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
+ $curlResult = DI::httpClient()->get($baseurl, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if ($curlResult->isSuccess()) {
if (!empty($curlResult->getRedirectUrl()) && (parse_url($baseurl, PHP_URL_HOST) != parse_url($curlResult->getRedirectUrl(), PHP_URL_HOST))) {
Logger::info('Found redirect. Mark old entry as failure', ['old' => $url, 'new' => $curlResult->getRedirectUrl()]);
// When the base path doesn't seem to contain a social network we try the complete path.
// Most detectable system have to be installed in the root directory.
// We checked the base to avoid false positives.
- $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
+ $curlResult = DI::httpClient()->get($url, [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_HTML]);
if ($curlResult->isSuccess()) {
$urldata = self::analyseRootHeader($curlResult, $serverdata);
$urldata = self::analyseRootBody($curlResult, $urldata, $url);
// All following checks are done for systems that always have got a "host-meta" endpoint.
// With this check we don't have to waste time and ressources for dead systems.
// Also this hopefully prevents us from receiving abuse messages.
- if (empty($serverdata['network']) && !self::validHostMeta($url)) {
+ $validHostMeta = self::validHostMeta($url);
+
+ if (empty($serverdata['network']) && !$validHostMeta) {
+ $serverdata = self::detectFromContacts($url, $serverdata);
+ }
+
+ if (empty($serverdata['network']) && !$validHostMeta) {
self::setFailure($url);
return false;
}
{
Logger::info('Discover relay data', ['server' => $server_url]);
- $curlResult = DI::httpClient()->get($server_url . '/.well-known/x-social-relay');
+ $curlResult = DI::httpClient()->get($server_url . '/.well-known/x-social-relay', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return;
}
*/
private static function fetchStatistics(string $url)
{
- $curlResult = DI::httpClient()->get($url . '/statistics.json');
+ $curlResult = DI::httpClient()->get($url . '/statistics.json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return [];
}
*/
private static function parseNodeinfo1(string $nodeinfo_url)
{
- $curlResult = DI::httpClient()->get($nodeinfo_url);
-
+ $curlResult = DI::httpClient()->get($nodeinfo_url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return [];
}
*/
private static function parseNodeinfo2(string $nodeinfo_url)
{
- $curlResult = DI::httpClient()->get($nodeinfo_url);
+ $curlResult = DI::httpClient()->get($nodeinfo_url, [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return [];
}
*/
private static function fetchSiteinfo(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/siteinfo.json');
+ $curlResult = DI::httpClient()->get($url . '/siteinfo.json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return $serverdata;
}
private static function validHostMeta(string $url)
{
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta', [HttpClientOptions::TIMEOUT => $xrd_timeout]);
+ $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta', [HttpClientOptions::TIMEOUT => $xrd_timeout, HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_XRD_XML]);
if (!$curlResult->isSuccess()) {
return false;
}
{
$serverdata['poco'] = '';
- $curlResult = DI::httpClient()->get($url . '/poco');
+ $curlResult = DI::httpClient()->get($url . '/poco', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return $serverdata;
}
*/
public static function checkMastodonDirectory(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/api/v1/directory?limit=1');
+ $curlResult = DI::httpClient()->get($url . '/api/v1/directory?limit=1', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return $serverdata;
}
*/
private static function detectPeertube(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/api/v1/config');
-
+ $curlResult = DI::httpClient()->get($url . '/api/v1/config', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata;
}
*/
private static function detectNextcloud(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/status.php');
-
+ $curlResult = DI::httpClient()->get($url . '/status.php', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata;
}
}
private static function fetchWeeklyUsage(string $url, array $serverdata) {
- $curlResult = DI::httpClient()->get($url . '/api/v1/instance/activity');
-
+ $curlResult = DI::httpClient()->get($url . '/api/v1/instance/activity', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata;
}
return $serverdata;
}
+
+ /**
+ * Detects the server network type from contacts of that server
+ *
+ * @param string $url URL of the given server
+ * @param array $serverdata array with server data
+ *
+ * @return array server data
+ */
+ private static function detectFromContacts(string $url, array $serverdata)
+ {
+ $gserver = DBA::selectFirst('gserver', ['id'], ['nurl' => Strings::normaliseLink($url)]);
+ if (empty($gserver)) {
+ return $serverdata;
+ }
+
+ $contact = Contact::selectFirst(['id'], ['uid' => 0, 'failed' => false, 'gsid' => $gserver['id']]);
+
+ // Via probing we can be sure that the server is responding
+ if (Contact::updateFromProbe($contact['id'])) {
+ $contact = Contact::selectFirst(['network', 'failed'], ['id' => $contact['id']]);
+ if (!$contact['failed'] && in_array($contact['network'], Protocol::FEDERATED)) {
+ $serverdata['network'] = $contact['network'];
+ }
+ }
+
+ return $serverdata;
+ }
/**
* Detects data from a given server url if it was a mastodon alike system
*/
private static function detectMastodonAlikes(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/api/v1/instance');
-
+ $curlResult = DI::httpClient()->get($url . '/api/v1/instance', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata;
}
*/
private static function detectHubzilla(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/api/statusnet/config.json');
+ $curlResult = DI::httpClient()->get($url . '/api/statusnet/config.json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
return $serverdata;
}
*/
private static function detectPumpIO(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta.json');
+ $curlResult = DI::httpClient()->get($url . '/.well-known/host-meta.json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if (!$curlResult->isSuccess()) {
return $serverdata;
}
private static function detectGNUSocial(string $url, array $serverdata)
{
// Test for GNU Social
- $curlResult = DI::httpClient()->get($url . '/api/gnusocial/version.json');
+ $curlResult = DI::httpClient()->get($url . '/api/gnusocial/version.json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$serverdata['platform'] = 'gnusocial';
}
// Test for Statusnet
- $curlResult = DI::httpClient()->get($url . '/api/statusnet/version.json');
+ $curlResult = DI::httpClient()->get($url . '/api/statusnet/version.json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
*/
private static function detectFriendica(string $url, array $serverdata)
{
- $curlResult = DI::httpClient()->get($url . '/friendica/json');
+ // There is a bug in some versions of Friendica that will return an ActivityStream actor when the content type "application/json" is requested.
+ // Because of this me must not use ACCEPT_JSON here.
+ $curlResult = DI::httpClient()->get($url . '/friendica/json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
if (!$curlResult->isSuccess()) {
- $curlResult = DI::httpClient()->get($url . '/friendika/json');
+ $curlResult = DI::httpClient()->get($url . '/friendika/json', [HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_DEFAULT]);
$friendika = true;
$platform = 'Friendika';
} else {
if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0';
- $curlResult = DI::httpClient()->get($api, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]]]);
-
+ $curlResult = DI::httpClient()->get($api, [HttpClientOptions::HEADERS => ['Authorization' => ['Bearer ' . $accesstoken]], HttpClientOptions::ACCEPT_CONTENT => HttpClient::ACCEPT_JSON]);
if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBody(), true);