예제 #1
0
function checkDomainisValid($sld, $tld)
{
    global $CONFIG;
    if ($sld[0] == "-" || $sld[strlen($sld) - 1] == "-") {
        return 0;
    }
    $isidn = $isidntld = false;
    if ($CONFIG['AllowIDNDomains']) {
        if (!class_exists("idnhandler")) {
            require ROOTDIR . "/whoisfunctions.php";
        }
        $idnconv = new idnhandler();
        $idnconv->encode($sld);
        if ($idnconv->get_last_error() && $idnconv->get_last_error() != "The given string does not contain encodable chars") {
            return 0;
        }
        if ($idnconv->get_last_error() && $idnconv->get_last_error() == "The given string does not contain encodable chars") {
            $CONFIG['AllowIDNDomains'] = "";
        } else {
            $isidn = true;
        }
    }
    if ($isidn === FALSE) {
        if (preg_replace('/[^.%$^\'#~@&*(),_£?!+=:{}[]()|\\/ \\ ]/', '', $sld)) {
            return 0;
        }
        if (!$CONFIG['AllowIDNDomains'] && preg_replace("/[^a-z0-9-.]/i", "", $sld . $tld) != $sld . $tld) {
            return 0;
        }
        if (preg_replace("/[^a-z0-9-.]/", "", $tld) != $tld) {
            return 0;
        }
        $validmask = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
        if (strspn($sld, $validmask) != strlen($sld)) {
            return 0;
        }
    }
    run_hook("DomainValidation", array("sld" => $sld, "tld" => $tld));
    if ($sld === false && $sld !== 0 || !$tld) {
        return 0;
    }
    $coretlds = array(".com", ".net", ".org", ".info", "biz", ".mobi", ".name", ".asia", ".tel", ".in", ".mn", ".bz", ".cc", ".tv", ".us", ".me", ".co.uk", ".me.uk", ".org.uk", ".net.uk", ".ch", ".li", ".de", ".jp");
    $DomainMinLengthRestrictions = $DomainMaxLengthRestrictions = array();
    require ROOTDIR . "/configuration.php";
    foreach ($coretlds as $ctld) {
        if (!array_key_exists($ctld, $DomainMinLengthRestrictions)) {
            $DomainMinLengthRestrictions[$ctld] = 3;
        }
        if (!array_key_exists($ctld, $DomainMaxLengthRestrictions)) {
            $DomainMaxLengthRestrictions[$ctld] = 63;
            continue;
        }
    }
    if (array_key_exists($tld, $DomainMinLengthRestrictions) && strlen($sld) < $DomainMinLengthRestrictions[$tld]) {
        return 0;
    }
    if (array_key_exists($tld, $DomainMaxLengthRestrictions) && $DomainMaxLengthRestrictions[$tld] < strlen($sld)) {
        return 0;
    }
    return 1;
}