User login Portal
Arran Cudbard-Bell
A.Cudbard-Bell at sussex.ac.uk
Wed Apr 29 15:34:50 CEST 2009
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.
--
Arran Cudbard-Bell (A.Cudbard-Bell at sussex.ac.uk),
Authentication, Authorisation and Accounting Officer,
Infrastructure Services (IT Services),
E1-1-08, Engineering 1, University Of Sussex, Brighton, BN1 9QT
DDI+FAX: +44 1273 873900 | INT: 3900
GPG: 86FF A285 1AA1 EE40 D228 7C2E 71A9 25BB 1E68 54A2
More information about the Freeradius-Users
mailing list