line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Authen::ModAuthToken; |
2
|
2
|
|
|
2
|
|
87870
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
103
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
74
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
266
|
|
6
|
2
|
|
|
2
|
|
2606
|
use URI::Escape; |
|
2
|
|
|
|
|
3454
|
|
|
2
|
|
|
|
|
134
|
|
7
|
2
|
|
|
2
|
|
16
|
use Digest::MD5 qw/md5_hex/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
636
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw/generate_mod_auth_token/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub generate_mod_auth_token |
15
|
|
|
|
|
|
|
{ |
16
|
1
|
|
|
1
|
1
|
223
|
my %args = @_; |
17
|
|
|
|
|
|
|
|
18
|
1
|
50
|
|
|
|
7
|
my $secret = $args{secret} or croak "Missing 'secret' key value"; |
19
|
1
|
|
50
|
|
|
10
|
my $remote_addr = $args{remote_addr} || ""; |
20
|
1
|
50
|
|
|
|
9
|
my $filepath = $args{filepath} or croak "Missing 'filepath' key value"; |
21
|
1
|
50
|
|
|
|
6
|
die "'filepath' key value should start with '/'" unless substr($filepath,0,1) eq "/"; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
15
|
my $hexTime = sprintf("%08x", time()); |
24
|
1
|
|
|
|
|
13
|
my $token_md5 = md5_hex ( $secret . $filepath . $hexTime . $remote_addr); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
3
|
my $encoded_url = ""; |
27
|
1
|
|
|
|
|
5
|
foreach my $part ( split '/', $filepath ) { |
28
|
2
|
100
|
|
|
|
6
|
next unless $part; |
29
|
1
|
|
|
|
|
7
|
$encoded_url .= "/" . uri_escape($part) ; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
64
|
my $url = "/" . $token_md5 . "/" . $hexTime . $encoded_url; |
33
|
|
|
|
|
|
|
|
34
|
1
|
|
|
|
|
3
|
return $url; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# ABSTRACT: A Module to generate Mod-Auth-Token compatible URLs |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
__END__ |