|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Haineko::HTTPD::Auth;  | 
| 
2
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
47932
 | 
 use feature ':5.10';  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
235
 | 
    | 
| 
3
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
120
 | 
 use strict;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
70
 | 
    | 
| 
4
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
10
 | 
 use warnings;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
48
 | 
    | 
| 
5
 | 
1
 | 
 
 | 
 
 | 
  
1
  
 | 
 
 | 
1678
 | 
 use Try::Tiny;  | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
2930
 | 
    | 
| 
 
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
619
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $PasswordDB = undef;  | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
9
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub basic {  | 
| 
10
 | 
6
 | 
 
 | 
 
 | 
  
6
  
 | 
  
1
  
 | 
553
 | 
     my $class = shift;  | 
| 
11
 | 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
14
 | 
     my $argvs = { @_ };  | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
6
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
34
 | 
     return 0 unless exists $argvs->{'username'};  | 
| 
14
 | 
4
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
19
 | 
     return 0 unless exists $argvs->{'password'};  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
16
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
     my $passworddb = undef;  | 
| 
17
 | 
3
 | 
 
 | 
  
100
  
 | 
 
 | 
 
 | 
16
 | 
     my $credential = $PasswordDB // undef;  | 
| 
18
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
     my $exceptions = 0;  | 
| 
19
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
20
 | 
3
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     if( not $credential ) {  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         # Load username and password entries from a file  | 
| 
22
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
9
 | 
         return undef unless defined $ENV{'HAINEKO_ROOT'};  | 
| 
23
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         $passworddb = sprintf( "%s/etc/password", $ENV{'HAINEKO_ROOT'} );  | 
| 
24
 | 
0
 | 
  
  0
  
 | 
  
  0
  
 | 
 
 | 
 
 | 
0
 | 
         $passworddb .= '-debug' if( not -f $passworddb && $ENV{'HAINEKO_DEBUG'} );  | 
| 
25
 | 
0
 | 
  
  0
  
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         return undef unless -f -r -s $passworddb;  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
27
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         require Haineko::JSON;  | 
| 
28
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         try {  | 
| 
29
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
 
 | 
0
 | 
             $credential = Haineko::JSON->loadfile( $passworddb );  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
         } catch {  | 
| 
31
 | 
0
 | 
 
 | 
 
 | 
  
0
  
 | 
 
 | 
0
 | 
             $exceptions = 1;  | 
| 
32
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
0
 | 
         };  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     }  | 
| 
34
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
35
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     return undef if $exceptions;  | 
| 
36
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
6
 | 
     return undef unless defined $credential;  | 
| 
37
 | 
2
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
8
 | 
     return undef unless keys %$credential;  | 
| 
38
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
39
 | 
2
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
13
 | 
     return 0 unless exists $credential->{ $argvs->{'username'} };  | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
41
 | 
1
 | 
 
 | 
  
 50
  
 | 
 
 | 
 
 | 
5
 | 
     my $password00 = $credential->{ $argvs->{'username'} } // undef;  | 
| 
42
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
3
 | 
     my $password01 = $argvs->{'password'};  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
44
 | 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
12339
 | 
     require Crypt::SaltedHash;  | 
| 
45
 | 
1
 | 
  
 50
  
 | 
 
 | 
 
 | 
 
 | 
7212
 | 
     return 1 if Crypt::SaltedHash->validate( $password00, $password01 );  | 
| 
46
 | 
0
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     return 0;  | 
| 
47
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
48
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |