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.

Bandwidth script?

Discussion in 'cPanel Developers' started by uninvited13th, Apr 15, 2011.

  1. uninvited13th

    uninvited13th Member

    Joined:
    Apr 15, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Hello,


    Is there any script to show user the bandwidth used as image?


    I found this script but its not working anymore.. Can someone rewrite it? Thanks :D


    PHP:
    <?php 
    $sAuth 
    base64_encode("username:pass");  //your username:password for cpanel 
    $domain "www.domain.com"//domain of your website 
    $total 10000//amount of bandwidth you get in mb 
    $cpanelport 2082//port of cpanel default is 2082 

    $hSocket fsockopen($domain,$cpanelport); 
    if(!
    $hSocket) { 
        die(
    "Connection Failed."); 
    } else { 
        
    fputs($hSocket"POST /frontend/x3/index.html HTTP/1.0\r\n"); //based on the x3 theme of cpanel 
        
    fputs($hSocket"Host: $domain\r\n"); 
        
    fputs($hSocket"Authorization: Basic $sAuth\r\n"); 
        
    fputs($hSocket"Connection: Close\r\n"); 
        
    fputs($hSocket"\r\n"); 
        
    $printNext false
        
    $bw 0
        while(!
    feof($hSocket)) { 
            
    $response fgets($hSocket4096); 
            
    $response strip_tags($response); 
            
    $response addslashes($response); 
            
    $pos strpos($response'Monthly Bandwidth Transfer'); 
            if(
    $pos 0) { 
                
    $response explode("/"$response); 
                
    $t array_pop($response); 
                
    $t array_shift($response); 
                
    $response explode("Monthly Bandwidth Transfer"$response[0]); 
                
    $t array_shift($response); 
                break; 
            } 
        } 

    fclose($hSocket); 
    header("Content-type: image/png"); 
    if(!
    $total) { 
        
    $total 100

    function 
    drawBar($bandwidth$total) { 
        
    //$total=$bandwidth+3.14; 
        
    $barWidth 200//set this for bar width 
        
    $barHeight 16//set this for bar height 
        
    $fontSize 2//HTML Font Size 
        
    $imgWidth $barWidth//Keep this 
        
    $imgHeight $barHeight//Keep this 
        
    $image imagecreate($imgWidth$imgHeight); 
        
    $back ImageColorAllocate($image255255255); 
        
    $border ImageColorAllocate($image000); 
        
    $fill ImageColorAllocate($image2551390); 
        
    $text ImageColorAllocate($image071255); 
        
    ImageFilledRectangle($image00$barWidth$barHeight 1$back); 
        
    $adjBar = (float)(($bandwidth $total) * ($barWidth 1)); 
        
    ImageFilledRectangle($image11$adjBar, ($barHeight 2), $fill); 
        
    ImageRectangle($image00$barWidth 1$barHeight 1$border); 
        
    $PerCent = (float)(($bandwidth $total) * 100); 
        
    $myText = (string )("Usage: " round($bandwidth2) . "MB/" $total "MB"); 
        
    $textLength strlen($myText); 
        
    $textLeft = (($barWidth 1) / 2) - (($textLength 2) * imagefontwidth($fontSize)); 
        
    $textTop = ($barHeight imagefontheight($fontSize)) / 2
        
    ImageString($image$fontSize$textLeft$textTop$myText$text); 
        
    imagePNG($image); 
        
    imagedestroy($image); 

    drawBar((float)$response[0], $total); 
    ?>
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
  3. uninvited13th

    uninvited13th Member

    Joined:
    Apr 15, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
  4. uninvited13th

    uninvited13th Member

    Joined:
    Apr 15, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    okay.. I think his script is for whm coz it uses hash remote access key .. how about for cpanel only..? :huh:
     
  5. uninvited13th

    uninvited13th Member

    Joined:
    Apr 15, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    Hello, it doesnt work even in whm...
     
  6. uninvited13th

    uninvited13th Member

    Joined:
    Apr 15, 2011
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    1
    okay.. I make it work now.. many thanks.. :D
     
Loading...

Share This Page