/**
 * \brief validation function check_fossology_url().
 * check if the url is valid,
 *
 * \param $url - the url which will be checked 
 *
 * \return  1: valid, 0: invalid
 */
function check_fossology_url($url)
{
    $url_array = explode("/", $url, 2);
    $name = $url_array[0];
    if (!empty($name)) {
        $hostname = exec("hostname -f");
        if (empty($hostname)) {
            $hostname = "localhost";
        }
        if (check_IP($name)) {
            $hostname1 = gethostbyaddr($name);
            if (strcmp($hostname, $hostname1) == 0) {
                return 0;
            }
            // host is not reachable
        }
        $server_name = $_SERVER['SERVER_NAME'];
        /* intput $name must match either the hostname or the server name */
        if (strcmp($name, $hostname) && strcmp($name, $server_name)) {
            return 0;
        }
    } else {
        return 0;
    }
    return 1;
}
 /**
  * \brief clean the env
  */
 public function test_check_IP()
 {
     foreach (array('' => false, '1.2.3.4' => true, '1.7.49.343' => false, '255.249.199.0' => true) as $ip => $correct) {
         $this->assertEquals(check_IP($ip), $correct, $message = "result for IP {$ip} is false");
         print '.';
     }
 }
/**
 * \brief validation function check_fossology_url().
 * check if the url is valid,
 *
 * \param $url - the url which will be checked 
 *
 * \return  1: valid, 0: invalid
 */
function check_fossology_url($url)
{
    $url_array = explode("/", $url, 2);
    $name = $url_array[0];
    if (!empty($name)) {
        $hostname = exec("hostname -f");
        if (empty($hostname)) {
            $hostname = "localhost";
        }
        $res = check_IP($name);
        if ($res) {
            $hostname1 = gethostbyaddr($name);
        }
        $server_name = $_SERVER['SERVER_NAME'];
        if (strcmp($name, $hostname) && strcmp($hostname, $hostname1) && strcmp($name, $server_name)) {
            return 0;
        }
    } else {
        return 0;
    }
    return 1;
}