#use Apache2::RequestIO (); # 预加载的类库
use Apache2::RequestRec ();
use Apache2::Connection ();
use Apache2::RequestUtil ();
use Apache2::ServerUtil ();
use Apache2::Log ();
use Apache2::Request ();
1; # 不要丢了这个1,表示返回真给调用者
DLAuth2.pm内容类似如下:
package DLAuth2;
use strict;
use warnings;
use Socket qw(inet_aton);
use POSIX qw(strftime);
use Digest::MD5 qw(md5_hex);
#use Apache2::RequestIO ();
use Apache2::RequestRec ();
use Apache2::Connection ();
use Apache2::RequestUtil ();
use Apache2::ServerUtil ();
use Apache2::Log ();
use Apache2::Request ();
use Apache2::Const -compile => qw(OK FORBIDDEN);
sub handler { # 处理器的钩子函数,函数名不能改
my $r = shift; # 请求目标
my $q = Apache2::Request->new($r);
my $s = Apache2::ServerUtil->server;
my $ip = $r->connection->remote_ip; # 获取访问者IP
my $fid = $q->param('fid') || get_fileid(); # 获取目标文件ID
my $ip_int = ip2int($ip); # 将IP转换成大整数
my $shareKey = $r->dir_config('ShareKey') || ''; # 从配置文件获取shareKey
my @passip = $r->dir_config->get('PassAuthIPs'); # 从配置文件获取白名单IP
my @passip_int; # 白名单IP数组
for (@passip) { # 将白名单IP转换成整数数组
if (/-/) {
my ($start,$end) = split/-/;
my $start_int = ip2int($start);
my $end_int = ip2int($end);
for (my $i=$start_int;$iparam('a') || '';
if ($str eq $auth_string) {
return Apache2::Const::OK; # 如果2串一致,则允许访问