Merge pull request #57 from MrPetovan/bug/45-drop-key-validation

Remove validity check on profile key parameter
This commit is contained in:
Michael Vogel 2020-09-26 23:07:49 +02:00 committed by GitHub
commit b48c436141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 13 deletions

View File

@ -9,6 +9,10 @@ use Friendica\Directory\Utils\Network;
*/
class Profile
{
const PROFILE_MISSING_REQUEST = 1;
const PROFILE_MISSING_CONFIRM = 2;
const PROFILE_MISSING_NOTIFY = 4;
const PROFILE_MISSING_POLL = 8;
/**
* @var \Atlas\Pdo\Connection
@ -171,8 +175,21 @@ class Profile
}
// This is most likely a problem with the site configuration. Ignore.
if (self::validateParams($params)) {
if ($error = self::validateParams($params)) {
$this->logger->warning('Poll aborted, parameters invalid.', ['params' => $params]);
if ($error & Profile::PROFILE_MISSING_REQUEST) {
$this->logger->notice('dfrn-request parameter is empty.');
}
if ($error & Profile::PROFILE_MISSING_CONFIRM) {
$this->logger->notice('dfrn-confirm parameter is empty.');
}
if ($error & Profile::PROFILE_MISSING_NOTIFY) {
$this->logger->notice('dfrn-notify parameter is empty.');
}
if ($error & Profile::PROFILE_MISSING_POLL) {
$this->logger->notice('dfrn-poll parameter is empty.');
}
return false;
}
@ -330,23 +347,24 @@ class Profile
return true;
}
/**
* @param array $params
* @return int
*/
private static function validateParams(array $params): int
{
$errors = 0;
if (empty($params['key'])) {
$errors++;
}
if (empty($params['dfrn-request'])) {
$errors++;
$errors &= self::PROFILE_MISSING_REQUEST;
}
if (empty($params['dfrn-confirm'])) {
$errors++;
$errors &= self::PROFILE_MISSING_CONFIRM;
}
if (empty($params['dfrn-notify'])) {
$errors++;
$errors &= self::PROFILE_MISSING_NOTIFY;
}
if (empty($params['dfrn-poll'])) {
$errors++;
$errors &= self::PROFILE_MISSING_POLL;
}
return $errors;

View File

@ -129,7 +129,7 @@ class Scrape
$nodes_left = max(intval($max_nodes), $minNodes);
$items = $dom->getElementsByTagName('*');
$targets = array('fn', 'pdesc', 'photo', 'key', 'locality', 'region', 'postal-code', 'country-name');
$targets = array('fn', 'pdesc', 'photo', 'locality', 'region', 'postal-code', 'country-name');
$targets_left = count($targets);
foreach ($items as $item) {
if (self::attributeContains($item->getAttribute('class'), 'vcard')) {
@ -147,10 +147,6 @@ class Scrape
$params['photo'] = $vcard_element->getAttribute('src');
$targets_left = self::popScrapeTarget($targets, 'photo');
}
if (self::attributeContains($vcard_element->getAttribute('class'), 'key')) {
$params['key'] = $vcard_element->textContent;
$targets_left = self::popScrapeTarget($targets, 'key');
}
if (self::attributeContains($vcard_element->getAttribute('class'), 'locality')) {
$params['locality'] = $vcard_element->textContent;
$targets_left = self::popScrapeTarget($targets, 'locality');