« blib/lib/Lemonldap/NG/Portal/UserDB/CAS.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Plugins/History.pm »
| 1 | package Lemonldap::NG::Portal::2F::Ext2F; | ||||||||||||
| 2 | |||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 12 | ▶ | use Mouse; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 12 | ▶ | use Lemonldap::NG::Portal::Main::Constants qw( | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | PE_OK | ||||||||||||
| 7 | PE_ERROR | ||||||||||||
| 8 | PE_BADOTP | ||||||||||||
| 9 | PE_NOTOKEN | ||||||||||||
| 10 | PE_FORMEMPTY | ||||||||||||
| 11 | PE_SENDRESPONSE | ||||||||||||
| 12 | PE_TOKENEXPIRED | ||||||||||||
| 13 | 12 | ); | |||||||||||
| 14 | |||||||||||||
| 15 | 12 | our $VERSION = '2.0.16'; | |||||||||||
| 16 | |||||||||||||
| 17 | 12 | extends 'Lemonldap::NG::Portal::Lib::Code2F'; | |||||||||||
| 18 | |||||||||||||
| 19 | # INITIALIZATION | ||||||||||||
| 20 | |||||||||||||
| 21 | # Prefix can overriden by sfExtra and is used for routes | ||||||||||||
| 22 | 12 | has prefix => ( is => 'rw', default => 'ext' ); | |||||||||||
| 23 | |||||||||||||
| 24 | # Used to lookup config | ||||||||||||
| 25 | 12 | has conf_type => ( is => 'ro', default => 'ext' ); | |||||||||||
| 26 | 12 | has legend => ( is => 'rw', default => 'enterExt2fCode' ); | |||||||||||
| 27 | |||||||||||||
| 28 | 12 | ▶ | sub init { | ||||||||||
|
Subroutine
init: called CC=5 SCAR=18.4
Pod
undocumented
| |||||||||||||
| 29 | 12 | my ($self) = @_; | |||||||||||
| 30 | |||||||||||||
| 31 | 12 | ▶ | if ( $self->code_activation ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 32 | 8 | ▶ | unless ( $self->conf->{ext2FSendCommand} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 33 | 0 | $self->error( $self->prefix | |||||||||||
| 34 | . '2f: missing "ext2FSendCommand" parameter, aborting' ); | ||||||||||||
| 35 | 0 | return 0; | |||||||||||
| 36 | } | ||||||||||||
| 37 | } | ||||||||||||
| 38 | else { | ||||||||||||
| 39 | 4 | foreach (qw(ext2FSendCommand ext2FValidateCommand)) { | |||||||||||
| 40 | 8 | ▶ | unless ( $self->conf->{$_} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 41 | 0 | $self->error( | |||||||||||
| 42 | $self->prefix . "2f: missing \"$_\" parameter, aborting" ); | ||||||||||||
| 43 | 0 | return 0; | |||||||||||
| 44 | } | ||||||||||||
| 45 | } | ||||||||||||
| 46 | } | ||||||||||||
| 47 | 12 | return $self->SUPER::init(); | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | # RUNNING METHODS | ||||||||||||
| 51 | |||||||||||||
| 52 | 0 | ▶ | sub verify_external { | ||||||||||
|
Subroutine
verify_external: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 53 | 0 | my ( $self, $req, $session, $code ) = @_; | |||||||||||
| 54 | |||||||||||||
| 55 | # Prepare command and launch it | ||||||||||||
| 56 | $self->logger->debug( $self->prefix | ||||||||||||
| 57 | . '2f: launching "Validate" command -> ' | ||||||||||||
| 58 | 0 | . $self->conf->{ext2FValidateCommand} ); | |||||||||||
| 59 | 0 | $self->logger->debug(" code -> $code"); | |||||||||||
| 60 | 0 | ▶ | if ( my $c = | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 61 | $self->launch( $session, $self->conf->{ext2FValidateCommand}, $code ) ) | ||||||||||||
| 62 | { | ||||||||||||
| 63 | $self->userLogger->warn( $self->prefix | ||||||||||||
| 64 | . '2f: validation failed for ' | ||||||||||||
| 65 | 0 | . $session->{ $self->conf->{whatToTrace} } ); | |||||||||||
| 66 | 0 | $self->logger->error( | |||||||||||
| 67 | $self->prefix . "2f: validate command failed ($c)" ); | ||||||||||||
| 68 | 0 | return PE_BADOTP; | |||||||||||
| 69 | } | ||||||||||||
| 70 | 0 | return PE_OK; | |||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub sendCode { | ||||||||||
|
Subroutine
sendCode: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 74 | 0 | my ( $self, $req, $sessionInfo, $code ) = @_; | |||||||||||
| 75 | |||||||||||||
| 76 | # Prepare command and launch it | ||||||||||||
| 77 | $self->logger->debug( $self->prefix | ||||||||||||
| 78 | . '2f: launching "Send" command -> ' | ||||||||||||
| 79 | 0 | . $self->conf->{ext2FSendCommand} ); | |||||||||||
| 80 | 0 | ▶ | if ( my $c = | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 81 | $self->launch( $sessionInfo, $self->conf->{ext2FSendCommand}, $code ) ) | ||||||||||||
| 82 | { | ||||||||||||
| 83 | 0 | $self->logger->error( $self->prefix . "2f: send command failed ($c)" ); | |||||||||||
| 84 | 0 | return 0; | |||||||||||
| 85 | } | ||||||||||||
| 86 | 0 | return 1; | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | # system() is used with an array to avoid shell injection | ||||||||||||
| 90 | 0 | ▶ | sub launch { | ||||||||||
|
Subroutine
launch: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 91 | 0 | my ( $self, $session, $command, $code ) = @_; | |||||||||||
| 92 | 0 | my @args; | |||||||||||
| 93 | 0 | foreach ( split( /\s+/, $command ) ) { | |||||||||||
| 94 | 0 | ▶ | if ( defined $code ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 95 | 0 | s#\$code\b#$code#g; | |||||||||||
| 96 | } | ||||||||||||
| 97 | 0 | ▶ | s#\$(\w+)#$session->{$1} // ''#ge; | ||||||||||
|
Condition0%0/2
$session->{$1} // ""
MC/DC0%0/1
$session->{$1} // ""
$session->{$1}
Truth table0%0/2
A
A= $session->{$1}
| |||||||||||||
| 98 | 0 | push @args, $_; | |||||||||||
| 99 | } | ||||||||||||
| 100 | $self->logger->debug( | ||||||||||||
| 101 | 0 | $self->prefix . "2f: executing command: " . join( " ", @args ) ); | |||||||||||
| 102 | 0 | return system @args; | |||||||||||
| 103 | } | ||||||||||||
| 104 | |||||||||||||
| 105 | 12 | 1; | |||||||||||
| 106 | |||||||||||||