| 1 | |||
| 2 | ################################################################################### | ||
| 3 | # | ||
| 4 | # Embperl - Copyright (c) 1997-2008 Gerald Richter / ecos gmbh www.ecos.de | ||
| 5 | # Embperl - Copyright (c) 2008-2015 Gerald Richter | ||
| 6 | # Embperl - Copyright (c) 2015-2023 actevy.io | ||
| 7 | # | ||
| 8 | # You may distribute under the terms of either the GNU General Public | ||
| 9 | # License or the Artistic License, as specified in the Perl README file. | ||
| 10 | # | ||
| 11 | # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR | ||
| 12 | # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED | ||
| 13 | # WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
| 14 | # | ||
| 15 | # $Id: IPAddr.pm 1578075 2014-03-16 14:01:14Z richter $ | ||
| 16 | # | ||
| 17 | ################################################################################### | ||
| 18 | |||
| 19 | |||
| 20 | package Embperl::Form::Validate::IPv6Addr ; | ||
| 21 | |||
| 22 | use base qw(Embperl::Form::Validate::Default); | ||
| 23 | use utf8 ; | ||
| 24 | |||
| 25 | my %errutf8 = | ||
| 26 | ( | ||
| 27 | validate_ipv6addr => 'Feld %0: "%1" ist keine gültige IPv6-Adresse. Geben Sie die IP-Adresse in der Form n:n:.... ein', | ||
| 28 | ) ; | ||
| 29 | |||
| 30 | no utf8 ; | ||
| 31 | |||
| 32 | my %error_messages = | ||
| 33 | ( | ||
| 34 | de => | ||
| 35 | { | ||
| 36 | validate_ipv6addr => 'Feld %0: "%1" ist keine gültige IPv6-Adresse. Geben Sie die IP-Adresse in der Form n:n:.... ein', | ||
| 37 | }, | ||
| 38 | |||
| 39 | 'de.utf-8' => \%errutf8, | ||
| 40 | |||
| 41 | en => | ||
| 42 | { | ||
| 43 | validate_ipv6addr => 'Field %0: "%1" isn\\\'t a valid ipv6-address. Please enter the ip-address as n:n:....', | ||
| 44 | } | ||
| 45 | ); | ||
| 46 | |||
| 47 | # -------------------------------------------------------------- | ||
| 48 | |||
| 49 | sub getmsg | ||
| 50 | { | ||
| 51 | my ($self, $id, $language, $default_language) = @_ ; | ||
| 52 | |||
| 53 | return $error_messages{$language}{$id} || | ||
| 54 | $error_messages{$default_language}{$id} || | ||
| 55 | $self -> SUPER::getmsg ($id, $language, $default_language) ; | ||
| 56 | } | ||
| 57 | |||
| 58 | |||
| 59 | # -------------------------------------------------------------- | ||
| 60 | |||
| 61 | =pod | ||
| 62 | |||
| 63 | see https://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses | ||
| 64 | |||
| 65 | # IPv6 RegEx | ||
| 66 | ( | ||
| 67 | ([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}| # 1:2:3:4:5:6:7:8 | ||
| 68 | ([0-9a-fA-F]{1,4}:){1,7}:| # 1:: 1:2:3:4:5:6:7:: | ||
| 69 | ([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}| # 1::8 1:2:3:4:5:6::8 1:2:3:4:5:6::8 | ||
| 70 | ([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}| # 1::7:8 1:2:3:4:5::7:8 1:2:3:4:5::8 | ||
| 71 | ([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}| # 1::6:7:8 1:2:3:4::6:7:8 1:2:3:4::8 | ||
| 72 | ([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}| # 1::5:6:7:8 1:2:3::5:6:7:8 1:2:3::8 | ||
| 73 | ([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}| # 1::4:5:6:7:8 1:2::4:5:6:7:8 1:2::8 | ||
| 74 | [0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})| # 1::3:4:5:6:7:8 1::3:4:5:6:7:8 1::8 | ||
| 75 | :((:[0-9a-fA-F]{1,4}){1,7}|:)| # ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 :: | ||
| 76 | fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}| # fe80::7:8%eth0 fe80::7:8%1 (link-local IPv6 addresses with zone index) | ||
| 77 | ::(ffff(:0{1,4}){0,1}:){0,1} | ||
| 78 | ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3} | ||
| 79 | (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])| # ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses) | ||
| 80 | ([0-9a-fA-F]{1,4}:){1,4}: | ||
| 81 | ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3} | ||
| 82 | (25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]) # 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33 (IPv4-Embedded IPv6 Address) | ||
| 83 | ) | ||
| 84 | |||
| 85 | # IPv4 RegEx | ||
| 86 | ((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]) | ||
| 87 | |||
| 88 | =cut | ||
| 89 | |||
| 90 | |||
| 91 | sub validate | ||
| 92 | { | ||
| 93 | my ($self, $key, $value, $fdat, $pref) = @_ ; | ||
| 94 | if ($value !~ /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/) | ||
| 95 | { | ||
| 96 | return ['validate_ipv6addr', $value] ; | ||
| 97 | } | ||
| 98 | return undef; | ||
| 99 | } | ||
| 100 | |||
| 101 | # -------------------------------------------------------------- | ||
| 102 | |||
| 103 | sub getscript_validate | ||
| 104 | { | ||
| 105 | my ($self, $arg, $pref) = @_ ; | ||
| 106 | |||
| 107 | return ('obj.value.search(/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/) >= 0', ['validate_ipv6addr', "'+obj.value+'"]) ; | ||
| 108 | } | ||
| 109 | |||
| 110 | |||
| 111 | 1; |