Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 14 of 14
  1. #1
    Member
    Join Date
    Oct 2003
    Posts
    9

    Default How to create PHP script for display Bandwidth Traffic?

    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. #2
    Member Jemshi's Avatar
    Join Date
    Sep 2003
    Location
    India
    Posts
    217

    Default

    what about reading domain-bytes-log file and adding up ?

    cPanel.net Support Ticket Number:
    Jemshad O K
    Sys Admin
    Bobcares.com
    http://www.poornam.com
    Winners don't do different things. They do things differently

  3. #3
    Member
    Join Date
    Sep 2003
    Posts
    66

    Default

    where are these files located?

    cPanel.net Support Ticket Number:

  4. #4
    Member Jemshi's Avatar
    Join Date
    Sep 2003
    Location
    India
    Posts
    217

    Default

    normally,

    /usr/local/apache/domlogs

    cPanel.net Support Ticket Number:
    Jemshad O K
    Sys Admin
    Bobcares.com
    http://www.poornam.com
    Winners don't do different things. They do things differently

  5. #5
    Member
    Join Date
    Sep 2003
    Posts
    66

    Default

    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. #6
    jcn
    jcn is offline
    Member
    Join Date
    Sep 2003
    Posts
    56

    Default

    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. #7
    Member
    Join Date
    Oct 2003
    Posts
    9

    Default

    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.

  8. #8
    Member
    Join Date
    Oct 2003
    Posts
    9

    Default

    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. #9
    jcn
    jcn is offline
    Member
    Join Date
    Sep 2003
    Posts
    56

    Default

    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. #10
    Member
    Join Date
    Oct 2003
    Posts
    9

    Default

    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 Code:
    $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?
    Last edited by hahawhoami; 10-18-2003 at 02:10 AM.

  11. #11
    jcn
    jcn is offline
    Member
    Join Date
    Sep 2003
    Posts
    56

    Default

    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. #12
    Member
    Join Date
    Oct 2003
    Posts
    9

    Default

    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. #13
    jcn
    jcn is offline
    Member
    Join Date
    Sep 2003
    Posts
    56

    Default

    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. #14
    Member
    Join Date
    Oct 2003
    Posts
    9

    Talking

    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

Similar Threads & Tags
Similar threads

  1. PHP script to create subdirectory
    By Ric3kg in forum New User Questions
    Replies: 4
    Last Post: 04-29-2010, 03:26 PM
  2. Create SUBDOMAIN via PHP script
    By mlotfi63 in forum New User Questions
    Replies: 0
    Last Post: 12-28-2006, 11:28 PM
  3. Display Bandwidth count in PHP pages
    By soapergem in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 12-19-2005, 10:08 PM
  4. How to create sub-domains with a PHP script?
    By joachim in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 06-10-2004, 06:34 AM
  5. Create subdomain with a php script
    By mahdionline in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 03-02-2004, 11:45 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube