]> git.mxchange.org Git - friendica.git/blobdiff - mod/salmon.php
Ops, one more left ...
[friendica.git] / mod / salmon.php
index 1434b7ae6c18357e84ce3ae46fdb0200880cd5f8..8bdfdefeee1663ba2d9c72bd3644f7848787dda0 100644 (file)
@@ -4,8 +4,9 @@
  */
 use Friendica\App;
 use Friendica\Core\PConfig;
+use Friendica\Core\Protocol;
 use Friendica\Core\System;
-use Friendica\Database\DBM;
+use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
@@ -13,19 +14,21 @@ 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('mod-salmon: new salmon ' . $xml, LOGGER_DATA);
+       logger('new salmon ' . $xml, LOGGER_DATA);
 
        $nick       = (($a->argc > 1) ? notags(trim($a->argv[1])) : '');
        $mentions   = (($a->argc > 2 && $a->argv[2] === 'mention') ? true : false);
 
        $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
-               dbesc($nick)
+               DBA::escape($nick)
        );
-       if (! DBM::is_result($r)) {
+       if (! DBA::isResult($r)) {
                System::httpExit(500);
        }
 
@@ -46,7 +49,7 @@ function salmon_post(App $a) {
                $base = $dom;
 
        if(! $base) {
-               logger('mod-salmon: unable to locate salmon data in xml ');
+               logger('unable to locate salmon data in xml ');
                System::httpExit(400);
        }
 
@@ -84,18 +87,18 @@ function salmon_post(App $a) {
        $author_link = $author["author-link"];
 
        if(! $author_link) {
-               logger('mod-salmon: Could not retrieve author URI.');
+               logger('Could not retrieve author URI.');
                System::httpExit(400);
        }
 
        // Once we have the author URI, go to the web and try to find their public key
 
-       logger('mod-salmon: Fetching key for ' . $author_link);
+       logger('Fetching key for ' . $author_link);
 
        $key = Salmon::getKey($author_link, $keyhash);
 
        if(! $key) {
-               logger('mod-salmon: Could not retrieve author key.');
+               logger('Could not retrieve author key.');
                System::httpExit(400);
        }
 
@@ -104,7 +107,7 @@ function salmon_post(App $a) {
        $m = base64url_decode($key_info[1]);
        $e = base64url_decode($key_info[2]);
 
-       logger('mod-salmon: key details: ' . print_r($key_info,true), LOGGER_DEBUG);
+       logger('key details: ' . print_r($key_info,true), LOGGER_DEBUG);
 
        $pubkey = Crypto::meToPem($m, $e);
 
@@ -115,23 +118,23 @@ function salmon_post(App $a) {
        $mode = 1;
 
        if (! $verify) {
-               logger('mod-salmon: message did not verify using protocol. Trying compliant format.');
+               logger('message did not verify using protocol. Trying compliant format.');
                $verify = Crypto::rsaVerify($compliant_format, $signature, $pubkey);
                $mode = 2;
        }
 
        if (! $verify) {
-               logger('mod-salmon: message did not verify using padding. Trying old statusnet format.');
+               logger('message did not verify using padding. Trying old statusnet format.');
                $verify = Crypto::rsaVerify($stnet_signed_data, $signature, $pubkey);
                $mode = 3;
        }
 
        if (! $verify) {
-               logger('mod-salmon: Message did not verify. Discarding.');
+               logger('Message did not verify. Discarding.');
                System::httpExit(400);
        }
 
-       logger('mod-salmon: Message verified with mode '.$mode);
+       logger('Message verified with mode '.$mode);
 
 
        /*
@@ -143,23 +146,23 @@ function salmon_post(App $a) {
        $r = q("SELECT * FROM `contact` WHERE `network` IN ('%s', '%s')
                                                AND (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s')
                                                AND `uid` = %d LIMIT 1",
-               dbesc(NETWORK_OSTATUS),
-               dbesc(NETWORK_DFRN),
-               dbesc(normalise_link($author_link)),
-               dbesc($author_link),
-               dbesc(normalise_link($author_link)),
+               DBA::escape(Protocol::OSTATUS),
+               DBA::escape(Protocol::DFRN),
+               DBA::escape(normalise_link($author_link)),
+               DBA::escape($author_link),
+               DBA::escape(normalise_link($author_link)),
                intval($importer['uid'])
        );
-       if (! DBM::is_result($r)) {
-               logger('mod-salmon: Author unknown to us.');
+       if (! DBA::isResult($r)) {
+               logger('Author ' . $author_link . ' unknown to user ' . $importer['uid'] . '.');
                if(PConfig::get($importer['uid'],'system','ostatus_autofriend')) {
                        $result = Contact::createFromProbe($importer['uid'], $author_link);
                        if($result['success']) {
                                $r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s')
                                        AND `uid` = %d LIMIT 1",
-                                       dbesc(NETWORK_OSTATUS),
-                                       dbesc($author_link),
-                                       dbesc($author_link),
+                                       DBA::escape(Protocol::OSTATUS),
+                                       DBA::escape($author_link),
+                                       DBA::escape($author_link),
                                        intval($importer['uid'])
                                );
                        }
@@ -169,9 +172,9 @@ function salmon_post(App $a) {
        // Have we ignored the person?
        // If so we can not accept this post.
 
-       //if((DBM::is_result($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == CONTACT_IS_FOLLOWER) || ($r[0]['blocked']))) {
-       if (DBM::is_result($r) && $r[0]['blocked']) {
-               logger('mod-salmon: Ignoring this author.');
+       //if((DBA::isResult($r)) && (($r[0]['readonly']) || ($r[0]['rel'] == Contact::FOLLOWER) || ($r[0]['blocked']))) {
+       if (DBA::isResult($r) && $r[0]['blocked']) {
+               logger('Ignoring this author.');
                System::httpExit(202);
                // NOTREACHED
        }
@@ -179,7 +182,7 @@ function salmon_post(App $a) {
        // Placeholder for hub discovery.
        $hub = '';
 
-       $contact_rec = ((DBM::is_result($r)) ? $r[0] : null);
+       $contact_rec = ((DBA::isResult($r)) ? $r[0] : null);
 
        OStatus::import($data, $importer, $contact_rec, $hub);