Friday, July 11, 2014

Setting up Freeradius with Daloradius in Ubuntu 12.04


1. Install freeradius
# apt-get install freeradius
2. Install pre-requisite package for daloradius
# apt-get install php5-common php5-gd php-pear php-db libapache2-mod-php5 php-mail
3. Download latest daloradius from http://sourceforge.net/projects/daloradius/ . Latest version as of now is 0.9.9
4. Uncompress daloradius-0.9-9.tar.gz to your web directory which is /var/www assuming you have installed apache2 prior to that. 
# cd /var/www
# tar xzf /your-directory/daloradius-0.9-9.tar.gz
5. Create a symbolic link for daloradius-0.9-9 for easy access
ln -s daloradius-0.9-9 daloradius
6. Install the freeradius + daloradius database from daloradius package. 
  Note: Use -h option if the mysql server is not installed in the same server
# cd daloradius/contrib/db
mysql -u -p < fr2-mysql-daloradius-and-freeradius.sql -h  -D 


Configure Database settings in Daloradius

1. Open db config file in Daloradius
# cd /var/www/daloradius/library
# vi daloradius.conf.php
2. Edit the following value according to your mysql setup
$configValues['CONFIG_DB_HOST'] = 'localhost';
$configValues['CONFIG_DB_USER'] = 'root';
$configValues['CONFIG_DB_PASS'] = '';
$configValues['CONFIG_DB_NAME'] = 'radius';
3. Save the file after changes made.


Configure MySQL in Freeradius

1. Open sql config file in freeradius
# cd /etc/freeradius
# vi sql.conf
2. Modify the following value under sql directive
server = “”
login = “”
password = “”
radius_db = “”
3. Uncomment “readclients = yes” for radius client (NAS) to be read from database
4. Save the file after changes made


Enable sql for Radius Authorization and Accounting

1. Install freeradius-mysql driver
# apt-get install freeradius-mysql
2. Uncomment the following line in radiusd.conf
# $INCLUDE sql.conf
3. Uncomment the line with sql” under “authorize” and “accounting” directive in /etc/freeradius/sites-available/default


Enable Max-All-Session attribute for controlling User maximum session time

1. Add the following snippet in /etc/freeradius/sites-available/default under authorize directive
noresetcounter {
    reject = 1
}
if(reject){
   update reply {
       Reply-Message := "You have reached your time limit"
   }
   ok = reject
}
2. Add the following snippet in /etc/freeradius/sql/mysql/counter.conf
sqlcounter noresetcounter {
        counter-name = Max-All-Session-Time
                check-name = Max-All-Session
                sqlmod-inst = sql
                key = User-Name
                reset = never
        Reply-Message = "Your Maximum Never Used time has been reached!"
        query = "SELECT IFNULL(SUM(AcctSessionTime),0) FROM radacct WHERE UserName='%{%k}'"
}

Enable Max-Octets attribute for controlling User maximum usage quota in bytes

1. Add the following snippet in /etc/freeradius/sites-available/default under authorize directive
noresetBytecounter {
    reject = 1
}
if(reject) {
    update reply {
        Reply-Message := "You have reached your bandwidth limit"
    }
    ok = reject
}
2. Add the following snippet in /etc/freeradius/sql/mysql/counter.conf
sqlcounter noresetBytecounter {
        counter-name = Total-Max-Octets
                check-name = Max-Octets
                reply-name = ChilliSpot-Max-Total-Octets
                sqlmod-inst = sql
                key = User-Name
                reset = never
        Reply-Message = "Your Maximum Data Usage Quota has been reached!"
        query = "SELECT (SUM(AcctInputOctets)+SUM(AcctOutputOctets)) FROM radacct WHERE UserName='%{%k}'"
}

No comments: