diff --git a/smadmin b/smadmin index dd71bdea076f17337b85dc5a272805c6a2775ff5..6ed1a4e7aa55a243bccea055d53839233cfd923a 100755 --- a/smadmin +++ b/smadmin @@ -29,6 +29,7 @@ use lib qw( smradius/modules/accounting smradius/modules/features smradius/modules/config + awitpt/db ); diff --git a/smradius/cache.pm b/smradius/cache.pm deleted file mode 100644 index c322b874820f3b6c4877d4f116701d23acf36111..0000000000000000000000000000000000000000 --- a/smradius/cache.pm +++ /dev/null @@ -1,217 +0,0 @@ -# Caching engine -# Copyright (C) 2007-2009, 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 smradius::cache; - -use strict; -use warnings; - - -require Exporter; -our (@ISA,@EXPORT); -@ISA = qw(Exporter); -@EXPORT = qw( - cacheStoreKeyPair - cacheGetKeyPair -); - -use Cache::FastMmap; - -# Cache stuff -my $cache_type = "FastMmap"; -my $cache; - - -# Our current error message -my $error = ""; - -# Set current error message -# Args: error_message -sub setError -{ - my $err = shift; - my ($package,$filename,$line) = caller; - my (undef,undef,undef,$subroutine) = caller(1); - - # Set error - $error = "$subroutine($line): $err"; -} - -# Return current error message -# Args: none -sub Error -{ - my $err = $error; - - # Reset error - $error = ""; - - # Return error - return $err; -} - - - - - -# Initialize cache -sub Init -{ - my $server = shift; - my $ch; - - - # Create Cache - $ch = Cache::FastMmap->new( - 'page_size' => 2048, - 'num_pages' => 1000, - 'raw_values' => 1, - 'unlink_on_exit' => 1, - ); - - # Stats - $ch->set('Cache/Stats/Hit',0); - $ch->set('Cache/Stats/Miss',0); - - # Set server vars - $server->{'cache_engine'}{'handle'} = $ch; -}; - -# Destroy cache -sub Destroy -{ - my $server = shift; - -}; - -# Connect child to cache -sub connect -{ - my $server = shift; - - $cache = $server->{'cache_engine'}{'handle'}; -} - - -# Disconnect child from cache -sub disconnect -{ - my $server = shift; - -} - - -# Store keypair in cache -# Parameters: -# CacheName - Name of cache we storing things in -# Key - Item key -# Value - Item value -sub cacheStoreKeyPair -{ - my ($cacheName,$key,$value) = @_; - - - if (!defined($cacheName)) { - setError("Cache name not defined in store"); - return -1; - } - - if (!defined($key)) { - setError("Key not defined for cache '$cacheName' store"); - return -1; - } - - if (!defined($value)) { - setError("Value not defined for cache '$cacheName' key '$key' store"); - return -1; - } - - # If we're not caching just return - return 0 if ($cache_type eq 'none'); - - # Store - $cache->set("$cacheName/$key",$value); - - return 0; -} - - -# Get data from key in cache -# Parameters: -# CacheName - Name of cache we storing things in -# Key - Item key -sub cacheGetKeyPair -{ - my ($cacheName,$key) = @_; - - - if (!defined($cacheName)) { - setError("Cache name not defined in get"); - return (-1); - } - - if (!defined($key)) { - setError("Key not defined for cache '$cacheName' get"); - return (-1); - } - - # If we're not caching just return - if ($cache_type eq 'none') { - return (0,undef); - } - - # Check and count - my $res = $cache->get("$cacheName/$key"); - if ($res) { - $cache->get_and_set('Cache/Stats/Hit',sub { return ++$_[1]; }); - } else { - $cache->get_and_set('Cache/Stats/Miss',sub { return ++$_[1]; }); - } - - return (0,$res); -} - - -# Return cache hit ratio -sub getHitRatio -{ - my $res; - - - # Get counter - $res = $cache->get('Cache/Stats/Hit'); - - return $res; -} - - -# Return cache miss ratio -sub getMissRatio -{ - my $res; - - - # Get counter - $res = $cache->get('Cache/Stats/Miss'); - - return $res; -} - - -1; -# vim: ts=4 diff --git a/smradius/dbilayer.pm b/smradius/dbilayer.pm deleted file mode 100644 index 1bf2c000dcba1f28fd5e704cdf7b093623f6a55a..0000000000000000000000000000000000000000 --- a/smradius/dbilayer.pm +++ /dev/null @@ -1,359 +0,0 @@ -# Database independent layer module -# Copyright (C) 2007-2009, AllWorldIT -# Copyright (C) 2005-2007, Nigel Kukard <nkukard@lbsd.net> -# -# 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 smradius::dbilayer; - -use strict; -use warnings; - - -use smradius::config; -use DBI; - - - -my $internalError = ""; - - -sub internalErr -{ - my $error = $internalError; - - $internalError = ""; - - return $error; -} - - -# Initialize class and return a fully connected object -sub Init -{ - my $server = shift; - my $dbconfig = $server->{'smradius'}->{'database'}; - - - # Check if we created - my $dbh = smradius::dbilayer->new($dbconfig->{'DSN'},$dbconfig->{'Username'},$dbconfig->{'Password'},$dbconfig->{'TablePrefix'}); - return undef if (!defined($dbh)); - - return $dbh; -} - - -# Constructor -sub new -{ - my ($class,$dsn,$username,$password,$table_prefix) = @_; - - # Iternals - my $self = { - _dbh => undef, - _error => undef, - - _dsn => undef, - _username => undef, - _password => undef, - - _table_prefix => "", - - _in_transaction => undef, - }; - - # Set database parameters - if (defined($dsn)) { - $self->{_dsn} = $dsn; - $self->{_username} = $username; - $self->{_password} = $password; - $self->{_table_prefix} = $table_prefix if (defined($table_prefix) && $table_prefix ne ""); - } else { - $internalError = "Invalid DSN given"; - return undef; - } - - # Create... - bless $self, $class; - return $self; -} - - - -# Return current error message -# Args: none -sub Error -{ - my ($self) = @_; - - my $err = $self->{_error}; - - # Reset error - $self->{_error} = ""; - - # Return error - return $err; -} - - -# Return connection to database -# Args: none -sub connect -{ - my ($self) = @_; - - - $self->{_dbh} = DBI->connect($self->{_dsn}, $self->{_username}, $self->{_password}, { - 'AutoCommit' => 1, - 'PrintError' => 0, - 'FetchHashKeyName' => 'NAME_lc' - }); - - # Connect to database if we have to, check if we ok - if (!$self->{_dbh}) { - $self->{_error} = "Error connecting to database: $DBI::errstr"; - return -1; - } - - # Apon connect we are not in a transaction - $self->{_in_transaction} = 0; - - return 0; -} - - -# Check database connection -# Args: none -sub _check -{ - my $self = shift; - - - # If we not in a transaction try connect - if ($self->{_in_transaction} == 0) { - # Try ping - if (!$self->{_dbh}->ping()) { - # Disconnect & reconnect - $self->{_dbh}->disconnect(); - $self->connect(); - } - } -} - - -# Return database selection results... -# Args: <select statement> -sub select -{ - my ($self,$query,@params) = @_; - - - $self->_check(); - -# # Build single query instead of using binding of params -# # not all databases support binding, and not all support all -# # the places we use ? -# $query =~ s/\?/%s/g; -# # Map each element in params to the quoted value -# $query = sprintf($query, -# map { $self->quote($_) } @params -# ); -#use Data::Dumper; print STDERR Dumper($query); - # Prepare query - my $sth; - if (!($sth = $self->{_dbh}->prepare($query))) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - # Check for execution error -# if (!$sth->execute()) { - if (!$sth->execute(@params)) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - return $sth; -} - - -# Perform a command -# Args: <command statement> -sub do -{ - my ($self,$command,@params) = @_; - - - $self->_check(); - -# # Build single command instead of using binding of params -# # not all databases support binding, and not all support all -# # the places we use ? -# $command =~ s/\?/%s/g; -# # Map each element in params to the quoted value -# $command = sprintf($command, -# map { $self->quote($_) } @params -# ); -#use Data::Dumper; print STDERR Dumper($command); - - # Prepare query - my $sth; -# if (!($sth = $self->{_dbh}->do($command))) { - if (!($sth = $self->{_dbh}->do($command,undef,@params))) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - return $sth; -} - - -# Function to get last insert id -# Args: <table> <column> -sub lastInsertID -{ - my ($self,$table,$column) = @_; - - - # Get last insert id - my $res; - if (!($res = $self->{_dbh}->last_insert_id(undef,undef,$table,$column))) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - return $res; -} - - -# Function to begin a transaction -# Args: none -sub begin -{ - my ($self) = @_; - - $self->_check(); - - $self->{_in_transaction}++; - - # Don't really start transaction if we more than 1 deep - if ($self->{_in_transaction} > 1) { - return 1; - } - - # Begin - my $res; - if (!($res = $self->{_dbh}->begin_work())) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - return $res; -} - - -# Function to commit a transaction -# Args: none -sub commit -{ - my ($self) = @_; - - - # Reduce level - $self->{_in_transaction}--; - - # If we not at top level, return success - if ($self->{_in_transaction} > 0) { - return 1; - } - - # Reset transaction depth to 0 - $self->{_in_transaction} = 0; - - # Commit - my $res; - if (!($res = $self->{_dbh}->commit())) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - return $res; -} - - -# Function to rollback a transaction -# Args: none -sub rollback -{ - my ($self) = @_; - - - # If we at top level, return success - if ($self->{_in_transaction} < 1) { - return 1; - } - - $self->{_in_transaction} = 0; - - # Rollback - my $res; - if (!($res = $self->{_dbh}->rollback())) { - $self->{_error} = $self->{_dbh}->errstr; - return undef; - } - - return $res; -} - - -# Function to quote a database variable -# Args: <stuff to quote> -sub quote -{ - my ($self,$stuff) = @_; - - return $self->{_dbh}->quote($stuff); -} - - -# Function to cleanup DB query -# Args: <sth> -sub free -{ - my ($self,$sth) = @_; - - - if ($sth) { - $sth->finish(); - } -} - - -# Function to return the table prefix -sub table_prefix -{ - my $self = shift; - - return $self->{_table_prefix}; -} - - - - -1; -# vim: ts=4 diff --git a/smradius/dblayer.pm b/smradius/dblayer.pm deleted file mode 100644 index 5dd69a4e65cd51fffe371be95df15926ed3fb290..0000000000000000000000000000000000000000 --- a/smradius/dblayer.pm +++ /dev/null @@ -1,292 +0,0 @@ -# Common database layer module -# Copyright (C) 2007-2009, AllWorldIT -# Copyright (C) 2005-2007 Nigel Kukard <nkukard@lbsd.net> -# -# 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 smradius::dblayer; - -use strict; -use warnings; - -# Exporter stuff -require Exporter; -our (@ISA,@EXPORT); -@ISA = qw(Exporter); -@EXPORT = qw( - DBConnect - DBSelect - DBDo - DBLastInsertID - DBBegin - DBCommit - DBRollback - DBQuote - DBFreeRes - - DBSelectNumResults - - hashifyLCtoMC -); - - - -use smradius::config; - -use smradius::dbilayer; - - -# Database handle -my $dbh = undef; - -# Our current error message -my $error = ""; - -# Set current error message -# Args: error_message -sub setError -{ - my $err = shift; - my ($package,$filename,$line) = caller; - my (undef,undef,undef,$subroutine) = caller(1); - - # Set error - $error = "$subroutine($line): $err"; -} - -# Return current error message -# Args: none -sub Error -{ - my $err = $error; - - # Reset error - $error = ""; - - # Return error - return $err; -} - - - -# Initialize database handle -# Args: <database handle> -sub setHandle -{ - my $handle = shift; - - $dbh = $handle; -} - - -# Return database selection results... -# Args: <select statement> -sub DBSelect -{ - my ($query,@params) = @_; - - - my $table_prefix = $dbh->table_prefix(); - - # Replace table prefix macro - $query =~ s/\@TP\@/$table_prefix/g; - - # Prepare query - my $sth; - if (!($sth = $dbh->select($query,@params))) { - setError("Error executing select '$query': ".$dbh->Error()); - return undef; - } - - return $sth; -} - - -# Perform a command -# Args: <command statement> -sub DBDo -{ - my ($command,@params) = @_; - - - my $table_prefix = $dbh->table_prefix(); - - # Replace table prefix macro - $command =~ s/\@TP\@/$table_prefix/g; - - # Prepare query - my $sth; - if (!($sth = $dbh->do($command,@params))) { - setError("Error executing command '$command': ".$dbh->Error()); - return undef; - } - - return $sth; -} - - -# Function to get last insert id -# Args: <table> <column> -sub DBLastInsertID -{ - my ($table,$column) = @_; - - - my $res; - if (!($res = $dbh->lastInsertID(undef,undef,$table,$column))) { - setError("Error getting last inserted id: ".$dbh->Error()); - return undef; - } - - return $res; -} - - -# Function to begin a transaction -# Args: none -sub DBBegin -{ - my $res; - if (!($res = $dbh->begin())) { - setError("Error beginning transaction: ".$dbh->Error()); - return undef; - } - - return $res; -} - - -# Function to commit a transaction -# Args: none -sub DBCommit -{ - my $res; - if (!($res = $dbh->commit())) { - setError("Error committing transaction: ".$dbh->Error()); - return undef; - } - - return $res; -} - - -# Function to rollback a transaction -# Args: none -sub DBRollback -{ - my $res; - if (!($res = $dbh->rollback())) { - setError("Error rolling back transaction: ".$dbh->Error()); - return undef; - } - - return $res; -} - - -# Function to quote a database variable -# Args: <stuff to quote> -sub DBQuote -{ - my $stuff = shift; - - - return $dbh->quote($stuff); -} - - -# Function to cleanup DB query -# Args: <sth> -sub DBFreeRes -{ - my $sth = shift; - - - if ($sth) { - $sth->finish(); - } -} - - - -# -# Value Added Functions -# - - -# Function to get table prefix -sub DBTablePrefix -{ - return $dbh->table_prefix(); -} - - - -# Return how many results came up from the specific SELECT query -# Args: <select statement> -sub DBSelectNumResults -{ - my $query = shift; - - - # Prepare query - my $sth; - if (!($sth = $dbh->select("SELECT COUNT(*) AS num_results $query"))) { - setError("Error executing select: ".$dbh->Error()); - return undef; - } - - # Grab row - my $row = $sth->fetchrow_hashref(); - if (!defined($row)) { - setError("Failed to get results from a select: ".$dbh->Error()); - return undef; - } - - # Pull number - my $num_results = $row->{'num_results'}; - $sth->finish(); - - return $num_results; -} - - -# Convert a lower case array to mixed case -sub hashifyLCtoMC -{ - my ($record,@entries) = @_; - - - # If we undefined, return - return undef if (!defined($record)); - - my $res; - - # Loop with each item, assign from lowecase database record to our result - foreach my $entry (@entries) { - $res->{$entry} = $record->{lc($entry)}; - } - - return $res; -} - - - - - -1; -# vim: ts=4 diff --git a/smradius/modules/accounting/mod_accounting_sql.pm b/smradius/modules/accounting/mod_accounting_sql.pm index 04d5f0a357fb4402529f8a5846c1a642be180110..68ad616f5723f50d30857a93ddf02f9177247011 100644 --- a/smradius/modules/accounting/mod_accounting_sql.pm +++ b/smradius/modules/accounting/mod_accounting_sql.pm @@ -22,7 +22,7 @@ use warnings; # Modules we need use smradius::constants; -use smradius::dblayer; +use awitpt::db::dblayer; use smradius::logging; use smradius::util; @@ -225,7 +225,7 @@ sub getUsage # Fetch data my $sth = DBSelect(@dbDoParams); if (!$sth) { - $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Database query failed: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Database query failed: ".awitpt::db::dblayer::Error()); return; } @@ -306,7 +306,7 @@ sub acct_log my $sth = DBDo(@dbDoParams); if (!$sth) { $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Failed to insert accounting START record: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); return MOD_RES_NACK; } @@ -318,7 +318,7 @@ sub acct_log my $sth = DBDo(@dbDoParams); if (!$sth) { $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Failed to update accounting ALIVE record: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); return MOD_RES_NACK; } @@ -329,7 +329,7 @@ sub acct_log # Update database my $sth = DBDo(@dbDoParams); if (!$sth) { - $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Failed to update accounting STOP record: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Failed to update accounting STOP record: ".awitpt::db::dblayer::Error()); return MOD_RES_NACK; } } @@ -380,7 +380,7 @@ sub cleanup if (!$sth) { $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Cleanup => Failed to select accounting record: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); return; } @@ -440,7 +440,7 @@ sub cleanup if (!$sth) { DBRollback(); $server->log(LOG_ERR,"[MOD_ACCOUNTING_SQL] Cleanup => Failed to insert accounting record: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); return; } diff --git a/smradius/modules/config/mod_config_sql.pm b/smradius/modules/config/mod_config_sql.pm index 509d0cf42676d0d4a2e9c55e9ed8fe3721ec7cdc..054fa1086854c58e6675ead6d4e3911a8cca06ba 100644 --- a/smradius/modules/config/mod_config_sql.pm +++ b/smradius/modules/config/mod_config_sql.pm @@ -1,16 +1,16 @@ # SQL config database support # Copyright (C) 2007-2009, 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. @@ -23,7 +23,7 @@ use warnings; # Modules we need use smradius::constants; use smradius::logging; -use smradius::dblayer; +use awitpt::db::dblayer; use smradius::util; use smradius::attributes; @@ -42,7 +42,7 @@ our (@ISA,@EXPORT,@EXPORT_OK); our $pluginInfo = { Name => "SQL Config Database", Init => \&init, - + # User database Config_get => \&getConfig, }; @@ -66,10 +66,10 @@ sub init # Default configs... $config->{'get_config_query'} = ' - SELECT + SELECT Name, Operator, Value - FROM - @TP@realm_attributes + FROM + @TP@realm_attributes '; # Setup SQL queries @@ -82,7 +82,7 @@ sub init } else { $config->{'get_config_query'} = $scfg->{'mod_config_sql'}->{'get_config_query'}; } - + } } } @@ -106,10 +106,10 @@ sub getConfig # Query database my $sth = DBSelect(@dbDoParams); if (!$sth) { - $server->log(LOG_ERR,"Failed to get config attributes: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"Failed to get config attributes: ".awitpt::db::dblayer::Error()); return MOD_RES_NACK; } - + # Loop with user attributes while (my $row = $sth->fetchrow_hashref()) { processConfigAttribute($server,$user->{'ConfigAttributes'},hashifyLCtoMC($row,qw(Name Operator Value))); diff --git a/smradius/modules/config/mod_config_sql_topups.pm b/smradius/modules/config/mod_config_sql_topups.pm index 56a9e75daf2c20012117b808d793f02c6e74a21a..073f8453e4a7b0a535f8e30674e5ea39b20f4166 100644 --- a/smradius/modules/config/mod_config_sql_topups.pm +++ b/smradius/modules/config/mod_config_sql_topups.pm @@ -23,7 +23,7 @@ use warnings; # Modules we need use smradius::constants; use smradius::logging; -use smradius::dblayer; +use awitpt::db::dblayer; use smradius::util; use smradius::attributes; @@ -155,7 +155,7 @@ sub getTopups # Query database my $sth = DBSelect($config->{'get_topups_summary_query'},$periodKey,$packet->attr('User-Name')); if (!$sth) { - $server->log(LOG_ERR,"Failed to get topup information: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"Failed to get topup information: ".awitpt::db::dblayer::Error()); return MOD_RES_NACK; } @@ -176,7 +176,7 @@ sub getTopups # Query database $sth = DBSelect($config->{'get_topups_query'},$thisMonth,$now,$packet->attr('User-Name')); if (!$sth) { - $server->log(LOG_ERR,"Failed to get topup information: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"Failed to get topup information: ".awitpt::db::dblayer::Error()); return MOD_RES_NACK; } @@ -268,7 +268,7 @@ sub cleanup if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to select from users: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); return; } @@ -340,7 +340,7 @@ sub cleanup if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to select accounting records: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } @@ -392,7 +392,7 @@ sub cleanup if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to select usage caps: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } @@ -436,7 +436,7 @@ sub cleanup if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to select topup summaries: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } @@ -492,7 +492,7 @@ sub cleanup if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to select topups: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } @@ -768,7 +768,7 @@ sub cleanup ); if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups_summary: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } } @@ -788,7 +788,7 @@ sub cleanup ); if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } } @@ -808,7 +808,7 @@ sub cleanup ); if (!$sth) { $server->log(LOG_ERR,"[MOD_CONFIG_SQL_TOPUPS] Cleanup => Failed to update topups_summary: ". - smradius::dblayer::Error()); + awitpt::db::dblayer::Error()); goto FAIL_ROLLBACK; } } diff --git a/smradius/modules/userdb/mod_userdb_sql.pm b/smradius/modules/userdb/mod_userdb_sql.pm index 985a5cea4cf3632ff75e6808e4e0f3df90b68603..6e1ac2cd96452bac396d6a4d54c79d3cafb6ae54 100644 --- a/smradius/modules/userdb/mod_userdb_sql.pm +++ b/smradius/modules/userdb/mod_userdb_sql.pm @@ -23,7 +23,7 @@ use warnings; # Modules we need use smradius::constants; use smradius::logging; -use smradius::dblayer; +use awitpt::db::dblayer; use smradius::util; use smradius::attributes; @@ -155,7 +155,7 @@ sub find my $sth = DBSelect(@dbDoParams); if (!$sth) { - $server->log(LOG_ERR,"[MOD_USERDB_SQL] Failed to find user data: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"[MOD_USERDB_SQL] Failed to find user data: ".awitpt::db::dblayer::Error()); return MOD_RES_SKIP; } @@ -209,7 +209,7 @@ sub get # Query database my $sth = DBSelect(@dbDoParams); if (!$sth) { - $server->log(LOG_ERR,"Failed to get group attributes: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"Failed to get group attributes: ".awitpt::db::dblayer::Error()); return -1; } @@ -227,7 +227,7 @@ sub get # Query database $sth = DBSelect(@dbDoParams); if (!$sth) { - $server->log(LOG_ERR,"Failed to get user attributes: ".smradius::dblayer::Error()); + $server->log(LOG_ERR,"Failed to get user attributes: ".awitpt::db::dblayer::Error()); return -1; } diff --git a/smradiusd b/smradiusd index f21032ac20ff01a546d5f53bee01f4f5cc7a99a7..d25c8748c49dfe1eadacedf0a899da1670d64044 100755 --- a/smradiusd +++ b/smradiusd @@ -28,6 +28,7 @@ use lib qw( smradius/modules/accounting smradius/modules/features smradius/modules/config + awitpt/db ); package radiusd; @@ -43,8 +44,8 @@ use smradius::version; use smradius::constants; use smradius::logging; use smradius::config; -use smradius::dbilayer; -use smradius::cache; +use awitpt::db::dbilayer; +use awitpt::cache; use smradius::util; use smradius::attributes; @@ -246,12 +247,23 @@ sub configure { exit 1; } # Split off dictionaries to load - foreach my $fn (@{$dictionary->{'load'}}) { - $fn =~ s/\s+//g; + if (ref($dictionary->{'load'}) eq "ARRAY") { + foreach my $dict (@{$dictionary->{'load'}}) { + $dict =~ s/\s+//g; + # Skip comments + next if ($dict =~ /^#/); + push(@{$cfg->{'dictionary_list'}},$dict); + } + } else { + my @dictList = split(/\s+/,$dictionary->{'load'}); + foreach my $dict (@dictList) { + # Skip comments + next if ($dict =~ /^#/); + push(@{$cfg->{'dictionary_list'}},$dict); + } } $cfg->{'authentication'} = $auth; - $cfg->{'dictionary'} = $dictionary; $cfg->{'plugins'} = [ @{$auth->{'mechanisms'}}, @@ -288,12 +300,12 @@ sub post_configure_hook { # Load dictionaries $self->log(LOG_NOTICE,"[SMRADIUS] Initializing dictionaries..."); my $dict = new Radius::Dictionary; - foreach my $fn (@{$config->{'dictionary'}->{'load'}}) { + foreach my $df (@{$config->{'dictionary_list'}}) { # Load dictionary - if (!$dict->readfile($fn)) { - $self->log(LOG_WARN,"[SMRADIUS] Failed to load dictionary '$fn': $!"); + if (!$dict->readfile($df)) { + $self->log(LOG_WARN,"[SMRADIUS] Failed to load dictionary '$df': $!"); } - $self->log(LOG_DEBUG,"[SMRADIUS] Loaded plugin '$fn'."); + $self->log(LOG_DEBUG,"[SMRADIUS] Loaded plugin '$df'."); } $self->log(LOG_NOTICE,"[SMRADIUS] Dictionaries initialized."); # Store the dictionary