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 (476)
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:
=============
Nigel Kukard <nkukard@lbsd.net>
Programmers:
============
Robert Anderson <randerson@lbsd.net>
Contributors:
=============
Robert Anderson
Wembu Pongo
......@@ -27,7 +27,7 @@ Enhanced features:
* Plugin: Topups
* Plugin: Auto-topups
* 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: Notifications, % based or approximate time based
* Plugin: User blacklists
......
......@@ -6,12 +6,13 @@ Installing SMRadius.
- Net::Server >= 0.96
- Config::IniFiles (Debian based: libconfig-inifiles-perl, RPM based: perl-Config-IniFiles)
- Cache::FastMmap (Debian based: libcache-fastmmap-perl, RPM based: perl-Cache-FastMmap)
- DateTime
- DateTime (requires: perl-Class-Singleton)
- TimeDate
- Crypt::DES
- Crytpt::RC4
- Digest::SHA1
- Digest::MD4
- Crypt::DES (Debian based: libcrypt-des-perl)
- Crytpt::RC4 (Debian based: libcrypt-rc4-perl)
- Digest::SHA1 (Debian based: libdigest-sha-perl)
- Digest::MD4 (Debian based: libdigest-md4-perl)
- Math::Expression
* Requirements for webui
- PHP v5+
......@@ -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
Version 2, June 1991
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
Preamble
The licenses for most software are designed to take away your
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.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
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
of preserving the free status of all derivatives of our free software and
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
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
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
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
possible use to the public, the best way to achieve this is to make it
......
# SMRadius Utility Functions
# Copyright (C) 2007-2009, AllWorldIT
# 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
......@@ -16,70 +16,34 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
## @class smradius::util
# Utility functions
package smradius::util;
use strict;
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
while (my ($entireMacro,$section,$item,$default) = ($string =~ /(\%{([a-z]+)\.([a-z0-9\-]+)(?:=([^}]+))?})/i )) {
# Replace macro with ?
$string =~ s/$entireMacro/\?/;
'VERSION_FROM' => "lib/smradius/version.pm",
# Get value to substitute
my $value = defined($hashref->{$section}->{$item}) ? $hashref->{$section}->{$item} : $default;
'DIR' => ["3rdparty"],
# Add value onto our array
push(@valueArray,$value);
}
return ($string, @valueArray);
}
'EXE_FILES' => [qw(
bin/smradiusd
bin/smadmin
bin/smradclient
)],
);
1;
# 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
------------------------------------
......
[![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,11 +3,12 @@ smradiusd:
* Strip off whitespaces around attributes
* Create a raddbpath config option which is prepended to dict paths
webgui:
* Group & attribute updates of WiSP users broken
* Realms with <> not displaying properly in realm window
* Inserting of realms with special characters, eg. <>, -
* Configurable 'use defaults for POD/CoA' we may not want to send these
smadmin:
* Ability to run smadmin before the end of current month and updating the records as necessary at a later stage
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
ALTER TABLE accounting ADD PeriodKey VARCHAR(7);
ALTER TABLE accounting_summary DROP COLUMN AcctInputPackets;
# smradiusd.conf
Modified:
accounting_start_query=<<EOT
INSERT INTO
@TP@accounting
(
Username,
ServiceType,
FramedProtocol,
NASPort,
NASPortType,
CallingStationID,
CalledStationID,
NASPortID,
AcctSessionID,
FramedIPAddress,
AcctAuthentic,
EventTimestamp,
AcctStatusType,
NASIdentifier,
NASIPAddress,
AcctDelayTime,
PeriodKey
)
VALUES
(
%{request.User-Name},
%{request.Service-Type},
%{request.Framed-Protocol},
%{request.NAS-Port},
%{request.NAS-Port-Type},
%{request.Calling-Station-Id},
%{request.Called-Station-Id},
%{request.NAS-Port-Id},
%{request.Acct-Session-Id},
%{request.Framed-IP-Address},
%{request.Acct-Authentic},
%{request.Timestamp},
%{request.Acct-Status-Type},
%{request.NAS-Identifier},
%{request.NAS-IP-Address},
%{request.Acct-Delay-Time},
%{query.PeriodKey}
)
EOT
accounting_update_query=<<EOT
UPDATE
@TP@accounting
SET
AcctSessionTime = %{query.AcctSessionTime},
AcctInputOctets = %{query.AcctInputOctets},
AcctInputGigawords = %{query.AcctInputGigawords},
AcctInputPackets = %{query.AcctInputPackets},
AcctOutputOctets = %{query.AcctOutputOctets},
AcctOutputGigawords = %{query.AcctOutputGigawords},
AcctOutputPackets = %{query.AcctOutputPackets},
AcctStatusType = %{request.Acct-Status-Type}
WHERE
Username = %{request.User-Name}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND PeriodKey = %{query.PeriodKey}
EOT
accounting_stop_query=<<EOT
UPDATE
@TP@accounting
SET
AcctSessionTime = %{query.Acct-Session-Time},
AcctInputOctets = %{query.Acct-Input-Octets},
AcctInputGigawords = %{query.Acct-Input-Gigawords},
AcctInputPackets = %{query.Acct-Input-Packets},
AcctOutputOctets = %{query.Acct-Output-Octets},
AcctOutputGigawords = %{query.Acct-Output-Gigawords},
AcctOutputPackets = %{query.Acct-Output-Packets}
WHERE
Username = %{request.User-Name}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
AND PeriodKey = %{query.PeriodKey}
EOT
Added:
accounting_update_get_records_query=<<EOT
SELECT
SUM(AcctInputOctets) AS InputOctets,
SUM(AcctInputPackets) AS InputPackets,
SUM(AcctOutputOctets) AS OutputOctets,
SUM(AcctOutputPackets) AS OutputPackets,
SUM(AcctInputGigawords) AS InputGigawords,
SUM(AcctOutputGigawords) AS OutputGigawords,
SUM(AcctSessionTime) AS SessionTime,
PeriodKey
FROM
@TP@accounting
WHERE
Username = %{request.User-Name}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
GROUP BY
PeriodKey
ORDER BY
ID ASC
EOT
accounting_stop_status_query=<<EOT
UPDATE
@TP@accounting
SET
AcctStatusType = %{request.Acct-Status-Type},
AcctTerminateCause = %{request.Acct-Terminate-Cause}
WHERE
Username = %{request.User-Name}
AND AcctSessionID = %{request.Acct-Session-Id}
AND NASIPAddress = %{request.NAS-IP-Address}
EOT
#!/usr/bin/perl
# SMRadius administration tool
# Copyright (C) 2009, AllWorldIT
# Copyright (C) 2009-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
......@@ -17,30 +17,37 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
use strict;
use warnings;
# Set library directory
use lib qw(
../ ./
smradius/modules/authentication
smradius/modules/userdb
smradius/modules/accounting
smradius/modules/features
smradius/modules/config
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 smradius::logging;
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...
my %opts;
......@@ -48,7 +55,9 @@ GetOptions(
\%opts,
"help",
"config:s",
"cleanup-date:s",
"cleanup",
"reset-userdata",
"debug",
);
......@@ -60,7 +69,7 @@ if ($opts{'help'}) {
# Set defaults
my $cfg;
$cfg->{'config_file'} = "smradiusd.conf.testing";
$cfg->{'config_file'} = "smradiusd.conf";
# Check if we must override
if (defined($opts{'config'}) && $opts{'config'} ne "") {
......@@ -81,7 +90,6 @@ tie my %inifile, 'Config::IniFiles', (
) or die "Failed to open config file '".$cfg->{'config_file'}."': $!";
# Copy config
my %config = %inifile;
# FIXME: This now generates a warning as Config::Inifiles doesn't implement UNTIE
# untie(%inifile);
......@@ -95,15 +103,35 @@ my $server;
# We must cleanup
if ($opts{'cleanup'}) {
# Check if we need to reset user data
my $reset_userdata = defined($opts{'reset-userdata'}) ? 1 : 0;
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
foreach my $module ( @{$server->{'modules'}} ) {
$server->log(LOG_INFO,"Module: " . $module->{'Name'});
my @sortedModules = sort {
(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 (defined($module->{'Cleanup'})) {
$server->log(LOG_INFO," -> running cleanup...");
$module->{'Cleanup'}($server);
$module->{'Cleanup'}($server,$cleanupMonth->epoch(),$reset_userdata);
}
}
......@@ -120,7 +148,7 @@ if ($opts{'cleanup'}) {
#
# Register plugin info
# Register module info
sub plugin_register {
my ($self,$module,$info) = @_;
......@@ -133,7 +161,7 @@ sub plugin_register {
# Set real module name & save
$info->{'Module'} = $module;
push(@{$self->{'modules'}},$info);
push(@{$self->{'modules_list'}},$info);
# If we should, init the module
if (defined($info->{'init'})) {
......@@ -148,95 +176,135 @@ sub plugin_register {
# Function to load our modules
sub loadModules
{
# FIXME HERE - START
#
# System plugins
# System modules
#
my @system_params = (
'plugins',
);
my $system;
foreach my $param (@system_params) {
$system->{$param} = $config{'system'}{$param} if (defined($config{'system'}{$param}));
}
if (!defined($system->{'plugins'})) {
$server->log(LOG_ERR,"[SMRADIUS] System configuration error: System plugins not found");
exit 1;
if (ref($config{'system'}{'modules'}) eq "ARRAY") {
foreach my $module (@{$config{'system'}{'modules'}}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "system/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'system'}{'modules'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "system/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
#
# Authentication plugins
# Authentication modules
#
my @auth_params = (
'mechanisms',
'users',
);
my $auth;
foreach my $param (@auth_params) {
$auth->{$param} = $config{'authentication'}{$param} if (defined($config{'authentication'}{$param}));
if (ref($config{'authentication'}{'mechanisms'}) eq "ARRAY") {
foreach my $module (@{$config{'authentication'}{'mechanisms'}}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "authentication/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'authentication'}{'mechanisms'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "authentication/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
if (!defined($auth->{'users'})) {
$server->log(LOG_ERR,"[SMRADIUS] Authentication configuration error: Userdb plugins not found");
exit 1;
if (ref($config{'authentication'}{'users'}) eq "ARRAY") {
foreach my $module (@{$config{'authentication'}{'users'}}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "userdb/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'authentication'}{'users'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "userdb/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
#
# Accounting plugins
# Accounting modules
#
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'})) {
$server->log(LOG_ERR,"[SMRADIUS] Accounting configuration error: Plugins not found");
exit 1;
if (ref($config{'accounting'}{'modules'}) eq "ARRAY") {
foreach my $module (@{$config{'accounting'}{'modules'}}) {
$module =~ s/\s+//g;
# Skip comments
next if ($module =~ /^#/);
$module = "accounting/$module";
push(@{$cfg->{'module_list'}},$module);
}
} else {
my @moduleList = split(/\s+/,$config{'accounting'}{'modules'});
foreach my $module (@moduleList) {
# Skip comments
next if ($module =~ /^#/);
$module = "accounting/$module";
push(@{$cfg->{'module_list'}},$module);
}
}
#
# Feature plugins
# Feature modules
#
my $features;
$features->{'plugins'} = [ ];
$features->{'plugins'} = $config{'features'}{'plugins'} if (defined($config{'features'}{'plugins'}));
# FIXME HERE = END
my $pluginlist = [
@{$auth->{'mechanisms'}},
@{$auth->{'users'}},
@{$acct->{'plugins'}},
@{$features->{'plugins'}},
@{$system->{'plugins'}}
];
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
$server = new smserver;
$server = smserver->new();
$server->{'inifile'} = \%config;
# Init everything
$server->init();
# Load plugins
foreach my $plugin (@{$pluginlist}) {
# Load plugin
my $res = eval("
use $plugin;
plugin_register(\$server,\"$plugin\",\$${plugin}::pluginInfo);
");
# Load modules
foreach my $module (@{$cfg->{'module_list'}}) {
# Split off dir and mod name
$module =~ /^(\w+)\/(\w+)$/;
my ($mod_dir,$mod_name) = ($1,$2);
# Load module
## no critic (BuiltinFunctions::ProhibitStringyEval)
my $res = eval qq{
use smradius::modules::${mod_dir}::${mod_name};
plugin_register(\$server,\"${mod_name}\",\$smradius::modules::${mod_dir}::${mod_name}::pluginInfo);
};
## use critic
if ($@ || (defined($res) && $res != 0)) {
$server->log(LOG_ERR,"WARNING: Error loading plugin $plugin ($@)");
$server->log(LOG_ERR,"WARNING: Error loading module $module ($@)");
} else {
$server->log(LOG_DEBUG,"[SMRADIUS] Plugin '$module' loaded.");
}
}
return;
}
......@@ -246,14 +314,17 @@ sub loadModules
# Display help
sub displayHelp {
print(<<EOF);
print(<<"EOF");
Usage: $0 [args]
--config=<file> Configuration file
--debug Put into debug mode
--cleanup Cleanup database records
--reset-userdata Reset user data counters in addition to --cleanup
EOF
return;
}
......@@ -267,8 +338,8 @@ use warnings;
use smradius::logging;
use smradius::config;
use smradius::dbilayer;
use smradius::dblayer;
use AWITPT::DB::DBILayer;
use AWITPT::DB::DBLayer;
# Return oursevles
sub new
......@@ -291,9 +362,9 @@ sub init
smradius::config::Init($self);
# Init system stuff
$self->{'client'}->{'dbh'} = smradius::dbilayer::Init($self);
$self->{'client'}->{'dbh'} = AWITPT::DB::DBILayer::Init($self,'smradius');
if (!defined($self->{'client'}->{'dbh'})) {
$self->log(LOG_WARN,"Failed to Initialize: ".smradius::dbilayer::internalErr()." ($$)");
$self->log(LOG_WARN,"Failed to Initialize: ".AWITPT::DB::DBILayer::internalError()." ($$)");
die;
}
if ($self->{'client'}->{'dbh'}->connect()) {
......@@ -301,16 +372,56 @@ sub init
die;
}
# Setup database handle
smradius::dblayer::setHandle($self->{'client'}->{'dbh'});
AWITPT::DB::DBLayer::setHandle($self->{'client'}->{'dbh'});
return;
}
sub log
# 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 ## 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
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 (
Timestamp DATETIME,
/* 1 = traffic topup, 2 = uptime topup */
/* 1 = traffic topup, 2 = uptime topup, 4 = auto-topup */
Type @INT_UNSIGNED@,
ValidFrom DATETIME,
......@@ -168,6 +168,7 @@ CREATE TABLE @PREFIX@topups (
Value @INT_UNSIGNED@,
Depleted SMALLINT NOT NULL DEFAULT '0',
SMAdminDepletedOn DATETIME,
FOREIGN KEY (UserID) REFERENCES @PREFIX@users(ID)
) @CREATE_TABLE_SUFFIX@;
......@@ -178,11 +179,12 @@ CREATE TABLE @PREFIX@topups_summary (
TopupID @SERIAL_REF_TYPE@ NOT NULL,
PeriodKey VARCHAR(255) NOT NULL,
PeriodKey VARCHAR(255) NOT NULL,
Balance @INT_UNSIGNED@,
Depleted SMALLINT NOT NULL DEFAULT '0',
SMAdminDepletedOn DATETIME,
FOREIGN KEY (TopupID) REFERENCES @PREFIX@topups(ID)
) @CREATE_TABLE_SUFFIX@;
......@@ -197,13 +199,13 @@ CREATE TABLE @PREFIX@accounting (
ServiceType @INT_UNSIGNED@,
FramedProtocol @INT_UNSIGNED@,
FramedProtocol @INT_UNSIGNED@,
NASPort VARCHAR(255),
NASPortType @INT_UNSIGNED@,
CallingStationID VARCHAR(255),
CallingStationID VARCHAR(255),
CalledStationID VARCHAR(255),
......@@ -239,9 +241,19 @@ CREATE TABLE @PREFIX@accounting (
AcctStatusType @INT_UNSIGNED@,
AcctTerminateCause @INT_UNSIGNED@
AcctTerminateCause @INT_UNSIGNED@,
PeriodKey VARCHAR(255)
) @CREATE_TABLE_SUFFIX@;
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);
......@@ -251,17 +263,31 @@ CREATE TABLE @PREFIX@accounting_summary (
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@;
AcctInputPackets @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);
AcctOutputOctets @INT_UNSIGNED@,
AcctOutputGigawords @INT_UNSIGNED@
/* Users data */
CREATE TABLE @PREFIX@users_data (
ID @SERIAL_TYPE@,
UserID @INT_UNSIGNED@,
LastUpdated DATETIME,
Name VARCHAR(255),
Value VARCHAR(255),
UNIQUE (UserID,Name)
) @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 $
#
......