2012-09-18 - [GRASE-Hotspot] Reset user’s “Data Usage” back to zero?

Header Data

From: Bob Hunt <bo***2@gmail.com>
Message Hash: ed89eef8194e07b2f0dd383d580df9210bcab86124fc856300f10d0d603d7474
Message ID: <CAA-jMMSEiAoH43vazop2D7jYYnNo_RBtkw2Z=611qQVuBy3a=g@mail.gmail.com>
Reply To: <CAA-jMMTPZ=f9TsyZUDYYh7jpFM_dRtOK-cq=KTNX5vmGaNJorg@mail.gmail.com>
UTC Datetime: 2012-09-18 21:37:06 UTC
Raw Date: Wed, 19 Sep 2012 14:37:06 +1000

Raw message

Hi Tim,

Thanks for the reply. I think I might have responded to a wrong
address, a few days back, so retrying.

Adding data for a user doesn't help me , I think because of the
Freeradius 4Gig data_allocation_limit_bug.

Even after I add extra data and it looks as if the user is within
their quota (ie no longer highlighted in red or listed in the "out of
quota" group) they still get the "you have reached your bandwidth
limit" message and can't login.

Adding extra time I think only applies to online time based accounts,
rather than expiry based ones, which I use.

I thought that a solution might be to delete the user and then
recreate them with the exact same username/password but had concerns
that this could compromise the usage history data which I need to
preserve. I tried it and the data does seems to be preserved but so is
the total usage, so the problem remains.

I ran the following commands and it achieved what I wanted and reset
the user's data_usage to zero. You also lose the every session's d/l &
u/l amounts, but thats not an issue for me:

---------------------------------------------------------------------------
root@ubuntu-T60:/# mysql -u root -p radius;
Enter password:
mysql> UPDATE radacct
          -> SET AcctInputOctets=0 , AcctOutputOctets=0
           -> WHERE UserName="$user";
------------------------------------------------------------------------------

I can write a script doing this to be run outside the Grase
environment, to reset the data_usage for each user every month when I
reset their expiry date but it would be nice to have the function
available from the Grase edit user page.

Any chance?


++++++++++++++++++++++++++++++++++++++++++++++


I had a go myself.............

With your advice Tim, and (a lot of) help from my son, I have added a
function which does what I want to the Grase edituser page on my
install.

FYI, here are the details of what I did. I'm sure it can be cleaned up
a lot and it doesn't really follow your conventions, but it appears to
work OK for me;

I added a button after line 85 of ..radmin/templates/edituser.tpl with
the following line:
---------------------------------------------------------------------------------
<button class="negative" type="submit" name="resetdatause"
value="{t}Reset Data Usage to Zero for User{/t}" onClick="return
confirm('{t}Are you sure you want to reset this users
data_usage?{/t}')"><img src="/grase/images/icons/tick.png" alt=""/>{t
username=$user.Username}Reset Data Usage to Zero for User
%1{/t}</button>
------------------------------------------------------------------------------------



And I added the following lines to ../radmin/edituser.php at around line 37:
-----------------------------------------------------------------------------------
if(isset($_POST['resetdatause']))
        {   // Process form for resetting data used fields

                AdminLog::getInstance()->log("data reset to zero for
$username");
                $dbhost = 'localhost:3306';
                $dbuser = 'root';
                $dbpass = 'xxxxxxxxx';
                $conn = mysql_connect($dbhost, $dbuser, $dbpass);
                if(! $conn )
                {
                  die('Could not connect: ' . mysql_error());
                }
                $sql = "UPDATE radacct
                        SET AcctOutputOctets=0, AcctInputOctets=0
                        WHERE UserName=\"$username\"";

                mysql_select_db('radius');
                $retval = mysql_query( $sql, $conn );
                if(! $retval )
                {
                  die('Could not update data: ' . mysql_error());
                }
                echo "Updated data successfully\n";
                mysql_close($conn);
        }

-----------------------------------------------------------------------------------------


Can you please let me know if you think this will break anything and
will you consider including something like this in Grase as I've
already found it very useful ?

Regards,

Bob




Thread