Hostname.php 57 KB

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