aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-07-23 12:38:22 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-07-23 12:38:22 +0200
commit339e32424fa60fc0c99a4c10890abef139444f6d (patch)
tree6e293d2dec618b04cfd3fedca36484ac51eb455a /lib
parenteaccc1eba4bf7a00a6cce26de9e4da22067fe86b (diff)
Add a simple test to detect if server is public
If the server is not accessible by an external server, pubsubhubbub should be disable. See https://github.com/FreshRSS/FreshRSS/issues/865
Diffstat (limited to 'lib')
-rw-r--r--lib/lib_rss.php27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index c99e2c7e8..2a23fca45 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -83,6 +83,33 @@ function checkUrl($url) {
}
}
+
+/**
+ * Test if a given server address is publicly accessible.
+ *
+ * Note: for the moment it tests only if address is corresponding to a
+ * localhost address.
+ *
+ * @param $address the address to test, can be an IP or a URL.
+ * @return true if server is accessible, false else.
+ * @todo improve test with a more valid technique (e.g. test with an external server?)
+ */
+function server_is_public($address) {
+ $host = parse_url($address, PHP_URL_HOST);
+
+ $is_public = !in_array($host, array(
+ '127.0.0.1',
+ 'localhost',
+ 'localhost.localdomain',
+ '[::1]',
+ 'localhost6',
+ 'localhost6.localdomain6',
+ ));
+
+ return $is_public;
+}
+
+
function format_number($n, $precision = 0) {
// number_format does not seem to be Unicode-compatible
return str_replace(' ', ' ', //Espace fine insécable