/usr/share/otrs/Kernel/System/CheckItem.pm is in otrs2 6.0.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 | # --
# Copyright (C) 2001-2018 OTRS AG, http://otrs.com/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --
package Kernel::System::CheckItem;
use strict;
use warnings;
use Email::Valid;
our @ObjectDependencies = (
'Kernel::Config',
'Kernel::System::Log',
);
=head1 NAME
Kernel::System::CheckItem - check items
=head1 DESCRIPTION
All item check functions.
=head1 PUBLIC INTERFACE
=head2 new()
Don't use the constructor directly, use the ObjectManager instead:
my $CheckItemObject = $Kernel::OM->Get('Kernel::System::CheckItem');
=cut
sub new {
my ( $Type, %Param ) = @_;
# allocate new hash for object
my $Self = {};
bless( $Self, $Type );
return $Self;
}
=head2 CheckError()
get the error of check item back
my $Error = $CheckItemObject->CheckError();
=cut
sub CheckError {
my $Self = shift;
return $Self->{Error};
}
=head2 CheckErrorType()
get the error's type of check item back
my $ErrorType = $CheckItemObject->CheckErrorType();
=cut
sub CheckErrorType {
my $Self = shift;
return $Self->{ErrorType};
}
=head2 CheckEmail()
returns true if check was successful, if it's false, get the error message
from CheckError()
my $Valid = $CheckItemObject->CheckEmail(
Address => 'info@example.com',
);
=cut
sub CheckEmail {
my ( $Self, %Param ) = @_;
# check needed stuff
if ( !$Param{Address} ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need Address!'
);
return;
}
# get config object
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
# check if it's to do
return 1 if !$ConfigObject->Get('CheckEmailAddresses');
# check valid email addresses
my $RegExp = $ConfigObject->Get('CheckEmailValidAddress');
if ( $RegExp && $Param{Address} =~ /$RegExp/i ) {
return 1;
}
my $Error = '';
# Workaround for https://github.com/Perl-Email-Project/Email-Valid/issues/36:
# remove comment from address when checking.
$Param{Address} =~ s{ \s* \( [^()]* \) \s* $ }{}smxg;
# email address syntax check
if ( !Email::Valid->address( $Param{Address} ) ) {
$Error = "Invalid syntax";
$Self->{ErrorType} = 'InvalidSyntax';
}
# email address syntax check
# period (".") may not be used to end the local part,
# nor may two or more consecutive periods appear
if ( $Param{Address} =~ /(\.\.)|(\.@)/ ) {
$Error = "Invalid syntax";
$Self->{ErrorType} = 'InvalidSyntax';
}
# mx check
elsif (
$ConfigObject->Get('CheckMXRecord')
&& eval { require Net::DNS } ## no critic
)
{
# get host
my $Host = $Param{Address};
$Host =~ s/^.*@(.*)$/$1/;
$Host =~ s/\s+//g;
$Host =~ s/(^\[)|(\]$)//g;
# do dns query
my $Resolver = Net::DNS::Resolver->new();
if ($Resolver) {
# it's no fun to have this hanging in the web interface
$Resolver->tcp_timeout(3);
$Resolver->udp_timeout(3);
# check if we need to use a specific name server
my $Nameserver = $ConfigObject->Get('CheckMXRecord::Nameserver');
if ($Nameserver) {
$Resolver->nameservers($Nameserver);
}
# A-record lookup to verify proper DNS setup
my $Packet = $Resolver->send( $Host, 'A' );
if ( !$Packet ) {
$Self->{ErrorType} = 'InvalidDNS';
$Error = "DNS problem: " . $Resolver->errorstring();
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => $Error,
);
}
else {
# RFC 5321: first check MX record and fallback to A record if present.
# mx record lookup
my @MXRecords = Net::DNS::mx( $Resolver, $Host );
if ( !@MXRecords ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message =>
"$Host has no mail exchanger (MX) defined, trying A resource record instead.",
);
# see if our previous A-record lookup returned a RR
if ( scalar $Packet->answer() eq 0 ) {
$Self->{ErrorType} = 'InvalidMX';
$Error = "$Host has no mail exchanger (MX) or A resource record defined.";
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'debug',
Message => $Error,
);
}
}
}
}
}
elsif ( $ConfigObject->Get('CheckMXRecord') ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Can't load Net::DNS, no mx lookups possible",
);
}
# check address
if ( !$Error ) {
# check special stuff
my $RegExp = $ConfigObject->Get('CheckEmailInvalidAddress');
if ( $RegExp && $Param{Address} =~ /$RegExp/i ) {
$Self->{Error} = "invalid $Param{Address} (config)!";
$Self->{ErrorType} = 'InvalidConfig';
return;
}
return 1;
}
else {
# remember error
$Self->{Error} = "invalid $Param{Address} ($Error)! ";
return;
}
}
=head2 StringClean()
clean a given string
my $StringRef = $CheckItemObject->StringClean(
StringRef => \'String',
TrimLeft => 0, # (optional) default 1
TrimRight => 0, # (optional) default 1
RemoveAllNewlines => 1, # (optional) default 0
RemoveAllTabs => 1, # (optional) default 0
RemoveAllSpaces => 1, # (optional) default 0
);
=cut
sub StringClean {
my ( $Self, %Param ) = @_;
if ( !$Param{StringRef} || ref $Param{StringRef} ne 'SCALAR' ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need a scalar reference!'
);
return;
}
return $Param{StringRef} if !defined ${ $Param{StringRef} };
return $Param{StringRef} if ${ $Param{StringRef} } eq '';
# check for invalid utf8 characters and remove invalid strings
if ( !utf8::valid( ${ $Param{StringRef} } ) ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => "Removed string containing invalid utf8: '${ $Param{StringRef} }'!",
);
${ $Param{StringRef} } = '';
return;
}
# set default values
$Param{TrimLeft} = defined $Param{TrimLeft} ? $Param{TrimLeft} : 1;
$Param{TrimRight} = defined $Param{TrimRight} ? $Param{TrimRight} : 1;
my %TrimAction = (
RemoveAllNewlines => qr{ [\n\r\f] }xms,
RemoveAllTabs => qr{ \t }xms,
RemoveAllSpaces => qr{ [ ] }xms,
TrimLeft => qr{ \A \s+ }xms,
TrimRight => qr{ \s+ \z }xms,
);
ACTION:
for my $Action ( sort keys %TrimAction ) {
next ACTION if !$Param{$Action};
${ $Param{StringRef} } =~ s{ $TrimAction{$Action} }{}xmsg;
}
return $Param{StringRef};
}
=head2 CreditCardClean()
clean a given string and remove credit card
my ($StringRef, $Found) = $CheckItemObject->CreditCardClean(
StringRef => \'String',
);
=cut
sub CreditCardClean {
my ( $Self, %Param ) = @_;
if ( !$Param{StringRef} || ref $Param{StringRef} ne 'SCALAR' ) {
$Kernel::OM->Get('Kernel::System::Log')->Log(
Priority => 'error',
Message => 'Need a scalar reference!'
);
return;
}
return ( $Param{StringRef}, 0 ) if ${ $Param{StringRef} } eq '';
return ( $Param{StringRef}, 0 ) if !defined ${ $Param{StringRef} };
# strip credit card numbers
my $Count = 0;
${ $Param{StringRef} } =~ s{
\b(\d{4})(\s|\.|\+|_|-|\\|/)(\d{4})(\s|\.|\+|_|-|\\|/|)(\d{4})(\s|\.|\+|_|-|\\|/)(\d{3,4})\b
}
{
$Count++;
"$1$2XXXX$4XXXX$6$7";
}egx;
return $Param{StringRef}, $Count;
}
1;
=head1 TERMS AND CONDITIONS
This software is part of the OTRS project (L<http://otrs.org/>).
This software comes with ABSOLUTELY NO WARRANTY. For details, see
the enclosed file COPYING for license information (AGPL). If you
did not receive this file, see L<http://www.gnu.org/licenses/agpl.txt>.
=cut
|