stapibas
********
The standalone Pingback server, written in PHP.
+
+
+
+=================
+Pingback receiver
+=================
+stapibas receives pingbacks for your website and puts them into a database.
+
+
+Setup
+=====
+Let your website send out the following HTTP header::
+
+ X-Pingback: http://stapibas.example.org/xmlrpc.php
+
+That's all.
+
+
+===============
+Pingback sender
+===============
+stapibas is able to send pingbacks out to other websites at behalf of
+your website.
+
+It does this by watching your website's Atom feed.
+Whenever it changes, it fetches the articles that are new or got updated and
+sends out pingbacks to the remote websites.
+
+
+Setup
+=====
+Insert your feed URL in the ``feeds`` database table.
+
+Whenever you update your website, tell stapibas about it via a
+HTTP POST request::
+
+ $ curl -d url=http://example.org/feed/ http://stapibas.example.org/request-feed-update.php
PRIMARY KEY (`p_id`),
UNIQUE KEY `p_id` (`p_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+CREATE TABLE IF NOT EXISTS `feeds` (
+ `f_id` int(11) NOT NULL AUTO_INCREMENT,
+ `f_url` varchar(2048) NOT NULL,
+ `f_updated` datetime NOT NULL,
+ `f_needs_update` tinyint(4) NOT NULL,
+ PRIMARY KEY (`f_id`),
+ UNIQUE KEY `f_id` (`f_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
--- /dev/null
+<?php
+/**
+ * Request that a feed shall get updated, marks it as "requires update"
+ * in the database
+ *
+ * Has to be called via POST, url given in parameter "url".
+ */
+header('HTTP/1.0 500 Internal Server Error');
+header('Content-type: text/plain');
+
+require_once __DIR__ . '/../data/config.php';
+
+if (!isset($_POST['url'])) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "HTTP POST 'url' parameter missing\n";
+ exit(1);
+}
+$url = $_POST['url'];
+if ($url === '') {
+ header('HTTP/1.0 400 Bad Request');
+ echo "'url' parameter is empty\n";
+ exit(1);
+}
+if (filter_var($url, FILTER_VALIDATE_URL) === false) {
+ header('HTTP/1.0 400 Bad Request');
+ echo "Invalid URL given\n";
+ exit(1);
+}
+
+
+$db = new PDO($dbdsn, $dbuser, $dbpass);
+$res = $db->query(
+ 'SELECT f_id, f_needs_update FROM feeds WHERE f_url = ' . $db->quote($url)
+);
+$row = $res->fetch(PDO::FETCH_OBJ);
+if ($row === false) {
+ header('HTTP/1.0 404 Not Found');
+ echo "Feed URL could not be found in database\n";
+ exit(1);
+}
+if ($row->f_needs_update == 1) {
+ header('HTTP/1.0 200 OK');
+ echo "Already in the queue\n";
+ exit(0);
+}
+
+$db->exec(
+ 'UPDATE feeds SET f_needs_update = 1'
+ . ' WHERE f_id = ' . $db->quote($row->f_id)
+);
+
+header('HTTP/1.0 202 Accepted');
+echo "Feed has been put into the queue\n";
+exit(0);
+?>