Hypolite Petovan
0ee5bf55b1
- Add http dependency with custom User Agent - Simplify profile poll to remove the second profile call to check availability - Remove obsolete Network::fetchURL and Network::testURL
53 lines
1.1 KiB
PHP
53 lines
1.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* To change this license header, choose License Headers in Project Properties.
|
|
* To change this template file, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
namespace Friendica\Directory\Utils;
|
|
|
|
/**
|
|
* Description of Network
|
|
*
|
|
* @author Hypolite Petovan <hypolite@mrpetovan.com>
|
|
*/
|
|
class Network
|
|
{
|
|
/**
|
|
* Check if a hostname is public and non-reserved
|
|
*
|
|
* @param string $host
|
|
* @return bool
|
|
*/
|
|
public static function isPublicHost(string $host): bool
|
|
{
|
|
if (!$host) {
|
|
return false;
|
|
}
|
|
|
|
if ($host === 'localhost') {
|
|
return false;
|
|
}
|
|
|
|
// RFC 2606
|
|
if ($host === 'example.com' || $host === 'example.net' || $host === 'example.org') {
|
|
return false;
|
|
}
|
|
|
|
// RFC 2606 -continued
|
|
$tld = substr($host, strrpos($host, '.'));
|
|
if ($tld === '.test' || $tld === '.example' || $tld === '.invalid' || $tld === '.localhost') {
|
|
return false;
|
|
}
|
|
|
|
// Private/Reserved IP ranges
|
|
if (filter_var($host, FILTER_VALIDATE_IP) && !filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|