Hostname.php 47 KB

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