Show User Accounts Balance

Use this forum to post questions relating to WinGate, feature requests, technical or configuration problems

Moderator: Qbik Staff

Show User Accounts Balance

Postby rodo37 » Jul 31 07 3:10 am

Hello,

I've a hotspot and I've created a PHP file to read data from "Export User Accounts" task.

Features :

Show in HTML the Export User Accounts file
Translation is possible

Version 1.1
+ Add N/A is cell is blank - Thanks to logan

Version 1.2
+ Data show now KB, MB or GB
+ Time online show now min or hours
+ Balance show device (USD, EUR, ...)
Thanks to logan who help me to add these functions

Code: Select all
<style type="text/css">
  <!--
    body,td,th {
      font-family: Verdana, Arial, Helvetica, sans-serif;
      font-size: 10px;
    }
  -->
</style>

<table width="100%" border="1" cellspacing="2" cellpadding="2">

<?php

  /* BEGIN SCRIPT CONFIGURATION */

  //Location of exported accounts file
  $exported_accounts = "accounts.txt";
 
  //Translation of column headers
  $translation[0] = "Timestamp";        //Timestamp
  $translation[1] = "Account";          //Username
  $translation[2] = "Full Name";        //Real Name
  $translation[3] = "Downloaded";     //Client Send (b)
  $translation[4] = "Uploaded";       //Client Recv (b)
  $translation[5] = "Uploaded For";   //Server Send (b)
  $translation[6] = "Downloaded For"; //Server Recv (b)
  $translation[7] = "Time Online";          //Time (s)
  $translation[8] = "Opening Balance";  //Opening
  $translation[9] = "Closing Balance";  //Closing
 
  // Other Translation
 
  $hours = "hours"; // hours
  $minutes = "min"; // minutes
  $GB = "GB"; // Gigabytes
  $MB = "MB"; // Megabytes
  $KB = "KB"; // Kilobytes
  $Bytes = "Bytes"; // Bytes
  $device = "USD";
 
  /* END SCRIPT CONFIGURATION */
 
 
  $header = array("Timestamp", "Username", "Real Name", "Client Send (b)", "Client Recv (b)", "Server Send (b)", "Server Recv (b)", "Time (s)", "Opening", "Closing");
  $handle = fopen($exported_accounts, "r");
  $row = 0;
 
while (($data = fgetcsv($handle, 1000, "   ")) !== FALSE) {
 $num = count($data);
 $data = str_replace($header, $translation, $data);
 $row++;
   
    echo "<tr>";
   
for ($c=0; $c < $num; $c++) {
If ($data[$c] == "" or $data[$c] == "<system>")
echo "<td>&nbsp;</td>";
else { 
If ($c == 7 and $row > 1)

// Time Function
If ($data[$c] < 3600)
{$data[$c] = round($data[$c] / 60, 2)." ".$minutes;}
else
{$data[$c] = round($data[$c] / 3600, 2)." ".$hours;}

// Datas Transfered Function
If ($c > 2 and $c < 7 and $row > 1)
if ($data[$c] > 1073741824)
{$data[$c] = round($data[$c] / 1073741824, 2)." ".$GB;}      
else If ($data[$c] > 1048576)
{$data[$c] = round($data[$c] / 1048576, 2)." ".$MB;}      
else If ($data[$c] > 1024)
{$data[$c] = round($data[$c] / 1024, 2)." ".$KB;}   
else If ($data[$c] < 1024)
{$data[$c] = round($data[$c], 2)." ".$Bytes;}      

// Balance Function
If ($c > 7 and $c < 10 and $row > 1) $data[$c] = round($data[$c], 2)." ".$device;

     
echo "<td>".$data[$c]."</td>";
}
}
   
echo "</tr>";
}
 
fclose($handle);
?>

</table>


Let me know your feedback ;)
Last edited by rodo37 on Aug 02 07 9:33 pm, edited 5 times in total.
rodo37
 
Posts: 5
Joined: Jul 31 07 2:57 am

Postby genie » Aug 01 07 12:03 pm

Thanks - I am sure many users would benefit from the script.
genie
Qbik Staff
 
Posts: 1788
Joined: Sep 30 03 10:29 am

Postby logan » Aug 01 07 3:17 pm

I took a look at your script in action and I must say, it is pretty neat. There were just a couple of modifications I had to do to make it work for me.


1) The forum must have changed the delimiter in the fgetcsv command from a tab, to three spaces. This needs to be changed back into a tab after copying the script for it to work properly.

Code: Select all
while (($data = fgetcsv($handle, 1000, "   ")) !== FALSE) {



2) If there is no data in a cell, the cell loses its formatting. I modified the following code to enter an &nbsp; if the $data[$c] string is empty or contains the username "<system>", which also appeared blank on screen.

Originally:

Code: Select all
for ($c=0; $c < $num; $c++)
{
 echo "<td>".$data[$c]."</td>";
}


Now;

Code: Select all
for ($c=0; $c < $num; $c++)
{
If ($data[$c] == "" or $data[$c] == "<system>")
 echo "<td>&nbsp;</td>";
else
 echo "<td>".$data[$c]."</td>";
}

Other than that formatting problem, everything else is working awesomely. I was trying to make the $data[$c] string contain "system" if it contained "<system>" but couldn't get it to work for me. I'm still a novice PHP coder and the code defeated me again :).
Last edited by logan on Aug 02 07 7:31 am, edited 1 time in total.
logan
Qbik Staff
 
Posts: 671
Joined: Oct 19 06 2:49 pm
Location: Auckland, New Zealand

Postby rodo37 » Aug 01 07 8:24 pm

Hello logan,

Thanks for you suggestions, me too I'm newbie, it's my first PHP Script ;)
I'm using the doc from php.net to look example and create my script from them.

But just a question
echo "<td>".$edit."</td>";

Why $edit ?

I must replace $edit by $data[$c] for to work for me
rodo37
 
Posts: 5
Joined: Jul 31 07 2:57 am

Postby logan » Aug 02 07 7:30 am

Why $edit ?

You're right. It is meant to be $data[$c]. The $edit string was a remnant of me checking for and replacing the <system> username. I just forgot to change it back.

It would be cool if the Time Online was shown in minutes rather than seconds. I can't visualise lengths of time very well from seconds ;).

For people who want to see what this script looks like in action but don't have the time or resource to do so, here's a screenshot.

Image
logan
Qbik Staff
 
Posts: 671
Joined: Oct 19 06 2:49 pm
Location: Auckland, New Zealand

Postby rodo37 » Aug 02 07 8:53 pm

New version 1.2
Thanks to logan to provide many help and improvement ;)

Error in posting: You are not allowed to post any websites here at the moment.
rodo37
 
Posts: 5
Joined: Jul 31 07 2:57 am

Postby rodo37 » Aug 08 07 8:31 pm

Hello,

I'm creating a script to import all users data into a MySQL base.

If anyone would like help me you can go to
code.google.com/p/wingatephpaddon/

You can also download source code to test the script
wingatephpaddon.googlecode.com/svn/trunk/
rodo37
 
Posts: 5
Joined: Jul 31 07 2:57 am

Postby stlony » Aug 23 07 10:14 am

i did export the user account. how can i make it viewed in this page i put them all in one folder and opened index it dosent worked. what is the using method?
stlony
 
Posts: 82
Joined: Aug 16 07 9:11 am

Postby logan » Aug 23 07 10:23 am

To get this script to work, first, you need to change the $exported_accounts variable to the filename of your exported textfile.


Code: Select all
  //Location of exported accounts file
  $exported_accounts = "accounts.txt";


Then, there is a problem with the forum where tab's are recorded as multiple spaces, rather than a tab. So you need to change the delimiter for reading the text file back to a tab.

Code: Select all
while (($data = fgetcsv($handle, 1000, "   ")) !== FALSE) {


Remove the three spaces between the two quote marks, and put a tab there instead.
logan
Qbik Staff
 
Posts: 671
Joined: Oct 19 06 2:49 pm
Location: Auckland, New Zealand

Postby stlony » Aug 24 07 9:13 am

I did what you said. It is not working with me. every time i open index.htm or quota.htm file it give me bad carachters in quota and give me the logo page in index file i don't know why?
please any one leave a packege with sample file working and all i just to do is to replace the user account file.txt. please help i need to use this method.
stlony
 
Posts: 82
Joined: Aug 16 07 9:11 am

Postby defeX! » Aug 24 07 2:40 pm

Here is a working copy of the script from my web server.

http://defex.orcon.net.nz/accounts.zip
defeX!
 
Posts: 9
Joined: Feb 15 07 6:48 am

Postby stlony » Aug 25 07 12:04 am

should i open "accounts.php" with internet explorer or another program?
sorry about this question but it didn't worked with internet explorer? what should i do?
stlony
 
Posts: 82
Joined: Aug 16 07 9:11 am

Postby rodo37 » Aug 25 07 5:38 am

stlony wrote:should i open "accounts.php" with internet explorer or another program?
sorry about this question but it didn't worked with internet explorer? what should i do?


You must put accounts.php on your webserver with PHP4 or PHP5
I've tested my script with PHP5 and work

But check this line
while (($data = fgetcsv($handle, 1000, " ")) !== FALSE) {

due to the forum, you must check the TAB in 1000, "TAB")
rodo37
 
Posts: 5
Joined: Jul 31 07 2:57 am


Return to WinGate

Who is online

Users browsing this forum: No registered users and 4 guests

cron