2014-09-16 01:58:21 +02:00
|
|
|
package Qpsmtpd::Base;
|
2002-09-24 20:53:45 +02:00
|
|
|
use strict;
|
|
|
|
|
2014-09-11 22:34:32 +02:00
|
|
|
use Net::IP;
|
|
|
|
|
2014-09-16 08:41:31 +02:00
|
|
|
sub new {
|
|
|
|
return bless {}, shift;
|
|
|
|
};
|
|
|
|
|
2002-09-24 20:53:45 +02:00
|
|
|
sub tildeexp {
|
2014-09-10 22:43:46 +02:00
|
|
|
my ($self, $path) = @_;
|
2014-09-16 14:11:54 +02:00
|
|
|
$path =~ s{^~([^/]*)} {
|
|
|
|
$1 ? (getpwnam($1))[7]
|
|
|
|
: ( $ENV{HOME} || $ENV{LOGDIR} || (getpwuid($>))[7])
|
|
|
|
}ex;
|
2002-09-24 20:53:45 +02:00
|
|
|
return $path;
|
|
|
|
}
|
|
|
|
|
2014-09-10 22:43:46 +02:00
|
|
|
sub is_localhost {
|
|
|
|
my ($self, $ip) = @_;
|
|
|
|
return if ! $ip;
|
|
|
|
return 1 if $ip =~ /^127\./; # IPv4
|
|
|
|
return 1 if $ip =~ /:127\./; # IPv4 mapped IPv6
|
|
|
|
return 1 if $ip eq '::1'; # IPv6
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-11 22:34:32 +02:00
|
|
|
sub is_valid_ip {
|
|
|
|
my ($self, $ip) = @_;
|
|
|
|
|
|
|
|
if (Net::IP::ip_is_ipv4($ip)) {
|
|
|
|
return if $ip eq '0.0.0.0';
|
|
|
|
return if $ip eq '255.255.255.255';
|
|
|
|
return if $ip =~ /255/;
|
|
|
|
return 1;
|
|
|
|
};
|
|
|
|
return 1 if Net::IP::ip_is_ipv6($ip);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-24 20:53:45 +02:00
|
|
|
1;
|