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