use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Register;
use Friendica\Network\CurlResult;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Module\Register;
use Friendica\Network\CurlResult;
private static function setFailure(string $url)
{
if (DBA::exists('gserver', ['nurl' => Strings::normaliseLink($url)])) {
private static function setFailure(string $url)
{
if (DBA::exists('gserver', ['nurl' => Strings::normaliseLink($url)])) {
- DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow(), 'detection-method' => null],
+ DBA::update('gserver', ['failed' => true, 'last_failure' => DateTimeFormat::utcNow(), 'detection-method' => null],
['nurl' => Strings::normaliseLink($url)]);
Logger::info('Set failed status for existing server', ['url' => $url]);
return;
}
DBA::insert('gserver', ['url' => $url, 'nurl' => Strings::normaliseLink($url),
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
['nurl' => Strings::normaliseLink($url)]);
Logger::info('Set failed status for existing server', ['url' => $url]);
return;
}
DBA::insert('gserver', ['url' => $url, 'nurl' => Strings::normaliseLink($url),
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
// If the URL missmatches, then we mark the old entry as failure
if ($url != $original_url) {
// If the URL missmatches, then we mark the old entry as failure
if ($url != $original_url) {
- DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($original_url)]);
+ DBA::update('gserver', ['failed' => true, 'last_failure' => DateTimeFormat::utcNow()],
+ ['nurl' => Strings::normaliseLink($original_url)]);
}
// When a nodeinfo is present, we don't need to dig further
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
}
// When a nodeinfo is present, we don't need to dig further
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = Network::curl($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]);
+ $curlResult = DI::httpRequest()->get($url . '/.well-known/nodeinfo', false, ['timeout' => $xrd_timeout]);
if ($curlResult->isSuccess()) {
$basedata = self::analyseRootHeader($curlResult, $basedata);
$basedata = self::analyseRootBody($curlResult, $basedata, $baseurl);
if ($curlResult->isSuccess()) {
$basedata = self::analyseRootHeader($curlResult, $basedata);
$basedata = self::analyseRootBody($curlResult, $basedata, $baseurl);
// 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.
// 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.
if ($curlResult->isSuccess()) {
$urldata = self::analyseRootHeader($curlResult, $serverdata);
$urldata = self::analyseRootBody($curlResult, $urldata, $url);
if ($curlResult->isSuccess()) {
$urldata = self::analyseRootHeader($curlResult, $serverdata);
$urldata = self::analyseRootBody($curlResult, $urldata, $url);
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
if (!DBA::isResult($gserver)) {
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
if (!DBA::isResult($gserver)) {
private static function validHostMeta(string $url)
{
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
private static function validHostMeta(string $url)
{
$xrd_timeout = DI::config()->get('system', 'xrd_timeout');
- $curlResult = Network::curl($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]);
+ $curlResult = DI::httpRequest()->get($url . '/.well-known/host-meta', false, ['timeout' => $xrd_timeout]);
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$serverdata['platform'] = 'gnusocial';
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$serverdata['platform'] = 'gnusocial';
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
if ($curlResult->isSuccess() && ($curlResult->getBody() != '{"error":"not implemented"}') &&
($curlResult->getBody() != '') && (strlen($curlResult->getBody()) < 30)) {
$gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
FROM `gserver`
$gservers = DBA::p("SELECT `id`, `url`, `nurl`, `network`, `poco`
FROM `gserver`
AND `poco` != ''
AND `last_poco_query` < ?
ORDER BY RAND()", $last_update
AND `poco` != ''
AND `last_poco_query` < ?
ORDER BY RAND()", $last_update
$protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus'];
foreach ($protocols as $protocol) {
$query = '{nodes(protocol:"' . $protocol . '"){host}}';
$protocols = ['activitypub', 'diaspora', 'dfrn', 'ostatus'];
foreach ($protocols as $protocol) {
$query = '{nodes(protocol:"' . $protocol . '"){host}}';
if (!empty($curlResult)) {
$data = json_decode($curlResult, true);
if (!empty($data['data']['nodes'])) {
foreach ($data['data']['nodes'] as $server) {
// Using "only_nodeinfo" since servers that are listed on that page should always have it.
if (!empty($curlResult)) {
$data = json_decode($curlResult, true);
if (!empty($data['data']['nodes'])) {
foreach ($data['data']['nodes'] as $server) {
// Using "only_nodeinfo" since servers that are listed on that page should always have it.
Worker::add(PRIORITY_LOW, 'UpdateGServer', 'https://' . $server['host'], true);
}
}
Worker::add(PRIORITY_LOW, 'UpdateGServer', 'https://' . $server['host'], true);
}
}
if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0';
$header = ['Authorization: Bearer '.$accesstoken];
if (!empty($accesstoken)) {
$api = 'https://instances.social/api/1.0/instances/list?count=0';
$header = ['Authorization: Bearer '.$accesstoken];
if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBody(), true);
if ($curlResult->isSuccess()) {
$servers = json_decode($curlResult->getBody(), true);