aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2020-03-06 18:33:42 +0100
committerChristian Weiske <cweiske@cweiske.de>2020-03-06 18:33:42 +0100
commit973ef8c4f8c15848dfc135e11053e5eb6f5dcdb7 (patch)
tree5cb1ad71cfd0512522bcea2db656c6703de4092b
parent54fbef1610d1c2ecb48fb149602e3b88f80747df (diff)
downloadphinde-973ef8c4f8c15848dfc135e11053e5eb6f5dcdb7.tar.gz
phinde-973ef8c4f8c15848dfc135e11053e5eb6f5dcdb7.zip
Store the hub that was used for Websub subscription
-rwxr-xr-xbin/subscribe.php3
-rw-r--r--data/schema.sql1
-rw-r--r--src/phinde/Subscriptions.php8
-rw-r--r--www/push-subscription.php4
4 files changed, 10 insertions, 6 deletions
diff --git a/bin/subscribe.php b/bin/subscribe.php
index 7d05f79..9df5b08 100755
--- a/bin/subscribe.php
+++ b/bin/subscribe.php
@@ -45,7 +45,7 @@ if ($topic != $url) {
$sub = $subDb->get($topic);
if ($sub === false) {
- $subDb->create($topic);
+ $subDb->create($topic, $hub);
} else {
Log::info(
'Topic exists already in subscription table with status '
@@ -53,6 +53,7 @@ if ($sub === false) {
);
Log::info('Renewing subscription...');
$subDb->renew($sub->sub_id);
+ $hub = $sub->sub_hub;
}
$sub = $subDb->get($topic);
diff --git a/data/schema.sql b/data/schema.sql
index 7f9312a..fe7850e 100644
--- a/data/schema.sql
+++ b/data/schema.sql
@@ -6,6 +6,7 @@ CREATE TABLE `subscriptions` (
`sub_expires` datetime NOT NULL,
`sub_secret` varchar(256) NOT NULL,
`sub_capkey` varchar(128) NOT NULL,
+ `sub_hub` varchar(4096) NOT NULL,
`sub_created` datetime NOT NULL,
`sub_updated` datetime NOT NULL,
`sub_pings` int NOT NULL,
diff --git a/src/phinde/Subscriptions.php b/src/phinde/Subscriptions.php
index e49e817..454d191 100644
--- a/src/phinde/Subscriptions.php
+++ b/src/phinde/Subscriptions.php
@@ -110,19 +110,20 @@ class Subscriptions
* - send subscription requests to the hub
*
* @param string $topic URL to subscribe to
+ * @param string $hub URL of the hub subscribing to
*
* @return void
*/
- public function create($topic)
+ public function create($topic, $hub)
{
$stmt = $this->db->prepare(
'INSERT INTO subscriptions'
. ' (sub_topic, sub_status, sub_lease_seconds, sub_expires'
- . ', sub_secret, sub_capkey, sub_created, sub_updated'
+ . ', sub_secret, sub_capkey, sub_hub, sub_created, sub_updated'
. ', sub_pings, sub_lastping, sub_statusmessage)'
. ' VALUES '
. ' (:topic, "subscribing", :lease_seconds, "0000-00-00 00:00:00"'
- . ', :secret, :capkey, NOW(), NOW()'
+ . ', :secret, :capkey, :hub, NOW(), NOW()'
. ', 0, "0000-00-00 00:00:00", "")'
);
$stmt->execute(
@@ -131,6 +132,7 @@ class Subscriptions
':lease_seconds' => 86400 * 30,
':secret' => bin2hex(openssl_random_pseudo_bytes(16)),
':capkey' => bin2hex(openssl_random_pseudo_bytes(16)),
+ ':hub' => $hub,
]
);
}
diff --git a/www/push-subscription.php b/www/push-subscription.php
index 6fc20f6..5216e6a 100644
--- a/www/push-subscription.php
+++ b/www/push-subscription.php
@@ -1,7 +1,7 @@
<?php
namespace phinde;
/**
- * Handles PuSH subscription responses
+ * Handles WebSub subscription responses
*/
header('HTTP/1.0 500 Internal Server Error');
require_once 'www-header.php';
@@ -122,4 +122,4 @@ function err($msg, $statusline)
echo $msg . "\n";
exit(1);
}
-?> \ No newline at end of file
+?>