From 973ef8c4f8c15848dfc135e11053e5eb6f5dcdb7 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Fri, 6 Mar 2020 18:33:42 +0100 Subject: [PATCH 1/1] Store the hub that was used for Websub subscription --- bin/subscribe.php | 3 ++- data/schema.sql | 1 + src/phinde/Subscriptions.php | 8 +++++--- www/push-subscription.php | 4 ++-- 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 @@ \ No newline at end of file +?> -- 2.30.2