From f1d0e15e87c0e2c1f0d73f4a4b12780e974932f0 Mon Sep 17 00:00:00 2001 From: Christian Weiske Date: Sun, 18 Nov 2012 22:56:38 +0100 Subject: [PATCH] first simple code --- .gitignore | 1 + README.rst | 4 +++ data/config.php.dist | 5 +++ data/tables.sql | 11 +++++++ www/robots.txt | 2 ++ www/xmlrpc.php | 76 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 .gitignore create mode 100644 README.rst create mode 100644 data/config.php.dist create mode 100644 data/tables.sql create mode 100644 www/robots.txt create mode 100644 www/xmlrpc.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ce138d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +data/config.php diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..9fff7c4 --- /dev/null +++ b/README.rst @@ -0,0 +1,4 @@ +******** +stapibas +******** +The standalone Pingback server, written in PHP. diff --git a/data/config.php.dist b/data/config.php.dist new file mode 100644 index 0000000..4b9a97c --- /dev/null +++ b/data/config.php.dist @@ -0,0 +1,5 @@ + diff --git a/data/tables.sql b/data/tables.sql new file mode 100644 index 0000000..a8bdda4 --- /dev/null +++ b/data/tables.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS `pingbacks` ( + `p_id` int(11) NOT NULL AUTO_INCREMENT, + `p_source` varchar(1024) NOT NULL, + `p_target` varchar(1024) NOT NULL, + `p_time` datetime NOT NULL, + `p_client_ip` varchar(40) NOT NULL, + `p_client_agent` varchar(128) NOT NULL, + `p_client_referer` varchar(1024) NOT NULL, + PRIMARY KEY (`p_id`), + UNIQUE KEY `p_id` (`p_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/www/robots.txt b/www/robots.txt new file mode 100644 index 0000000..1254dbf --- /dev/null +++ b/www/robots.txt @@ -0,0 +1,2 @@ +User-Agent: * +Disallow / diff --git a/www/xmlrpc.php b/www/xmlrpc.php new file mode 100644 index 0000000..baaceea --- /dev/null +++ b/www/xmlrpc.php @@ -0,0 +1,76 @@ +db = $db; + } + + public function storePingback( + $target, $source, $sourceBody, \HTTP_Request2_Response $res + ) { + $stmt = $this->db->prepare( + 'INSERT INTO pingbacks' + . ' (p_source, p_target, p_time, p_client_ip, p_client_agent, p_client_referer)' + . ' VALUES(:source, :target, NOW(), :ip, :agent, :referer)' + ); + $stmt->execute( + array( + ':source' => $source, + ':target' => $target, + ':ip' => isset($_SERVER['REMOTE_ADDR']) + ? $_SERVER['REMOTE_ADDR'] : '', + ':agent' => isset($_SERVER['HTTP_USER_AGENT']) + ? $_SERVER['HTTP_USER_AGENT'] : '', + ':referer' => isset($_SERVER['HTTP_REFERER']) + ? $_SERVER['HTTP_REFERER'] : '', + ) + ); + } + /** + * Verifies that a link from $source to $target exists. + * + * @param string $target Target URI that should be linked in $source + * @param string $source Pingback source URI that should link to target + * @param string $sourceBody Content of $source URI + * @param object $res HTTP response from fetching $source + * + * @return boolean True if $source links to $target + * + * @throws Exception When something fatally fails + */ + public function verifyLinkExists( + $target, $source, $sourceBody, \HTTP_Request2_Response $res + ) { + return false; + } +} + +$s = new \PEAR2\Services\Pingback2\Server(); +$s->addCallback(new PingbackStorage($db)); +$s->run(); +?> -- 2.30.2