aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/config.php.dist10
-rw-r--r--src/phinde/Subscriptions.php12
-rw-r--r--www/push-subscription.php104
3 files changed, 125 insertions, 1 deletions
diff --git a/data/config.php.dist b/data/config.php.dist
index 4c6a14f..7eb8ccf 100644
--- a/data/config.php.dist
+++ b/data/config.php.dist
@@ -4,6 +4,14 @@ $GLOBALS['phinde'] = array(
'domains' => array(
'www.example.org',
'test.example.org'
- )
+ ),
+ //list of URL beginnings that should be ignored
+ 'blacklist' => array(
+ 'http://bad.example.org/'
+ ),
+ //list of URLs that should be subscribed to with PubSubHubbub
+ 'subscriptions' => array(
+ 'http://www.example.org/feed',
+ ),
);
?> \ No newline at end of file
diff --git a/src/phinde/Subscriptions.php b/src/phinde/Subscriptions.php
new file mode 100644
index 0000000..9db4b16
--- /dev/null
+++ b/src/phinde/Subscriptions.php
@@ -0,0 +1,12 @@
+<?php
+namespace phinde;
+
+class Subscriptions
+{
+ public function get($url)
+ {
+ //FIXME
+ return false;
+ }
+}
+?>
diff --git a/www/push-subscription.php b/www/push-subscription.php
new file mode 100644
index 0000000..014f15d
--- /dev/null
+++ b/www/push-subscription.php
@@ -0,0 +1,104 @@
+<?php
+namespace phinde;
+/**
+ * Handles PuSH subscription responses
+ */
+header('HTTP/1.0 500 Internal Server Error');
+require 'www-header.php';
+
+//PHP converts dots to underscore, so hub.mode becomes hub_mode
+if (!isset($_GET['hub_mode'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Parameter missing: hub.mode\n";
+ exit(1);
+}
+$hubMode = $_GET['hub_mode'];
+
+if (!isset($_GET['hub_topic'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Parameter missing: hub.topic\n";
+ exit(1);
+}
+if (!isValidUrl($_GET['hub_topic'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Invalid parameter value for hub.topic: Invalid URL\n";
+ exit(1);
+}
+$hubTopic = $_GET['hub_topic'];
+
+$subDb = new Subscriptions();
+
+if ($hubMode == 'denied') {
+ //TODO: Inspect Location header to retry subscription
+ //TODO: remove subscription
+ return;
+} else if ($hubMode == 'subscribe') {
+ //FIXME
+ $pos = array_search($hubTopic, $GLOBALS['phinde']['subscriptions']);
+ if ($pos === false) {
+ //we do not want to subscribe
+ header('HTTP/1.0 404 Not Found');
+ echo "We are not interested in this hub.topic\n";
+ exit(1);
+ }
+ if (!isset($_GET['hub_challenge'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Parameter missing: hub.challenge\n";
+ exit(1);
+ }
+ $hubChallenge = $_GET['hub_challenge'];
+
+ if (!isset($_GET['hub_lease_seconds'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Parameter missing: hub.lease_seconds\n";
+ exit(1);
+ }
+ $hubLeaseSeconds = $_GET['hub_lease_seconds'];
+
+ //FIXME: store in database
+
+ header('HTTP/1.0 200 OK');
+ header('Content-type: text/plain');
+ echo $hubChallenge;
+ exit(0);
+
+} else if ($hubMode == 'unsubscribe') {
+ $sub = $subDb->get($hubTopic);
+ if ($sub === false) {
+ //we do not know this subscription
+ header('HTTP/1.0 404 Not Found');
+ echo "We are not subscribed to this hub.topic\n";
+ exit(1);
+ }
+ $pos = array_search($hubTopic, $GLOBALS['phinde']['subscriptions']);
+ if ($pos !== false) {
+ //we do not want to unsubscribe
+ header('HTTP/1.0 404 Not Found');
+ echo "We do not want to unsubscribe from this hub.topic\n";
+ exit(1);
+ }
+ $sub->remove($hubTopic);
+ header('HTTP/1.0 200 OK');
+ header('Content-type: text/plain');
+ echo "Unsubscribed.\n";
+ exit(0);
+} else {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Invalid parameter value for hub.mode\n";
+ exit(1);
+}
+
+
+function isValidUrl($url)
+{
+ if (filter_var($url, FILTER_VALIDATE_URL) === false) {
+ return false;
+ }
+ if (substr($url, 0, 7) == 'http://'
+ || substr($url, 0, 8) == 'https://'
+ ) {
+ return true;
+ }
+ return false;
+}
+?> \ No newline at end of file