From: Michael Date: Fri, 23 Mar 2018 05:08:47 +0000 (+0000) Subject: DFRN payload is receivable via the Diaspora transport layer X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9d83369d88bb49ce44acf973fc600856f2b87b4b;p=friendica.git DFRN payload is receivable via the Diaspora transport layer --- diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index db96729066..0743b21435 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -12,6 +12,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Protocol\DFRN; +use Friendica\Protocol\Diaspora; require_once 'include/items.php'; require_once 'include/event.php'; @@ -19,9 +20,52 @@ require_once 'include/event.php'; function dfrn_notify_post(App $a) { logger(__function__, LOGGER_TRACE); - if (empty($_POST)) { - require_once 'mod/salmon.php'; - salmon_post($a); + $postdata = file_get_contents('php://input'); + + if (empty($_POST) || !empty($postdata)) { + $data = json_decode($postdata); + if (is_object($data)) { + $nick = defaults($a->argv, 1, ''); + $user = dba::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]); + if (!DBM::is_result($user)) { + System::httpExit(500); + } + $msg = Diaspora::decodeRaw($user, $postdata); + + // Check if the user has got this contact + $cid = getIdForURL($msg['author'], $user['uid']); + if (!$cid) { + // Otherwise there should be a public contact + $cid = getIdForURL($msg['author']); + if (!$cid) { + logger('Contact not found for address ' . $msg['author']); + System::xmlExit(3, 'Contact not found'); + } + } + + // We now have some contact, so we fetch it + $importer = dba::fetch_first("SELECT *, `name` as `senderName` + FROM `contact` + WHERE NOT `blocked` AND `id` = ? LIMIT 1", + $cid); + + // This should never fail + if (!DBM::is_result($importer)) { + logger('Contact not found for address ' . $msg['author']); + System::xmlExit(3, 'Contact not found'); + } + + // Set the user id. This is important if this is a public contact + $importer['uid'] = $user['uid']; + $importer['importer_uid'] = $user['uid']; + + // Now we should be able to import it + $ret = DFRN::import($msg['message'], $importer); + System::xmlExit($ret, 'Processed'); + } else { + require_once 'mod/salmon.php'; + salmon_post($a, $postdata); + } } $dfrn_id = ((x($_POST,'dfrn_id')) ? notags(trim($_POST['dfrn_id'])) : ''); diff --git a/mod/salmon.php b/mod/salmon.php index 2b6014adf5..22da151cf8 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -13,9 +13,11 @@ use Friendica\Util\Crypto; require_once 'include/items.php'; -function salmon_post(App $a) { +function salmon_post(App $a, $xml = '') { - $xml = file_get_contents('php://input'); + if (empty($xml)) { + $xml = file_get_contents('php://input'); + } logger('new salmon ' . $xml, LOGGER_DATA);