diff --git a/smradius/modules/accounting/mod_accounting_test.pm b/smradius/modules/accounting/mod_accounting_test.pm new file mode 100644 index 0000000000000000000000000000000000000000..263290270ee5b9b37e231648192748a328fac76a --- /dev/null +++ b/smradius/modules/accounting/mod_accounting_test.pm @@ -0,0 +1,78 @@ +# Test accounting database +# +# Copyright (C) 2008, AllWorldIT +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +package mod_accounting_test; + +use strict; +use warnings; + +# Modules we need +use smradius::constants; +use smradius::logging; + + +# Exporter stuff +require Exporter; +our (@ISA,@EXPORT,@EXPORT_OK); +@ISA = qw(Exporter); +@EXPORT = qw( +); +@EXPORT_OK = qw( +); + + + +# Plugin info +our $pluginInfo = { + Name => "Test Accounting Database", + Init => \&init, + + # Accounting database + Accounting_log => \&acct_log, +}; + + + +## @internal +# Initialize module +sub init +{ + my $server = shift; +} + + + +## @log +# Try find a user +# +# @param server Server object +# @param packet Radius packet +# +# @return Result +sub acct_log +{ + my ($server,$packet) = @_; + + + $server->log(LOG_DEBUG,"Packet: ".$packet->dump()); + + return MOD_RES_SKIP; +} + + +1; diff --git a/smradiusd b/smradiusd index 20f95900562dd96aa6f4946dc32766b05bdffc9d..b738f728fae19f09b1e63cd1fad50e672a3bc9ed 100755 --- a/smradiusd +++ b/smradiusd @@ -26,6 +26,7 @@ use lib qw( ../ ./ smradius/modules/authentication smradius/modules/userdb + smradius/modules/accounting ); package radiusd; @@ -195,6 +196,27 @@ sub configure { $plugin =~ s/\s+//g; } + # + # Accounting plugins + # + my @acct_params = ( + 'plugins', + ); + my $acct; + foreach my $param (@acct_params) { + $acct->{$param} = $config{'accounting'}{$param} if (defined($config{'accounting'}{$param})); + } + + if (!defined($acct->{'plugins'})) { + $self->log(LOG_ERR,"[SMRADIUS] Accounting configuration error: Plugins not found"); + exit 1; + } + + # Split off plugins + foreach my $plugin (@{$auth->{'plugins'}}) { + $plugin =~ s/\s+//g; + } + # # Dictionary configuration # @@ -220,7 +242,8 @@ sub configure { $cfg->{'plugins'} = [ @{$auth->{'mechanisms'}}, - @{$auth->{'users'}} + @{$auth->{'users'}}, + @{$acct->{'plugins'}} ]; # Save our config and stuff @@ -465,6 +488,33 @@ sub process_request { $self->log(LOG_DEBUG,"[SMRADIUS] Accounting Request Packet"); + # Loop with modules to try something that handles accounting + foreach my $module (@{$self->{'plugins'}}) { + # Try find user + if ($module->{'Accounting_log'}) { + $self->log(LOG_INFO,"[SMRADIUS] ACCOUNTING: Trying plugin '".$module->{'Name'}."'"); + my $res = $module->{'Accounting_log'}($self,$pkt); + + # Check result + if (!defined($res)) { + $self->log(LOG_DEBUG,"[SMRADIUS] ACCOUNTING: Error with plugin '".$module->{'Name'}."'"); + + # Check if we skipping this plugin + } elsif ($res == MOD_RES_SKIP) { + $self->log(LOG_DEBUG,"[SMRADIUS] ACCOUNTING: Skipping '".$module->{'Name'}."'"); + + # Check if we got a positive result back + } elsif ($res == MOD_RES_ACK) { + $self->log(LOG_NOTICE,"[SMRADIUS] ACCOUNTING: Accounting logged using '".$module->{'Name'}."'"); + + # Check if we got a negative result back + } elsif ($res == MOD_RES_NACK) { + $self->log(LOG_NOTICE,"[SMRADIUS] ACCOUNTING: Accounting NOT LOGGED using '".$module->{'Name'}."'"); + } + } + } + + # Or maybe a access request } elsif ($pkt->code eq "Access-Request") {