Hostname.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  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-2014 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-2014 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 2014112800, Last Updated Fri Nov 28 07:07:01 2014 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. 'abogado',
  110. 'ac',
  111. 'academy',
  112. 'accountants',
  113. 'active',
  114. 'actor',
  115. 'ad',
  116. 'ae',
  117. 'aero',
  118. 'af',
  119. 'ag',
  120. 'agency',
  121. 'ai',
  122. 'airforce',
  123. 'al',
  124. 'allfinanz',
  125. 'alsace',
  126. 'am',
  127. 'an',
  128. 'android',
  129. 'ao',
  130. 'aq',
  131. 'ar',
  132. 'archi',
  133. 'army',
  134. 'arpa',
  135. 'as',
  136. 'asia',
  137. 'associates',
  138. 'at',
  139. 'attorney',
  140. 'au',
  141. 'auction',
  142. 'audio',
  143. 'autos',
  144. 'aw',
  145. 'ax',
  146. 'axa',
  147. 'az',
  148. 'ba',
  149. 'band',
  150. 'bar',
  151. 'bargains',
  152. 'bayern',
  153. 'bb',
  154. 'bd',
  155. 'be',
  156. 'beer',
  157. 'berlin',
  158. 'best',
  159. 'bf',
  160. 'bg',
  161. 'bh',
  162. 'bi',
  163. 'bid',
  164. 'bike',
  165. 'bio',
  166. 'biz',
  167. 'bj',
  168. 'black',
  169. 'blackfriday',
  170. 'bloomberg',
  171. 'blue',
  172. 'bm',
  173. 'bmw',
  174. 'bn',
  175. 'bnpparibas',
  176. 'bo',
  177. 'boo',
  178. 'boutique',
  179. 'br',
  180. 'brussels',
  181. 'bs',
  182. 'bt',
  183. 'budapest',
  184. 'build',
  185. 'builders',
  186. 'business',
  187. 'buzz',
  188. 'bv',
  189. 'bw',
  190. 'by',
  191. 'bz',
  192. 'bzh',
  193. 'ca',
  194. 'cab',
  195. 'cal',
  196. 'camera',
  197. 'camp',
  198. 'cancerresearch',
  199. 'capetown',
  200. 'capital',
  201. 'caravan',
  202. 'cards',
  203. 'care',
  204. 'career',
  205. 'careers',
  206. 'casa',
  207. 'cash',
  208. 'cat',
  209. 'catering',
  210. 'cc',
  211. 'cd',
  212. 'center',
  213. 'ceo',
  214. 'cern',
  215. 'cf',
  216. 'cg',
  217. 'ch',
  218. 'channel',
  219. 'cheap',
  220. 'christmas',
  221. 'chrome',
  222. 'church',
  223. 'ci',
  224. 'citic',
  225. 'city',
  226. 'ck',
  227. 'cl',
  228. 'claims',
  229. 'cleaning',
  230. 'click',
  231. 'clinic',
  232. 'clothing',
  233. 'club',
  234. 'cm',
  235. 'cn',
  236. 'co',
  237. 'coach',
  238. 'codes',
  239. 'coffee',
  240. 'college',
  241. 'cologne',
  242. 'com',
  243. 'community',
  244. 'company',
  245. 'computer',
  246. 'condos',
  247. 'construction',
  248. 'consulting',
  249. 'contractors',
  250. 'cooking',
  251. 'cool',
  252. 'coop',
  253. 'country',
  254. 'cr',
  255. 'credit',
  256. 'creditcard',
  257. 'cricket',
  258. 'crs',
  259. 'cruises',
  260. 'cu',
  261. 'cuisinella',
  262. 'cv',
  263. 'cw',
  264. 'cx',
  265. 'cy',
  266. 'cymru',
  267. 'cz',
  268. 'dad',
  269. 'dance',
  270. 'dating',
  271. 'day',
  272. 'de',
  273. 'deals',
  274. 'degree',
  275. 'delivery',
  276. 'democrat',
  277. 'dental',
  278. 'dentist',
  279. 'desi',
  280. 'diamonds',
  281. 'diet',
  282. 'digital',
  283. 'direct',
  284. 'directory',
  285. 'discount',
  286. 'dj',
  287. 'dk',
  288. 'dm',
  289. 'dnp',
  290. 'do',
  291. 'domains',
  292. 'durban',
  293. 'dvag',
  294. 'dz',
  295. 'eat',
  296. 'ec',
  297. 'edu',
  298. 'education',
  299. 'ee',
  300. 'eg',
  301. 'email',
  302. 'emerck',
  303. 'energy',
  304. 'engineer',
  305. 'engineering',
  306. 'enterprises',
  307. 'equipment',
  308. 'er',
  309. 'es',
  310. 'esq',
  311. 'estate',
  312. 'et',
  313. 'eu',
  314. 'eus',
  315. 'events',
  316. 'everbank',
  317. 'exchange',
  318. 'expert',
  319. 'exposed',
  320. 'fail',
  321. 'farm',
  322. 'feedback',
  323. 'fi',
  324. 'finance',
  325. 'financial',
  326. 'firmdale',
  327. 'fish',
  328. 'fishing',
  329. 'fitness',
  330. 'fj',
  331. 'fk',
  332. 'flights',
  333. 'florist',
  334. 'flsmidth',
  335. 'fly',
  336. 'fm',
  337. 'fo',
  338. 'foo',
  339. 'forsale',
  340. 'foundation',
  341. 'fr',
  342. 'frl',
  343. 'frogans',
  344. 'fund',
  345. 'furniture',
  346. 'futbol',
  347. 'ga',
  348. 'gal',
  349. 'gallery',
  350. 'gb',
  351. 'gbiz',
  352. 'gd',
  353. 'ge',
  354. 'gent',
  355. 'gf',
  356. 'gg',
  357. 'gh',
  358. 'gi',
  359. 'gift',
  360. 'gifts',
  361. 'gives',
  362. 'gl',
  363. 'glass',
  364. 'gle',
  365. 'global',
  366. 'globo',
  367. 'gm',
  368. 'gmail',
  369. 'gmo',
  370. 'gmx',
  371. 'gn',
  372. 'google',
  373. 'gop',
  374. 'gov',
  375. 'gp',
  376. 'gq',
  377. 'gr',
  378. 'graphics',
  379. 'gratis',
  380. 'green',
  381. 'gripe',
  382. 'gs',
  383. 'gt',
  384. 'gu',
  385. 'guide',
  386. 'guitars',
  387. 'guru',
  388. 'gw',
  389. 'gy',
  390. 'hamburg',
  391. 'haus',
  392. 'healthcare',
  393. 'help',
  394. 'here',
  395. 'hiphop',
  396. 'hiv',
  397. 'hk',
  398. 'hm',
  399. 'hn',
  400. 'holdings',
  401. 'holiday',
  402. 'homes',
  403. 'horse',
  404. 'host',
  405. 'hosting',
  406. 'house',
  407. 'how',
  408. 'hr',
  409. 'ht',
  410. 'hu',
  411. 'ibm',
  412. 'id',
  413. 'ie',
  414. 'il',
  415. 'im',
  416. 'immo',
  417. 'immobilien',
  418. 'in',
  419. 'industries',
  420. 'info',
  421. 'ing',
  422. 'ink',
  423. 'institute',
  424. 'insure',
  425. 'int',
  426. 'international',
  427. 'investments',
  428. 'io',
  429. 'iq',
  430. 'ir',
  431. 'is',
  432. 'it',
  433. 'je',
  434. 'jetzt',
  435. 'jm',
  436. 'jo',
  437. 'jobs',
  438. 'joburg',
  439. 'jp',
  440. 'juegos',
  441. 'kaufen',
  442. 'ke',
  443. 'kg',
  444. 'kh',
  445. 'ki',
  446. 'kim',
  447. 'kitchen',
  448. 'kiwi',
  449. 'km',
  450. 'kn',
  451. 'koeln',
  452. 'kp',
  453. 'kr',
  454. 'krd',
  455. 'kred',
  456. 'kw',
  457. 'ky',
  458. 'kz',
  459. 'la',
  460. 'lacaixa',
  461. 'land',
  462. 'lawyer',
  463. 'lb',
  464. 'lc',
  465. 'lds',
  466. 'lease',
  467. 'legal',
  468. 'lgbt',
  469. 'li',
  470. 'life',
  471. 'lighting',
  472. 'limited',
  473. 'limo',
  474. 'link',
  475. 'lk',
  476. 'loans',
  477. 'london',
  478. 'lotto',
  479. 'lr',
  480. 'ls',
  481. 'lt',
  482. 'ltda',
  483. 'lu',
  484. 'luxe',
  485. 'luxury',
  486. 'lv',
  487. 'ly',
  488. 'ma',
  489. 'madrid',
  490. 'maison',
  491. 'management',
  492. 'mango',
  493. 'market',
  494. 'marketing',
  495. 'mc',
  496. 'md',
  497. 'me',
  498. 'media',
  499. 'meet',
  500. 'melbourne',
  501. 'meme',
  502. 'memorial',
  503. 'menu',
  504. 'mg',
  505. 'mh',
  506. 'miami',
  507. 'mil',
  508. 'mini',
  509. 'mk',
  510. 'ml',
  511. 'mm',
  512. 'mn',
  513. 'mo',
  514. 'mobi',
  515. 'moda',
  516. 'moe',
  517. 'monash',
  518. 'money',
  519. 'mormon',
  520. 'mortgage',
  521. 'moscow',
  522. 'motorcycles',
  523. 'mov',
  524. 'mp',
  525. 'mq',
  526. 'mr',
  527. 'ms',
  528. 'mt',
  529. 'mu',
  530. 'museum',
  531. 'mv',
  532. 'mw',
  533. 'mx',
  534. 'my',
  535. 'mz',
  536. 'na',
  537. 'nagoya',
  538. 'name',
  539. 'navy',
  540. 'nc',
  541. 'ne',
  542. 'net',
  543. 'network',
  544. 'neustar',
  545. 'new',
  546. 'nexus',
  547. 'nf',
  548. 'ng',
  549. 'ngo',
  550. 'nhk',
  551. 'ni',
  552. 'ninja',
  553. 'nl',
  554. 'no',
  555. 'np',
  556. 'nr',
  557. 'nra',
  558. 'nrw',
  559. 'nu',
  560. 'nyc',
  561. 'nz',
  562. 'okinawa',
  563. 'om',
  564. 'ong',
  565. 'onl',
  566. 'ooo',
  567. 'org',
  568. 'organic',
  569. 'otsuka',
  570. 'ovh',
  571. 'pa',
  572. 'paris',
  573. 'partners',
  574. 'parts',
  575. 'party',
  576. 'pe',
  577. 'pf',
  578. 'pg',
  579. 'ph',
  580. 'pharmacy',
  581. 'photo',
  582. 'photography',
  583. 'photos',
  584. 'physio',
  585. 'pics',
  586. 'pictures',
  587. 'pink',
  588. 'pizza',
  589. 'pk',
  590. 'pl',
  591. 'place',
  592. 'plumbing',
  593. 'pm',
  594. 'pn',
  595. 'pohl',
  596. 'poker',
  597. 'post',
  598. 'pr',
  599. 'praxi',
  600. 'press',
  601. 'pro',
  602. 'prod',
  603. 'productions',
  604. 'prof',
  605. 'properties',
  606. 'property',
  607. 'ps',
  608. 'pt',
  609. 'pub',
  610. 'pw',
  611. 'py',
  612. 'qa',
  613. 'qpon',
  614. 'quebec',
  615. 're',
  616. 'realtor',
  617. 'recipes',
  618. 'red',
  619. 'rehab',
  620. 'reise',
  621. 'reisen',
  622. 'reit',
  623. 'ren',
  624. 'rentals',
  625. 'repair',
  626. 'report',
  627. 'republican',
  628. 'rest',
  629. 'restaurant',
  630. 'reviews',
  631. 'rich',
  632. 'rio',
  633. 'rip',
  634. 'ro',
  635. 'rocks',
  636. 'rodeo',
  637. 'rs',
  638. 'rsvp',
  639. 'ru',
  640. 'ruhr',
  641. 'rw',
  642. 'ryukyu',
  643. 'sa',
  644. 'saarland',
  645. 'sarl',
  646. 'sb',
  647. 'sc',
  648. 'sca',
  649. 'scb',
  650. 'schmidt',
  651. 'schule',
  652. 'science',
  653. 'scot',
  654. 'sd',
  655. 'se',
  656. 'services',
  657. 'sexy',
  658. 'sg',
  659. 'sh',
  660. 'shiksha',
  661. 'shoes',
  662. 'si',
  663. 'singles',
  664. 'sj',
  665. 'sk',
  666. 'sl',
  667. 'sm',
  668. 'sn',
  669. 'so',
  670. 'social',
  671. 'software',
  672. 'sohu',
  673. 'solar',
  674. 'solutions',
  675. 'soy',
  676. 'space',
  677. 'spiegel',
  678. 'sr',
  679. 'st',
  680. 'su',
  681. 'supplies',
  682. 'supply',
  683. 'support',
  684. 'surf',
  685. 'surgery',
  686. 'suzuki',
  687. 'sv',
  688. 'sx',
  689. 'sy',
  690. 'sydney',
  691. 'systems',
  692. 'sz',
  693. 'taipei',
  694. 'tatar',
  695. 'tattoo',
  696. 'tax',
  697. 'tc',
  698. 'td',
  699. 'technology',
  700. 'tel',
  701. 'tf',
  702. 'tg',
  703. 'th',
  704. 'tienda',
  705. 'tips',
  706. 'tirol',
  707. 'tj',
  708. 'tk',
  709. 'tl',
  710. 'tm',
  711. 'tn',
  712. 'to',
  713. 'today',
  714. 'tokyo',
  715. 'tools',
  716. 'top',
  717. 'town',
  718. 'toys',
  719. 'tp',
  720. 'tr',
  721. 'trade',
  722. 'training',
  723. 'travel',
  724. 'tt',
  725. 'tui',
  726. 'tv',
  727. 'tw',
  728. 'tz',
  729. 'ua',
  730. 'ug',
  731. 'uk',
  732. 'university',
  733. 'uno',
  734. 'uol',
  735. 'us',
  736. 'uy',
  737. 'uz',
  738. 'va',
  739. 'vacations',
  740. 'vc',
  741. 've',
  742. 'vegas',
  743. 'ventures',
  744. 'versicherung',
  745. 'vet',
  746. 'vg',
  747. 'vi',
  748. 'viajes',
  749. 'villas',
  750. 'vision',
  751. 'vlaanderen',
  752. 'vn',
  753. 'vodka',
  754. 'vote',
  755. 'voting',
  756. 'voto',
  757. 'voyage',
  758. 'vu',
  759. 'wales',
  760. 'wang',
  761. 'watch',
  762. 'webcam',
  763. 'website',
  764. 'wed',
  765. 'wedding',
  766. 'wf',
  767. 'whoswho',
  768. 'wien',
  769. 'wiki',
  770. 'williamhill',
  771. 'wme',
  772. 'work',
  773. 'works',
  774. 'world',
  775. 'ws',
  776. 'wtc',
  777. 'wtf',
  778. 'xn--1qqw23a',
  779. 'xn--3bst00m',
  780. 'xn--3ds443g',
  781. 'xn--3e0b707e',
  782. 'xn--45brj9c',
  783. 'xn--45q11c',
  784. 'xn--4gbrim',
  785. 'xn--55qw42g',
  786. 'xn--55qx5d',
  787. 'xn--6frz82g',
  788. 'xn--6qq986b3xl',
  789. 'xn--80adxhks',
  790. 'xn--80ao21a',
  791. 'xn--80asehdb',
  792. 'xn--80aswg',
  793. 'xn--90a3ac',
  794. 'xn--c1avg',
  795. 'xn--cg4bki',
  796. 'xn--clchc0ea0b2g2a9gcd',
  797. 'xn--czr694b',
  798. 'xn--czru2d',
  799. 'xn--d1acj3b',
  800. 'xn--d1alf',
  801. 'xn--fiq228c5hs',
  802. 'xn--fiq64b',
  803. 'xn--fiqs8s',
  804. 'xn--fiqz9s',
  805. 'xn--flw351e',
  806. 'xn--fpcrj9c3d',
  807. 'xn--fzc2c9e2c',
  808. 'xn--gecrj9c',
  809. 'xn--h2brj9c',
  810. 'xn--i1b6b1a6a2e',
  811. 'xn--io0a7i',
  812. 'xn--j1amh',
  813. 'xn--j6w193g',
  814. 'xn--kprw13d',
  815. 'xn--kpry57d',
  816. 'xn--kput3i',
  817. 'xn--l1acc',
  818. 'xn--lgbbat1ad8j',
  819. 'xn--mgb9awbf',
  820. 'xn--mgba3a4f16a',
  821. 'xn--mgbaam7a8h',
  822. 'xn--mgbab2bd',
  823. 'xn--mgbayh7gpa',
  824. 'xn--mgbbh1a71e',
  825. 'xn--mgbc0a9azcg',
  826. 'xn--mgberp4a5d4ar',
  827. 'xn--mgbx4cd0ab',
  828. 'xn--ngbc5azd',
  829. 'xn--node',
  830. 'xn--nqv7f',
  831. 'xn--nqv7fs00ema',
  832. 'xn--o3cw4h',
  833. 'xn--ogbpf8fl',
  834. 'xn--p1acf',
  835. 'xn--p1ai',
  836. 'xn--pgbs0dh',
  837. 'xn--q9jyb4c',
  838. 'xn--qcka1pmc',
  839. 'xn--rhqv96g',
  840. 'xn--s9brj9c',
  841. 'xn--ses554g',
  842. 'xn--unup4y',
  843. 'xn--vermgensberater-ctb',
  844. 'xn--vermgensberatung-pwb',
  845. 'xn--vhquv',
  846. 'xn--wgbh1c',
  847. 'xn--wgbl6a',
  848. 'xn--xhq521b',
  849. 'xn--xkc2al3hye2a',
  850. 'xn--xkc2dl3a5ee0h',
  851. 'xn--yfro4i67o',
  852. 'xn--ygbi2ammx',
  853. 'xn--zfr164b',
  854. 'xxx',
  855. 'xyz',
  856. 'yachts',
  857. 'yandex',
  858. 'ye',
  859. 'yoga',
  860. 'yokohama',
  861. 'youtube',
  862. 'yt',
  863. 'za',
  864. 'zip',
  865. 'zm',
  866. 'zone',
  867. 'zw',
  868. '测试',
  869. 'परीक्षा',
  870. '佛山',
  871. '集团',
  872. '在线',
  873. '한국',
  874. 'ভারত',
  875. '八卦',
  876. 'موقع',
  877. 'বাংলা',
  878. '公益',
  879. '公司',
  880. '移动',
  881. '我爱你',
  882. 'москва',
  883. 'испытание',
  884. 'қаз',
  885. 'онлайн',
  886. 'сайт',
  887. 'срб',
  888. 'бел',
  889. '테스트',
  890. 'орг',
  891. '삼성',
  892. 'சிங்கப்பூர்',
  893. '商标',
  894. '商城',
  895. 'дети',
  896. 'мкд',
  897. 'טעסט',
  898. '中文网',
  899. '中信',
  900. '中国',
  901. '中國',
  902. '谷歌',
  903. 'భారత్',
  904. 'ලංකා',
  905. '測試',
  906. 'ભારત',
  907. 'भारत',
  908. 'آزمایشی',
  909. 'பரிட்சை',
  910. 'संगठन',
  911. '网络',
  912. 'укр',
  913. '香港',
  914. 'δοκιμή',
  915. 'إختبار',
  916. '台湾',
  917. '台灣',
  918. '手机',
  919. 'мон',
  920. 'الجزائر',
  921. 'عمان',
  922. 'ایران',
  923. 'امارات',
  924. 'بازار',
  925. 'پاکستان',
  926. 'الاردن',
  927. 'بھارت',
  928. 'المغرب',
  929. 'السعودية',
  930. 'سودان',
  931. 'عراق',
  932. 'مليسيا',
  933. 'شبكة',
  934. 'გე',
  935. '机构',
  936. '组织机构',
  937. 'ไทย',
  938. 'سورية',
  939. 'рус',
  940. 'рф',
  941. 'تونس',
  942. 'みんな',
  943. 'グーグル',
  944. '世界',
  945. 'ਭਾਰਤ',
  946. '网址',
  947. '游戏',
  948. 'vermögensberater',
  949. 'vermögensberatung',
  950. '企业',
  951. 'مصر',
  952. 'قطر',
  953. '广东',
  954. 'இலங்கை',
  955. 'இந்தியா',
  956. 'հայ',
  957. '新加坡',
  958. 'فلسطين',
  959. 'テスト',
  960. '政务',
  961. );
  962. /**
  963. * @var string
  964. */
  965. protected $_tld;
  966. /**
  967. * Array for valid Idns
  968. * @see http://www.iana.org/domains/idn-tables/ Official list of supported IDN Chars
  969. * (.AC) Ascension Island http://www.nic.ac/pdf/AC-IDN-Policy.pdf
  970. * (.AR) Argentinia http://www.nic.ar/faqidn.html
  971. * (.AS) American Samoa http://www.nic.as/idn/chars.cfm
  972. * (.AT) Austria http://www.nic.at/en/service/technical_information/idn/charset_converter/
  973. * (.BIZ) International http://www.iana.org/domains/idn-tables/
  974. * (.BR) Brazil http://registro.br/faq/faq6.html
  975. * (.BV) Bouvett Island http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html
  976. * (.CA) Canada http://www.iana.org/domains/idn-tables/tables/ca_fr_1.0.html
  977. * (.CAT) Catalan http://www.iana.org/domains/idn-tables/tables/cat_ca_1.0.html
  978. * (.CH) Switzerland https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1
  979. * (.CL) Chile http://www.iana.org/domains/idn-tables/tables/cl_latn_1.0.html
  980. * (.COM) International http://www.verisign.com/information-services/naming-services/internationalized-domain-names/index.html
  981. * (.DE) Germany http://www.denic.de/en/domains/idns/liste.html
  982. * (.DK) Danmark http://www.dk-hostmaster.dk/index.php?id=151
  983. * (.ES) Spain https://www.nic.es/media/2008-05/1210147705287.pdf
  984. * (.FI) Finland http://www.ficora.fi/en/index/palvelut/fiverkkotunnukset/aakkostenkaytto.html
  985. * (.GR) Greece https://grweb.ics.forth.gr/CharacterTable1_en.jsp
  986. * (.HU) Hungary http://www.domain.hu/domain/English/szabalyzat/szabalyzat.html
  987. * (.INFO) International http://www.nic.info/info/idn
  988. * (.IO) British Indian Ocean Territory http://www.nic.io/IO-IDN-Policy.pdf
  989. * (.IR) Iran http://www.nic.ir/Allowable_Characters_dot-iran
  990. * (.IS) Iceland http://www.isnic.is/domain/rules.php
  991. * (.KR) Korea http://www.iana.org/domains/idn-tables/tables/kr_ko-kr_1.0.html
  992. * (.LI) Liechtenstein https://nic.switch.ch/reg/ocView.action?res=EF6GW2JBPVTG67DLNIQXU234MN6SC33JNQQGI7L6#anhang1
  993. * (.LT) Lithuania http://www.domreg.lt/static/doc/public/idn_symbols-en.pdf
  994. * (.MD) Moldova http://www.register.md/
  995. * (.MUSEUM) International http://www.iana.org/domains/idn-tables/tables/museum_latn_1.0.html
  996. * (.NET) International http://www.verisign.com/information-services/naming-services/internationalized-domain-names/index.html
  997. * (.NO) Norway http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html
  998. * (.NU) Niue http://www.worldnames.net/
  999. * (.ORG) International http://www.pir.org/index.php?db=content/FAQs&tbl=FAQs_Registrant&id=2
  1000. * (.PE) Peru https://www.nic.pe/nuevas_politicas_faq_2.php
  1001. * (.PL) Poland http://www.dns.pl/IDN/allowed_character_sets.pdf
  1002. * (.PR) Puerto Rico http://www.nic.pr/idn_rules.asp
  1003. * (.PT) Portugal https://online.dns.pt/dns_2008/do?com=DS;8216320233;111;+PAGE(4000058)+K-CAT-CODIGO(C.125)+RCNT(100);
  1004. * (.RU) Russia http://www.iana.org/domains/idn-tables/tables/ru_ru-ru_1.0.html
  1005. * (.RS) Serbia http://www.iana.org/domains/idn-tables/tables/rs_sr-rs_1.0.pdf
  1006. * (.SA) Saudi Arabia http://www.iana.org/domains/idn-tables/tables/sa_ar_1.0.html
  1007. * (.SE) Sweden http://www.iis.se/english/IDN_campaignsite.shtml?lang=en
  1008. * (.SH) Saint Helena http://www.nic.sh/SH-IDN-Policy.pdf
  1009. * (.SJ) Svalbard and Jan Mayen http://www.norid.no/domeneregistrering/idn/idn_nyetegn.en.html
  1010. * (.TH) Thailand http://www.iana.org/domains/idn-tables/tables/th_th-th_1.0.html
  1011. * (.TM) Turkmenistan http://www.nic.tm/TM-IDN-Policy.pdf
  1012. * (.TR) Turkey https://www.nic.tr/index.php
  1013. * (.UA) Ukraine http://www.iana.org/domains/idn-tables/tables/ua_cyrl_1.2.html
  1014. * (.VE) Venice http://www.iana.org/domains/idn-tables/tables/ve_es_1.0.html
  1015. * (.VN) Vietnam http://www.vnnic.vn/english/5-6-300-2-2-04-20071115.htm#1.%20Introduction
  1016. *
  1017. * @var array
  1018. */
  1019. protected $_validIdns = array(
  1020. 'AC' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēėęěĝġģĥħīįĵķĺļľŀłńņňŋőœŕŗřśŝşšţťŧūŭůűųŵŷźżž]{1,63}$/iu'),
  1021. 'AR' => array(1 => '/^[\x{002d}0-9a-zà-ãç-êìíñ-õü]{1,63}$/iu'),
  1022. 'AS' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĸĺļľłńņňŋōŏőœŕŗřśŝşšţťŧũūŭůűųŵŷźż]{1,63}$/iu'),
  1023. 'AT' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœšž]{1,63}$/iu'),
  1024. 'BIZ' => 'Hostname/Biz.php',
  1025. 'BR' => array(1 => '/^[\x{002d}0-9a-zà-ãçéíó-õúü]{1,63}$/iu'),
  1026. 'BV' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'),
  1027. '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'),
  1028. 'CAT' => array(1 => '/^[\x{002d}0-9a-z·àç-éíïòóúü]{1,63}$/iu'),
  1029. 'CH' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœ]{1,63}$/iu'),
  1030. 'CL' => array(1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'),
  1031. 'CN' => 'Hostname/Cn.php',
  1032. 'COM' => 'Hostname/Com.php',
  1033. 'DE' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'),
  1034. 'DK' => array(1 => '/^[\x{002d}0-9a-zäéöüæøå]{1,63}$/iu'),
  1035. 'ES' => array(1 => '/^[\x{002d}0-9a-zàáçèéíïñòóúü·]{1,63}$/iu'),
  1036. 'EU' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿ]{1,63}$/iu',
  1037. 2 => '/^[\x{002d}0-9a-zāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĺļľŀłńņňʼnŋōŏőœŕŗřśŝšťŧũūŭůűųŵŷźżž]{1,63}$/iu',
  1038. 3 => '/^[\x{002d}0-9a-zșț]{1,63}$/iu',
  1039. 4 => '/^[\x{002d}0-9a-zΐάέήίΰαβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ]{1,63}$/iu',
  1040. 5 => '/^[\x{002d}0-9a-zабвгдежзийклмнопрстуфхцчшщъыьэюя]{1,63}$/iu',
  1041. 6 => '/^[\x{002d}0-9a-zἀ-ἇἐ-ἕἠ-ἧἰ-ἷὀ-ὅὐ-ὗὠ-ὧὰ-ὼώᾀ-ᾇᾐ-ᾗᾠ-ᾧᾰ-ᾴᾶᾷῂῃῄῆῇῐ-ῒΐῖῗῠ-ῧῲῳῴῶῷ]{1,63}$/iu'),
  1042. 'FI' => array(1 => '/^[\x{002d}0-9a-zäåö]{1,63}$/iu'),
  1043. 'GR' => array(1 => '/^[\x{002d}0-9a-zΆΈΉΊΌΎ-ΡΣ-ώἀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼῂῃῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲῳῴῶ-ῼ]{1,63}$/iu'),
  1044. 'HK' => 'Hostname/Cn.php',
  1045. 'HU' => array(1 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu'),
  1046. 'IL' => array(1 => '/^[\x{002d}0-9\x{05D0}-\x{05EA}]{1,63}$/iu',
  1047. 2 => '/^[\x{002d}0-9a-z]{1,63}$/i'),
  1048. 'INFO'=> array(1 => '/^[\x{002d}0-9a-zäåæéöøü]{1,63}$/iu',
  1049. 2 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu',
  1050. 3 => '/^[\x{002d}0-9a-záæéíðóöúýþ]{1,63}$/iu',
  1051. 4 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu',
  1052. 5 => '/^[\x{002d}0-9a-zāčēģīķļņōŗšūž]{1,63}$/iu',
  1053. 6 => '/^[\x{002d}0-9a-ząčėęįšūųž]{1,63}$/iu',
  1054. 7 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu',
  1055. 8 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu'),
  1056. 'IO' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'),
  1057. 'IS' => array(1 => '/^[\x{002d}0-9a-záéýúíóþæöð]{1,63}$/iu'),
  1058. 'IT' => array(1 => '/^[\x{002d}0-9a-zàâäèéêëìîïòôöùûüæœçÿß-]{1,63}$/iu'),
  1059. 'JP' => 'Hostname/Jp.php',
  1060. 'KR' => array(1 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu'),
  1061. 'LI' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿœ]{1,63}$/iu'),
  1062. 'LT' => array(1 => '/^[\x{002d}0-9ąčęėįšųūž]{1,63}$/iu'),
  1063. 'MD' => array(1 => '/^[\x{002d}0-9ăâîşţ]{1,63}$/iu'),
  1064. 'MUSEUM' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćċčďđēėęěğġģħīįıķĺļľłńņňŋōőœŕŗřśşšţťŧūůűųŵŷźżžǎǐǒǔ\x{01E5}\x{01E7}\x{01E9}\x{01EF}ə\x{0292}ẁẃẅỳ]{1,63}$/iu'),
  1065. 'NET' => 'Hostname/Com.php',
  1066. 'NO' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'),
  1067. 'NU' => 'Hostname/Com.php',
  1068. 'ORG' => array(1 => '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu',
  1069. 2 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu',
  1070. 3 => '/^[\x{002d}0-9a-záäåæéëíðóöøúüýþ]{1,63}$/iu',
  1071. 4 => '/^[\x{002d}0-9a-záéíóöúüőű]{1,63}$/iu',
  1072. 5 => '/^[\x{002d}0-9a-ząčėęįšūųž]{1,63}$/iu',
  1073. 6 => '/^[\x{AC00}-\x{D7A3}]{1,17}$/iu',
  1074. 7 => '/^[\x{002d}0-9a-zāčēģīķļņōŗšūž]{1,63}$/iu'),
  1075. 'PE' => array(1 => '/^[\x{002d}0-9a-zñáéíóúü]{1,63}$/iu'),
  1076. 'PL' => array(1 => '/^[\x{002d}0-9a-zāčēģīķļņōŗšūž]{1,63}$/iu',
  1077. 2 => '/^[\x{002d}а-ик-ш\x{0450}ѓѕјљњќџ]{1,63}$/iu',
  1078. 3 => '/^[\x{002d}0-9a-zâîăşţ]{1,63}$/iu',
  1079. 4 => '/^[\x{002d}0-9а-яё\x{04C2}]{1,63}$/iu',
  1080. 5 => '/^[\x{002d}0-9a-zàáâèéêìíîòóôùúûċġħż]{1,63}$/iu',
  1081. 6 => '/^[\x{002d}0-9a-zàäåæéêòóôöøü]{1,63}$/iu',
  1082. 7 => '/^[\x{002d}0-9a-zóąćęłńśźż]{1,63}$/iu',
  1083. 8 => '/^[\x{002d}0-9a-zàáâãçéêíòóôõúü]{1,63}$/iu',
  1084. 9 => '/^[\x{002d}0-9a-zâîăşţ]{1,63}$/iu',
  1085. 10=> '/^[\x{002d}0-9a-záäéíóôúýčďĺľňŕšťž]{1,63}$/iu',
  1086. 11=> '/^[\x{002d}0-9a-zçë]{1,63}$/iu',
  1087. 12=> '/^[\x{002d}0-9а-ик-шђјљњћџ]{1,63}$/iu',
  1088. 13=> '/^[\x{002d}0-9a-zćčđšž]{1,63}$/iu',
  1089. 14=> '/^[\x{002d}0-9a-zâçöûüğış]{1,63}$/iu',
  1090. 15=> '/^[\x{002d}0-9a-záéíñóúü]{1,63}$/iu',
  1091. 16=> '/^[\x{002d}0-9a-zäõöüšž]{1,63}$/iu',
  1092. 17=> '/^[\x{002d}0-9a-zĉĝĥĵŝŭ]{1,63}$/iu',
  1093. 18=> '/^[\x{002d}0-9a-zâäéëîô]{1,63}$/iu',
  1094. 19=> '/^[\x{002d}0-9a-zàáâäåæçèéêëìíîïðñòôöøùúûüýćčłńřśš]{1,63}$/iu',
  1095. 20=> '/^[\x{002d}0-9a-zäåæõöøüšž]{1,63}$/iu',
  1096. 21=> '/^[\x{002d}0-9a-zàáçèéìíòóùú]{1,63}$/iu',
  1097. 22=> '/^[\x{002d}0-9a-zàáéíóöúüőű]{1,63}$/iu',
  1098. 23=> '/^[\x{002d}0-9ΐά-ώ]{1,63}$/iu',
  1099. 24=> '/^[\x{002d}0-9a-zàáâåæçèéêëðóôöøüþœ]{1,63}$/iu',
  1100. 25=> '/^[\x{002d}0-9a-záäéíóöúüýčďěňřšťůž]{1,63}$/iu',
  1101. 26=> '/^[\x{002d}0-9a-z·àçèéíïòóúü]{1,63}$/iu',
  1102. 27=> '/^[\x{002d}0-9а-ъьюя\x{0450}\x{045D}]{1,63}$/iu',
  1103. 28=> '/^[\x{002d}0-9а-яёіў]{1,63}$/iu',
  1104. 29=> '/^[\x{002d}0-9a-ząčėęįšūųž]{1,63}$/iu',
  1105. 30=> '/^[\x{002d}0-9a-záäåæéëíðóöøúüýþ]{1,63}$/iu',
  1106. 31=> '/^[\x{002d}0-9a-zàâæçèéêëîïñôùûüÿœ]{1,63}$/iu',
  1107. 32=> '/^[\x{002d}0-9а-щъыьэюяёєіїґ]{1,63}$/iu',
  1108. 33=> '/^[\x{002d}0-9א-ת]{1,63}$/iu'),
  1109. 'PR' => array(1 => '/^[\x{002d}0-9a-záéíóúñäëïüöâêîôûàèùæçœãõ]{1,63}$/iu'),
  1110. 'PT' => array(1 => '/^[\x{002d}0-9a-záàâãçéêíóôõú]{1,63}$/iu'),
  1111. '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)'),
  1112. 'RU' => array(1 => '/^[\x{002d}0-9а-яё]{1,63}$/iu'),
  1113. 'SA' => array(1 => '/^[\x{002d}.0-9\x{0621}-\x{063A}\x{0641}-\x{064A}\x{0660}-\x{0669}]{1,63}$/iu'),
  1114. 'SE' => array(1 => '/^[\x{002d}0-9a-zäåéöü]{1,63}$/iu'),
  1115. 'SH' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿăąāćĉčċďđĕěėęēğĝġģĥħĭĩįīıĵķĺľļłńňņŋŏőōœĸŕřŗśŝšşťţŧŭůűũųūŵŷźžż]{1,63}$/iu'),
  1116. 'SI' => array(
  1117. 1 => '/^[\x{002d}0-9a-zà-öø-ÿ]{1,63}$/iu',
  1118. 2 => '/^[\x{002d}0-9a-zāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĺļľŀłńņňʼnŋōŏőœŕŗřśŝšťŧũūŭůűųŵŷźżž]{1,63}$/iu',
  1119. 3 => '/^[\x{002d}0-9a-zșț]{1,63}$/iu'),
  1120. 'SJ' => array(1 => '/^[\x{002d}0-9a-zàáä-éêñ-ôöøüčđńŋšŧž]{1,63}$/iu'),
  1121. 'TH' => array(1 => '/^[\x{002d}0-9a-z\x{0E01}-\x{0E3A}\x{0E40}-\x{0E4D}\x{0E50}-\x{0E59}]{1,63}$/iu'),
  1122. 'TM' => array(1 => '/^[\x{002d}0-9a-zà-öø-ÿāăąćĉċčďđēėęěĝġģĥħīįĵķĺļľŀłńņňŋőœŕŗřśŝşšţťŧūŭůűųŵŷźżž]{1,63}$/iu'),
  1123. 'TW' => 'Hostname/Cn.php',
  1124. 'TR' => array(1 => '/^[\x{002d}0-9a-zğıüşöç]{1,63}$/iu'),
  1125. 'UA' => array(1 => '/^[\x{002d}0-9a-zабвгдежзийклмнопрстуфхцчшщъыьэюяѐёђѓєѕіїјљњћќѝўџґӂʼ]{1,63}$/iu'),
  1126. 'VE' => array(1 => '/^[\x{002d}0-9a-záéíóúüñ]{1,63}$/iu'),
  1127. 'VN' => array(1 => '/^[ÀÁÂÃÈÉÊÌÍÒÓÔÕÙÚÝàáâãèéêìíòóôõùúýĂăĐđĨĩŨũƠơƯư\x{1EA0}-\x{1EF9}]{1,63}$/iu'),
  1128. 'мон' => array(1 => '/^[\x{002d}0-9\x{0430}-\x{044F}]{1,63}$/iu'),
  1129. 'срб' => array(1 => '/^[\x{002d}0-9а-ик-шђјљњћџ]{1,63}$/iu'),
  1130. 'сайт' => array(1 => '/^[\x{002d}0-9а-яёіїѝйўґг]{1,63}$/iu'),
  1131. 'онлайн' => array(1 => '/^[\x{002d}0-9а-яёіїѝйўґг]{1,63}$/iu'),
  1132. '中国' => 'Hostname/Cn.php',
  1133. '中國' => 'Hostname/Cn.php',
  1134. 'ලංකා' => array(1 => '/^[\x{0d80}-\x{0dff}]{1,63}$/iu'),
  1135. '香港' => 'Hostname/Cn.php',
  1136. '台湾' => 'Hostname/Cn.php',
  1137. '台灣' => 'Hostname/Cn.php',
  1138. 'امارات' => 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'),
  1139. 'الاردن' => 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'),
  1140. 'السعودية' => 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'),
  1141. 'ไทย' => array(1 => '/^[\x{002d}0-9a-z\x{0E01}-\x{0E3A}\x{0E40}-\x{0E4D}\x{0E50}-\x{0E59}]{1,63}$/iu'),
  1142. 'рф' => array(1 => '/^[\x{002d}0-9а-яё]{1,63}$/iu'),
  1143. 'تونس' => 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'),
  1144. 'مصر' => 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'),
  1145. 'இலங்கை' => array(1 => '/^[\x{0b80}-\x{0bff}]{1,63}$/iu'),
  1146. 'فلسطين' => 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'),
  1147. 'شبكة' => 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'),
  1148. );
  1149. protected $_idnLength = array(
  1150. 'BIZ' => array(5 => 17, 11 => 15, 12 => 20),
  1151. 'CN' => array(1 => 20),
  1152. 'COM' => array(3 => 17, 5 => 20),
  1153. 'HK' => array(1 => 15),
  1154. 'INFO'=> array(4 => 17),
  1155. 'KR' => array(1 => 17),
  1156. 'NET' => array(3 => 17, 5 => 20),
  1157. 'ORG' => array(6 => 17),
  1158. 'TW' => array(1 => 20),
  1159. 'ایران' => array(1 => 30),
  1160. '中国' => array(1 => 20),
  1161. '公司' => array(1 => 20),
  1162. '网络' => array(1 => 20),
  1163. );
  1164. protected $_options = array(
  1165. 'allow' => self::ALLOW_DNS,
  1166. 'idn' => true,
  1167. 'tld' => true,
  1168. 'ip' => null
  1169. );
  1170. /**
  1171. * Sets validator options
  1172. *
  1173. * @see http://www.iana.org/cctld/specifications-policies-cctlds-01apr02.htm Technical Specifications for ccTLDs
  1174. * @param array $options Validator options
  1175. */
  1176. public function __construct($options = array())
  1177. {
  1178. if ($options instanceof Zend_Config) {
  1179. $options = $options->toArray();
  1180. } else if (!is_array($options)) {
  1181. $options = func_get_args();
  1182. $temp['allow'] = array_shift($options);
  1183. if (!empty($options)) {
  1184. $temp['idn'] = array_shift($options);
  1185. }
  1186. if (!empty($options)) {
  1187. $temp['tld'] = array_shift($options);
  1188. }
  1189. if (!empty($options)) {
  1190. $temp['ip'] = array_shift($options);
  1191. }
  1192. $options = $temp;
  1193. }
  1194. $options += $this->_options;
  1195. $this->setOptions($options);
  1196. }
  1197. /**
  1198. * Returns all set options
  1199. *
  1200. * @return array
  1201. */
  1202. public function getOptions()
  1203. {
  1204. return $this->_options;
  1205. }
  1206. /**
  1207. * Sets the options for this validator
  1208. *
  1209. * @param array $options
  1210. * @return Zend_Validate_Hostname
  1211. */
  1212. public function setOptions($options)
  1213. {
  1214. if (array_key_exists('allow', $options)) {
  1215. $this->setAllow($options['allow']);
  1216. }
  1217. if (array_key_exists('idn', $options)) {
  1218. $this->setValidateIdn($options['idn']);
  1219. }
  1220. if (array_key_exists('tld', $options)) {
  1221. $this->setValidateTld($options['tld']);
  1222. }
  1223. if (array_key_exists('ip', $options)) {
  1224. $this->setIpValidator($options['ip']);
  1225. }
  1226. return $this;
  1227. }
  1228. /**
  1229. * Returns the set ip validator
  1230. *
  1231. * @return Zend_Validate_Ip
  1232. */
  1233. public function getIpValidator()
  1234. {
  1235. return $this->_options['ip'];
  1236. }
  1237. /**
  1238. * @param Zend_Validate_Ip $ipValidator OPTIONAL
  1239. * @return Zend_Validate_Hostname
  1240. */
  1241. public function setIpValidator(Zend_Validate_Ip $ipValidator = null)
  1242. {
  1243. if ($ipValidator === null) {
  1244. $ipValidator = new Zend_Validate_Ip();
  1245. }
  1246. $this->_options['ip'] = $ipValidator;
  1247. return $this;
  1248. }
  1249. /**
  1250. * Returns the allow option
  1251. *
  1252. * @return integer
  1253. */
  1254. public function getAllow()
  1255. {
  1256. return $this->_options['allow'];
  1257. }
  1258. /**
  1259. * Sets the allow option
  1260. *
  1261. * @param integer $allow
  1262. * @return Zend_Validate_Hostname Provides a fluent interface
  1263. */
  1264. public function setAllow($allow)
  1265. {
  1266. $this->_options['allow'] = $allow;
  1267. return $this;
  1268. }
  1269. /**
  1270. * Returns the set idn option
  1271. *
  1272. * @return boolean
  1273. */
  1274. public function getValidateIdn()
  1275. {
  1276. return $this->_options['idn'];
  1277. }
  1278. /**
  1279. * Set whether IDN domains are validated
  1280. *
  1281. * This only applies when DNS hostnames are validated
  1282. *
  1283. * @param boolean $allowed Set allowed to true to validate IDNs, and false to not validate them
  1284. * @return $this
  1285. */
  1286. public function setValidateIdn ($allowed)
  1287. {
  1288. $this->_options['idn'] = (bool) $allowed;
  1289. return $this;
  1290. }
  1291. /**
  1292. * Returns the set tld option
  1293. *
  1294. * @return boolean
  1295. */
  1296. public function getValidateTld()
  1297. {
  1298. return $this->_options['tld'];
  1299. }
  1300. /**
  1301. * Set whether the TLD element of a hostname is validated
  1302. *
  1303. * This only applies when DNS hostnames are validated
  1304. *
  1305. * @param boolean $allowed Set allowed to true to validate TLDs, and false to not validate them
  1306. * @return $this
  1307. */
  1308. public function setValidateTld ($allowed)
  1309. {
  1310. $this->_options['tld'] = (bool) $allowed;
  1311. return $this;
  1312. }
  1313. /**
  1314. * Defined by Zend_Validate_Interface
  1315. *
  1316. * Returns true if and only if the $value is a valid hostname with respect to the current allow option
  1317. *
  1318. * @param string $value
  1319. * @throws Zend_Validate_Exception if a fatal error occurs for validation process
  1320. * @return boolean
  1321. */
  1322. public function isValid($value)
  1323. {
  1324. if (!is_string($value)) {
  1325. $this->_error(self::INVALID);
  1326. return false;
  1327. }
  1328. $this->_setValue($value);
  1329. // Check input against IP address schema
  1330. if (preg_match('/^[0-9a-f:.]*$/i', $value) &&
  1331. $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
  1332. if (!($this->_options['allow'] & self::ALLOW_IP)) {
  1333. $this->_error(self::IP_ADDRESS_NOT_ALLOWED);
  1334. return false;
  1335. } else {
  1336. return true;
  1337. }
  1338. }
  1339. // RFC3986 3.2.2 states:
  1340. //
  1341. // The rightmost domain label of a fully qualified domain name
  1342. // in DNS may be followed by a single "." and should be if it is
  1343. // necessary to distinguish between the complete domain name and
  1344. // some local domain.
  1345. //
  1346. // (see ZF-6363)
  1347. // Local hostnames are allowed to be partitial (ending '.')
  1348. if ($this->_options['allow'] & self::ALLOW_LOCAL) {
  1349. if (substr($value, -1) === '.') {
  1350. $value = substr($value, 0, -1);
  1351. if (substr($value, -1) === '.') {
  1352. // Empty hostnames (ending '..') are not allowed
  1353. $this->_error(self::INVALID_LOCAL_NAME);
  1354. return false;
  1355. }
  1356. }
  1357. }
  1358. $domainParts = explode('.', $value);
  1359. // Prevent partitial IP V4 adresses (ending '.')
  1360. if ((count($domainParts) == 4) && preg_match('/^[0-9.a-e:.]*$/i', $value) &&
  1361. $this->_options['ip']->setTranslator($this->getTranslator())->isValid($value)) {
  1362. $this->_error(self::INVALID_LOCAL_NAME);
  1363. }
  1364. // Check input against DNS hostname schema
  1365. if ((count($domainParts) > 1) && (strlen($value) >= 4) && (strlen($value) <= 254)) {
  1366. $status = false;
  1367. $origenc = PHP_VERSION_ID < 50600
  1368. ? iconv_get_encoding('internal_encoding')
  1369. : ini_get('default_charset');
  1370. if (PHP_VERSION_ID < 50600) {
  1371. iconv_set_encoding('internal_encoding', 'UTF-8');
  1372. } else {
  1373. ini_set('default_charset', 'UTF-8');
  1374. }
  1375. do {
  1376. // First check TLD
  1377. $matches = array();
  1378. if (preg_match('/([^.]{2,63})$/iu', end($domainParts), $matches)
  1379. || (array_key_exists(end($domainParts), $this->_validIdns))) {
  1380. reset($domainParts);
  1381. // Hostname characters are: *(label dot)(label dot label); max 254 chars
  1382. // label: id-prefix [*ldh{61} id-prefix]; max 63 chars
  1383. // id-prefix: alpha / digit
  1384. // ldh: alpha / digit / dash
  1385. // Match TLD against known list
  1386. $this->_tld = $matches[1];
  1387. if ($this->_options['tld']) {
  1388. if (!in_array(strtolower($this->_tld), $this->_validTlds)
  1389. && !in_array($this->_tld, $this->_validTlds)) {
  1390. $this->_error(self::UNKNOWN_TLD);
  1391. $status = false;
  1392. break;
  1393. }
  1394. // We have already validated that the TLD is fine. We don't want it to go through the below
  1395. // checks as new UTF-8 TLDs will incorrectly fail if there is no IDN regex for it.
  1396. array_pop($domainParts);
  1397. }
  1398. /**
  1399. * Match against IDN hostnames
  1400. * Note: Keep label regex short to avoid issues with long patterns when matching IDN hostnames
  1401. * @see Zend_Validate_Hostname_Interface
  1402. */
  1403. $regexChars = array(0 => '/^[a-z0-9\x2d]{1,63}$/i');
  1404. if ($this->_options['idn'] && isset($this->_validIdns[strtoupper($this->_tld)])) {
  1405. if (is_string($this->_validIdns[strtoupper($this->_tld)])) {
  1406. $regexChars += include($this->_validIdns[strtoupper($this->_tld)]);
  1407. } else {
  1408. $regexChars += $this->_validIdns[strtoupper($this->_tld)];
  1409. }
  1410. }
  1411. // Check each hostname part
  1412. $check = 0;
  1413. foreach ($domainParts as $domainPart) {
  1414. // If some domain part is empty (i.e. zend..com), it's invalid
  1415. if (empty($domainPart)) {
  1416. $this->_error(self::INVALID_HOSTNAME);
  1417. return false;
  1418. }
  1419. // Decode Punycode domainnames to IDN
  1420. if (strpos($domainPart, 'xn--') === 0) {
  1421. $domainPart = $this->decodePunycode(substr($domainPart, 4));
  1422. if ($domainPart === false) {
  1423. return false;
  1424. }
  1425. }
  1426. // Check dash (-) does not start, end or appear in 3rd and 4th positions
  1427. if ((strpos($domainPart, '-') === 0)
  1428. || ((strlen($domainPart) > 2) && (strpos($domainPart, '-', 2) == 2) && (strpos($domainPart, '-', 3) == 3))
  1429. || (strpos($domainPart, '-') === (strlen($domainPart) - 1))) {
  1430. $this->_error(self::INVALID_DASH);
  1431. $status = false;
  1432. break 2;
  1433. }
  1434. // Check each domain part
  1435. $checked = false;
  1436. foreach($regexChars as $regexKey => $regexChar) {
  1437. $status = preg_match($regexChar, $domainPart);
  1438. if ($status > 0) {
  1439. $length = 63;
  1440. if (array_key_exists(strtoupper($this->_tld), $this->_idnLength)
  1441. && (array_key_exists($regexKey, $this->_idnLength[strtoupper($this->_tld)]))) {
  1442. $length = $this->_idnLength[strtoupper($this->_tld)];
  1443. }
  1444. if (iconv_strlen($domainPart, 'UTF-8') > $length) {
  1445. $this->_error(self::INVALID_HOSTNAME);
  1446. } else {
  1447. $checked = true;
  1448. break;
  1449. }
  1450. }
  1451. }
  1452. if ($checked) {
  1453. ++$check;
  1454. }
  1455. }
  1456. // If one of the labels doesn't match, the hostname is invalid
  1457. if ($check !== count($domainParts)) {
  1458. $this->_error(self::INVALID_HOSTNAME_SCHEMA);
  1459. $status = false;
  1460. }
  1461. } else {
  1462. // Hostname not long enough
  1463. $this->_error(self::UNDECIPHERABLE_TLD);
  1464. $status = false;
  1465. }
  1466. } while (false);
  1467. if (PHP_VERSION_ID < 50600) {
  1468. iconv_set_encoding('internal_encoding', $origenc);
  1469. } else {
  1470. ini_set('default_charset', $origenc);
  1471. }
  1472. // If the input passes as an Internet domain name, and domain names are allowed, then the hostname
  1473. // passes validation
  1474. if ($status && ($this->_options['allow'] & self::ALLOW_DNS)) {
  1475. return true;
  1476. }
  1477. } else if ($this->_options['allow'] & self::ALLOW_DNS) {
  1478. $this->_error(self::INVALID_HOSTNAME);
  1479. }
  1480. // Check for URI Syntax (RFC3986)
  1481. if ($this->_options['allow'] & self::ALLOW_URI) {
  1482. if (preg_match("/^([a-zA-Z0-9-._~!$&\'()*+,;=]|%[[:xdigit:]]{2}){1,254}$/i", $value)) {
  1483. return true;
  1484. } else {
  1485. $this->_error(self::INVALID_URI);
  1486. }
  1487. }
  1488. // Check input against local network name schema; last chance to pass validation
  1489. $regexLocal = '/^(([a-zA-Z0-9\x2d]{1,63}\x2e)*[a-zA-Z0-9\x2d]{1,63}[\x2e]{0,1}){1,254}$/';
  1490. $status = @preg_match($regexLocal, $value);
  1491. // If the input passes as a local network name, and local network names are allowed, then the
  1492. // hostname passes validation
  1493. $allowLocal = $this->_options['allow'] & self::ALLOW_LOCAL;
  1494. if ($status && $allowLocal) {
  1495. return true;
  1496. }
  1497. // If the input does not pass as a local network name, add a message
  1498. if (!$status) {
  1499. $this->_error(self::INVALID_LOCAL_NAME);
  1500. }
  1501. // If local network names are not allowed, add a message
  1502. if ($status && !$allowLocal) {
  1503. $this->_error(self::LOCAL_NAME_NOT_ALLOWED);
  1504. }
  1505. return false;
  1506. }
  1507. /**
  1508. * Decodes a punycode encoded string to it's original utf8 string
  1509. * In case of a decoding failure the original string is returned
  1510. *
  1511. * @param string $encoded Punycode encoded string to decode
  1512. * @return string
  1513. */
  1514. protected function decodePunycode($encoded)
  1515. {
  1516. if (!preg_match('/^[a-z0-9-]+$/i', $encoded)) {
  1517. // no punycode encoded string
  1518. $this->_error(self::CANNOT_DECODE_PUNYCODE);
  1519. return false;
  1520. }
  1521. $decoded = array();
  1522. $separator = strrpos($encoded, '-');
  1523. if ($separator > 0) {
  1524. for ($x = 0; $x < $separator; ++$x) {
  1525. // prepare decoding matrix
  1526. $decoded[] = ord($encoded[$x]);
  1527. }
  1528. }
  1529. $lengthd = count($decoded);
  1530. $lengthe = strlen($encoded);
  1531. // decoding
  1532. $init = true;
  1533. $base = 72;
  1534. $index = 0;
  1535. $char = 0x80;
  1536. for ($indexe = ($separator) ? ($separator + 1) : 0; $indexe < $lengthe; ++$lengthd) {
  1537. for ($old_index = $index, $pos = 1, $key = 36; 1 ; $key += 36) {
  1538. $hex = ord($encoded[$indexe++]);
  1539. $digit = ($hex - 48 < 10) ? $hex - 22
  1540. : (($hex - 65 < 26) ? $hex - 65
  1541. : (($hex - 97 < 26) ? $hex - 97
  1542. : 36));
  1543. $index += $digit * $pos;
  1544. $tag = ($key <= $base) ? 1 : (($key >= $base + 26) ? 26 : ($key - $base));
  1545. if ($digit < $tag) {
  1546. break;
  1547. }
  1548. $pos = (int) ($pos * (36 - $tag));
  1549. }
  1550. $delta = intval($init ? (($index - $old_index) / 700) : (($index - $old_index) / 2));
  1551. $delta += intval($delta / ($lengthd + 1));
  1552. for ($key = 0; $delta > 910 / 2; $key += 36) {
  1553. $delta = intval($delta / 35);
  1554. }
  1555. $base = intval($key + 36 * $delta / ($delta + 38));
  1556. $init = false;
  1557. $char += (int) ($index / ($lengthd + 1));
  1558. $index %= ($lengthd + 1);
  1559. if ($lengthd > 0) {
  1560. for ($i = $lengthd; $i > $index; $i--) {
  1561. $decoded[$i] = $decoded[($i - 1)];
  1562. }
  1563. }
  1564. $decoded[$index++] = $char;
  1565. }
  1566. // convert decoded ucs4 to utf8 string
  1567. foreach ($decoded as $key => $value) {
  1568. if ($value < 128) {
  1569. $decoded[$key] = chr($value);
  1570. } elseif ($value < (1 << 11)) {
  1571. $decoded[$key] = chr(192 + ($value >> 6));
  1572. $decoded[$key] .= chr(128 + ($value & 63));
  1573. } elseif ($value < (1 << 16)) {
  1574. $decoded[$key] = chr(224 + ($value >> 12));
  1575. $decoded[$key] .= chr(128 + (($value >> 6) & 63));
  1576. $decoded[$key] .= chr(128 + ($value & 63));
  1577. } elseif ($value < (1 << 21)) {
  1578. $decoded[$key] = chr(240 + ($value >> 18));
  1579. $decoded[$key] .= chr(128 + (($value >> 12) & 63));
  1580. $decoded[$key] .= chr(128 + (($value >> 6) & 63));
  1581. $decoded[$key] .= chr(128 + ($value & 63));
  1582. } else {
  1583. $this->_error(self::CANNOT_DECODE_PUNYCODE);
  1584. return false;
  1585. }
  1586. }
  1587. return implode($decoded);
  1588. }
  1589. }