Esempio n. 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;
}
Esempio n. 2
0
 /**
  * the constructor
  *
  * @param array $options
  * @return boolean
  * @since 0.5.2
  */
 public function __construct($options = false)
 {
     $this->slast = $this->_sbase + $this->_lcount * $this->_vcount * $this->_tcount;
     // If parameters are given, pass these to the respective method
     if (is_array($options)) {
         $this->set_parameter($options);
     }
     // populate mbstring overloading cache if not set
     if (self::$_mb_string_overload === null) {
         self::$_mb_string_overload = extension_loaded('mbstring') && (ini_get('mbstring.func_overload') & 0x2) === 0x2;
     }
 }