Skip to content
Snippets Groups Projects
Forked from smradius / smradius
631 commits behind the upstream repository.
acct-filter 26.48 KiB
#!/usr/bin/perl -w
# Author: Nigel Kukard  <nkukard@lbsd.net>
# Date: 17/04/2007
# Desc: Accounting filter for GNU Radius
# License: GPL

use strict;
use Benchmark;
use Getopt::Long;
use DateTime;
use Time::HiRes qw( gettimeofday tv_interval );

use MIME::Lite;

# Set library directory
use lib qw(../../);

use sm::config;
use sm::dblayer;

# Radius stuff
use Authen::Radius;

# Common stuff
require("common.pm");

use Data::Dumper;


# Notify constants
use constant {
	NOTIFY_CHECK	=> 1,
	NOTIFY_RESET	=> 2,
};


my %optctl = ();

GetOptions(\%optctl, "help");


# Check if user wants usage
if (defined($optctl{'help'})) {
	displayUsage();
}

# Open up logfile
my $logfile = "/var/log/radius/acct-filter";
open(FH,">> $logfile") or die "Failed to open '$logfile': $!";


# Load radius dictionaries
Authen::Radius->load_dictionary("raddb/dictionary");


# Databases
my $dbh;  # Authentication
my $dbh_log;  # Logs

# Get db handle
$dbh = sm::dbilayer->new($cfg_db_DSN, $cfg_db_Username, $cfg_db_Password);
if (!$dbh) {
	print(STDERR "Error creating database object: ".sm::dbilayer->internalErr());
	exit 1;
}

# Connect to database
if ($dbh->connect() != 0) {
	print(STDERR "Error connecting to database: ".$dbh->err); 
	exit 1;