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.

Show disk usage and bandwidth in web page

Discussion in 'cPanel Developers' started by applepie, Mar 17, 2007.

  1. applepie

    applepie Registered

    Joined:
    Apr 5, 2004
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    I'd like to show clients their bandwidth and disk usage in a web page outside of cPanel's control panel. How can I do this?
     
  2. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    User bandwidth usage data is stored in /var/cpanel/bandwidth/ and I've commented in a related thread on the whereabouts of disk usage data.

    From a command-line perspective, this gives you the ability to derive all the necessary values.

    You can write a root-owned script to retrieve all the necessary values. I won't explain here how as that would take a long time and this is really something you should be able to handle yourself.

    Once you have a root-owned script that can be run from the command line and which produces the output you need, refer to my tutorial on how to use the cPanel remote access features to call the script from a user-level account.
     
  3. SoftDux

    SoftDux Well-Known Member

    Joined:
    May 27, 2006
    Messages:
    983
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Johannesburg, South Africa
    cPanel Access Level:
    Root Administrator
    do you know how to display web stats on an external page?
     
  4. hostmedic

    hostmedic Well-Known Member

    Joined:
    Apr 30, 2003
    Messages:
    559
    Likes Received:
    0
    Trophy Points:
    16
    Location:
    Washington Court House, Ohio, United States
    cPanel Access Level:
    DataCenter Provider
    answered elsewhere

    AwStats External


    PHP:
    <?php

    $user 
    'username';//Username for cPanel
    $pass 'password';//Password for cPanel
    $domain 'domainname.com';//Do not include 'http://' or 'www'

    /*
    NO NEED TO TOUCH ANYTHING BELOW HERE
    */

    //retrieves the file, either .pl or .png
    function getFile($fileQuery){
      global 
    $user$pass$domain;
      return 
    file_get_contents("http://$user:$pass@$domain:2082/".$fileQuery,'r');
    }

    //it's a .png file...
    if(strpos($_SERVER['QUERY_STRING'],'.png')!==false) {
      
    $fileQuery $_SERVER['QUERY_STRING'];
    }
    //probably first time to access page...
    elseif(empty($_SERVER['QUERY_STRING'])){
      
    $fileQuery "awstats.pl?config=$domain";
    }
    //otherwise, all other accesses
    else {
      
    $fileQuery 'awstats.pl?'.$_SERVER['QUERY_STRING'];
    }

    //now get the file
    $file getFile($fileQuery);

    //check again to see if it was a .png file
    //if it's not, replace the links
    if(strpos($_SERVER['QUERY_STRING'],'.png')===false) {
      
    $file str_replace('awstats.pl'basename($_SERVER['PHP_SELF']), $file);
      
    $file str_replace('="/images','="'.basename($_SERVER['PHP_SELF']).'?images',$file);
    }
    //if it is a png, output appropriate header
    else {
      
    header("Content-type: image/png");
    }

    //output the file
    echo $file;
    ?> 


    Webalizer Stats External
    PHP:
    <?php
    $user 
    'user'//cpanel username
    $pass 'pass'//cpanel password
    $url 'www.yourdomain.com'//do not include 'http://'

    //retrieves the webalizer file, either .html or .png
    function getFile($file) {
    global 
    $user$pass$url;
    return 
    file_get_contents("http://" $user ":" $pass "@" $url ":2082/tmp/" $user "/webalizer/" $file);
    }
    //alters links, either .html or .png
    function changeLinks($subject$type) {
    return 
    preg_replace("/($type=\")(?!http)(.*?)\"/is","$1$PHP_SELF?$2\"",$subject);
    }

    if(!empty(
    $_SERVER['QUERY_STRING'])) {

    //get file (whether png or html)
    $page getFile($_SERVER['QUERY_STRING']);

    //if png, output appropriate header
    if(strpos($_SERVER['QUERY_STRING'],'.png') !== false) {
    header("Content-type: image/png");
    }
    //change the .png src(s)
    else {
    $page changeLinks($page'src');
    }
    }
    else {
    //get index
    $page getFile('index.html');

    //change links
    $page changeLinks($page'href');

    //change the usage.png src
    $page changeLinks($page'src');
    }
    //output it
    echo $page;

    ?>
     
  5. SCARECR0W

    SCARECR0W Registered

    Joined:
    Jul 27, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Excellent!

    This works nice, thanks...

    However, the images are broken for me - the paths are showing as incorrect. How can I fix that?
     
Loading...

Share This Page