hi

 

I have some problem with perl module in freeradius

 

There are an errors after that radius is fall down

 

Tue Apr 28 19:23:07 2009 : Error: rlm_perl: perl_embed:: module = /usr/local/etc/raddb/processing.pl , func = reject_log exit status= Undefined subroutine &DBD::mysql::dr::reject_log called at /usr/local/lib/perl5/site_perl/5.8.9/mach/DBD/mysql.pm line 142.

 

Tue Apr 28 19:45:41 2009 : Error: rlm_perl: perl_embed:: module = /usr/local/etc/raddb/processing.pl , func = reject_log exit status= Undefined subroutine &DBD::mysql::dr::reject_log called at /usr/local/lib/perl5/site_perl/5.8.9/mach/DBD/mysql.pm line 142.

 

Wed Apr 29 15:11:52 2009 : Error: rlm_perl: perl_embed:: module = /usr/local/etc/raddb/processing.pl , func = reject_log exit status= Undefined subroutine &DBI::Const::GetInfo::ODBC::reject_log called at /usr/local/lib/perl5/site_perl/5.8.9/mach/DBI/Const/GetInfo/ODBC.pm line 1337.

 

Here is a processing.pl

 

use strict;

# use ...

 

# This is very important ! Without this script will not get the filled hashesh from main.

use vars qw(%RAD_REQUEST %RAD_REPLY %RAD_CHECK);

use Data::Dumper;

 

my $username;

 

my $debugšššššš = '1';

 

#

# This the remapping of return values

#

ššššššš use constantššš RLM_MODULE_REJECT=>ššš 0;#š /* immediately reject the request */

ššššššš use constantššš RLM_MODULE_FAIL=>ššššš 1;#š /* module failed, don't reply */

ššššššš use constantššš RLM_MODULE_OK=>ššššššš 2;#š /* the module is OK, continue */

ššššššš use constant šššRLM_MODULE_HANDLED=>šš 3;#š /* the module handled the request, so stop. */

ššššššš use constantššš RLM_MODULE_INVALID=>šš 4;#š /* the module considers the request invalid. */

ššššššš use constantššš RLM_MODULE_USERLOCK=>š 5;#š /* reject the request (user is locked out) */

ššššššš use constantššš RLM_MODULE_NOTFOUND=>š 6;#š /* user not found */

ššššššš use constantššš RLM_MODULE_NOOP=>ššššš 7;#š /* module succeeded without doing anything */

ššššššš use constantššš RLM_MODULE_UPDATED=>šš 8;#š /* OK (pairs modified) */

ššššššš use constantššš RLM_MODULE_NUMCODES=>š 9;#š /* How many return codes there are */

 

sub reject_log {

ššš #

ššš # -- function to log rejected users in xml format

ššš #

 

ššš $username = $RAD_REQUEST{'User-Name'};

ššš $username =~ s/[^a-zA-Z0-9_-]//g;

ššš &radiusd::radlog(1, "DEBUG reject_log: RAD_REQUEST User-Name: ".$RAD_REQUEST{'User-Name'}) if $debug;

ššš &radiusd::radlog(1, "DEBUG reject_log: UserName: ".$username) if $debug;

 

ššš my $textlog;ššššššš #šššššš /* !!! Don't comment this line !!! */

ššš # Uncomment next line for text log readable from unix console (by default log in xml)

#ššš $textlog = '1';

 

ššš # Log file

ššš my $logfile = '/var/log/radreject.log' if $textlog;

ššš my $logfilexml = '/var/log/radreject.xml';

ššš open (LOG, ">>$logfile") or $RAD_REPLY{'Module-Failure-Message'} = "rlm_rejectlog: Can't open logfile." if $textlog;

ššš open (LOGXML, ">>$logfilexml") or $RAD_REPLY{'Module-Failure-Message'} = "rlm_rejectlog: Can't open xml logfile." and return RLM_MODULE_FAIL;

ššš my $now = localtime;

 

ššš if ($RAD_REQUEST{'Module-Failure-Message'} eq "rlm_chap: Wrong user password") {

ššššššš print LOG $now.

ššššššš " Password incorrect [ ".

ššššššš $RAD_REQUEST{'User-Name'}

ššššššš ." ]. (from ".

ššššššš $RAD_REQUEST{'NAS-IP-Address'}

ššššššš ." client ".

ššššššš $RAD_REQUEST{'Calling-Station-Id'}

ššššššš .")\n" if $textlog;

 

ššššššš print LOGXML "<date>".

ššššššš $now

ššššššš ."</date><message>Password incorrect</message><login>".

ššššššš $RAD_REQUEST{'User-Name'}

ššššššš ."</login><nas>".

ššššššš $RAD_REQUEST{'NAS-IP-Address'}

ššššššš ."</nas><cli_mac>".

ššššššš $RAD_REQUEST{'Calling-Station-Id'}

ššššššš ."</cli_mac>\n";

ššš }

ššš elsif($RAD_REQUEST{'Module-Failure-Message'} eq "rlm_chap: Clear text password not available") {

ššš ššššprint LOG $now.

ššššššš " Login incorrect [ ".

ššššššš $RAD_REQUEST{'User-Name'}

ššššššš ." ]. (from ".

ššššššš $RAD_REQUEST{'NAS-IP-Address'}

ššššššš ." client ".

ššššššš $RAD_REQUEST{'Calling-Station-Id'}

ššššššš .")\n" if $textlog;

 

ššššššš print LOGXML "<date>".

ššššššš $now

ššššššš ."</date><message>Login incorrect</message><login>".

ššššššš $RAD_REQUEST{'User-Name'}

ššššššš ."</login><nas>".

ššššššš $RAD_REQUEST{'NAS-IP-Address'}

ššššššš ."</nas><cli_mac>".

ššššššš $RAD_REQUEST{'Calling-Station-Id'}

ššššššš ."</cli_mac>\n";

ššš }

ššš else {

ššššššš close LOGXML;

ššššššš close LOG if $textlog;

ššššššš return RLM_MODULE_NOOP;

ššš }

ššš close LOGXML;

ššš close LOG if $textlog;

ššš return RLM_MODULE_UPDATED;

}

 

sub post_auth {

ššš #

ššš # -- this function add attributes to reply

ššš #

 

ššš use DBI;

ššš use Time::HiRes qw(usleep);

 

ššš my $dbloginšššššššššššš = 'radius';

ššš my $dbpassššššššššššššš = 'secret';

ššš my $dbnameššššššššššššš = 'RADDB';

 

ššš my $dbh = DBI->connect("dbi:mysql:dbname=$dbname","$dblogin","$dbpass",{PrintError => 0})

ššš or &radiusd::radlog(1, "DEBUG post_auth: DBI error: ".$DBI::errstr) if $debug;

ššš if ($DBI::err != 0) {

ššššššš usleep(100000);

ššššššš $RAD_REPLY {'Reply-Message'} = "Error connecting to database.";

ššššššš return RLM_MODULE_FAIL;

ššš }

 

ššš $username = $RAD_REQUEST{'User-Name'};

ššš $username =~ s/[^a-zA-Z0-9_-]//g;

ššš &radiusd::radlog(1, "DEBUG post_auth: RAD_REQUEST User-Name: ".$RAD_REQUEST{'User-Name'}) if $debug;

ššš &radiusd::radlog(1, "DEBUG post_auth: UserName: ".$username) if $debug;

 

ššš my $query = "CALL rad_reply('".$username."')";

 

ššš my $sth = $dbh->prepare($query);

ššš my $rv = $sth->execute();

ššš &radiusd::radlog(1, "DEBUG: query error: ".$sth->errstr) if $debug;

 

šš šif (!defined $rv) {

ššššššš usleep(100000);

ššššššš $RAD_REPLY {'Reply-Message'} = "Error executing SQL query.";

 

#

#

# -- why db disconnect don’t work in next line? It’s say that db connect already closed

#

#

#šššššš $dbh->disconnect();

ššššššš return RLM_MODULE_FAIL;

ššš }

 

ššš my $attr_hash = $sth->fetchrow_hashref();

ššš if ($attr_hash->{is_blocked} == '0'){

ššššššš $RAD_REPLY {'Filter-Id'} = 'allow';

ššš }

ššš $RAD_REPLY {'Framed-IP-Address'} = $attr_hash->{ip};

ššš $RAD_REPLY {'Framed-IP-Netmask'} = '255.255.255.255';

ššš if ($attr_hash->{attr} ne 'NULL'){

ššššššš $RAD_REPLY {'Mikrotik-Rate-Limit'} = $attr_hash->{attr};

ššš }

ššš $RAD_REPLY {'Session-Timeout'} = '86400';

#

# -- here is the same – don’t work L

#

#ššš $dbh->disconnect;

ššš return RLM_MODULE_UPDATED;

}

 

Other files

raddb/modules/rejectlog

#

# This module made for loggin reject radius answers

# using perl function reject_log

#

 

perl rejectlog {

ššš module = /usr/local/etc/raddb/rejectlog.pl

ššš func_post_auth = reject_log

}

 

raddb/sites-enable/my-site

post-auth {

ššššššš Post-Auth-Type REJECT {

ššššššššššššššš attr_filter.access_reject

 

ššššššššššššššš #

ššššššššššššššš # Log failed logins to xml log file or to unix log.

ššššššššššššššš #

ššššššššššššššš rejectlog

ššššššš }

ššššššš # Perl

ššššššš perl

}

 

Radiusd work fine a little time – an hour or an 2-3 hours but then its fall

What can I do with that errors?