This standalone software is meant to provide a global public directory of Friendica profiles across nodes.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
friendica-directory/src/classes/Utils/Network.php

52 lines
1.1 KiB

<?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;
}
}