User login Portal
Tudor
tudor at cotswoldpc.co.uk
Wed Apr 29 16:09:36 CEST 2009
like i say my php is basic
this is answer is helpful thanks
i have changed it a bit
as the user will not be logging in with their real username in the radius
server as it is a mac adress
so i changed the line
"FROM radacct WHERE UserName = '00-00-00-00-00-13'"
the idea is that the users home page will know the mac address
and i have changed the db connect line to my details for my server
but no result
like i say guidence really would be appreciated
> On 29/4/09 13:12, tudorg wrote:
>> I am trying to create a user login area where they can view their usage.
>> my php is very basic
>> My radius will authenticate user by mac address which i have working
>> so the user login for will take them to a home page in that page will be
>> a
>> link
>> to view usage
>> i would like a small pop up window (in the same page)with the result of
>> their total download and upload together
>> the mysql query would be
>> SELECT SUM( AcctInputOctets ) + SUM( AcctOutputOctets )/(1024*1024)
>> FROM radacct
>> WHERE UserName = '00-00-00-00-00-13'
>> any ideas on a small script for this would be appreciated
>
> PHP doesn't have a long int equivalent, you can do what you're doing, but
> it's better to use the BC maths library.
>
>
> <?php
>
> $unitsBytesBin =
> array('B','KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB');
>
> function bcHighPow($val, $precision = 2, $expLimit = 10, $base = 1024){
> $i = 0; $pDiv = 1; $val = (string) $val; $base = (string) $base;
> while (true) {
> $i++;
> $div = bcpow($base, (string) $i);
> if((bccomp($val, $div) === -1) || ($i >= $expLimit)){
> $out = bcdiv($val,$pDiv,$precision);
> break;
> }else
> $pDiv = $div;
> }
> return array((float) $out,$unitBytesBin[$i]);
> }
>
>
>
> $db = mysql_connect('mysqhost.example.com','user','password',true);
> mysql_select_db('database',$db);
>
> $dbResult = mysql_query(
> "SELECT CAST(SUM(`AcctInputOctets`) + SUM(`AcctOutputOctets`) AS CHAR)".
> "FROM radacct WHERE UserName = '$user'"
> );
>
> if(mysql_num_rows($dbResult)){
> $res = mysql_fetch_array($dbResult,MYSQL_NUM);
> /* insert HTML here */
> $nRes = bcHighPow($res[0]);
> echo $nRes[0]." ".$nRes[1];
> }else
> echo 'No data found';
>
> mysql_free_result($dbResult);
> mysql_close($db);
>
> ?>
>
> Not tested, but should give you an idea of what to do.
More information about the Freeradius-Users
mailing list