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 -- View this message in context: http://www.nabble.com/User-login-Portal-tp23295565p23295565.html Sent from the FreeRadius - User mailing list archive at Nabble.com.
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@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
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.
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
still blank heres what i have done so far still need big help much appreciated <?php error_reporting(E_ALL); $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('localhost','root','*******',true); mysql_select_db('radius',$db); $dbResult = mysql_query( "SELECT CAST(SUM(`AcctInputOctets`) + SUM(`AcctOutputOctets`) AS CHAR)". "FROM radacct WHERE UserName = '00-00-00-00-00-13'" ); if(mysql_num_rows($dbResult)){ $res = mysql_fetch_array($dbResult,MYSQL_NUM); /* insert HTML here */ $nRes = bcHighPow(bcmul($res[0],'8')); echo $nRes[0]." ".$nRes[1]; }else echo 'No data found'; mysql_free_result($dbResult); mysql_close($db); ?>
I am trying to create a user login area where they can view their usage. my php is very basic
So are your requirements.
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
You can trawl the Internet for hours looking for it. Or you can spend a couple of hours working through something like: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/default.aspx (connect to and retrieve data from MySQL tutorials) and be able to do it yourself. Ivan Kalik Kalik Informatika ISP
participants (4)
-
Arran Cudbard-Bell -
Ivan Kalik -
Tudor -
tudorg