fix more errors

This commit is contained in:
Art4 2024-11-17 22:13:01 +00:00
parent 36484309d1
commit 08ecf2c9a4
3 changed files with 25 additions and 17 deletions

View file

@ -220,14 +220,16 @@ class Probe
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
return []; return [];
} }
$ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0); $ssl_connection_error = ($curlResult->getErrorNumber() == CURLE_COULDNT_CONNECT) || ($curlResult->getReturnCode() == 0);
$host_url = $host;
if ($curlResult->isSuccess()) { if ($curlResult->isSuccess()) {
$xml = $curlResult->getBodyString(); $xml = $curlResult->getBodyString();
$xrd = XML::parseString($xml, true); $xrd = XML::parseString($xml, true);
if (!empty($url)) { if (!empty($url)) {
$host_url = 'https://' . $host; $host_url = 'https://' . $host;
} else {
$host_url = $host;
} }
} elseif ($curlResult->isTimeout()) { } elseif ($curlResult->isTimeout()) {
Logger::info('Probing timeout', ['url' => $ssl_url]); Logger::info('Probing timeout', ['url' => $ssl_url]);
@ -550,6 +552,7 @@ class Probe
public static function getWebfingerArray(string $uri): array public static function getWebfingerArray(string $uri): array
{ {
$parts = parse_url($uri); $parts = parse_url($uri);
$lrdd = [];
if (!empty($parts['scheme']) && !empty($parts['host'])) { if (!empty($parts['scheme']) && !empty($parts['host'])) {
$host = $parts['host']; $host = $parts['host'];
@ -563,7 +566,7 @@ class Probe
$addr = ''; $addr = '';
$path_parts = explode('/', trim($parts['path'] ?? '', '/')); $path_parts = explode('/', trim($parts['path'] ?? '', '/'));
if (!empty($path_parts)) { if (is_array($path_parts)) {
$nick = ltrim(end($path_parts), '@'); $nick = ltrim(end($path_parts), '@');
$addr = $nick . '@' . $host; $addr = $nick . '@' . $host;
} }
@ -668,8 +671,10 @@ class Probe
return null; return null;
} }
$detected = '';
// First try the address because this is the primary purpose of webfinger // First try the address because this is the primary purpose of webfinger
if (!empty($addr)) { if ($addr !== '') {
$detected = $addr; $detected = $addr;
$path = str_replace('{uri}', urlencode('acct:' . $addr), $template); $path = str_replace('{uri}', urlencode('acct:' . $addr), $template);
$webfinger = self::webfinger($path, $type); $webfinger = self::webfinger($path, $type);
@ -823,13 +828,15 @@ class Probe
*/ */
private static function zot(array $webfinger, array $data): array private static function zot(array $webfinger, array $data): array
{ {
$zot_url = '';
foreach ($webfinger['links'] as $link) { foreach ($webfinger['links'] as $link) {
if (($link['rel'] == 'http://purl.org/zot/protocol/6.0') && !empty($link['href'])) { if (($link['rel'] == 'http://purl.org/zot/protocol/6.0') && !empty($link['href'])) {
$zot_url = $link['href']; $zot_url = $link['href'];
} }
} }
if (empty($zot_url)) { if ($zot_url === '') {
return $data; return $data;
} }
@ -871,7 +878,7 @@ class Probe
$data['url'] = $link['href']; $data['url'] = $link['href'];
} }
} }
$data = self::pollZot($zot_url, $data); $data = self::pollZot($zot_url, $data);
if (!empty($data['url']) && !empty($webfinger['aliases']) && is_array($webfinger['aliases'])) { if (!empty($data['url']) && !empty($webfinger['aliases']) && is_array($webfinger['aliases'])) {
@ -1429,7 +1436,7 @@ class Probe
&& !empty($data['guid']) && !empty($data['guid'])
&& !empty($data['baseurl']) && !empty($data['baseurl'])
&& !empty($data['pubkey']) && !empty($data['pubkey'])
&& !empty($hcard_url) && $hcard_url !== ''
) { ) {
$data['network'] = Protocol::DIASPORA; $data['network'] = Protocol::DIASPORA;
$data['manually-approve'] = false; $data['manually-approve'] = false;
@ -1776,7 +1783,7 @@ class Probe
$password = ''; $password = '';
openssl_private_decrypt(hex2bin($mailacct['pass']), $password, $user['prvkey']); openssl_private_decrypt(hex2bin($mailacct['pass']), $password, $user['prvkey']);
$mbox = Email::connect($mailbox, $mailacct['user'], $password); $mbox = Email::connect($mailbox, $mailacct['user'], $password);
if (!$mbox) { if ($mbox === false) {
return []; return [];
} }
@ -1828,7 +1835,7 @@ class Probe
} }
} }
if (!empty($mbox)) { if ($mbox !== false) {
imap_close($mbox); imap_close($mbox);
} }

View file

@ -25,7 +25,7 @@ class Email
* @param string $mailbox The mailbox name * @param string $mailbox The mailbox name
* @param string $username The username * @param string $username The username
* @param string $password The password * @param string $password The password
* @return Connection|resource|bool * @return Connection|false
* @throws \Exception * @throws \Exception
*/ */
public static function connect(string $mailbox, string $username, string $password) public static function connect(string $mailbox, string $username, string $password)

View file

@ -220,7 +220,7 @@ class OnePoll
Logger::info('Mail is enabled'); Logger::info('Mail is enabled');
$mbox = null; $mbox = false;
$user = DBA::selectFirst('user', ['prvkey'], ['uid' => $importer_uid]); $user = DBA::selectFirst('user', ['prvkey'], ['uid' => $importer_uid]);
$condition = ["`server` != ? AND `user` != ? AND `port` != ? AND `uid` = ?", '', '', 0, $importer_uid]; $condition = ["`server` != ? AND `user` != ? AND `port` != ? AND `uid` = ?", '', '', 0, $importer_uid];
@ -232,17 +232,18 @@ class OnePoll
$mbox = Email::connect($mailbox, $mailconf['user'], $password); $mbox = Email::connect($mailbox, $mailconf['user'], $password);
unset($password); unset($password);
Logger::notice('Connect', ['user' => $mailconf['user']]); Logger::notice('Connect', ['user' => $mailconf['user']]);
if ($mbox) {
$fields = ['last_check' => $updated]; if ($mbox === false) {
DBA::update('mailacct', $fields, ['id' => $mailconf['id']]);
Logger::notice('Connected', ['user' => $mailconf['user']]);
} else {
Logger::notice('Connection error', ['user' => $mailconf['user'], 'error' => imap_errors()]); Logger::notice('Connection error', ['user' => $mailconf['user'], 'error' => imap_errors()]);
return false; return false;
} }
$fields = ['last_check' => $updated];
DBA::update('mailacct', $fields, ['id' => $mailconf['id']]);
Logger::notice('Connected', ['user' => $mailconf['user']]);
} }
if (empty($mbox)) { if ($mbox === false) {
return false; return false;
} }