mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-05-24 16:25:00 -04:00
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
This commit is contained in:
@@ -229,6 +229,7 @@ function saveStep3() {
|
||||
'prefix' => $_SESSION['bd_prefix'],
|
||||
'pdo_options' => array(),
|
||||
),
|
||||
'enable_pubsubhubbub' => server_is_public($base_url),
|
||||
);
|
||||
|
||||
@unlink(join_path(DATA_PATH, 'config.php')); //To avoid access-rights problems
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user