aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-01-24 11:06:43 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2016-01-24 11:06:43 +0100
commitcf2b7b1a64dfd94826ce7d762f86948dc17bfbf4 (patch)
tree65bb6a89a704ec49fc22e9c74f67d6145a508bda
parent5ff53736e80869ac8b73e3a044cc3c02c79fbcab (diff)
parent0915772fe6735f6051c6b56a3b3e59dd3c44833b (diff)
Merge branch 'pshb-unsubscribe' into dev
-rw-r--r--app/Models/Feed.php9
-rw-r--r--p/api/pshb.php9
2 files changed, 13 insertions, 5 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 23491ee8d..986cc5015 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -451,6 +451,10 @@ class FreshRSS_Feed extends Minz_Model {
Minz_Log::warning('Invalid callback for PubSubHubbub: ' . $this->url);
return false;
}
+ if (!$state) { //unsubscribe
+ $hubJson['lease_end'] = time() - 60;
+ file_put_contents($hubFilename, json_encode($hubJson));
+ }
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $this->hubUrl,
@@ -470,11 +474,6 @@ class FreshRSS_Feed extends Minz_Model {
'PubSubHubbub ' . ($state ? 'subscribe' : 'unsubscribe') . ' to ' . $this->selfUrl .
' with callback ' . $callbackUrl . ': ' . $info['http_code'] . ' ' . $response . "\n", FILE_APPEND);
- if (!$state) { //unsubscribe
- $hubJson['lease_end'] = time() - 60;
- file_put_contents($hubFilename, json_encode($hubJson));
- }
-
if (substr($info['http_code'], 0, 1) == '2') {
return true;
} else {
diff --git a/p/api/pshb.php b/p/api/pshb.php
index 4bb4694b3..7de4cc1a2 100644
--- a/p/api/pshb.php
+++ b/p/api/pshb.php
@@ -68,6 +68,15 @@ if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'subscribe') {
exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : '');
}
+if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] === 'unsubscribe') {
+ if (empty($hubJson['lease_end']) || $hubJson['lease_end'] < time()) {
+ exit(isset($_REQUEST['hub_challenge']) ? $_REQUEST['hub_challenge'] : '');
+ } else {
+ header('HTTP/1.1 422 Unprocessable Entity');
+ die('We did not ask to unsubscribe!');
+ }
+}
+
if ($ORIGINAL_INPUT == '') {
header('HTTP/1.1 422 Unprocessable Entity');
die('Missing XML payload!');