The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to create PHP script for display Bandwidth Traffic?

Discussion in 'General Discussion' started by hahawhoami, Oct 14, 2003.

  1. hahawhoami

    hahawhoami Member

    Joined:
    Oct 14, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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:
     
  2. Jemshi

    Jemshi Well-Known Member

    Joined:
    Sep 11, 2003
    Messages:
    210
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    what about reading domain-bytes-log file and adding up ?

    cPanel.net Support Ticket Number:
     
  3. foxboy

    foxboy Well-Known Member

    Joined:
    Sep 20, 2003
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    where are these files located?

    cPanel.net Support Ticket Number:
     
  4. Jemshi

    Jemshi Well-Known Member

    Joined:
    Sep 11, 2003
    Messages:
    210
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    India
    normally,

    /usr/local/apache/domlogs

    cPanel.net Support Ticket Number:
     
  5. foxboy

    foxboy Well-Known Member

    Joined:
    Sep 20, 2003
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    6
    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:
     
  6. jcn

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
    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:
     
  7. hahawhoami

    hahawhoami Member

    Joined:
    Oct 14, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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.
     
  8. hahawhoami

    hahawhoami Member

    Joined:
    Oct 14, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    Hi jcn,

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

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
  10. hahawhoami

    hahawhoami Member

    Joined:
    Oct 14, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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:password@www.cpanel.com/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?
     
    #10 hahawhoami, Oct 18, 2003
    Last edited: Oct 18, 2003
  11. jcn

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
  12. hahawhoami

    hahawhoami Member

    Joined:
    Oct 14, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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?
     
  13. jcn

    jcn Well-Known Member

    Joined:
    Sep 17, 2003
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    6
    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.
     
  14. hahawhoami

    hahawhoami Member

    Joined:
    Oct 14, 2003
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    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
     
Loading...

Share This Page