*
* @param string $url
* @param boolean $only_nodeinfo
+ *
* @return void
*/
public static function add(string $url, bool $only_nodeinfo = false)
*
* @param string $url
* @param boolean $no_check Don't check if the server hadn't been found
+ *
* @return int|null gserver id or NULL on empty URL or failed check
*/
- public static function getID(string $url, bool $no_check = false)
+ public static function getID(string $url, bool $no_check = false): ?int
{
if (empty($url)) {
return null;
* The pattern is a simple fnmatch() pattern with ? for single wildcard and * for multiple wildcard
*
* @param string $pattern
+ *
* @return array
+ *
* @throws Exception
*/
public static function listByDomainPattern(string $pattern): array
return self::check($server, $network, $force);
}
- public static function getNextUpdateDate(bool $success, string $created = '', string $last_contact = '', bool $undetected = false)
+ /**
+ * Calculate the next update day
+ *
+ * @param bool $success
+ * @param string $created
+ * @param string $last_contact
+ * @param bool $undetected
+ *
+ * @return string
+ *
+ * @throws Exception
+ */
+ public static function getNextUpdateDate(bool $success, string $created = '', string $last_contact = '', bool $undetected = false): string
{
// On successful contact process check again next week when it is a detected system.
// When we haven't detected the system, it could be a static website or a really old system.
Logger::info('Set failed status for existing server', ['url' => $url]);
return;
}
- DBA::insert('gserver', ['url' => $url, 'nurl' => Strings::normaliseLink($url),
+ self::insert(['url' => $url, 'nurl' => Strings::normaliseLink($url),
'network' => Protocol::PHANTOM, 'created' => DateTimeFormat::utcNow(),
'failed' => true, 'last_failure' => DateTimeFormat::utcNow()]);
Logger::info('Set failed status for new server', ['url' => $url]);
* Remove unwanted content from the given URL
*
* @param string $url
+ *
* @return string cleaned URL
*/
public static function cleanURL(string $url): string
if (!self::getID($valid_url, true)) {
self::detect($valid_url, $network, $only_nodeinfo);
}
- return false;
+ return false;
}
Logger::debug('Found redirect, but ignore it.', ['old' => $url, 'new' => $valid_url]);
}
$serverdata['registered-users'] = $serverdata['registered-users'] ?? 0;
+ // Numbers above a reasonable value (10 millions) are ignored
+ if ($serverdata['registered-users'] > 10000000) {
+ $serverdata['registered-users'] = 0;
+ }
+
// On an active server there has to be at least a single user
- if (!in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED]) && ($serverdata['registered-users'] == 0)) {
+ if (!in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED]) && ($serverdata['registered-users'] <= 0)) {
$serverdata['registered-users'] = 1;
} elseif (in_array($serverdata['network'], [Protocol::PHANTOM, Protocol::FEED])) {
$serverdata['registered-users'] = 0;
$gserver = DBA::selectFirst('gserver', ['network'], ['nurl' => Strings::normaliseLink($url)]);
if (!DBA::isResult($gserver)) {
$serverdata['created'] = DateTimeFormat::utcNow();
- $ret = DBA::insert('gserver', $serverdata);
+ $ret = self::insert($serverdata);
$id = DBA::lastInsertId();
} else {
$ret = self::update($serverdata, ['nurl' => $serverdata['nurl']]);
* Fetch relay data from a given server url
*
* @param string $server_url address of the server
+ *
* @return void
+ *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function discoverRelay(string $server_url)
* Fetch server data from '/statistics.json' on the given server
*
* @param string $url URL of the given server
+ *
* @return array server data
*/
- private static function fetchStatistics(string $url, array $serverdata)
+ private static function fetchStatistics(string $url, array $serverdata): array
{
$curlResult = DI::httpClient()->get($url . '/statistics.json', HttpClientAccept::JSON);
if (!$curlResult->isSuccess()) {
* @param ICanHandleHttpResponses $httpResult
*
* @return array Server data
+ *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function fetchNodeinfo(string $url, ICanHandleHttpResponses $httpResult): array
* Parses Nodeinfo 1
*
* @param string $nodeinfo_url address of the nodeinfo path
+ *
* @return array Server data
+ *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function parseNodeinfo1(string $nodeinfo_url): array
* Parses Nodeinfo 2
*
* @see https://git.feneas.org/jaywink/nodeinfo2
+ *
* @param string $nodeinfo_url address of the nodeinfo path
+ *
* @return array Server data
+ *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
private static function parseNodeinfo2(string $nodeinfo_url): array
* Parses NodeInfo2 protocol 1.0
*
* @see https://github.com/jaywink/nodeinfo2/blob/master/PROTOCOL.md
+ *
* @param string $nodeinfo_url address of the nodeinfo path
+ *
* @return array Server data
+ *
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
- private static function parseNodeinfo210(ICanHandleHttpResponses $httpResult)
+ private static function parseNodeinfo210(ICanHandleHttpResponses $httpResult): array
{
if (!$httpResult->isSuccess()) {
return [];
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function fetchSiteinfo(string $url, array $serverdata): array
return $serverdata;
}
- private static function fetchDataFromSystemActor(array $data, array $serverdata)
+ /**
+ * Fetches server data via an ActivityPub account with url of that server
+ *
+ * @param string $url URL of the given server
+ * @param array $serverdata array with server data
+ *
+ * @return array server data
+ *
+ * @throws Exception
+ */
+ private static function fetchDataFromSystemActor(array $data, array $serverdata): array
{
if (empty($data)) {
return ['server' => $serverdata, 'actor' => ''];
* Checks if the server contains a valid host meta file
*
* @param string $url URL of the given server
+ *
* @return boolean 'true' if the server seems to be vital
*/
private static function validHostMeta(string $url): bool
return false;
}
- $xrd = XML::parseString($curlResult->getBody());
+ $xrd = XML::parseString($curlResult->getBody(), true);
if (!is_object($xrd)) {
return false;
}
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function detectNetworkViaContacts(string $url, array $serverdata): array
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function checkPoCo(string $url, array $serverdata): array
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
public static function checkMastodonDirectory(string $url, array $serverdata): array
*
* @return array server data
*/
- private static function detectNextcloud(string $url, array $serverdata, bool $validHostMeta)
+ private static function detectNextcloud(string $url, array $serverdata, bool $validHostMeta): array
{
$curlResult = DI::httpClient()->get($url . '/status.php', HttpClientAccept::JSON);
if (!$curlResult->isSuccess() || ($curlResult->getBody() == '')) {
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function fetchWeeklyUsage(string $url, array $serverdata): array
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function detectMastodonAlikes(string $url, array $serverdata): array
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function detectHubzilla(string $url, array $serverdata): array
* Converts input value to a boolean value
*
* @param string|integer $val
+ *
* @return boolean
*/
private static function toBoolean($val): bool
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function detectGNUSocial(string $url, array $serverdata): array
*
* @param string $url URL of the given server
* @param array $serverdata array with server data
+ *
* @return array server data
*/
private static function detectFriendica(string $url, array $serverdata): array
*
* @return array server data
*/
- private static function analyseRootBody($curlResult, array $serverdata): array
+ private static function analyseRootBody($curlResult, array $serverdata): array
{
if (empty($curlResult->getBody())) {
return $serverdata;
}
- if (file_exists(__DIR__ . '/../../static/generator.config.php')) {
- require __DIR__ . '/../../static/generator.config.php';
+ if (file_exists(__DIR__ . '/../../static/platforms.config.php')) {
+ require __DIR__ . '/../../static/platforms.config.php';
} else {
- throw new HTTPException\InternalServerErrorException('Invalid generator file');
+ throw new HTTPException\InternalServerErrorException('Invalid platform file');
}
$platforms = array_merge($ap_platforms, $dfrn_platforms, $zap_platforms, $platforms);
*
* @param int $gsid Server id
* @param int $protocol Protocol id
- * @return void
+ *
* @throws Exception
*/
public static function setProtocol(int $gsid, int $protocol)
* Fetch the protocol of the given server
*
* @param int $gsid Server id
+ *
* @return ?int One of Post\DeliveryData protocol constants or null if unknown or gserver is missing
+ *
* @throws Exception
*/
public static function getProtocol(int $gsid): ?int
}
/**
+ * Update rows in the gserver table.
* Enforces gserver table field maximum sizes to avoid "Data too long" database errors
*
* @param array $fields
* @param array $condition
+ *
* @return bool
+ *
* @throws Exception
*/
public static function update(array $fields, array $condition): bool
return DBA::update('gserver', $fields, $condition);
}
+
+ /**
+ * Insert a row into the gserver table.
+ * Enforces gserver table field maximum sizes to avoid "Data too long" database errors
+ *
+ * @param array $fields
+ * @param int $duplicate_mode What to do on a duplicated entry
+ *
+ * @return bool
+ *
+ * @throws Exception
+ */
+ public static function insert(array $fields, int $duplicate_mode = Database::INSERT_DEFAULT): bool
+ {
+ $fields = DI::dbaDefinition()->truncateFieldsForTable('gserver', $fields);
+
+ return DBA::insert('gserver', $fields, $duplicate_mode);
+ }
}