Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • smradius/smradius
  • centiva-shail/smradius
  • nkukard/smradius
3 results
Show changes
Commits on Source (435)
stages:
- quality
- tests
- install
code-quality:
stage: quality
script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get dist-upgrade -y
- apt-get install -y perl-modules
- apt-get install -y make
- apt-get install -y libperl-critic-perl
- perlcritic --gentle "$CI_PROJECT_DIR"
make-test:
stage: tests
script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get dist-upgrade -y
- apt-get install -y git make
- apt-get install -y libdevel-cover-perl libpod-coverage-perl libtest-most-perl
- apt-get install -y libnet-server-perl libconfig-inifiles-perl libdatetime-perl libcache-fastmmap-perl libtimedate-perl
libcrypt-des-perl libcrypt-rc4-perl libdigest-sha-perl libdigest-md4-perl libmime-lite-perl
- apt-get install -y mariadb-server
# Start services and create dirs we need
- service mysql start
- mkdir /var/run/smradius
# Update our dependencies
- cd "$CI_PROJECT_DIR"
- ./update-git-modules
- perl -MCPAN -e 'install Math::Expression' < /dev/null
# Build Makefile and make
- perl Makefile.PL
- make
# Convert DB into MySQL
- blib/script/convert-tsql MySQL database/core.tsql > database/core.mysql
- blib/script/convert-tsql MySQL database/users-accounting-summary.tsql > database/users-accounting-summary.mysql
- blib/script/convert-tsql MySQL database/wisp.tsql > database/wisp.mysql
# Load SQL into DB
- echo "CREATE DATABASE smradiustest;" | mysql -u root
- mysql -u root smradiustest < database/core.mysql
- mysql -u root smradiustest < database/users-accounting-summary.mysql
- mysql -u root smradiustest < database/wisp.mysql
# Sort out config file
- cp smradiusd.conf smradiusd.conf.test
- perl -pi -e 's/database=smradius/database=smradiustest/' smradiusd.conf.test
# Run tests, exclude all but smradius
- DBTESTS=1 cover -test -ignore_re '.*' -select_re '^blib\/lib\/smradius\/' | tee devel-coverage.txt
- grep "^Total" devel-coverage.txt | awk '{ print "(" $8 "%) covered" }'
make-install:
stage: install
script:
- export DEBIAN_FRONTEND=noninteractive
- apt-get update
- apt-get dist-upgrade -y
- apt-get install -y git make
- apt-get install -y mariadb-server
- cd "$CI_PROJECT_DIR"
- ./update-git-modules
- perl Makefile.PL
- make install
[submodule "webgui/awitef"]
path = webgui/awitef
url = https://gitlab.devlabs.linuxassist.net/awit-frameworks/awit-extjs-framework.git
[submodule "awitpt"]
path = 3rdparty/awitpt
url = https://gitlab.devlabs.linuxassist.net/awit-frameworks/awit-perl-toolkit.git
branch = v1.0.x
# Makefile
# Copyright (C) 2014-2016, 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.
use strict;
use warnings;
use ExtUtils::MakeMaker;
use File::Find;
my @additionalDirs = ();
find(
{
wanted => sub {
if (/^Makefile.PL$/) {
my $dirname = $File::Find::dir;
if ($dirname ne ".") {
$dirname =~ s,\./,,;
push(@additionalDirs,$dirname);
}
};
},
bydepth => 1,
},
".",
);
WriteMakefile(
'NAME' => 'SMRadius-3rdParty',
'DIR' => \@additionalDirs,
);
# vim: ts=4
awitpt @ 6944c201
Subproject commit 6944c2017372a13a334f902fdd8461e171393949
...@@ -2,7 +2,9 @@ Project Lead: ...@@ -2,7 +2,9 @@ Project Lead:
============= =============
Nigel Kukard <nkukard@lbsd.net> Nigel Kukard <nkukard@lbsd.net>
Programmers:
============ Contributors:
Robert Anderson <randerson@lbsd.net> =============
Robert Anderson
Wembu Pongo
...@@ -27,7 +27,7 @@ Enhanced features: ...@@ -27,7 +27,7 @@ Enhanced features:
* Plugin: Topups * Plugin: Topups
* Plugin: Auto-topups * Plugin: Auto-topups
* Plugin: Usage/Time caps * Plugin: Usage/Time caps
* Plugin: Prepaid accounting based on usage/time * Plugin: Prepaid accounting based on usage/time
* Plugin: Creation of accounting START records when no START record has been received but an interim update has - helps on slow/lossly links * Plugin: Creation of accounting START records when no START record has been received but an interim update has - helps on slow/lossly links
* Plugin: Notifications, % based or approximate time based * Plugin: Notifications, % based or approximate time based
* Plugin: User blacklists * Plugin: User blacklists
......
...@@ -6,12 +6,13 @@ Installing SMRadius. ...@@ -6,12 +6,13 @@ Installing SMRadius.
- Net::Server >= 0.96 - Net::Server >= 0.96
- Config::IniFiles (Debian based: libconfig-inifiles-perl, RPM based: perl-Config-IniFiles) - Config::IniFiles (Debian based: libconfig-inifiles-perl, RPM based: perl-Config-IniFiles)
- Cache::FastMmap (Debian based: libcache-fastmmap-perl, RPM based: perl-Cache-FastMmap) - Cache::FastMmap (Debian based: libcache-fastmmap-perl, RPM based: perl-Cache-FastMmap)
- DateTime - DateTime (requires: perl-Class-Singleton)
- TimeDate - TimeDate
- Crypt::DES - Crypt::DES (Debian based: libcrypt-des-perl)
- Crytpt::RC4 - Crytpt::RC4 (Debian based: libcrypt-rc4-perl)
- Digest::SHA1 - Digest::SHA1 (Debian based: libdigest-sha-perl)
- Digest::MD4 - Digest::MD4 (Debian based: libdigest-md4-perl)
- Math::Expression
* Requirements for webui * Requirements for webui
- PHP v5+ - PHP v5+
...@@ -19,3 +20,13 @@ Installing SMRadius. ...@@ -19,3 +20,13 @@ Installing SMRadius.
1. Setup system dirs
mkdir /var/log/smradius
mkdir /var/run/smradius
If you are running smradius as an unpriv user, then ...
chown smradius.smradius /var/log/smradius /var/run/smradius
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
Version 2, June 1991 Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc., Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
Preamble Preamble
The licenses for most software are designed to take away your The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public freedom to share and change it. By contrast, the GNU General Public
...@@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all. ...@@ -56,7 +56,7 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and The precise terms and conditions for copying, distribution and
modification follow. modification follow.
GNU GENERAL PUBLIC LICENSE GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains 0. This License applies to any program or other work which contains
...@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals ...@@ -255,7 +255,7 @@ make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally. of promoting the sharing and reuse of software generally.
NO WARRANTY NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
...@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER ...@@ -277,9 +277,9 @@ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES. POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it possible use to the public, the best way to achieve this is to make it
......
# SMRadius Utility Functions # Makefile
# Copyright (C) 2007-2009, AllWorldIT # Copyright (C) 2014-2016, AllWorldIT
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -16,70 +16,34 @@ ...@@ -16,70 +16,34 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
## @class smradius::util
# Utility functions
package smradius::util;
use strict; use strict;
use warnings; use warnings;
# Exporter stuff
require Exporter;
our (@ISA,@EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
niceUndef
templateReplace
);
## @fn niceUndef($string)
# If string defined return 'string', or if undefined return -undef-
#
# @param string String to check
#
# @return Return 'string' if defined, or -undef- otherwise
sub niceUndef
{
my $string = shift;
return defined($string) ? "'$string'" : '-undef-'; use ExtUtils::MakeMaker;
} use File::Find;
## @fn templateReplace($string,$hashref)
# Template string replacer function
#
# @param string String to replace template items in
# @param hashref Hashref containing the hash of tempalte items & values
#
# @return String with replaced items
sub templateReplace
{
my ($string,$hashref) = @_;
WriteMakefile(
'NAME' => 'SMRadius',
my @valueArray = (); 'VENDORPREFIX' => '/opt/smradius',
'INSTALLDIRS' => 'vendor',
# Replace blanks 'VERSION_FROM' => "lib/smradius/version.pm",
while (my ($entireMacro,$section,$item,$default) = ($string =~ /(\%{([a-z]+)\.([a-z0-9\-]+)(?:=([^}]+))?})/i )) {
# Replace macro with ?
$string =~ s/$entireMacro/\?/;
# Get value to substitute 'DIR' => ["3rdparty"],
my $value = defined($hashref->{$section}->{$item}) ? $hashref->{$section}->{$item} : $default;
# Add value onto our array 'EXE_FILES' => [qw(
push(@valueArray,$value); bin/smradiusd
bin/smadmin
} bin/smradclient
)],
return ($string, @valueArray); );
}
1;
# vim: ts=4 # vim: ts=4
# Copyright (C) 2007-2016, AllWorldIT
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The FreeRADIUS Server Project
#
# The following attribute examples and ideas is a derivative work of
# the files, documentation and operators used in the FreeRADIUS Server
# Project, which is licensed GPLv2. This file therefore is also licensed
# under the terms of the GNU Public License, verison 2
#
# 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.
Op Example and documentation Op Example and documentation
------------------------------------ ------------------------------------
......
[![build status](https://gitlab.devlabs.linuxassist.net/smradius/smradius/badges/master/build.svg)](https://gitlab.devlabs.linuxassist.net/smradius/smradius/commits/master)
[![coverage report](https://gitlab.devlabs.linuxassist.net/smradius/smradius/badges/master/coverage.svg)](https://gitlab.devlabs.linuxassist.net/smradius/smradius/commits/master)
\ No newline at end of file
...@@ -3,8 +3,12 @@ smradiusd: ...@@ -3,8 +3,12 @@ smradiusd:
* Strip off whitespaces around attributes * Strip off whitespaces around attributes
usage related queries: * Create a raddbpath config option which is prepended to dict paths
* Use Math module to perform calculations
* Configurable 'use defaults for POD/CoA' we may not want to send these
smadmin: smadmin:
* Update or possibly ignore entries instead of deleting (topup summaries) * Ability to run smadmin before the end of current month and updating the records as necessary at a later stage
r509: 2011-11-08:
/* change accounting index accounting_idx4 and accounting_idx5 */
DROP INDEX accounting_idx4 ON accounting;
DROP INDEX accounting_idx5 ON accounting;
CREATE INDEX accounting_idx5 ON accounting (Username,AcctSessionID,NASIPAddress,NASPort,PeriodKey);
CREATE INDEX accounting_idx4 ON accounting (Username,AcctSessionID,NASIPAddress,NASPort);
2011-11-04:
/* accounting_stop_status_query */
CREATE INDEX accounting_idx4 ON accounting (Username,AcctSessionID,NASIPAddress,NASPortID);
/* accounting_update_query */
CREATE INDEX accounting_idx5 ON accounting (Username,AcctSessionID,NASIPAddress,NASPortID,PeriodKey);
2011-10-14:
ALTER TABLE accounting_summary ADD COLUMN PeriodKey2 VARCHAR(255) AFTER PeriodKey;
UPDATE accounting_summary set PeriodKey2 = DATE_FORMAT(PeriodKey,'%Y-%m');
ALTER TABLE accounting_summary DROP COLUMN PeriodKey;
ALTER TABLE accounting_summary CHANGE COLUMN PeriodKey2 PeriodKey VARCHAR(255);
2011-03-22:
Add users_data table for various functions
CREATE TABLE @PREFIX@users_data (
ID @SERIAL_TYPE@,
UserID @INT_UNSIGNED@,
LastUpdated DATETIME,
Name VARCHAR(255),
Value VARCHAR(255),
UNIQUE (UserID,Name)
);
2011-01-11:
Move configuration file item "use_packet_timestamp=" to "[radius]" section
mkdir /var/log/smradius
mkdir /var/run/smradius
If you are running smradius as an unpriv user, then ...
chown smradius.smradius /var/log/smradius /var/run/smradius
---
r574:
# Database
ALTER TABLE topups ADD COLUMN SMAdminDepletedOn DATETIME;
ALTER TABLE topups_summary ADD COLUMN SMAdminDepletedOn DATETIME;
r538:
# Database
ALTER TABLE accounting_summary DROP COLUMN AcctSessionTime;
ALTER TABLE accounting_summary DROP COLUMN AcctInputOctets;
ALTER TABLE accounting_summary DROP COLUMN AcctInputGigawords;
ALTER TABLE accounting_summary DROP COLUMN AcctOutputOctets;
ALTER TABLE accounting_summary DROP COLUMN AcctOutputGigawords;
ALTER TABLE accounting_summary ADD COLUMN TotalSessionTime INT UNSIGNED;
ALTER TABLE accounting_summary ADD COLUMN TotalInput INT UNSIGNED;
ALTER TABLE accounting_summary ADD COLUMN TotalOutput INT UNSIGNED;
r509:
# Database # Database
ALTER TABLE accounting ADD PeriodKey VARCHAR(7); ALTER TABLE accounting ADD PeriodKey VARCHAR(7);
......
#!/usr/bin/perl #!/usr/bin/perl
# SMRadius administration tool # SMRadius administration tool
# Copyright (C) 2009, AllWorldIT # Copyright (C) 2009-2016, AllWorldIT
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -17,26 +17,37 @@ ...@@ -17,26 +17,37 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict; use strict;
use warnings; use warnings;
# Set library directory
use lib qw(
../ ./
smradius
awitpt/db
);
use Config;
use FindBin;
use lib ("$FindBin::Bin/../lib", "$FindBin::Bin/../share/perl5", "$FindBin::Bin/../share/perl/$Config{'version'}");
# Check Config::IniFiles is instaslled
if (!eval {require Config::IniFiles; 1;}) {
print STDERR "You're missing Config::IniFiles, try 'apt-get install libconfig-inifiles-perl'\n";
exit 1;
}
# Check DateTime is installed
if (!eval {require DateTime; 1;}) {
print STDERR "You're missing DateTime, try 'apt-get install libdatetime-perl'\n";
exit 1;
}
use Config::IniFiles;
use Getopt::Long; use Getopt::Long;
use smradius::logging; use smradius::logging;
use smradius::version; use smradius::version;
print("SMRadius Admin Tool v".VERSION." - Copyright (c) 2008-2009 AllWorldIT\n"); print("SMRadius Admin Tool v".VERSION." - Copyright (c) 2008-2016 AllWorldIT\n");
# Fire up commandline processing... # Fire up commandline processing...
my %opts; my %opts;
...@@ -44,7 +55,9 @@ GetOptions( ...@@ -44,7 +55,9 @@ GetOptions(
\%opts, \%opts,
"help", "help",
"config:s", "config:s",
"cleanup-date:s",
"cleanup", "cleanup",
"reset-userdata",
"debug", "debug",
); );
...@@ -90,15 +103,35 @@ my $server; ...@@ -90,15 +103,35 @@ my $server;
# We must cleanup # We must cleanup
if ($opts{'cleanup'}) { if ($opts{'cleanup'}) {
# Check if we need to reset user data
my $reset_userdata = defined($opts{'reset-userdata'}) ? 1 : 0;
loadModules(); loadModules();
# Pull where we are now and default to that, if we truncate the day we mess up the timezone calculations
my $cleanupMonth = DateTime->now()->set_time_zone($server->{'smradius'}->{'event_timezone'});
# If so the ndo it
if (defined($opts{'cleanup-date'}) && $opts{'cleanup-date'} ne "") {
# Split up and setup
my ($year,$month,$day) = split(/-/,$opts{'cleanup-date'});
$cleanupMonth = DateTime->new(year => $year, month => (defined($month) ? $month : 1), day => (defined($day) ? $day : 1));
}
$server->log(LOG_INFO,"Running cleanup for '%s'",$cleanupMonth->ymd());
# Loop with modules # Loop with modules
foreach my $module ( @{$server->{'modules_list'}} ) { my @sortedModules = sort {
$server->log(LOG_INFO,"Module: " . $module->{'Name'}); (defined($a->{'CleanupOrder'}) ? $a->{'CleanupOrder'} : 50) cmp (defined($b->{'CleanupOrder'}) ? $b->{'CleanupOrder'} : 50)
} @{$server->{'modules_list'}};
foreach my $module ( @sortedModules ) {
my $prio = defined($module->{'CleanupOrder'}) ? $module->{'CleanupOrder'} : 50;
$server->log(LOG_INFO,"Module: ".$module->{'Name'}." (prio: ".($module->{'CleanupOrder'} ? $prio : "default 50").")");
# If we have a cleanup module, run it # If we have a cleanup module, run it
if (defined($module->{'Cleanup'})) { if (defined($module->{'Cleanup'})) {
$server->log(LOG_INFO," -> running cleanup..."); $server->log(LOG_INFO," -> running cleanup...");
$module->{'Cleanup'}($server); $module->{'Cleanup'}($server,$cleanupMonth->epoch(),$reset_userdata);
} }
} }
...@@ -164,27 +197,6 @@ sub loadModules ...@@ -164,27 +197,6 @@ sub loadModules
} }
} }
#
# Feature modules
#
if (ref($config{'features'}{'modules'}) eq "ARRAY") {
foreach my $module (@{$config{'features'}{'modules'}}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "features/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'features'}{'modules'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "features/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
# #
# Authentication modules # Authentication modules
# #
...@@ -245,8 +257,29 @@ sub loadModules ...@@ -245,8 +257,29 @@ sub loadModules
} }
} }
#
# Feature modules
#
if (ref($config{'features'}{'modules'}) eq "ARRAY") {
foreach my $module (@{$config{'features'}{'modules'}}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "features/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'features'}{'modules'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "features/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
# Emulate server # Emulate server
$server = new smserver; $server = smserver->new();
$server->{'inifile'} = \%config; $server->{'inifile'} = \%config;
# Init everything # Init everything
$server->init(); $server->init();
...@@ -258,16 +291,20 @@ sub loadModules ...@@ -258,16 +291,20 @@ sub loadModules
my ($mod_dir,$mod_name) = ($1,$2); my ($mod_dir,$mod_name) = ($1,$2);
# Load module # Load module
my $res = eval(" ## no critic (BuiltinFunctions::ProhibitStringyEval)
my $res = eval qq{
use smradius::modules::${mod_dir}::${mod_name}; use smradius::modules::${mod_dir}::${mod_name};
plugin_register(\$server,\"${mod_name}\",\$smradius::modules::${mod_dir}::${mod_name}::pluginInfo); plugin_register(\$server,\"${mod_name}\",\$smradius::modules::${mod_dir}::${mod_name}::pluginInfo);
"); };
## use critic
if ($@ || (defined($res) && $res != 0)) { if ($@ || (defined($res) && $res != 0)) {
$server->log(LOG_ERR,"WARNING: Error loading module $module ($@)"); $server->log(LOG_ERR,"WARNING: Error loading module $module ($@)");
} else { } else {
$server->log(LOG_DEBUG,"[SMRADIUS] Plugin '$module' loaded."); $server->log(LOG_DEBUG,"[SMRADIUS] Plugin '$module' loaded.");
} }
} }
return;
} }
...@@ -277,14 +314,17 @@ sub loadModules ...@@ -277,14 +314,17 @@ sub loadModules
# Display help # Display help
sub displayHelp { sub displayHelp {
print(<<EOF); print(<<"EOF");
Usage: $0 [args] Usage: $0 [args]
--config=<file> Configuration file --config=<file> Configuration file
--debug Put into debug mode --debug Put into debug mode
--cleanup Cleanup database records --cleanup Cleanup database records
--reset-userdata Reset user data counters in addition to --cleanup
EOF EOF
return;
} }
...@@ -298,8 +338,8 @@ use warnings; ...@@ -298,8 +338,8 @@ use warnings;
use smradius::logging; use smradius::logging;
use smradius::config; use smradius::config;
use awitpt::db::dbilayer; use AWITPT::DB::DBILayer;
use awitpt::db::dblayer; use AWITPT::DB::DBLayer;
# Return oursevles # Return oursevles
sub new sub new
...@@ -322,9 +362,9 @@ sub init ...@@ -322,9 +362,9 @@ sub init
smradius::config::Init($self); smradius::config::Init($self);
# Init system stuff # Init system stuff
$self->{'client'}->{'dbh'} = awitpt::db::dbilayer::Init($self,'smradius'); $self->{'client'}->{'dbh'} = AWITPT::DB::DBILayer::Init($self,'smradius');
if (!defined($self->{'client'}->{'dbh'})) { if (!defined($self->{'client'}->{'dbh'})) {
$self->log(LOG_WARN,"Failed to Initialize: ".awitpt::db::dbilayer::internalError()." ($$)"); $self->log(LOG_WARN,"Failed to Initialize: ".AWITPT::DB::DBILayer::internalError()." ($$)");
die; die;
} }
if ($self->{'client'}->{'dbh'}->connect()) { if ($self->{'client'}->{'dbh'}->connect()) {
...@@ -332,16 +372,56 @@ sub init ...@@ -332,16 +372,56 @@ sub init
die; die;
} }
# Setup database handle # Setup database handle
awitpt::db::dblayer::setHandle($self->{'client'}->{'dbh'}); AWITPT::DB::DBLayer::setHandle($self->{'client'}->{'dbh'});
return;
}
# Same format as Net::Server
sub log_time {
my ($sec,$min,$hour,$day,$mon,$year) = localtime;
return sprintf("%04d/%02d/%02d-%02d:%02d:%02d",
$year+1900, $mon+1, $day, $hour, $min, $sec);
} }
sub log
sub log ## no critic (Subroutines::ProhibitBuiltinHomonyms)
{ {
my ($self,$level,@msg) = @_; my ($self,$level,$msg,@args) = @_;
# Check log level and set text
my $logtxt = "UNKNOWN";
if ($level == LOG_DEBUG) {
$logtxt = "DEBUG";
} elsif ($level == LOG_INFO) {
$logtxt = "INFO";
} elsif ($level == LOG_NOTICE) {
$logtxt = "NOTICE";
} elsif ($level == LOG_WARN) {
$logtxt = "WARNING";
} elsif ($level == LOG_ERR) {
$logtxt = "ERROR";
}
# Parse message nicely
if ($msg =~ /^(\[[^\]]+\]) (.*)/s) {
$msg = "$1 $logtxt: $2";
} else {
$msg = "[CORE] $logtxt: $msg";
}
# If we have args, this is more than likely a format string & args
if (@args > 0) {
$msg = sprintf($msg,@args);
}
# FIXME: we shouldn't ignore $level # FIXME: we shouldn't ignore $level
print(@msg, "\n"); print(STDERR "[".log_time()." - $$] $msg\n");
return;
} }
......
#!/usr/bin/perl
# Radius client
# Copyright (C) 2007-2016, 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.
use strict;
use warnings;
use Config;
use FindBin;
use lib ("$FindBin::Bin/../lib", "$FindBin::Bin/../share/perl5", "$FindBin::Bin/../share/perl/$Config{'version'}");
use smradius::client;
# Grab and exit with result received
my $res = smradius::client->run();
exit($res);
# vim: ts=4
#!/usr/bin/perl
# Radius daemon
# Copyright (C) 2007-2016, 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.
use strict;
use warnings;
use Config;
use FindBin;
use lib ("$FindBin::Bin/../lib", "$FindBin::Bin/../share/perl5", "$FindBin::Bin/../share/perl/$Config{'version'}");
use smradius::daemon;
smradius::daemon->run();
1;
# vim: ts=4
#!/bin/bash
# Database translation/creation script
# Copyright (C) 2009, AllWorldIT
# Copyright (C) 2008, LinuxRulz
#
# 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.
database="$1"
file="$2"
prefix="$3"
# Display usage info
display_usage() {
echo "Usage: $0 <database type> <file> [prefix]"
echo
echo "Valid database types:"
echo " mysql4 - For MySQL v4"
echo " mysql - For MySQL v5"
echo " pgsql - For PostgreSQL"
echo " sqlite - For SQLite v3"
echo
exit
}
# Check we have our params
if [ -z "$database" -o -z "$file" ]
then
display_usage
fi
# Check file exists
if [ ! -f "$file" ]
then
echo "ERROR: Cannot open file '$file'"
exit 1
fi
# Check what we converting for
case "$database" in
"mysql4")
sed \
-e "s/@PREFIX@/$prefix/g" \
-e 's/@PRELOAD@/SET FOREIGN_KEY_CHECKS=0;/' \
-e 's/@POSTLOAD@/SET FOREIGN_KEY_CHECKS=1;/' \
-e 's/@CREATE_TABLE_SUFFIX@/TYPE=InnoDB CHARACTER SET latin1 COLLATE latin1_bin/' \
-e 's/@SERIAL_TYPE@/SERIAL/' \
-e 's/@BIGINT_UNSIGNED@/BIGINT UNSIGNED/' \
-e 's/@INT_UNSIGNED@/INT UNSIGNED/' \
-e 's/@TRACK_KEY_LEN@/255/' \
-e 's/@SERIAL_REF_TYPE@/BIGINT UNSIGNED/' < "$file"
;;
"mysql")
sed \
-e "s/@PREFIX@/$prefix/g" \
-e 's/@PRELOAD@/SET FOREIGN_KEY_CHECKS=0;/' \
-e 's/@POSTLOAD@/SET FOREIGN_KEY_CHECKS=1;/' \
-e 's/@CREATE_TABLE_SUFFIX@/TYPE=InnoDB CHARACTER SET latin1 COLLATE latin1_bin/' \
-e 's/@SERIAL_TYPE@/SERIAL/' \
-e 's/@BIGINT_UNSIGNED@/BIGINT UNSIGNED/' \
-e 's/@INT_UNSIGNED@/INT UNSIGNED/' \
-e 's/@TRACK_KEY_LEN@/512/' \
-e 's/@SERIAL_REF_TYPE@/BIGINT UNSIGNED/' < "$file"
;;
"pgsql")
sed \
-e "s/@PREFIX@/$prefix/g" \
-e 's/@PRELOAD@/SET CONSTRAINTS ALL DEFERRED;/' \
-e 's/@POSTLOAD@//' \
-e 's/@CREATE_TABLE_SUFFIX@//' \
-e 's/@SERIAL_TYPE@/SERIAL PRIMARY KEY/' \
-e 's/@BIGINT_UNSIGNED@/INT8/' \
-e 's/@INT_UNSIGNED@/INT8/' \
-e 's/@TRACK_KEY_LEN@/512/' \
-e 's/@SERIAL_REF_TYPE@/INT8/' < "$file"
;;
"sqlite")
sed \
-e "s/@PREFIX@/$prefix/g" \
-e 's/@PRELOAD@//' \
-e 's/@POSTLOAD@//' \
-e 's/@CREATE_TABLE_SUFFIX@//' \
-e 's/@SERIAL_TYPE@/INTEGER PRIMARY KEY AUTOINCREMENT/' \
-e 's/@BIGINT_UNSIGNED@/INT8/' \
-e 's/@INT_UNSIGNED@/INT8/' \
-e 's/@TRACK_KEY_LEN@/512/' \
-e 's/@SERIAL_REF_TYPE@/INT8/' < "$file"
;;
*)
echo "ERROR: Invalid database type '$database'"
exit 1
;;
esac
...@@ -159,7 +159,7 @@ CREATE TABLE @PREFIX@topups ( ...@@ -159,7 +159,7 @@ CREATE TABLE @PREFIX@topups (
Timestamp DATETIME, Timestamp DATETIME,
/* 1 = traffic topup, 2 = uptime topup */ /* 1 = traffic topup, 2 = uptime topup, 4 = auto-topup */
Type @INT_UNSIGNED@, Type @INT_UNSIGNED@,
ValidFrom DATETIME, ValidFrom DATETIME,
...@@ -168,6 +168,7 @@ CREATE TABLE @PREFIX@topups ( ...@@ -168,6 +168,7 @@ CREATE TABLE @PREFIX@topups (
Value @INT_UNSIGNED@, Value @INT_UNSIGNED@,
Depleted SMALLINT NOT NULL DEFAULT '0', Depleted SMALLINT NOT NULL DEFAULT '0',
SMAdminDepletedOn DATETIME,
FOREIGN KEY (UserID) REFERENCES @PREFIX@users(ID) FOREIGN KEY (UserID) REFERENCES @PREFIX@users(ID)
) @CREATE_TABLE_SUFFIX@; ) @CREATE_TABLE_SUFFIX@;
...@@ -178,11 +179,12 @@ CREATE TABLE @PREFIX@topups_summary ( ...@@ -178,11 +179,12 @@ CREATE TABLE @PREFIX@topups_summary (
TopupID @SERIAL_REF_TYPE@ NOT NULL, TopupID @SERIAL_REF_TYPE@ NOT NULL,
PeriodKey VARCHAR(255) NOT NULL, PeriodKey VARCHAR(255) NOT NULL,
Balance @INT_UNSIGNED@, Balance @INT_UNSIGNED@,
Depleted SMALLINT NOT NULL DEFAULT '0', Depleted SMALLINT NOT NULL DEFAULT '0',
SMAdminDepletedOn DATETIME,
FOREIGN KEY (TopupID) REFERENCES @PREFIX@topups(ID) FOREIGN KEY (TopupID) REFERENCES @PREFIX@topups(ID)
) @CREATE_TABLE_SUFFIX@; ) @CREATE_TABLE_SUFFIX@;
...@@ -197,13 +199,13 @@ CREATE TABLE @PREFIX@accounting ( ...@@ -197,13 +199,13 @@ CREATE TABLE @PREFIX@accounting (
ServiceType @INT_UNSIGNED@, ServiceType @INT_UNSIGNED@,
FramedProtocol @INT_UNSIGNED@, FramedProtocol @INT_UNSIGNED@,
NASPort VARCHAR(255), NASPort VARCHAR(255),
NASPortType @INT_UNSIGNED@, NASPortType @INT_UNSIGNED@,
CallingStationID VARCHAR(255), CallingStationID VARCHAR(255),
CalledStationID VARCHAR(255), CalledStationID VARCHAR(255),
...@@ -244,6 +246,14 @@ CREATE TABLE @PREFIX@accounting ( ...@@ -244,6 +246,14 @@ CREATE TABLE @PREFIX@accounting (
PeriodKey VARCHAR(255) PeriodKey VARCHAR(255)
) @CREATE_TABLE_SUFFIX@; ) @CREATE_TABLE_SUFFIX@;
CREATE INDEX @PREFIX@accounting_idx1 ON @PREFIX@accounting (Username); CREATE INDEX @PREFIX@accounting_idx1 ON @PREFIX@accounting (Username);
CREATE INDEX @PREFIX@accounting_idx2 ON @PREFIX@accounting (PeriodKey);
/* accounting_stop_status_query */
CREATE INDEX @PREFIX@accounting_idx4 ON @PREFIX@accounting (Username,AcctSessionID,NASIPAddress,NASPort);
/* accounting_update_query */
CREATE INDEX @PREFIX@accounting_idx5 ON @PREFIX@accounting (Username,AcctSessionID,NASIPAddress,NASPort,PeriodKey);
/* Index for the EventTimestamp */
CREATE INDEX @PREFIX@accounting_idx7 ON @PREFIX@accounting (EventTimestamp);
CREATE INDEX @PREFIX@accounting_idx8 ON @PREFIX@accounting (Username,EventTimestamp);
...@@ -253,15 +263,31 @@ CREATE TABLE @PREFIX@accounting_summary ( ...@@ -253,15 +263,31 @@ CREATE TABLE @PREFIX@accounting_summary (
Username VARCHAR(255), Username VARCHAR(255),
PeriodKey DATETIME, PeriodKey VARCHAR(255),
AcctSessionTime @INT_UNSIGNED@, TotalSessionTime @INT_UNSIGNED@,
AcctInputOctets @INT_UNSIGNED@, TotalInput @INT_UNSIGNED@,
AcctInputGigawords @INT_UNSIGNED@, TotalOutput @INT_UNSIGNED@
) @CREATE_TABLE_SUFFIX@;
AcctOutputOctets @INT_UNSIGNED@, CREATE INDEX @PREFIX@accounting_summary_idx1 ON @PREFIX@accounting_summary (Username);
CREATE INDEX @PREFIX@accounting_summary_idx2 ON @PREFIX@accounting_summary (PeriodKey);
CREATE INDEX @PREFIX@accounting_summary_idx3 ON @PREFIX@accounting_summary (Username,PeriodKey);
/* Users data */
CREATE TABLE @PREFIX@users_data (
ID @SERIAL_TYPE@,
UserID @INT_UNSIGNED@,
LastUpdated DATETIME,
Name VARCHAR(255),
Value VARCHAR(255),
AcctOutputGigawords @INT_UNSIGNED@ UNIQUE (UserID,Name)
) @CREATE_TABLE_SUFFIX@; ) @CREATE_TABLE_SUFFIX@;
ALTER TABLE @PREFIX@users ADD COLUMN PeriodKey VARCHAR(255);
ALTER TABLE @PREFIX@users ADD COLUMN TotalTraffic @INT_UNSIGNED@;
ALTER TABLE @PREFIX@users ADD COLUMN TotalUptime @INT_UNSIGNED@;
ALTER TABLE @PREFIX@users ADD COLUMN NASIdentifier VARCHAR(255);
ALTER TABLE @PREFIX@users ADD COLUMN LastAcctUpdate DATETIME;
# Copyright (C) 2007-2016, AllWorldIT
# Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The FreeRADIUS Server Project
#
# The following dictionary file is a derivative work of the dictionary file
# from the FreeRADIUS Server Project, which is licensed GPLv2. This file
# therefore is also licensed under the terms of the GNU Public License,
# verison 2
#
# 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.
# #
# Version $Id: dictionary,v 1.1 2006/11/14 17:45:00 lem Exp $ # Version $Id: dictionary,v 1.1 2006/11/14 17:45:00 lem Exp $
# #
......