SiteControl/Radius.pm untested

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