From b4c673a6203a5b31599f23dbb35617a712304958 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 30 Jul 2019 22:26:01 +0000 Subject: [PATCH] We now use a central function for fetching the postdata --- include/api.php | 2 +- mod/dfrn_notify.php | 3 ++- mod/pubsub.php | 3 ++- mod/receive.php | 3 ++- mod/salmon.php | 3 ++- src/Module/Inbox.php | 3 ++- src/Util/Network.php | 10 ++++++++++ 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/api.php b/include/api.php index 0e190b84c1..5665a7fbdd 100644 --- a/include/api.php +++ b/include/api.php @@ -1267,7 +1267,7 @@ function api_media_metadata_create($type) api_get_user($a); - $postdata = file_get_contents('php://input'); + $postdata = Network::postdata(); if (empty($postdata)) { throw new BadRequestException("No post data"); diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index e75d975a82..3f0ecba005 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -16,11 +16,12 @@ use Friendica\Model\User; use Friendica\Protocol\DFRN; use Friendica\Protocol\Diaspora; use Friendica\Util\Strings; +use Friendica\Util\Network; function dfrn_notify_post(App $a) { Logger::log(__function__, Logger::TRACE); - $postdata = file_get_contents('php://input'); + $postdata = Network::postdata(); if (empty($_POST) || !empty($postdata)) { $data = json_decode($postdata); diff --git a/mod/pubsub.php b/mod/pubsub.php index e5ede6c80a..d10d7031d6 100644 --- a/mod/pubsub.php +++ b/mod/pubsub.php @@ -7,6 +7,7 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Protocol\OStatus; use Friendica\Util\Strings; +use Friendica\Util\Network; use Friendica\Core\System; function hub_return($valid, $body) @@ -83,7 +84,7 @@ function pubsub_init(App $a) function pubsub_post(App $a) { - $xml = file_get_contents('php://input'); + $xml = Network::postdata(); Logger::log('Feed arrived from ' . $_SERVER['REMOTE_ADDR'] . ' for ' . $a->cmd . ' with user-agent: ' . $_SERVER['HTTP_USER_AGENT']); Logger::log('Data: ' . $xml, Logger::DATA); diff --git a/mod/receive.php b/mod/receive.php index db1287ea6f..182a1df8c5 100644 --- a/mod/receive.php +++ b/mod/receive.php @@ -10,6 +10,7 @@ use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Protocol\Diaspora; +use Friendica\Util\Network; /** * @param App $a App @@ -47,7 +48,7 @@ function receive_post(App $a) Logger::log('mod-diaspora: receiving post', Logger::DEBUG); if (empty($_POST['xml'])) { - $postdata = file_get_contents("php://input"); + $postdata = Network::postdata(); if ($postdata == '') { throw new \Friendica\Network\HTTPException\InternalServerErrorException(); } diff --git a/mod/salmon.php b/mod/salmon.php index ba1bc8d465..67e467a73f 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -13,11 +13,12 @@ use Friendica\Protocol\OStatus; use Friendica\Protocol\Salmon; use Friendica\Util\Crypto; use Friendica\Util\Strings; +use Friendica\Util\Network; function salmon_post(App $a, $xml = '') { if (empty($xml)) { - $xml = file_get_contents('php://input'); + $xml = Network::postdata(); } Logger::log('new salmon ' . $xml, Logger::DATA); diff --git a/src/Module/Inbox.php b/src/Module/Inbox.php index 5367adb7e1..2cc273b139 100644 --- a/src/Module/Inbox.php +++ b/src/Module/Inbox.php @@ -12,6 +12,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Protocol\ActivityPub; use Friendica\Util\HTTPSignature; +use Friendica\Util\Network; /** * ActivityPub Inbox @@ -22,7 +23,7 @@ class Inbox extends BaseModule { $a = self::getApp(); - $postdata = file_get_contents('php://input'); + $postdata = Network::postdata(); if (empty($postdata)) { throw new \Friendica\Network\HTTPException\BadRequestException(); diff --git a/src/Util/Network.php b/src/Util/Network.php index 75b928bea2..cd66abe0b2 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -342,6 +342,16 @@ class Network return $curlResponse; } + /** + * Return raw post data from a post request + * + * @return string post data + */ + public static function postdata() + { + return file_get_contents('php://input'); + } + /** * @brief Check URL to see if it's real *