How to create PHP script for display Bandwidth Traffic?

hahawhoami

Member
Oct 14, 2003
9
0
151
Hi all,

Does anyone know how to create php script for get/display bandwidth traffic for user/domain without login to cPanel?

I don't know where the banswidth store is? and I don't know how to access to bandwidth section from outside cPanel, please told me if you have more ideas.

Thank you.

cPanel.net Support Ticket Number:
 

foxboy

Well-Known Member
Sep 20, 2003
66
0
156
i tried this:

Code:
<?
$dir = directoryList("/usr/local/apache/domlogs");
print_r($dir);
exit;

function directoryList ($url) {
    $outp = "";
    $d = dir($url);
    while($entry = $d->read()) {
        $size = round(filesize($url.$entry)/1024);
        if ($size > 999) $sizestring = ((round($size/100))/10)." mb";
        else $sizestring = $size." kb";
        $outp .= "<a href='".$url.$entry."'>".$entry."</a> [ ".$sizestring." ]<br>\n";
    }
    $outp = "Path: ".$d->path."<br>\n".$outp;
    $d->close();
    return $outp;
}
?>
but i don't have access to that directory...

cPanel.net Support Ticket Number:
 

jcn

Well-Known Member
Sep 17, 2003
56
0
156
I wrote a script that reads the files that are in /var/cpanel/bandwidth to get the bandwidth for the current month.

The problem (as you've already found) is that all of those files are owned by root. Maybe you should run a cron job as root and then dump all of the appropriate data into static files that can be read by the web server.

cPanel.net Support Ticket Number:
 

hahawhoami

Member
Oct 14, 2003
9
0
151
Originally posted by Jemshi
what about reading domain-bytes-log file and adding up ?
Thank you Jemshi and foxboy for good idea and I'll try to use that script.
By the way, I think... Reseller account or user account can't put/get this script to run without permission root.
Yesterday, I tried to get Bandwidth Image from WEB/FTP Stats area (Bandwidth area) but it always required username and password to log in via cPanel url and port.

That's ok, I'll try again. Maybe I can find the other ways to access bandwidth section without logged in to cPanel.
 

hahawhoami

Member
Oct 14, 2003
9
0
151
Hi jcn,

What is the name of file that you get from /var/cpanel/bandwidth to process on your script to view Bandwidth usage?
 

jcn

Well-Known Member
Sep 17, 2003
56
0
156
There are domain files in there (domain.com) and then files that contain total usage for all of a user's accounts (including addon and subdomains).

At least that's what I understand is happening.
 

hahawhoami

Member
Oct 14, 2003
9
0
151
Originally posted by jcn
There are domain files in there (domain.com) and then files that contain total usage for all of a user's accounts (including addon and subdomains).

At least that's what I understand is happening.
Hi jcn,

Thank you for your idea but It's seem I must have permission root to run.

I saw some comments from other forum post script like this but not test it yet.


"if cpanel uses http headers for authentication, you can simplify things drastically by sending the authentication parameters in the URL, like so:

PHP:
$contents = file("http://username:[email protected]/siteStatistics?siteID=12345");
Note the username:password in the URL, these will be used for HTTP header authorization requests from the server. Not terribly secure, since the password is being sent unencrypted, but hey.

Once you get the contents, you can parse through it and look for usage numbers."


I don't have many experience to used cPanel so.. maybe someone or you can tell me how?
 
Last edited:

jcn

Well-Known Member
Sep 17, 2003
56
0
156
You're absolutely correct: you will need root privs to read these files. I have a script that runs nightly as root and checks the bandwidth of all of my users. If you need something more timely that is accessible to everyone you could run a cron job that writes out files that you can then chown to the appropriate users.
 

hahawhoami

Member
Oct 14, 2003
9
0
151
OK, thank you jcn.
By the way... We have other way to access and get Bandwidth without permission root and without logged in to cPanel?
 

jcn

Well-Known Member
Sep 17, 2003
56
0
156
I feel like that would be a bit weird, since it would be accessible to everyone. Though you can install your own bandwidth monitoring software and protect it however you want, I'd imagine.
 

hahawhoami

Member
Oct 14, 2003
9
0
151
Thanks for fast reply jcn.
I'll find other way and install my own bandwidth script to monitoring, if I have more news i'll told you.

Many thanks again