| 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 | ################################################################################### | ||
| 16 | |||
| 17 | |||
| 18 | package Embperl::Form::Validate::FQDN_IPAddr ; | ||
| 19 | |||
| 20 | use base qw(Embperl::Form::Validate::Default); | ||
| 21 | use utf8 ; | ||
| 22 | |||
| 23 | |||
| 24 | my %errutf8 = | ||
| 25 | ( | ||
| 26 | validate_fqdn_ipaddr => 'Feld %0: "%1" ist keine gültiger Hostname oder IP-Adresse.', | ||
| 27 | ) ; | ||
| 28 | |||
| 29 | no utf8 ; | ||
| 30 | |||
| 31 | my %error_messages = | ||
| 32 | ( | ||
| 33 | de => | ||
| 34 | { | ||
| 35 | validate_fqdn_ipaddr => 'Feld %0: "%1" ist keine g�ltiger Hostname oder IP-Adresse.', | ||
| 36 | }, | ||
| 37 | |||
| 38 | 'de.utf-8' => \%errutf8, | ||
| 39 | |||
| 40 | en => | ||
| 41 | { | ||
| 42 | validate_fqdn_ipaddr => 'Field %0: "%1" isn\\\'t a valid hostname or ip-address.', | ||
| 43 | } | ||
| 44 | ); | ||
| 45 | |||
| 46 | # -------------------------------------------------------------- | ||
| 47 | |||
| 48 | sub getmsg | ||
| 49 | { | ||
| 50 | my ($self, $id, $language, $default_language) = @_ ; | ||
| 51 | |||
| 52 | return $error_messages{$language}{$id} || | ||
| 53 | $error_messages{$default_language}{$id} || | ||
| 54 | $self -> SUPER::getmsg ($id, $language, $default_language) ; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | # -------------------------------------------------------------- | ||
| 59 | |||
| 60 | sub validate | ||
| 61 | { | ||
| 62 | my ($self, $key, $value, $fdat, $pref) = @_ ; | ||
| 63 | |||
| 64 | if ($value =~ /^(\d+)\.(\d+).(\d+)\.(\d+)$/) | ||
| 65 | { | ||
| 66 | if ($1 < 0 || $1 > 255 || | ||
| 67 | $2 < 0 || $2 > 255 || | ||
| 68 | $3 < 0 || $3 > 255 || | ||
| 69 | $4 < 0 || $4 > 255) | ||
| 70 | { | ||
| 71 | ; | ||
| 72 | } | ||
| 73 | else | ||
| 74 | { | ||
| 75 | return undef ; | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 | return undef if ($value =~ /^[-.a-zA-Z0-9]+$/) ; | ||
| 80 | return ['validate_fqdn_ipaddr', $value] ; | ||
| 81 | } | ||
| 82 | |||
| 83 | # -------------------------------------------------------------- | ||
| 84 | |||
| 85 | sub getscript_validate | ||
| 86 | { | ||
| 87 | my ($self, $arg, $pref) = @_ ; | ||
| 88 | |||
| 89 | return ('obj.value.search(/^[-.a-zA-Z0-9]+$/) >= 0 ', ['validate_fqdn_ipaddr', "'+obj.value+'"]) ; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | 1; |