File Coverage

blib/lib/PlugAuth/Plugin/Finger.pm
Criterion Covered Total %
statement 21 59 35.5
branch 0 16 0.0
condition 0 9 0.0
subroutine 7 9 77.7
pod 0 1 0.0
total 28 94 29.7


line stmt bran cond sub pod time code
1             package PlugAuth::Plugin::Finger;
2              
3 1     1   637 use strict;
  1         3  
  1         32  
4 1     1   5 use warnings;
  1         2  
  1         30  
5 1     1   11 use v5.10;
  1         10  
  1         38  
6 1     1   715 use Role::Tiny::With;
  1         5273  
  1         99  
7 1     1   728 use YAML::XS qw( Dump );
  1         2792  
  1         44  
8 1     1   884 use AnyEvent::Finger::Server;
  1         50662  
  1         29  
9 1     1   1125 use Log::Log4perl qw( :easy );
  1         56978  
  1         10  
10              
11             with 'PlugAuth::Role::Plugin';
12              
13             # ABSTRACT: Add a finger protocol interface to your PlugAuth server
14             our $VERSION = '0.01'; # VERSION
15              
16              
17             sub init
18             {
19 0     0 0   my($self) = @_;
20 0 0 0       my $port = ($> && $^O !~ /^(cygwin|MSWin32)$/) ? 8079 : 79;
21            
22 0           INFO "finger binding to port $port";
23            
24 0           my $server = $self->{server} = AnyEvent::Finger::Server->new(
25             port => $port,
26             forward_deny => 1,
27             );
28            
29             $server->start(sub {
30 0     0     my $tx = shift;
31 0           $self->app->refresh;
32 0 0         if($tx->req->listing_request)
33             {
34 0           $tx->res->say("users: ");
35 0           $tx->res->say(" $_") for $self->app->auth->all_users;
36 0           $tx->res->say("groups: ");
37 0           $tx->res->say(" $_") for $self->app->authz->all_groups;
38 0 0         if($tx->req->verbose)
39             {
40 0           $tx->res->say("grants: ");
41 0           $tx->res->say(" $_") for @{ $self->app->authz->granted };
  0            
42             }
43             }
44             else
45             {
46 0           my $name = lc $tx->req->as_string; # stringifying gets the user and the hostname, but not the verbosity
47 0           my $found = 0;
48 0 0         if(my $groups = $self->app->authz->groups_for_user($name))
    0          
49             {
50 0           $tx->res->say("user: " . $name);
51 0           $tx->res->say("belongs to: ");
52 0           $tx->res->say(" " . join(', ', sort @$groups));
53 0           $found = 1;
54             }
55             elsif(my $users = $self->app->authz->users_in_group($name))
56             {
57 0           $tx->res->say("group: " . $name);
58 0           $tx->res->say("members: ");
59 0           $tx->res->say(" " . join(', ', sort @$users));
60 0           $found = 1;
61             }
62             else
63             {
64 0           $tx->res->say("no such user or group");
65             }
66 0 0 0       if($tx->req->verbose && $found)
67             {
68 0           $tx->res->say("granted: ");
69 0           foreach my $grant (@{ $self->app->authz->granted })
  0            
70             {
71 0 0         $tx->res->say(" $grant")
72 0 0 0       if $grant =~ /:(.*)$/ && grep { $name eq lc $_ || $_ eq '#u' } map { s/^\s+//; s/\s+$//; $_ } split /,/, $1;
  0            
  0            
  0            
73             }
74             }
75             }
76 0           $tx->res->done;
77 0           });
78             }
79              
80             1;
81              
82             __END__