On 29/4/09 15:09, Tudor wrote:
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
Did you change the 'database' string to your actual database ? Insert error_reporting(E_ALL); at the top and see if you get any errors. Oh and /* insert HTML here */ $nRes = bcHighPow($res[0]); should be /* insert HTML here */ $nRes = bcHighPow(bcmul($res[0],'8')); Arran
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.
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
-- Arran Cudbard-Bell (A.Cudbard-Bell@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