SiteControl/Radius.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 51 CC 4 SCAR 23.0
CC
4
Cov
0%
check_credentials
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 10.0
1 package Apache2::SiteControl::Radius;
2  
3 use 5.008;
4 use strict;
5 use warnings;
6 use Carp;
7 use Authen::Radius;
8 #use Apache2::Connection;
9 #use Apache2::RequestRec;
10 #use APR::SockAddr;
11  
12 sub check_credentials
13 {
14 my $r = shift; # Apache request object
15 my $username = shift;
16 my $password = shift;
17 my $host = $r->dir_config("RadiusSiteControlHost") || "localhost";
18 my $secret = $r->dir_config("RadiusSiteControlSecret") || "unknown";
19 my $radius;
20  
21 # Get my IP address to pass as the
22 # Source IP and NAS IP Address
23 # TODO: Only works with apache 2...uncommented for now
24 #my $c = $r->connection;
25 #my $sockaddr = $c->local_addr if defined($c);
26 my $nas_ip_address = undef; # $sockaddr->ip_get if defined($sockaddr);
27  
28 $r->log_error("WARNING: Shared secret is not set. Use RadiusSiteControlSecret in httpd.conf") if $secret eq "unknown";
29  
30 $radius = new Authen::Radius(Host => $host, Secret => $secret);
31 if(!$radius) {
32 $r->log_error("Could not contact radius server!");
33 return 0;
34 }
35 if($radius->check_pwd($username, $password, $nas_ip_address)) {
36 return 1;
37 }
38 $r->log_error("User $username failed authentication:" . $radius->strerror);
39 return 0;
40 }
41  
42 1;
43  
44 __END__