Hostname.php 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Validate
  17. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /**
  22. * @see Zend_Validate_Abstract
  23. */
  24. #require_once 'Zend/Validate/Abstract.php';
  25. /**
  26. * @see Zend_Validate_Ip
  27. */
  28. #require_once 'Zend/Validate/Ip.php';
  29. /**
  30. * Please note there are two standalone test scripts for testing IDN characters due to problems
  31. * with file encoding.
  32. *
  33. * The first is tests/Zend/Validate/HostnameTestStandalone.php which is designed to be run on
  34. * the command line.
  35. *
  36. * The second is tests/Zend/Validate/HostnameTestForm.php which is designed to be run via HTML
  37. * to allow users to test entering UTF-8 characters in a form.
  38. *
  39. * @category Zend
  40. * @package Zend_Validate
  41. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. */
  44. class Zend_Validate_Hostname extends Zend_Validate_Abstract
  45. {
  46. const CANNOT_DECODE_PUNYCODE = 'hostnameCannotDecodePunycode';
  47. const INVALID = 'hostnameInvalid';
  48. const INVALID_DASH = 'hostnameDashCharacter';
  49. const INVALID_HOSTNAME = 'hostnameInvalidHostname';
  50. const INVALID_HOSTNAME_SCHEMA = 'hostnameInvalidHostnameSchema';
  51. const INVALID_LOCAL_NAME = 'hostnameInvalidLocalName';
  52. const INVALID_URI = 'hostnameInvalidUri';
  53. const IP_ADDRESS_NOT_ALLOWED = 'hostnameIpAddressNotAllowed';
  54. const LOCAL_NAME_NOT_ALLOWED = 'hostnameLocalNameNotAllowed';
  55. const UNDECIPHERABLE_TLD = 'hostnameUndecipherableTld';
  56. const UNKNOWN_TLD = 'hostnameUnknownTld';
  57. /**
  58. * @var array
  59. */
  60. protected $_messageTemplates = array(
  61. self::CANNOT_DECODE_PUNYCODE => "'%value%' appears to be a DNS hostname but the given punycode notation cannot be decoded",
  62. self::INVALID => "Invalid type given. String expected",
  63. self::INVALID_DASH => "'%value%' appears to be a DNS hostname but contains a dash in an invalid position",
  64. self::INVALID_HOSTNAME => "'%value%' does not match the expected structure for a DNS hostname",
  65. self::INVALID_HOSTNAME_SCHEMA => "'%value%' appears to be a DNS hostname but cannot match against hostname schema for TLD '%tld%'",
  66. self::INVALID_LOCAL_NAME => "'%value%' does not appear to be a valid local network name",
  67. self::INVALID_URI => "'%value%' does not appear to be a valid URI hostname",
  68. self::IP_ADDRESS_NOT_ALLOWED => "'%value%' appears to be an IP address, but IP addresses are not allowed",
  69. self::LOCAL_NAME_NOT_ALLOWED => "'%value%' appears to be a local network name but local network names are not allowed",
  70. self::UNDECIPHERABLE_TLD => "'%value%' appears to be a DNS hostname but cannot extract TLD part",
  71. self::UNKNOWN_TLD => "'%value%' appears to be a DNS hostname but cannot match TLD against known list",
  72. );
  73. /**
  74. * @var array
  75. */
  76. protected $_messageVariables = array(
  77. 'tld' => '_tld'
  78. );
  79. /**
  80. * Allows Internet domain names (e.g., example.com)
  81. */
  82. const ALLOW_DNS = 1;
  83. /**
  84. * Allows IP addresses
  85. */
  86. const ALLOW_IP = 2;
  87. /**
  88. * Allows local network names (e.g., localhost, www.localdomain)
  89. */
  90. const ALLOW_LOCAL = 4;
  91. /**
  92. * Allows all types of hostnames
  93. */
  94. const ALLOW_URI = 8;
  95. /**
  96. * Allows all types of hostnames
  97. */
  98. const ALLOW_ALL = 15;
  99. /**
  100. * Array of valid top-level-domains
  101. *
  102. * Version 2015091800, Last Updated Fri Sep 18 07:07:01 2015 UTC
  103. *
  104. * @see http://data.iana.org/TLD/tlds-alpha-by-domain.txt List of all TLDs by domain
  105. * @see http://www.iana.org/domains/root/db/ Official list of supported TLDs
  106. * @var array
  107. */
  108. protected $_validTlds = array(
  109. 'aaa',
  110. 'abb',
  111. 'abbott',
  112. 'abogado',
  113. 'ac',
  114. 'academy',
  115. 'accenture',
  116. 'accountant',
  117. 'accountants',
  118. 'aco',
  119. 'active',
  120. 'actor',
  121. 'ad',
  122. 'ads',
  123. 'adult',
  124. 'ae',
  125. 'aeg',
  126. 'aero',
  127. 'af',
  128. 'afl',
  129. 'ag',
  130. 'agency',
  131. 'ai',
  132. 'aig',
  133. 'airforce',
  134. 'airtel',
  135. 'al',
  136. 'allfinanz',
  137. 'alsace',
  138. 'am',
  139. 'amica',
  140. 'amsterdam',
  141. 'android',
  142. 'ao',
  143. 'apartments',
  144. 'app',
  145. 'aq',
  146. 'aquarelle',
  147. 'ar',
  148. 'aramco',
  149. 'archi',
  150. 'army',
  151. 'arpa',
  152. 'arte',
  153. 'as',
  154. 'asia',
  155. 'associates',
  156. 'at',
  157. 'attorney',
  158. 'au',
  159. 'auction',
  160. 'audio',
  161. 'auto',
  162. 'autos',
  163. 'aw',
  164. 'ax',
  165. 'axa',
  166. 'az',
  167. 'azure',
  168. 'ba',
  169. 'band',
  170. 'bank',
  171. 'bar',
  172. 'barcelona',
  173. 'barclaycard',
  174. 'barclays',
  175. 'bargains',
  176. 'bauhaus',
  177. 'bayern',
  178. 'bb',
  179. 'bbc',
  180. 'bbva',
  181. 'bcn',
  182. 'bd',
  183. 'be',
  184. 'beer',
  185. 'bentley',
  186. 'berlin',
  187. 'best',
  188. 'bet',
  189. 'bf',
  190. 'bg',
  191. 'bh',
  192. 'bharti',
  193. 'bi',
  194. 'bible',
  195. 'bid',
  196. 'bike',
  197. 'bing',
  198. 'bingo',
  199. 'bio',
  200. 'biz',
  201. 'bj',
  202. 'black',
  203. 'blackfriday',
  204. 'bloomberg',
  205. 'blue',
  206. 'bm',
  207. 'bms',
  208. 'bmw',
  209. 'bn',
  210. 'bnl',
  211. 'bnpparibas',
  212. 'bo',
  213. 'boats',
  214. 'bom',
  215. 'bond',
  216. 'boo',
  217. 'boots',
  218. 'boutique',
  219. 'br',
  220. 'bradesco',
  221. 'bridgestone',
  222. 'broker',
  223. 'brother',
  224. 'brussels',
  225. 'bs',
  226. 'bt',
  227. 'budapest',
  228. 'build',
  229. 'builders',
  230. 'business',
  231. 'buzz',
  232. 'bv',
  233. 'bw',
  234. 'by',
  235. 'bz',
  236. 'bzh',
  237. 'ca',
  238. 'cab',
  239. 'cafe',
  240. 'cal',
  241. 'camera',
  242. 'camp',
  243. 'cancerresearch',
  244. 'canon',
  245. 'capetown',
  246. 'capital',
  247. 'car',
  248. 'caravan',
  249. 'cards',
  250. 'care',
  251. 'career',
  252. 'careers',
  253. 'cars',
  254. 'cartier',
  255. 'casa',
  256. 'cash',
  257. 'casino',
  258. 'cat',
  259. 'catering',
  260. 'cba',
  261. 'cbn',
  262. 'cc',
  263. 'cd',
  264. 'ceb',
  265. 'center',
  266. 'ceo',
  267. 'cern',
  268. 'cf',
  269. 'cfa',
  270. 'cfd',
  271. 'cg',
  272. 'ch',
  273. 'chanel',
  274. 'channel',
  275. 'chat',
  276. 'cheap',
  277. 'chloe',
  278. 'christmas',
  279. 'chrome',
  280. 'church',
  281. 'ci',
  282. 'cipriani',
  283. 'cisco',
  284. 'citic',
  285. 'city',
  286. 'ck',
  287. 'cl',
  288. 'claims',
  289. 'cleaning',
  290. 'click',
  291. 'clinic',
  292. 'clothing',
  293. 'cloud',
  294. 'club',
  295. 'clubmed',
  296. 'cm',
  297. 'cn',
  298. 'co',
  299. 'coach',
  300. 'codes',
  301. 'coffee',
  302. 'college',
  303. 'cologne',
  304. 'com',
  305. 'commbank',
  306. 'community',
  307. 'company',
  308. 'computer',
  309. 'condos',
  310. 'construction',
  311. 'consulting',
  312. 'contractors',
  313. 'cooking',
  314. 'cool',
  315. 'coop',
  316. 'corsica',
  317. 'country',
  318. 'coupons',
  319. 'courses',
  320. 'cr',
  321. 'credit',
  322. 'creditcard',
  323. 'cricket',
  324. 'crown',
  325. 'crs',
  326. 'cruises',
  327. 'csc',
  328. 'cu',
  329. 'cuisinella',
  330. 'cv',
  331. 'cw',
  332. 'cx',
  333. 'cy',
  334. 'cymru',
  335. 'cyou',
  336. 'cz',
  337. 'dabur',
  338. 'dad',
  339. 'dance',
  340. 'date',
  341. 'dating',
  342. 'datsun',
  343. 'day',
  344. 'dclk',
  345. 'de',
  346. 'deals',
  347. 'degree',
  348. 'delivery',
  349. 'dell',
  350. 'delta',
  351. 'democrat',
  352. 'dental',
  353. 'dentist',
  354. 'desi',
  355. 'design',
  356. 'dev',
  357. 'diamonds',
  358. 'diet',
  359. 'digital',
  360. 'direct',
  361. 'directory',
  362. 'discount',
  363. 'dj',
  364. 'dk',
  365. 'dm',
  366. 'dnp',
  367. 'do',
  368. 'docs',
  369. 'dog',
  370. 'doha',
  371. 'domains',
  372. 'doosan',
  373. 'download',
  374. 'drive',
  375. 'durban',
  376. 'dvag',
  377. 'dz',
  378. 'earth',
  379. 'eat',
  380. 'ec',
  381. 'edu',
  382. 'education',
  383. 'ee',
  384. 'eg',
  385. 'email',
  386. 'emerck',
  387. 'energy',
  388. 'engineer',
  389. 'engineering',
  390. 'enterprises',
  391. 'epson',
  392. 'equipment',
  393. 'er',
  394. 'erni',
  395. 'es',
  396. 'esq',
  397. 'estate',
  398. 'et',
  399. 'eu',
  400. 'eurovision',
  401. 'eus',
  402. 'events',
  403. 'everbank',
  404. 'exchange',
  405. 'expert',
  406. 'exposed',
  407. 'express',
  408. 'fage',
  409. 'fail',
  410. 'faith',
  411. 'family',
  412. 'fan',
  413. 'fans',
  414. 'farm',
  415. 'fashion',
  416. 'feedback',
  417. 'fi',
  418. 'film',
  419. 'final',
  420. 'finance',
  421. 'financial',
  422. 'firmdale',
  423. 'fish',
  424. 'fishing',
  425. 'fit',
  426. 'fitness',
  427. 'fj',
  428. 'fk',
  429. 'flights',
  430. 'florist',
  431. 'flowers',
  432. 'flsmidth',
  433. 'fly',
  434. 'fm',
  435. 'fo',
  436. 'foo',
  437. 'football',
  438. 'forex',
  439. 'forsale',
  440. 'forum',
  441. 'foundation',
  442. 'fr',
  443. 'frl',
  444. 'frogans',
  445. 'fund',
  446. 'furniture',
  447. 'futbol',
  448. 'fyi',
  449. 'ga',
  450. 'gal',
  451. 'gallery',
  452. 'game',
  453. 'garden',
  454. 'gb',
  455. 'gbiz',
  456. 'gd',
  457. 'gdn',
  458. 'ge',
  459. 'gea',
  460. 'gent',
  461. 'genting',
  462. 'gf',
  463. 'gg',
  464. 'ggee',
  465. 'gh',
  466. 'gi',
  467. 'gift',
  468. 'gifts',
  469. 'gives',
  470. 'giving',
  471. 'gl',
  472. 'glass',
  473. 'gle',
  474. 'global',
  475. 'globo',
  476. 'gm',
  477. 'gmail',
  478. 'gmo',
  479. 'gmx',
  480. 'gn',
  481. 'gold',
  482. 'goldpoint',
  483. 'golf',
  484. 'goo',
  485. 'goog',
  486. 'google',
  487. 'gop',
  488. 'gov',
  489. 'gp',
  490. 'gq',
  491. 'gr',
  492. 'graphics',
  493. 'gratis',
  494. 'green',
  495. 'gripe',
  496. 'group',
  497. 'gs',
  498. 'gt',
  499. 'gu',
  500. 'gucci',
  501. 'guge',
  502. 'guide',
  503. 'guitars',
  504. 'guru',
  505. 'gw',
  506. 'gy',
  507. 'hamburg',
  508. 'hangout',
  509. 'haus',
  510. 'healthcare',
  511. 'help',
  512. 'here',
  513. 'hermes',
  514. 'hiphop',
  515. 'hitachi',
  516. 'hiv',
  517. 'hk',
  518. 'hm',
  519. 'hn',
  520. 'hockey',
  521. 'holdings',
  522. 'holiday',
  523. 'homedepot',
  524. 'homes',
  525. 'honda',
  526. 'horse',
  527. 'host',
  528. 'hosting',
  529. 'hoteles',
  530. 'hotmail',
  531. 'house',
  532. 'how',
  533. 'hr',
  534. 'hsbc',
  535. 'ht',
  536. 'hu',
  537. 'hyundai',
  538. 'ibm',
  539. 'icbc',
  540. 'ice',
  541. 'icu',
  542. 'id',
  543. 'ie',
  544. 'ifm',
  545. 'iinet',
  546. 'il',
  547. 'im',
  548. 'immo',
  549. 'immobilien',
  550. 'in',
  551. 'industries',
  552. 'infiniti',
  553. 'info',
  554. 'ing',
  555. 'ink',
  556. 'institute',
  557. 'insure',
  558. 'int',
  559. 'international',
  560. 'investments',
  561. 'io',
  562. 'ipiranga',
  563. 'iq',
  564. 'ir',
  565. 'irish',
  566. 'is',
  567. 'ist',
  568. 'istanbul',
  569. 'it',
  570. 'itau',
  571. 'iwc',
  572. 'jaguar',
  573. 'java',
  574. 'jcb',
  575. 'je',
  576. 'jetzt',
  577. 'jewelry',
  578. 'jlc',
  579. 'jll',
  580. 'jm',
  581. 'jo',
  582. 'jobs',
  583. 'joburg',
  584. 'jp',
  585. 'jprs',
  586. 'juegos',
  587. 'kaufen',
  588. 'kddi',
  589. 'ke',
  590. 'kg',
  591. 'kh',
  592. 'ki',
  593. 'kia',
  594. 'kim',
  595. 'kinder',
  596. 'kitchen',
  597. 'kiwi',
  598. 'km',
  599. 'kn',
  600. 'koeln',
  601. 'komatsu',
  602. 'kp',
  603. 'kr',
  604. 'krd',
  605. 'kred',
  606. 'kw',
  607. 'ky',
  608. 'kyoto',
  609. 'kz',
  610. 'la',
  611. 'lacaixa',
  612. 'lancaster',
  613. 'land',
  614. 'landrover',
  615. 'lasalle',
  616. 'lat',
  617. 'latrobe',
  618. 'law',
  619. 'lawyer',
  620. 'lb',
  621. 'lc',
  622. 'lds',
  623. 'lease',
  624. 'leclerc',
  625. 'legal',
  626. 'lexus',
  627. 'lgbt',
  628. 'li',
  629. 'liaison',
  630. 'lidl',
  631. 'life',
  632. 'lighting',
  633. 'limited',
  634. 'limo',
  635. 'linde',
  636. 'link',
  637. 'live',
  638. 'lixil',
  639. 'lk',
  640. 'loan',
  641. 'loans',
  642. 'lol',
  643. 'london',
  644. 'lotte',
  645. 'lotto',
  646. 'love',
  647. 'lr',
  648. 'ls',
  649. 'lt',
  650. 'ltd',
  651. 'ltda',
  652. 'lu',
  653. 'lupin',
  654. 'luxe',
  655. 'luxury',
  656. 'lv',
  657. 'ly',
  658. 'ma',
  659. 'madrid',
  660. 'maif',
  661. 'maison',
  662. 'man',
  663. 'management',
  664. 'mango',
  665. 'market',
  666. 'marketing',
  667. 'markets',
  668. 'marriott',
  669. 'mba',
  670. 'mc',
  671. 'md',
  672. 'me',
  673. 'media',
  674. 'meet',
  675. 'melbourne',
  676. 'meme',
  677. 'memorial',
  678. 'men',
  679. 'menu',
  680. 'mg',
  681. 'mh',
  682. 'miami',
  683. 'microsoft',
  684. 'mil',
  685. 'mini',
  686. 'mk',
  687. 'ml',
  688. 'mm',
  689. 'mma',
  690. 'mn',
  691. 'mo',
  692. 'mobi',
  693. 'moda',
  694. 'moe',
  695. 'moi',
  696. 'mom',
  697. 'monash',
  698. 'money',
  699. 'montblanc',
  700. 'mormon',
  701. 'mortgage',
  702. 'moscow',
  703. 'motorcycles',
  704. 'mov',
  705. 'movie',
  706. 'movistar',
  707. 'mp',
  708. 'mq',
  709. 'mr',
  710. 'ms',
  711. 'mt',
  712. 'mtn',
  713. 'mtpc',
  714. 'mtr',
  715. 'mu',
  716. 'museum',
  717. 'mutuelle',
  718. 'mv',
  719. 'mw',
  720. 'mx',
  721. 'my',
  722. 'mz',
  723. 'na',
  724. 'nadex',
  725. 'nagoya',
  726. 'name',
  727. 'navy',
  728. 'nc',
  729. 'ne',
  730. 'nec',
  731. 'net',
  732. 'netbank',
  733. 'network',
  734. 'neustar',
  735. 'new',
  736. 'news',
  737. 'nexus',
  738. 'nf',
  739. 'ng',
  740. 'ngo',
  741. 'nhk',
  742. 'ni',
  743. 'nico',
  744. 'ninja',
  745. 'nissan',
  746. 'nl',
  747. 'no',
  748. 'nokia',
  749. 'np',
  750. 'nr',
  751. 'nra',
  752. 'nrw',
  753. 'ntt',
  754. 'nu',
  755. 'nyc',
  756. 'nz',
  757. 'obi',
  758. 'office',
  759. 'okinawa',
  760. 'om',
  761. 'omega',
  762. 'one',
  763. 'ong',
  764. 'onl',
  765. 'online',
  766. 'ooo',
  767. 'oracle',
  768. 'orange',
  769. 'org',
  770. 'organic',
  771. 'osaka',
  772. 'otsuka',
  773. 'ovh',
  774. 'pa',
  775. 'page',
  776. 'panerai',
  777. 'paris',
  778. 'partners',
  779. 'parts',
  780. 'party',
  781. 'pe',
  782. 'pet',
  783. 'pf',
  784. 'pg',
  785. 'ph',
  786. 'pharmacy',
  787. 'philips',
  788. 'photo',
  789. 'photography',
  790. 'photos',
  791. 'physio',
  792. 'piaget',
  793. 'pics',
  794. 'pictet',
  795. 'pictures',
  796. 'pink',
  797. 'pizza',
  798. 'pk',
  799. 'pl',
  800. 'place',
  801. 'play',
  802. 'plumbing',
  803. 'plus',
  804. 'pm',
  805. 'pn',
  806. 'pohl',
  807. 'poker',
  808. 'porn',
  809. 'post',
  810. 'pr',
  811. 'praxi',
  812. 'press',
  813. 'pro',
  814. 'prod',
  815. 'productions',
  816. 'prof',
  817. 'properties',
  818. 'property',
  819. 'protection',
  820. 'ps',
  821. 'pt',
  822. 'pub',
  823. 'pw',
  824. 'py',
  825. 'qa',
  826. 'qpon',
  827. 'quebec',
  828. 'racing',
  829. 're',
  830. 'realtor',
  831. 'realty',
  832. 'recipes',
  833. 'red',
  834. 'redstone',
  835. 'rehab',
  836. 'reise',
  837. 'reisen',
  838. 'reit',
  839. 'ren',
  840. 'rent',
  841. 'rentals',
  842. 'repair',
  843. 'report',
  844. 'republican',
  845. 'rest',
  846. 'restaurant',
  847. 'review',
  848. 'reviews',
  849. 'rich',
  850. 'ricoh',
  851. 'rio',
  852. 'rip',
  853. 'ro',
  854. 'rocks',
  855. 'rodeo',
  856. 'rs',
  857. 'rsvp',
  858. 'ru',
  859. 'ruhr',
  860. 'run',
  861. 'rw',
  862. 'rwe',
  863. 'ryukyu',
  864. 'sa',
  865. 'saarland',
  866. 'sakura',
  867. 'sale',
  868. 'samsung',
  869. 'sandvik',
  870. 'sandvikcoromant',
  871. 'sanofi',
  872. 'sap',
  873. 'sarl',
  874. 'saxo',
  875. 'sb',
  876. 'sc',
  877. 'sca',
  878. 'scb',
  879. 'schmidt',
  880. 'scholarships',
  881. 'school',
  882. 'schule',
  883. 'schwarz',
  884. 'science',
  885. 'scor',
  886. 'scot',
  887. 'sd',
  888. 'se',
  889. 'seat',
  890. 'security',
  891. 'seek',
  892. 'sener',
  893. 'services',
  894. 'seven',
  895. 'sew',
  896. 'sex',
  897. 'sexy',
  898. 'sg',
  899. 'sh',
  900. 'shiksha',
  901. 'shoes',
  902. 'show',
  903. 'shriram',
  904. 'si',
  905. 'singles',
  906. 'site',
  907. 'sj',
  908. 'sk',
  909. 'ski',
  910. 'sky',
  911. 'skype',
  912. 'sl',
  913. 'sm',
  914. 'sn',
  915. 'sncf',
  916. 'so',
  917. 'soccer',
  918. 'social',
  919. 'software',
  920. 'sohu',
  921. 'solar',
  922. 'solutions',
  923. 'sony',
  924. 'soy',
  925. 'space',
  926. 'spiegel',
  927. 'spreadbetting',
  928. 'sr',
  929. 'srl',
  930. 'st',
  931. 'stada',
  932. 'starhub',
  933. 'statoil',
  934. 'stc',
  935. 'stcgroup',
  936. 'stockholm',
  937. 'studio',
  938. 'study',
  939. 'style',
  940. 'su',
  941. 'sucks',
  942. 'supplies',
  943. 'supply',
  944. 'support',
  945. 'surf',
  946. 'surgery',
  947. 'suzuki',
  948. 'sv',
  949. 'swatch',
  950. 'swiss',
  951. 'sx',
  952. 'sy',
  953. 'sydney',
  954. 'systems',
  955. 'sz',
  956. 'taipei',
  957. 'tatamotors',
  958. 'tatar',
  959. 'tattoo',
  960. 'tax',
  961. 'taxi',
  962. 'tc',
  963. 'td',
  964. 'team',
  965. 'tech',
  966. 'technology',
  967. 'tel',
  968. 'telefonica',
  969. 'temasek',
  970. 'tennis',
  971. 'tf',
  972. 'tg',
  973. 'th',
  974. 'thd',
  975. 'theater',
  976. 'theatre',
  977. 'tickets',
  978. 'tienda',
  979. 'tips',
  980. 'tires',
  981. 'tirol',
  982. 'tj',
  983. 'tk',
  984. 'tl',
  985. 'tm',
  986. 'tn',
  987. 'to',
  988. 'today',
  989. 'tokyo',
  990. 'tools',
  991. 'top',
  992. 'toray',
  993. 'toshiba',
  994. 'tours',
  995. 'town',
  996. 'toyota',
  997. 'toys',
  998. 'tr',
  999. 'trade',
  1000. 'trading',
  1001. 'training',
  1002. 'travel',
  1003. 'trust',
  1004. 'tt',
  1005. 'tui',
  1006. 'tv',
  1007. 'tw',
  1008. 'tz',
  1009. 'ua',
  1010. 'ubs',
  1011. 'ug',
  1012. 'uk',
  1013. 'university',
  1014. 'uno',
  1015. 'uol',
  1016. 'us',
  1017. 'uy',
  1018. 'uz',
  1019. 'va',
  1020. 'vacations',
  1021. 'vc',
  1022. 've',
  1023. 'vegas',
  1024. 'ventures',
  1025. 'versicherung',
  1026. 'vet',
  1027. 'vg',
  1028. 'vi',
  1029. 'viajes',
  1030. 'video',
  1031. 'villas',
  1032. 'vin',
  1033. 'virgin',
  1034. 'vision',
  1035. 'vista',
  1036. 'vistaprint',
  1037. 'viva',
  1038. 'vlaanderen',
  1039. 'vn',
  1040. 'vodka',
  1041. 'vote',
  1042. 'voting',
  1043. 'voto',
  1044. 'voyage',
  1045. 'vu',
  1046. 'wales',
  1047. 'walter',
  1048. 'wang',
  1049. 'watch',
  1050. 'webcam',
  1051. 'website',
  1052. 'wed',
  1053. 'wedding',
  1054. 'weir',
  1055. 'wf',
  1056. 'whoswho',
  1057. 'wien',
  1058. 'wiki',
  1059. 'williamhill',
  1060. 'win',
  1061. 'windows',
  1062. 'wine',
  1063. 'wme',
  1064. 'work',
  1065. 'works',
  1066. 'world',
  1067. 'ws',
  1068. 'wtc',
  1069. 'wtf',
  1070. 'xbox',
  1071. 'xerox',
  1072. 'xin',
  1073. 'xn--11b4c3d',
  1074. 'xn--1qqw23a',
  1075. 'xn--30rr7y',
  1076. 'xn--3bst00m',
  1077. 'xn--3ds443g',
  1078. 'xn--3e0b707e',
  1079. 'xn--3pxu8k',
  1080. 'xn--42c2d9a',
  1081. 'xn--45brj9c',
  1082. 'xn--45q11c',
  1083. 'xn--4gbrim',
  1084. 'xn--55qw42g',
  1085. 'xn--55qx5d',
  1086. 'xn--6frz82g',
  1087. 'xn--6qq986b3xl',
  1088. 'xn--80adxhks',
  1089. 'xn--80ao21a',
  1090. 'xn--80asehdb',
  1091. 'xn--80aswg',
  1092. 'xn--90a3ac',
  1093. 'xn--90ais',
  1094. 'xn--9dbq2a',
  1095. 'xn--9et52u',
  1096. 'xn--b4w605ferd',
  1097. 'xn--c1avg',
  1098. 'xn--c2br7g',
  1099. 'xn--cg4bki',
  1100. 'xn--clchc0ea0b2g2a9gcd',
  1101. 'xn--czr694b',
  1102. 'xn--czrs0t',
  1103. 'xn--czru2d',
  1104. 'xn--d1acj3b',
  1105. 'xn--d1alf',
  1106. 'xn--efvy88h',
  1107. 'xn--estv75g',
  1108. 'xn--fhbei',
  1109. 'xn--fiq228c5hs',
  1110. 'xn--fiq64b',
  1111. 'xn--fiqs8s',
  1112. 'xn--fiqz9s',
  1113. 'xn--fjq720a',
  1114. 'xn--flw351e',
  1115. 'xn--fpcrj9c3d',
  1116. 'xn--fzc2c9e2c',
  1117. 'xn--gecrj9c',
  1118. 'xn--h2brj9c',
  1119. 'xn--hxt814e',
  1120. 'xn--i1b6b1a6a2e',
  1121. 'xn--imr513n',
  1122. 'xn--io0a7i',
  1123. 'xn--j1aef',
  1124. 'xn--j1amh',
  1125. 'xn--j6w193g',
  1126. 'xn--kcrx77d1x4a',
  1127. 'xn--kprw13d',
  1128. 'xn--kpry57d',
  1129. 'xn--kput3i',
  1130. 'xn--l1acc',
  1131. 'xn--lgbbat1ad8j',
  1132. 'xn--mgb9awbf',
  1133. 'xn--mgba3a3ejt',
  1134. 'xn--mgba3a4f16a',
  1135. 'xn--mgbaam7a8h',
  1136. 'xn--mgbab2bd',
  1137. 'xn--mgbayh7gpa',
  1138. 'xn--mgbbh1a71e',
  1139. 'xn--mgbc0a9azcg',
  1140. 'xn--mgberp4a5d4ar',
  1141. 'xn--mgbpl2fh',
  1142. 'xn--mgbx4cd0ab',
  1143. 'xn--mk1bu44c',
  1144. 'xn--mxtq1m',
  1145. 'xn--ngbc5azd',
  1146. 'xn--node',
  1147. 'xn--nqv7f',
  1148. 'xn--nqv7fs00ema',
  1149. 'xn--nyqy26a',
  1150. 'xn--o3cw4h',
  1151. 'xn--ogbpf8fl',
  1152. 'xn--p1acf',
  1153. 'xn--p1ai',
  1154. 'xn--pgbs0dh',
  1155. 'xn--pssy2u',
  1156. 'xn--q9jyb4c',
  1157. 'xn--qcka1pmc',
  1158. 'xn--rhqv96g',
  1159. 'xn--s9brj9c',
  1160. 'xn--ses554g',
  1161. 'xn--t60b56a',
  1162. 'xn--tckwe',
  1163. 'xn--unup4y',
  1164. 'xn--vermgensberater-ctb',
  1165. 'xn--vermgensberatung-pwb',
  1166. 'xn--vhquv',
  1167. 'xn--vuq861b',
  1168. 'xn--wgbh1c',
  1169. 'xn--wgbl6a',
  1170. 'xn--xhq521b',
  1171. 'xn--xkc2al3hye2a',
  1172. 'xn--xkc2dl3a5ee0h',
  1173. 'xn--y9a3aq',
  1174. 'xn--yfro4i67o',
  1175. 'xn--ygbi2ammx',
  1176. 'xn--zfr164b',
  1177. 'xperia',
  1178. 'xxx',
  1179. 'xyz',
  1180. 'yachts',
  1181. 'yamaxun',
  1182. 'yandex',
  1183. 'ye',
  1184. 'yodobashi',
  1185. 'yoga',
  1186. 'yokohama',
  1187. 'youtube',
  1188. 'yt',
  1189. 'za',
  1190. 'zara',
  1191. 'zip',
  1192. 'zm',
  1193. 'zone',
  1194. 'zuerich',
  1195. 'zw',
  1196. '测试',
  1197. 'परीक्षा',
  1198. '佛山',
  1199. '集团',
  1200. '在线',
  1201. '한국',
  1202. 'ভারত',
  1203. '八卦',
  1204. 'موقع',
  1205. 'বাংলা',
  1206. '公益',
  1207. '公司',
  1208. '移动',
  1209. '我爱你',
  1210. 'москва',
  1211. 'испытание',
  1212. 'қаз',
  1213. 'онлайн',
  1214. 'сайт',
  1215. 'срб',
  1216. 'бел',
  1217. '테스트',
  1218. 'орг',
  1219. '삼성',
  1220. 'சிங்கப்பூர்',
  1221. '商标',
  1222. '商城',
  1223. 'дети',
  1224. 'мкд',
  1225. 'טעסט',
  1226. '中文网',
  1227. '中信',
  1228. '中国',
  1229. '中國',
  1230. '谷歌',
  1231. 'భారత్',
  1232. 'ලංකා',
  1233. '測試',
  1234. 'ભારત',
  1235. 'भारत',
  1236. 'آزمایشی',
  1237. 'பரிட்சை',
  1238. 'संगठन',
  1239. '网络',
  1240. 'укр',
  1241. '香港',
  1242. 'δοκιμή',
  1243. 'إختبار',
  1244. '台湾',
  1245. '台灣',
  1246. '手机',
  1247. 'мон',
  1248. 'الجزائر',
  1249. 'عمان',
  1250. 'ایران',
  1251. 'امارات',
  1252. 'بازار',
  1253. 'پاکستان',
  1254. 'الاردن',
  1255. 'بھارت',
  1256. 'المغرب',
  1257. 'السعودية',
  1258. 'سودان',
  1259. 'عراق',
  1260. 'مليسيا',
  1261. 'شبكة',
  1262. 'გე',
  1263. '机构',
  1264. '组织机构',
  1265. 'ไทย',
  1266. 'سورية',
  1267. 'рус',
  1268. 'рф',
  1269. 'تونس',
  1270. 'みんな',
  1271. 'グーグル',
  1272. '世界',
  1273. 'ਭਾਰਤ',
  1274. '网址',
  1275. '游戏',
  1276. 'vermögensberater',
  1277. 'vermögensberatung',
  1278. '企业',
  1279. 'مصر',
  1280. 'قطر',
  1281. '广东',
  1282. 'இலங்கை',
  1283. 'இந்தியா',
  1284. 'հայ',
  1285. '新加坡',
  1286. 'فلسطين',
  1287. 'テスト',
  1288. '政务',
  1289. );
  1290. /**
  1291. * @var string
  1292. */
  1293. protected $_tld;
  1294. /**
  1295. * Array for valid Idns
  1296. * @see http://www.iana.org/domains/idn-tables/ Official list of supported IDN Chars
  1297. * (.AC) Ascension Island http://www.nic.ac/pdf/AC-IDN-Policy.pdf
  1298. * (.AR) Argentinia http://www.nic.ar/faqidn.html
  1299. * (.AS) American Samoa http://www.nic.as/idn/chars.cfm
  1300. * (.AT) Austria http://www.nic.at/en/service/technical_information/idn/charset_converter/
  1301. * (.BIZ) International http://www.iana.org/domains/idn-tables/
  1302. * (.BR) Brazil http://registro.br/faq/faq6.html
  1303. * (.BV) Bouvett Island http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html
  1304. * (.CA) Canada http://www.iana.org/domains/idn-tables/tables/ca_fr_1.0.html
  1305. * (.CAT) Catalan http://www.iana.org/domains/idn-tables/tables/cat_ca_1.0.html
  1306. * (.CH) Switzerland https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1
  1307. * (.CL) Chile http://www.iana.org/domains/idn-tables/tables/cl_latn_1.0.html
  1308. * (.COM) International http://www.verisign.com/information-services/naming-services/internationalized-domain-names/index.html
  1309. * (.DE) Germany http://www.denic.de/en/domains/idns/liste.html
  1310. * (.DK) Danmark http://www.dk-hostmaster.dk/index.php?id=151
  1311. * (.ES) Spain https://www.nic.es/media/2008-05/1210147705287.pdf
  1312. * (.FI) Finland http://www.ficora.fi/en/index/palvelut/fiverkkotunnukset/aakkostenkaytto.html
  1313. * (.GR) Greece https://grweb.ics.forth.gr/CharacterTable1_en.jsp
  1314. * (.HU) Hungary http://www.domain.hu/domain/English/szabalyzat/szabalyzat.html
  1315. * (.INFO) International http://www.nic.info/info/idn
  1316. * (.IO) British Indian Ocean Territory http://www.nic.io/IO-IDN-Policy.pdf
  1317. * (.IR) Iran http://www.nic.ir/Allowable_Characters_dot-iran
  1318. * (.IS) Iceland http://www.isnic.is/domain/rules.php
  1319. * (.KR) Korea http://www.iana.org/domains/idn-tables/tables/kr_ko-kr_1.0.html
  1320. * (.LI) Liechtenstein https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1
  1321. * (.LT) Lithuania http://www.domreg.lt/static/doc/public/idn_symbols-en.pdf
  1322. * (.MD) Moldova http://www.register.md/
  1323. * (.MUSEUM) International http://www.iana.org/domains/idn-tables/tables/museum_latn_1.0.html
  1324. * (.NET) International http://www.verisign.com/information-services/naming-services/internationalized-domain-names/index.html
  1325. * (.NO) Norway http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html
  1326. * (.NU) Niue http://www.worldnames.net/
  1327. * (.ORG) International http://www.pir.org/index.php?db=content/FAQs&tbl=FAQs_Registrant&id=2
  1328. * (.PE) Peru https://www.nic.pe/nuevas_politicas_faq_2.php
  1329. * (.PL) Poland http://www.dns.pl/IDN/allowed_character_sets.pdf
  1330. * (.PR) Puerto Rico http://www.nic.pr/idn_rules.asp
  1331. * (.PT) Portugal https://online.dns.pt/dns_2008/do?com=DS;8216320233;111;+PAGE(4000058)+K-CAT-CODIGO(C.125)+RCNT(100);
  1332. * (.RU) Russia http://www.iana.org/domains/idn-tables/tables/ru_ru-ru_1.0.html
  1333. * (.RS) Serbia http://www.iana.org/domains/idn-tables/tables/rs_sr-rs_1.0.pdf
  1334. * (.SA) Saudi Arabia http://www.iana.org/domains/idn-tables/tables/sa_ar_1.0.html
  1335. * (.SE) Sweden http://www.iis.se/english/IDN_campaignsite.shtml?lang=en
  1336. * (.SH) Saint Helena http://www.nic.sh/SH-IDN-Policy.pdf
  1337. * (.SJ) Svalbard and Jan Mayen http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html
  1338. * (.TH) Thailand http://www.iana.org/domains/idn-tables/tables/th_th-th_1.0.html
  1339. * (.TM) Turkmenistan http://www.nic.tm/TM-IDN-Policy.pdf
  1340. * (.TR) Turkey https://www.nic.tr/index.php
  1341. * (.UA) Ukraine http://www.iana.org/domains/idn-tables/tables/ua_cyrl_1.2.html
  1342. * (.VE) Venice http://www.iana.org/domains/idn-tables/tables/ve_es_1.0.html
  1343. * (.VN) Vietnam http://www.vnnic.vn/english/5-6-300-2-2-04-20071115.htm#1.%20Introduction
  1344. *
  1345. * @var array
  1346. */
  1347. protected $_validIdns = array(
  1348. 'AC' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēėęěĝġģĥħīįĵķĺļľŀłńņňŋőœŕŗřśŝşšţťŧūŭůűųŵŷźżž]{1,63}$/iu'),
  1349. 'AR' => array(1 => '/^[\x{002d}0-9a-zà-ãç-êìíñ-õü]{1,63}$/iu'),
  1350. 'AS' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĸĺļľłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźż]{1,63}$/iu'),
  1351. 'AT' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœšž]{1,63}$/iu'),
  1352. 'BIZ' => 'Hostname/Biz.php',
  1353. 'BR' => array(1 => '/^[\x{002d}0-9a-zà-ãçéíó-õúü]{1,63}$/iu'),
  1354. 'BV' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'),
  1355. 'CA' => array(1 => '/^[\x{002d}0-9a-zàâæçéèêëîïôœùûüÿ\x{00E0}\x{00E2}\x{00E7}\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{00EE}\x{00EF}\x{00F4}\x{00F9}\x{00FB}\x{00FC}\x{00E6}\x{0153}\x{00FF}]{1,63}$/iu'),
  1356. 'CAT' => array(1 => '/^[\x{002d}0-9a-z·àç-éíïòóúü]{1,63}$/iu'),
  1357. 'CH' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœ]{1,63}$/iu'),
  1358. 'CL' => array(1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'),
  1359. 'CN' => 'Hostname/Cn.php',
  1360. 'COM' => 'Hostname/Com.php',
  1361. 'DE' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťßţŧŭůűũųūŵŷźžż]{1,63}$/iu'),
  1362. 'DK' => array(1 => '/^[\x{002d}0-9a-zäéöüæøå]{1,63}$/iu'),
  1363. 'ES' => array(1 => '/^[\x{002d}0-9a-zàáçèéíïñòóúü·]{1,63}$/iu'),
  1364. 'EU' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿ]{1,63}$/iu',
  1365. 2 => '/^[\x{002d}0-9a-zāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĺļľŀłńņňʼnŋōŏőœŕŗřśŝšťŧũūŭůűųŵŷźżž]{1,63}$/iu',
  1366. 3 => '/^[\x{002d}0-9a-zșț]{1,63}$/iu',
  1367. 4 => '/^[\x{002d}0-9a-zΐάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ]{1,63}$/iu',
  1368. 5 => '/^[\x{002d}0-9a-zабвгдежзийклмнопрстуфхцчшщъыьэюя]{1,63}$/iu',
  1369. 6 => '/^[\x{002d}0-9a-zἀ-ἇἐ-ἕἠ-ἧἰ-ἷὀ-ὅὐ-ὗὠ-ὧὰ-ὼώᾀ-ᾇᾐ-ᾗᾠ-ᾧᾰ-ᾴᾶᾷῂῃῄῆῇῐ-ῒΐῖῗῠ-ῧῲῳῴῶῷ]{1,63}$/iu'),
  1370. 'FI' => array(1 => '/^[\x{002d}0-9a-zäåö]{1,63}$/iu'),
  1371. 'GR' => array(1 => '/^[\x{002d}0-9a-zΆΈΉΊΌΎ-ΡΣ-ώἀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼῂῃῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲῳῴῶ-ῼ]{1,63}$/iu'),
  1372. 'HK' => 'Hostname/Cn.php',
  1373. 'HU' => array(1 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu'),
  1374. 'IL' => array(1 => '/^[\x{002d}0-9\x{05D0}-\x{05EA}]{1,63}$/iu',
  1375. 2 => '/^[\x{002d}0-9a-z]{1,63}$/i'),
  1376. 'INFO'=> array(1 => '/^[\x{002d}0-9a-zäåæéöøü]{1,63}$/iu',
  1377. 2 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu',
  1378. 3 => '/^[\x{002d}0-9a-záæéíðóöúýþ]{1,63}$/iu',
  1379. 4 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu',
  1380. 5 => '/^[\x{002d}0-9a-zāčēģīķļņōŗšūž]{1,63}$/iu',
  1381. 6 => '/^[\x{002d}0-9a-ząčėęįšūųž]{1,63}$/iu',
  1382. 7 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu',
  1383. 8 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'),
  1384. 'IO' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'),
  1385. 'IS' => array(1 => '/^[\x{002d}0-9a-záéýúíóþæöð]{1,63}$/iu'),
  1386. 'IT' => array(1 => '/^[\x{002d}0-9a-zàâäèéêëìîïòôöùûüæœçÿß-]{1,63}$/iu'),
  1387. 'JP' => 'Hostname/Jp.php',
  1388. 'KR' => array(1 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu'),
  1389. 'LI' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœ]{1,63}$/iu'),
  1390. 'LT' => array(1 => '/^[\x{002d}0-9ąčęėįšųūž]{1,63}$/iu'),
  1391. 'MD' => array(1 => '/^[\x{002d}0-9ăâîşţ]{1,63}$/iu'),
  1392. 'MUSEUM' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćċčďđēėęěğġģħīįıķĺļľłńņňŋōőœŕŗřśşšţťŧūůűųŵŷźżžǎǐǒǔ\x{01E5}\x{01E7}\x{01E9}\x{01EF}ə\x{0292}ẁẃẅỳ]{1,63}$/iu'),
  1393. 'NET' => 'Hostname/Com.php',
  1394. 'NO' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'),
  1395. 'NU' => 'Hostname/Com.php',
  1396. 'ORG' => array(1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu',
  1397. 2 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu',
  1398. 3 => '/^[\x{002d}0-9a-záäåæéëíðóöøúüýþ]{1,63}$/iu',
  1399. 4 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu',
  1400. 5 => '/^[\x{002d}0-9a-ząčėęįšūųž]{1,63}$/iu',
  1401. 6 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu',
  1402. 7 => '/^[\x{002d}0-9a-zāčēģīķļņōŗšūž]{1,63}$/iu'),
  1403. 'PE' => array(1 => '/^[\x{002d}0-9a-zñáéíóúü]{1,63}$/iu'),
  1404. 'PL' => array(1 => '/^[\x{002d}0-9a-zāčēģīķļņōŗšūž]{1,63}$/iu',
  1405. 2 => '/^[\x{002d}а-ик-ш\x{0450}ѓѕјљњќџ]{1,63}$/iu',
  1406. 3 => '/^[\x{002d}0-9a-zâîăşţ]{1,63}$/iu',
  1407. 4 => '/^[\x{002d}0-9а-яё\x{04C2}]{1,63}$/iu',
  1408. 5 => '/^[\x{002d}0-9a-zàáâèéêìíîòóôùúûċġħż]{1,63}$/iu',
  1409. 6 => '/^[\x{002d}0-9a-zàäåæéêòóôöøü]{1,63}$/iu',
  1410. 7 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu',
  1411. 8 => '/^[\x{002d}0-9a-zàáâãçéêíòóôõúü]{1,63}$/iu',
  1412. 9 => '/^[\x{002d}0-9a-zâîăşţ]{1,63}$/iu',
  1413. 10=> '/^[\x{002d}0-9a-záäéíóôúýčďĺľňŕšťž]{1,63}$/iu',
  1414. 11=> '/^[\x{002d}0-9a-zçë]{1,63}$/iu',
  1415. 12=> '/^[\x{002d}0-9а-ик-шђјљњћџ]{1,63}$/iu',
  1416. 13=> '/^[\x{002d}0-9a-zćčđšž]{1,63}$/iu',
  1417. 14=> '/^[\x{002d}0-9a-zâçöûüğış]{1,63}$/iu',
  1418. 15=> '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu',
  1419. 16=> '/^[\x{002d}0-9a-zäõöüšž]{1,63}$/iu',
  1420. 17=> '/^[\x{002d}0-9a-zĉĝĥĵŝŭ]{1,63}$/iu',
  1421. 18=> '/^[\x{002d}0-9a-zâäéëîô]{1,63}$/iu',
  1422. 19=> '/^[\x{002d}0-9a-zàáâäåæçèéêëìíîïðñòôöøùúûüýćčłńřśš]{1,63}$/iu',
  1423. 20=> '/^[\x{002d}0-9a-zäåæõöøüšž]{1,63}$/iu',
  1424. 21=> '/^[\x{002d}0-9a-zàáçèéìíòóùú]{1,63}$/iu',
  1425. 22=> '/^[\x{002d}0-9a-zàáéíóöúüőű]{1,63}$/iu',
  1426. 23=> '/^[\x{002d}0-9ΐά-ώ]{1,63}$/iu',
  1427. 24=> '/^[\x{002d}0-9a-zàáâåæçèéêëðóôöøüþœ]{1,63}$/iu',
  1428. 25=> '/^[\x{002d}0-9a-záäéíóöúüýčďěňřšťůž]{1,63}$/iu',
  1429. 26=> '/^[\x{002d}0-9a-z·àçèéíïòóúü]{1,63}$/iu',
  1430. 27=> '/^[\x{002d}0-9а-ъьюя\x{0450}\x{045D}]{1,63}$/iu',
  1431. 28=> '/^[\x{002d}0-9а-яёіў]{1,63}$/iu',
  1432. 29=> '/^[\x{002d}0-9a-ząčėęįšūųž]{1,63}$/iu',
  1433. 30=> '/^[\x{002d}0-9a-záäåæéëíðóöøúüýþ]{1,63}$/iu',
  1434. 31=> '/^[\x{002d}0-9a-zàâæçèéêëîïñôùûüÿœ]{1,63}$/iu',
  1435. 32=> '/^[\x{002d}0-9а-щъыьэюяёєіїґ]{1,63}$/iu',
  1436. 33=> '/^[\x{002d}0-9א-ת]{1,63}$/iu'),
  1437. 'PR' => array(1 => '/^[\x{002d}0-9a-záéíóúñäëïüöâêîôûàèùæçœãõ]{1,63}$/iu'),
  1438. 'PT' => array(1 => '/^[\x{002d}0-9a-záàâãçéêíóôõú]{1,63}$/iu'),
  1439. 'RS' => array(1 => '/^[\x{002D}\x{0030}-\x{0039}\x{0061}-\x{007A}\x{0107}\x{010D}\x{0111}\x{0161}\x{017E}]{1,63}$/iu)'),
  1440. 'RU' => array(1 => '/^[\x{002d}0-9а-яё]{1,63}$/iu'),
  1441. 'SA' => array(1 => '/^[\x{002d}.0-9\x{0621}-\x{063A}\x{0641}-\x{064A}\x{0660}-\x{0669}]{1,63}$/iu'),
  1442. 'SE' => array(1 => '/^[\x{002d}0-9a-zäåéöü]{1,63}$/iu'),
  1443. 'SH' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'),
  1444. 'SI' => array(
  1445. 1 => '/^[\x{002d}0-9a-zà-öø-ÿ]{1,63}$/iu',
  1446. 2 => '/^[\x{002d}0-9a-zāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĺļľŀłńņňʼnŋōŏőœŕŗřśŝšťŧũūŭůűųŵŷźżž]{1,63}$/iu',
  1447. 3 => '/^[\x{002d}0-9a-zșț]{1,63}$/iu'),
  1448. 'SJ' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'),
  1449. 'TH' => array(1 => '/^[\x{002d}0-9a-z\x{0E01}-\x{0E3A}\x{0E40}-\x{0E4D}\x{0E50}-\x{0E59}]{1,63}$/iu'),
  1450. 'TM' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēėęěĝġģĥħīįĵķĺļľŀłńņňŋőœŕŗřśŝşšţťŧūŭůűųŵŷźżž]{1,63}$/iu'),
  1451. 'TW' => 'Hostname/Cn.php',
  1452. 'TR' => array(1 => '/^[\x{002d}0-9a-zğıüşöç]{1,63}$/iu'),
  1453. 'UA' => array(1 => '/^[\x{002d}0-9a-zабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџґӂʼ]{1,63}$/iu'),
  1454. 'VE' => array(1 => '/^[\x{002d}0-9a-záéíóúüñ]{1,63}$/iu'),
  1455. 'VN' => array(1 => '/^[ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚÝàáâãèéêìíòóôõùúýĂăĐđĨĩŨũƠơƯư\x{1EA0}-\x{1EF9}]{1,63}$/iu'),
  1456. 'мон' => array(1 => '/^[\x{002d}0-9\x{0430}-\x{044F}]{1,63}$/iu'),
  1457. 'срб' => array(1 => '/^[\x{002d}0-9а-ик-шђјљњћџ]{1,63}$/iu'),
  1458. 'сайт' => array(1 => '/^[\x{002d}0-9а-яёіїѝйўґг]{1,63}$/iu'),
  1459. 'онлайн' => array(1 => '/^[\x{002d}0-9а-яёіїѝйўґг]{1,63}$/iu'),
  1460. '中国' => 'Hostname/Cn.php',
  1461. '中國' => 'Hostname/Cn.php',
  1462. 'ලංකා' => array(1 => '/^[\x{0d80}-\x{0dff}]{1,63}$/iu'),
  1463. '香港' => 'Hostname/Cn.php',
  1464. '台湾' => 'Hostname/Cn.php',
  1465. '台灣' => 'Hostname/Cn.php',
  1466. 'امارات' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1467. 'الاردن' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1468. 'السعودية' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1469. 'ไทย' => array(1 => '/^[\x{002d}0-9a-z\x{0E01}-\x{0E3A}\x{0E40}-\x{0E4D}\x{0E50}-\x{0E59}]{1,63}$/iu'),
  1470. 'рф' => array(1 => '/^[\x{002d}0-9а-яё]{1,63}$/iu'),
  1471. 'تونس' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1472. 'مصر' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1473. 'இலங்கை' => array(1 => '/^[\x{0b80}-\x{0bff}]{1,63}$/iu'),
  1474. 'فلسطين' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1475. 'شبكة' => array(1 => '/^[\x{0621}-\x{0624}\x{0626}-\x{063A}\x{0641}\x{0642}\x{0644}-\x{0648}\x{067E}\x{0686}\x{0698}\x{06A9}\x{06AF}\x{06CC}\x{06F0}-\x{06F9}]{1,30}$/iu'),
  1476. );
  1477. protected $_idnLength = array(
  1478. 'BIZ' => array(5 => 17, 11 => 15, 12 => 20),
  1479. 'CN' => array(1 => 20),
  1480. 'COM' => array(3 => 17, 5 => 20),
  1481. 'HK' => array(1 => 15),
  1482. 'INFO'=> array(4 => 17),
  1483. 'KR' => array(1 => 17),
  1484. 'NET' => array(3 => 17, 5 => 20),
  1485. 'ORG' => array(6 => 17),
  1486. 'TW' => array(1 => 20),
  1487. 'ایران' => array(1 => 30),
  1488. '中国' => array(1 => 20),
  1489. '公司' => array(1 => 20),
  1490. '网络' => array(1 => 20),
  1491. );
  1492. protected $_options = array(
  1493. 'allow' => self::ALLOW_DNS,
  1494. 'idn' => true,
  1495. 'tld' => true,
  1496. 'ip' => null
  1497. );
  1498. /**
  1499. * Sets validator options
  1500. *
  1501. * @see http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs
  1502. * @param array $options Validator options
  1503. */
  1504. public function __construct($options = array())
  1505. {
  1506. if ($options instanceof Zend_Config) {
  1507. $options = $options->toArray();
  1508. } else if (!is_array($options)) {
  1509. $options = func_get_args();
  1510. $temp['allow'] = array_shift($options);
  1511. if (!empty($options)) {
  1512. $temp['idn'] = array_shift($options);
  1513. }
  1514. if (!empty($options)) {
  1515. $temp['tld'] = array_shift($options);
  1516. }
  1517. if (!empty($options)) {
  1518. $temp['ip'] = array_shift($options);
  1519. }
  1520. $options = $temp;
  1521. }
  1522. $options += $this->_options;
  1523. $this->setOptions($options);
  1524. }
  1525. /**
  1526. * Returns all set options
  1527. *
  1528. * @return array
  1529. */
  1530. public function getOptions()
  1531. {
  1532. return $this->_options;
  1533. }
  1534. /**
  1535. * Sets the options for this validator
  1536. *
  1537. * @param array $options
  1538. * @return Zend_Validate_Hostname
  1539. */
  1540. public function setOptions($options)
  1541. {
  1542. if (array_key_exists('allow', $options)) {
  1543. $this->setAllow($options['allow']);
  1544. }
  1545. if (array_key_exists('idn', $options)) {
  1546. $this->setValidateIdn($options['idn']);
  1547. }
  1548. if (array_key_exists('tld', $options)) {
  1549. $this->setValidateTld($options['tld']);
  1550. }
  1551. if (array_key_exists('ip', $options)) {
  1552. $this->setIpValidator($options['ip']);
  1553. }
  1554. return $this;
  1555. }
  1556. /**
  1557. * Returns the set ip validator
  1558. *
  1559. * @return Zend_Validate_Ip
  1560. */
  1561. public function getIpValidator()
  1562. {
  1563. return $this->_options['ip'];
  1564. }
  1565. /**
  1566. * @param Zend_Validate_Ip $ipValidator OPTIONAL
  1567. * @return Zend_Validate_Hostname
  1568. */
  1569. public function setIpValidator(Zend_Validate_Ip $ipValidator = null)
  1570. {
  1571. if ($ipValidator === null) {
  1572. $ipValidator = new Zend_Validate_Ip();
  1573. }
  1574. $this->_options['ip'] = $ipValidator;
  1575. return $this;
  1576. }
  1577. /**
  1578. * Returns the allow option
  1579. *
  1580. * @return integer
  1581. */
  1582. public function getAllow()
  1583. {
  1584. return $this->_options['allow'];
  1585. }
  1586. /**
  1587. * Sets the allow option
  1588. *
  1589. * @param integer $allow
  1590. * @return Zend_Validate_Hostname Provides a fluent interface
  1591. */
  1592. public function setAllow($allow)
  1593. {
  1594. $this->_options['allow'] = $allow;
  1595. return $this;
  1596. }
  1597. /**
  1598. * Returns the set idn option
  1599. *
  1600. * @return boolean
  1601. */
  1602. public function getValidateIdn()
  1603. {
  1604. return $this->_options['idn'];
  1605. }
  1606. /**
  1607. * Set whether IDN domains are validated
  1608. *
  1609. * This only applies when DNS hostnames are validated
  1610. *
  1611. * @param boolean $allowed Set allowed to true to validate IDNs, and false to not validate them
  1612. * @return $this
  1613. */
  1614. public function setValidateIdn ($allowed)
  1615. {
  1616. $this->_options['idn'] = (bool) $allowed;
  1617. return $this;
  1618. }
  1619. /**
  1620. * Returns the set tld option
  1621. *
  1622. * @return boolean
  1623. */
  1624. public function getValidateTld()
  1625. {
  1626. return $this->_options['tld'];
  1627. }
  1628. /**
  1629. * Set whether the TLD element of a hostname is validated
  1630. *
  1631. * This only applies when DNS hostnames are validated
  1632. *
  1633. * @param boolean $allowed Set allowed to true to validate TLDs, and false to not validate them
  1634. * @return $this
  1635. */
  1636. public function setValidateTld ($allowed)
  1637. {
  1638. $this->_options['tld'] = (bool) $allowed;
  1639. return $this;
  1640. }
  1641. /**
  1642. * Defined by Zend_Validate_Interface
  1643. *
  1644. * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  1645. *
  1646. * @param string $value
  1647. * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  1648. * @return boolean
  1649. */
  1650. public function isValid($value)
  1651. {
  1652. if (!is_string($value)) {
  1653. $this->_error(self::INVALID);
  1654. return false;
  1655. }
  1656. $this->_setValue($value);
  1657. // Check input against IP address schema
  1658. if (preg_match('/^[0-9a-f:.]*$/i', $value) &&
  1659. $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
  1660. if (!($this->_options['allow'] & self::ALLOW_IP)) {
  1661. $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
  1662. return false;
  1663. } else {
  1664. return true;
  1665. }
  1666. }
  1667. // RFC3986 3.2.2 states:
  1668. //
  1669. // The rightmost domain label of a fully qualified domain name
  1670. // in DNS may be followed by a single "." and should be if it is
  1671. // necessary to distinguish between the complete domain name and
  1672. // some local domain.
  1673. //
  1674. // (see ZF-6363)
  1675. // Local hostnames are allowed to be partitial (ending '.')
  1676. if ($this->_options['allow'] & self::ALLOW_LOCAL) {
  1677. if (substr($value, -1) === '.') {
  1678. $value = substr($value, 0, -1);
  1679. if (substr($value, -1) === '.') {
  1680. // Empty hostnames (ending '..') are not allowed
  1681. $this->_error(self::INVALID_LOCAL_NAME);
  1682. return false;
  1683. }
  1684. }
  1685. }
  1686. $domainParts = explode('.', $value);
  1687. // Prevent partitial IP V4 adresses (ending '.')
  1688. if ((count($domainParts) == 4) && preg_match('/^[0-9.a-e:.]*$/i', $value) &&
  1689. $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
  1690. $this->_error(self::INVALID_LOCAL_NAME);
  1691. }
  1692. // Check input against DNS hostname schema
  1693. if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) {
  1694. $status = false;
  1695. $origenc = PHP_VERSION_ID < 50600
  1696. ? iconv_get_encoding('internal_encoding')
  1697. : ini_get('default_charset');
  1698. if (PHP_VERSION_ID < 50600) {
  1699. iconv_set_encoding('internal_encoding', 'UTF-8');
  1700. } else {
  1701. ini_set('default_charset', 'UTF-8');
  1702. }
  1703. do {
  1704. // First check TLD
  1705. $matches = array();
  1706. if (preg_match('/([^.]{2,63})$/iu', end($domainParts), $matches)
  1707. || (array_key_exists(end($domainParts), $this->_validIdns))) {
  1708. reset($domainParts);
  1709. // Hostname characters are: *(label dot)(label dot label); max 254 chars
  1710. // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
  1711. // id-prefix: alpha / digit
  1712. // ldh: alpha / digit / dash
  1713. // Match TLD against known list
  1714. $this->_tld = $matches[1];
  1715. if ($this->_options['tld']) {
  1716. if (!in_array(strtolower($this->_tld), $this->_validTlds)
  1717. && !in_array($this->_tld, $this->_validTlds)) {
  1718. $this->_error(self::UNKNOWN_TLD);
  1719. $status = false;
  1720. break;
  1721. }
  1722. // We have already validated that the TLD is fine. We don't want it to go through the below
  1723. // checks as new UTF-8 TLDs will incorrectly fail if there is no IDN regex for it.
  1724. array_pop($domainParts);
  1725. }
  1726. /**
  1727. * Match against IDN hostnames
  1728. * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
  1729. * @see Zend_Validate_Hostname_Interface
  1730. */
  1731. $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i');
  1732. if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) {
  1733. if (is_string($this->_validIdns[strtoupper($this->_tld)])) {
  1734. $regexChars += include($this->_validIdns[strtoupper($this->_tld)]);
  1735. } else {
  1736. $regexChars += $this->_validIdns[strtoupper($this->_tld)];
  1737. }
  1738. }
  1739. // Check each hostname part
  1740. $check = 0;
  1741. foreach ($domainParts as $domainPart) {
  1742. // If some domain part is empty (i.e. zend..com), it's invalid
  1743. if (empty($domainPart) && $domainPart !== '0') {
  1744. $this->_error(self::INVALID_HOSTNAME);
  1745. return false;
  1746. }
  1747. // Decode Punycode domainnames to IDN
  1748. if (strpos($domainPart, 'xn--') === 0) {
  1749. $domainPart = $this->decodePunycode(substr($domainPart, 4));
  1750. if ($domainPart === false) {
  1751. return false;
  1752. }
  1753. }
  1754. // Check dash (-) does not start, end or appear in 3rd and 4th positions
  1755. if ((strpos($domainPart, '-') === 0)
  1756. || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3))
  1757. || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) {
  1758. $this->_error(self::INVALID_DASH);
  1759. $status = false;
  1760. break 2;
  1761. }
  1762. // Check each domain part
  1763. $checked = false;
  1764. foreach($regexChars as $regexKey => $regexChar) {
  1765. $status = preg_match($regexChar, $domainPart);
  1766. if ($status > 0) {
  1767. $length = 63;
  1768. if (array_key_exists(strtoupper($this->_tld), $this->_idnLength)
  1769. && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) {
  1770. $length = $this->_idnLength[strtoupper($this->_tld)];
  1771. }
  1772. if (iconv_strlen($domainPart, 'UTF-8') > $length) {
  1773. $this->_error(self::INVALID_HOSTNAME);
  1774. } else {
  1775. $checked = true;
  1776. break;
  1777. }
  1778. }
  1779. }
  1780. if ($checked) {
  1781. ++$check;
  1782. }
  1783. }
  1784. // If one of the labels doesn't match, the hostname is invalid
  1785. if ($check !== count($domainParts)) {
  1786. $this->_error(self::INVALID_HOSTNAME_SCHEMA);
  1787. $status = false;
  1788. }
  1789. } else {
  1790. // Hostname not long enough
  1791. $this->_error(self::UNDECIPHERABLE_TLD);
  1792. $status = false;
  1793. }
  1794. } while (false);
  1795. if (PHP_VERSION_ID < 50600) {
  1796. iconv_set_encoding('internal_encoding', $origenc);
  1797. } else {
  1798. ini_set('default_charset', $origenc);
  1799. }
  1800. // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
  1801. // passes validation
  1802. if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) {
  1803. return true;
  1804. }
  1805. } else if ($this->_options['allow'] & self::ALLOW_DNS) {
  1806. $this->_error(self::INVALID_HOSTNAME);
  1807. }
  1808. // Check for URI Syntax (RFC3986)
  1809. if ($this->_options['allow'] & self::ALLOW_URI) {
  1810. if (preg_match("/^([a-zA-Z0-9-._~!$&\'()*+,;=]|%[[:xdigit:]]{2}){1,254}$/i", $value)) {
  1811. return true;
  1812. } else {
  1813. $this->_error(self::INVALID_URI);
  1814. }
  1815. }
  1816. // Check input against local network name schema; last chance to pass validation
  1817. $regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}[\x2e]{0,1}){1,254}$/';
  1818. $status = @preg_match($regexLocal, $value);
  1819. // If the input passes as a local network name, and local network names are allowed, then the
  1820. // hostname passes validation
  1821. $allowLocal = $this->_options['allow'] & self::ALLOW_LOCAL;
  1822. if ($status && $allowLocal) {
  1823. return true;
  1824. }
  1825. // If the input does not pass as a local network name, add a message
  1826. if (!$status) {
  1827. $this->_error(self::INVALID_LOCAL_NAME);
  1828. }
  1829. // If local network names are not allowed, add a message
  1830. if ($status && !$allowLocal) {
  1831. $this->_error(self::LOCAL_NAME_NOT_ALLOWED);
  1832. }
  1833. return false;
  1834. }
  1835. /**
  1836. * Decodes a punycode encoded string to it's original utf8 string
  1837. * In case of a decoding failure the original string is returned
  1838. *
  1839. * @param string $encoded Punycode encoded string to decode
  1840. * @return string
  1841. */
  1842. protected function decodePunycode($encoded)
  1843. {
  1844. if (!preg_match('/^[a-z0-9-]+$/i', $encoded)) {
  1845. // no punycode encoded string
  1846. $this->_error(self::CANNOT_DECODE_PUNYCODE);
  1847. return false;
  1848. }
  1849. $decoded = array();
  1850. $separator = strrpos($encoded, '-');
  1851. if ($separator > 0) {
  1852. for ($x = 0; $x < $separator; ++$x) {
  1853. // prepare decoding matrix
  1854. $decoded[] = ord($encoded[$x]);
  1855. }
  1856. }
  1857. $lengthd = count($decoded);
  1858. $lengthe = strlen($encoded);
  1859. // decoding
  1860. $init = true;
  1861. $base = 72;
  1862. $index = 0;
  1863. $char = 0x80;
  1864. for ($indexe = ($separator) ? ($separator + 1) : 0; $indexe < $lengthe; ++$lengthd) {
  1865. for ($old_index = $index, $pos = 1, $key = 36; 1 ; $key += 36) {
  1866. $hex = ord($encoded[$indexe++]);
  1867. $digit = ($hex - 48 < 10) ? $hex - 22
  1868. : (($hex - 65 < 26) ? $hex - 65
  1869. : (($hex - 97 < 26) ? $hex - 97
  1870. : 36));
  1871. $index += $digit * $pos;
  1872. $tag = ($key <= $base) ? 1 : (($key >= $base + 26) ? 26 : ($key - $base));
  1873. if ($digit < $tag) {
  1874. break;
  1875. }
  1876. $pos = (int) ($pos * (36 - $tag));
  1877. }
  1878. $delta = intval($init ? (($index - $old_index) / 700) : (($index - $old_index) / 2));
  1879. $delta += intval($delta / ($lengthd + 1));
  1880. for ($key = 0; $delta > 910 / 2; $key += 36) {
  1881. $delta = intval($delta / 35);
  1882. }
  1883. $base = intval($key + 36 * $delta / ($delta + 38));
  1884. $init = false;
  1885. $char += (int) ($index / ($lengthd + 1));
  1886. $index %= ($lengthd + 1);
  1887. if ($lengthd > 0) {
  1888. for ($i = $lengthd; $i > $index; $i--) {
  1889. $decoded[$i] = $decoded[($i - 1)];
  1890. }
  1891. }
  1892. $decoded[$index++] = $char;
  1893. }
  1894. // convert decoded ucs4 to utf8 string
  1895. foreach ($decoded as $key => $value) {
  1896. if ($value < 128) {
  1897. $decoded[$key] = chr($value);
  1898. } elseif ($value < (1 << 11)) {
  1899. $decoded[$key] = chr(192 + ($value >> 6));
  1900. $decoded[$key] .= chr(128 + ($value & 63));
  1901. } elseif ($value < (1 << 16)) {
  1902. $decoded[$key] = chr(224 + ($value >> 12));
  1903. $decoded[$key] .= chr(128 + (($value >> 6) & 63));
  1904. $decoded[$key] .= chr(128 + ($value & 63));
  1905. } elseif ($value < (1 << 21)) {
  1906. $decoded[$key] = chr(240 + ($value >> 18));
  1907. $decoded[$key] .= chr(128 + (($value >> 12) & 63));
  1908. $decoded[$key] .= chr(128 + (($value >> 6) & 63));
  1909. $decoded[$key] .= chr(128 + ($value & 63));
  1910. } else {
  1911. $this->_error(self::CANNOT_DECODE_PUNYCODE);
  1912. return false;
  1913. }
  1914. }
  1915. return implode($decoded);
  1916. }
  1917. }