Thursday, May 09, 2013

Modify Easyhotspot as Radius Server External

modify easyhotspot

EasyHotspot is an open source software, so it should not matter, if you make modifications. In this post, I will change a little EasyHotspot. And this relates to the previous post, Mikrotik and EasyHotspot as Hotspot, we can’t disconnect user  from radius server / EasyHotspot. so what should we do?
First, we must know how to disconnect the user. General command to disconnect users, in a radius server, including easyhotpsot, using the command radclient.
echo “user-name=<username>” | radclient -x ipaddress:3799 disconnect <password>
For example :
echo “User-Name=11” | radclient -x disconnect easyhotspot

Command above, only for FreeRadius and Chillispot / coovachilli, in 1 machine. What if we have an external radius server, and Chillispot / coovachilli replaced with mikrotik?? After searching with the help of “Om Google”, I finally found the way.

echo “user-name=<username>, Framed-IP-Address=<ipaddressclient>” | radclient -x ipaddress:3799 disconnect <password>
For example :
echo User-Name=11,Framed-IP-Address= | radclient -x disconnect testing123
It can also be without username.
echo Framed-IP-Address= | radclient -x disconnect testing123

The above command means, radius server sends a packet of disconnect (POD) to the radius client (mikrotik), to disconnect users. Next, modifying code PHP in EasyHotspot, so that the php code when executed, will produce a command to disconnect users, as above.

1.      Edit  /opt/EasyHotspot/htdocs/system/application/views/onlineusers_view.php.
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); ?>
<?php $this->load->view('header') ?>


<table class="stripe">
                <th>IP Address</th>
                <th>Force Disconnect</th>
        <?php foreach ($onlineusers->result() as $row): ?>
                <td><?=anchor('onlineuser/disconnect/'.$row->ipaddress,'disconnect','class="disconnect" ')?></td>
        <?php endforeach;?>

<? $this->load->view('footer'); ?>

2.      Edit /opt/EasyHotspot/htdocs/system/application/helpers/freeradius_helper.php. Adjust the following few lines of code.

 function freeradius_disconnectuser($ipaddress, $radiuscommand, $radiusserver, $radiussecret){
            $ci =& get_instance();
            $result = exec('echo Framed-IP-Address='.$ipaddress.' | '.$radiuscommand.' '.$radiusserver.' disconnect '.$radiussecret);
            $ci->db->query("UPDATE radacct SET acctstoptime=now(), acctterminatecause='Force Disconnect' WHERE username = '$username' and acctstoptime is NULL");

3.      Edit /opt/EasyHotspot/htdocs/system/application/models/onlineusermodel.php

Class Onlineusermodel extends model {
            function onlineusermodel(){
                        $this->_table_acct = 'radacct';
            function get_onlineusers() {
            // this works no matter what ...I think !!!
                        // return $this->db->query('select username, MAX(acctstarttime) as start, MAX(acctstoptime) as stop, sum(acctsessiontime) as time,sum(acctoutputoctets)+sum(acctinputoctets) as packet from radacct group by username having (start > stop) or (stop IS NULL)');
                        return $this->db->query('select username, framedipaddress as ipaddress, MAX(acctstarttime) as start, (acctstoptime) as stop, sum(acctsessiontime) as time,sum(acctoutputoctets)+sum(acctinputoctets) as packet from radacct  where (acctstoptime IS NULL) group by username');


4.      At last, edit /opt/EasyHotspot/htdocs/system/application/config/config.php
Make sure the FreeRADIUS section, ip address and a radius secret is correct.
$config['radiusserver'] =';
$config['radiuscommand'] = 'radclient -x';
$config['radiussecret'] = 'testing123';

At EasyHotspot, we do not need the section Chillispot. When click Chillispot, it would seem the error, and it is not nice views. To make it look better, we can remove the chillispot section. Edit /opt/EasyHotspot/htdocs/system/application/views/admin/header.php. Make sure a line about Chillispot, deleted, or given token comment.
<!--   <li class="chillispot"><?=anchor('admin/chillispot','Chillispot')?></li> -->
<!--   <li class="radius"><?=anchor('admin/freeradius','FreeRadius')?></li> -->

Done. Good luck...!!

1 comment:

  1. and how about different NAS's, placed at different places?