use Friendica\Module\BaseAdmin;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPException\ServiceUnavailableException;
+use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat;
class Summary extends BaseAdmin
// Check server vitality
if (!self::checkSelfHostMeta()) {
- $well_known = DI::baseUrl()->get() . '/.well-known/host-meta';
+ $well_known = DI::baseUrl()->get() . Probe::HOST_META;
$warningtext[] = DI::l10n()->t('<a href="%s">%s</a> is not reachable on your system. This is a severe configuration issue that prevents server to server communication. See <a href="%s">the installation page</a> for help.',
$well_known, $well_known, DI::baseUrl()->get() . '/help/Install');
}
$server_settings = [
'label' => DI::l10n()->t('Server Settings'),
- 'php' => [
+ 'php' => [
'upload_max_filesize' => ini_get('upload_max_filesize'),
- 'post_max_size' => ini_get('post_max_size'),
- 'memory_limit' => ini_get('memory_limit')
+ 'post_max_size' => ini_get('post_max_size'),
+ 'memory_limit' => ini_get('memory_limit')
],
'mysql' => [
'max_allowed_packet' => $max_allowed_packet
$t = Renderer::getMarkupTemplate('admin/summary.tpl');
return Renderer::replaceMacros($t, [
- '$title' => DI::l10n()->t('Administration'),
- '$page' => DI::l10n()->t('Summary'),
- '$queues' => $queues,
- '$users' => [DI::l10n()->t('Registered users'), $users],
- '$accounts' => $accounts,
- '$pending' => [DI::l10n()->t('Pending registrations'), $pending],
- '$version' => [DI::l10n()->t('Version'), App::VERSION],
- '$platform' => App::PLATFORM,
- '$codename' => App::CODENAME,
- '$build' => DI::config()->get('system', 'build'),
- '$addons' => [DI::l10n()->t('Active addons'), Addon::getEnabledList()],
+ '$title' => DI::l10n()->t('Administration'),
+ '$page' => DI::l10n()->t('Summary'),
+ '$queues' => $queues,
+ '$users' => [DI::l10n()->t('Registered users'), $users],
+ '$accounts' => $accounts,
+ '$pending' => [DI::l10n()->t('Pending registrations'), $pending],
+ '$version' => [DI::l10n()->t('Version'), App::VERSION],
+ '$platform' => App::PLATFORM,
+ '$codename' => App::CODENAME,
+ '$build' => DI::config()->get('system', 'build'),
+ '$addons' => [DI::l10n()->t('Active addons'), Addon::getEnabledList()],
'$serversettings' => $server_settings,
- '$warningtext' => $warningtext
+ '$warningtext' => $warningtext,
]);
}
private static function checkSelfHostMeta()
{
// Fetch the host-meta to check if this really is a vital server
- return DI::httpClient()->get(DI::baseUrl()->get() . '/.well-known/host-meta', HttpClientAccept::XRD_XML)->isSuccess();
+ return DI::httpClient()->get(DI::baseUrl()->get() . Probe::HOST_META, HttpClientAccept::XRD_XML)->isSuccess();
}
}
*/
class Probe
{
+ const HOST_META = '/.well-known/host-meta';
const WEBFINGER = '/.well-known/webfinger?resource={uri}';
+ /**
+ * @var string Base URL
+ */
private static $baseurl;
- private static $istimeout;
+
+ /**
+ * @var boolean Whether a timeout has occured
+ */
+ private static $isTimeout;
/**
* Checks if the provided network can be probed
*
* @param string $network
+ *
* @return boolean
*/
public static function isProbable(string $network): bool
$parts = parse_url($host);
if (!isset($parts['scheme'])) {
- $parts = parse_url('http://'.$host);
+ $parts = parse_url('http://' . $host);
}
if (!isset($parts['host'])) {
* It seems as if it was dropped from the standard.
*
* @param string $host The host part of an url
+ *
* @return array with template and type of the webfinger template for JSON or XML
* @throws HTTPException\InternalServerErrorException
*/
// Handles the case when the hostname contains the scheme
if (!parse_url($host, PHP_URL_SCHEME)) {
- $ssl_url = 'https://' . $host . '/.well-known/host-meta';
- $url = 'http://' . $host . '/.well-known/host-meta';
+ $ssl_url = 'https://' . $host . self::HOST_META;
+ $url = 'http://' . $host . self::HOST_META;
} else {
- $ssl_url = $host . '/.well-known/host-meta';
+ $ssl_url = $host . self::HOST_META;
$url = '';
}
}
} elseif ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $ssl_url]);
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
if ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $url]);
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
} elseif ($connection_error && $ssl_connection_error) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function uri($uri, $network = '', $uid = -1)
+ public static function uri(string $uri, string $network = '', int $uid = -1): array
{
// Local profiles aren't probed via network
if (empty($network) && Contact::isLocal($uri)) {
$ap_profile = [];
}
- self::$istimeout = false;
+ self::$isTimeout = false;
if ($network != Protocol::ACTIVITYPUB) {
$data = self::detect($uri, $network, $uid, $ap_profile);
*
* @param array $result Result array
* @param array $webfinger Webfinger data
+ *
* @return array result Altered/unaltered result array
*/
private static function getSubscribeLink(array $result, array $webfinger): array
* Get webfinger data from a given URI
*
* @param string $uri URI
+ *
* @return array Webfinger data
* @throws HTTPException\InternalServerErrorException
*/
$addr = $uri;
$webfinger = self::getWebfinger('https://' . $host . self::WEBFINGER, HttpClientAccept::JRD_JSON, $uri, $addr);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
if (empty($webfinger)) {
$webfinger = self::getWebfinger('http://' . $host . self::WEBFINGER, HttpClientAccept::JRD_JSON, $uri, $addr);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
} else {
if (empty($webfinger)) {
$lrdd = self::hostMeta($host);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
$baseurl = self::$baseurl;
* @param string $type
* @param string $uri
* @param string $addr
+ *
* @return array webfinger results
*/
private static function getWebfinger(string $template, string $type, string $uri, string $addr): array
$detected = $addr;
$path = str_replace('{uri}', urlencode('acct:' . $addr), $template);
$webfinger = self::webfinger($path, $type);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
}
$detected = $uri;
$path = str_replace('{uri}', urlencode($uri), $template);
$webfinger = self::webfinger($path, $type);
- if (self::$istimeout) {
+ if (self::$isTimeout) {
return [];
}
}
* @param array $webfinger Webfinger data
* @param array $data previously probed data
* @param string $baseUrl Base URL
+ *
* @return array Zot data
* @throws HTTPException\InternalServerErrorException
*/
*
* @param string $url Address that should be probed
* @param string $type type
+ *
* @return array webfinger data
* @throws HTTPException\InternalServerErrorException
*/
$curlResult = DI::httpClient()->get($url, $type, [HttpClientOptions::TIMEOUT => $xrd_timeout]);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$data = $curlResult->getBody();
*
* @param string $noscrape_url Link to the noscrape page
* @param array $data The already fetched data
+ *
* @return array noscrape data
* @throws HTTPException\InternalServerErrorException
*/
{
$curlResult = DI::httpClient()->get($noscrape_url, HttpClientAccept::JSON);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return $data;
}
$content = $curlResult->getBody();
*
* @return int Number of errors
*/
- public static function validDfrn($data)
+ public static function validDfrn(array $data): int
{
$errors = 0;
if (!isset($data['key'])) {
{
$curlResult = DI::httpClient()->get($hcard_url, HttpClientAccept::HTML);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$content = $curlResult->getBody();
* Check for Diaspora contact
*
* @param array $webfinger Webfinger data
+ *
* @return array Diaspora data
* @throws HTTPException\InternalServerErrorException
*/
*
* @param array $webfinger Webfinger data
* @param bool $short Short detection mode
+ *
* @return array|bool OStatus data or "false" on error or "true" on short mode
* @throws HTTPException\InternalServerErrorException
*/
} elseif (Strings::normaliseLink($pubkey) == 'http://') {
$curlResult = DI::httpClient()->get($pubkey, HttpClientAccept::MAGIC_KEY);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return $short ? false : [];
}
Logger::debug('Fetched public key', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $pubkey]);
// Fetch all additional data from the feed
$curlResult = DI::httpClient()->get($data['poll'], HttpClientAccept::FEED_XML);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$feed = $curlResult->getBody();
* Fetch data from a pump.io profile page
*
* @param string $profile_link Link to the profile page
+ *
* @return array Profile data
*/
private static function pumpioProfileData(string $profile_link): array
*
* @param array $webfinger Webfinger data
* @param string $addr
+ *
* @return array pump.io data
*/
private static function pumpio(array $webfinger, string $addr): array
*
* @param string $url Page link
* @param string $body Page body string
+ *
* @return string|false Feed link or false if body was invalid HTML document
*/
public static function getFeedLink(string $url, string $body)
* @param string $href The potential relative href found in the HTML document
* @param string $base The HTML document URL
* @param DOMXPath $xpath The HTML document XPath
+ *
* @return string Absolute URL
*/
private static function ensureAbsoluteLinkFromHTMLDoc(string $href, string $base, DOMXPath $xpath): string
*
* @param string $url Profile link
* @param boolean $probe Do a probe if the page contains a feed link
+ *
* @return array feed data
* @throws HTTPException\InternalServerErrorException
*/
{
$curlResult = DI::httpClient()->get($url, HttpClientAccept::FEED_XML);
if ($curlResult->isTimeout()) {
- self::$istimeout = true;
+ self::$isTimeout = true;
return [];
}
$feed = $curlResult->getBody();
*
* @param string $uri Profile link
* @param integer $uid User ID
+ *
* @return array mail data
* @throws \Exception
*/
$phost = substr($uri, strpos($uri, '@') + 1);
- $data = [];
- $data['addr'] = $uri;
- $data['network'] = Protocol::MAIL;
- $data['name'] = substr($uri, 0, strpos($uri, '@'));
+ $data = [
+ 'addr' => $uri,
+ 'network' => Protocol::MAIL,
+ 'name' => substr($uri, 0, strpos($uri, '@')),
+ 'photo' => Network::lookupAvatarByEmail($uri),
+ 'url' => 'mailto:' . $uri,
+ 'notify' => 'smtp ' . Strings::getRandomHex(),
+ 'poll' => 'email ' . Strings::getRandomHex(),
+ ];
+
$data['nick'] = $data['name'];
- $data['photo'] = Network::lookupAvatarByEmail($uri);
- $data['url'] = 'mailto:'.$uri;
- $data['notify'] = 'smtp ' . Strings::getRandomHex();
- $data['poll'] = 'email ' . Strings::getRandomHex();
$x = Email::messageMeta($mbox, $msgs[0]);
+
if (stristr($x[0]->from, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->from, '');
} elseif (stristr($x[0]->to, $uri)) {
$adr = imap_rfc822_parse_adrlist($x[0]->to, '');
}
+
if (isset($adr)) {
foreach ($adr as $feadr) {
if ((strcasecmp($feadr->mailbox, $data['name']) == 0)
}
}
}
+
if (!empty($mbox)) {
imap_close($mbox);
}
+
return $data;
}
*
* @param string $avatar Path to the avatar
* @param string $base Another path that is hopefully complete
+ *
* @return string fixed avatar path
* @throws \Exception
*/
* Fetch the last date that the contact had posted something (publically)
*
* @param array $data probing result
+ *
* @return string last activity
*/
public static function getLastUpdate(array $data): string
* Fetch the last activity date from the "noscrape" endpoint
*
* @param array $data Probing result
+ *
* @return string last activity or true if update was successful or the server was unreachable
*/
private static function updateFromNoScrape(array $data): string
*
* @param string $feed
* @param array $data Probing result
+ *
* @return string last activity
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
* Probe data from local profiles without network traffic
*
* @param string $url
+ *
* @return array probed data
* @throws HTTPException\InternalServerErrorException
* @throws HTTPException\NotFoundException
}
$data = [
- 'name' => $owner['name'], 'nick' => $owner['nick'], 'guid' => $approfile['diaspora:guid'] ?? '',
- 'url' => $owner['url'], 'addr' => $owner['addr'], 'alias' => $owner['alias'],
- 'photo' => User::getAvatarUrl($owner),
- 'header' => $owner['header'] ? Contact::getHeaderUrlForId($owner['id'], $owner['updated']) : '',
- 'account-type' => $owner['contact-type'], 'community' => ($owner['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
- 'keywords' => $owner['keywords'], 'location' => $owner['location'], 'about' => $owner['about'],
- 'xmpp' => $owner['xmpp'], 'matrix' => $owner['matrix'],
- 'hide' => !$owner['net-publish'], 'batch' => '', 'notify' => $owner['notify'],
- 'poll' => $owner['poll'], 'request' => $owner['request'], 'confirm' => $owner['confirm'],
- 'subscribe' => $approfile['generator']['url'] . '/follow?url={uri}', 'poco' => $owner['poco'],
- 'following' => $approfile['following'], 'followers' => $approfile['followers'],
- 'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'],
- 'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN,
- 'pubkey' => $owner['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $owner['gsid'],
+ 'name' => $owner['name'], 'nick' => $owner['nick'], 'guid' => $approfile['diaspora:guid'] ?? '',
+ 'url' => $owner['url'], 'addr' => $owner['addr'], 'alias' => $owner['alias'],
+ 'photo' => User::getAvatarUrl($owner),
+ 'header' => $owner['header'] ? Contact::getHeaderUrlForId($owner['id'], $owner['updated']) : '',
+ 'account-type' => $owner['contact-type'], 'community' => ($owner['contact-type'] == User::ACCOUNT_TYPE_COMMUNITY),
+ 'keywords' => $owner['keywords'], 'location' => $owner['location'], 'about' => $owner['about'],
+ 'xmpp' => $owner['xmpp'], 'matrix' => $owner['matrix'],
+ 'hide' => !$owner['net-publish'], 'batch' => '', 'notify' => $owner['notify'],
+ 'poll' => $owner['poll'], 'request' => $owner['request'], 'confirm' => $owner['confirm'],
+ 'subscribe' => $approfile['generator']['url'] . '/follow?url={uri}', 'poco' => $owner['poco'],
+ 'following' => $approfile['following'], 'followers' => $approfile['followers'],
+ 'inbox' => $approfile['inbox'], 'outbox' => $approfile['outbox'],
+ 'sharedinbox' => $approfile['endpoints']['sharedInbox'], 'network' => Protocol::DFRN,
+ 'pubkey' => $owner['upubkey'], 'baseurl' => $approfile['generator']['url'], 'gsid' => $owner['gsid'],
'manually-approve' => in_array($owner['page-flags'], [User::PAGE_FLAGS_NORMAL, User::PAGE_FLAGS_PRVGROUP])
];
} catch (Exception $e) {