+ Reply to Thread
Results 1 to 3 of 3

Thread: cPanel 11 Stats Script

  1. #1
    Penguin129's Avatar
    Penguin129 is offline x10Hosting Member Penguin129 is an unknown quantity at this point
    Join Date
    Aug 2007
    Posts
    68

    cPanel 11 Stats Script

    Ok, so I got really bored and wrote this class to get data from cPanel 11 and decided to share it. It only does bandwidth, disk space, and server status right now. If anyone wants something else, please post it here and I'll see what I can do. Erm the really big commented part should explain it, but I'll type it in a prettier form that isn't all orange.. Hope it helps anyone who needs it.. :happysad:

    cPanel Stats by William Chu
    Retrieves stuff from cPanel! :D
    Note: For cPanel 11!

    Declaring
    The class needs to be declared with three strings, url, username, and password.
    IE: a website is www.example.com and the login for cPanel 11 is example/elpmaxe so..
    PHP Code:
    $stats = new cPanelStats("www.example.com""example""elpmaxe"); 
    Functions
    Note: []s means optional
    • getData([filename])
      • retrieves a page from cPanel
      • .../frontend/x3/___
      • feel free to use this to read other pages
    • bandwidth([type])
      • gets bandwidth data
      • type gives a single string out of the normally returned array
    • disk([type])
      • gets disk data
      • specifying type gives a single string out of the normally returned array
    • server([type])
      • gets server data
      • specifying type gives a single string out of the normally returned array

    Example
    PHP Code:
    <?php
    include "cpanelstats.php";
    $stats = new cPanelStats("www.example.com""example""elpmaxe");
    echo 
    "<pre>";
    print_r($stats->bandwidth());
    print_r($stats->disk());
    print_r($stats->server());
    echo 
    "</pre>";
    ?>

    PHP Code:
    <?php
    class cPanelStats {
        
    ####
        # cPanel Stats by William Chu
        # Retrieves stuff from cPanel! :D
        # Note: For cPanel 11!
        ####
        #    Declaring
        # The class needs to be declared with three
        # strings, url, username, and password. IE:
        # website is www.example.com and the login
        # for cPanel 11 is example/elpmaxe so..
        # $stats = new cPanelStats("www.example.com", "example", "elpmaxe");
        ####
        # Functions
        # Note: []s means optional
        #    
        # getData([filename])
        #  - retrieves a page from cPanel
        #  - .../frontend/x3/___
        #  - feel free to use this to read other pages
        # bandwidth([type])
        #  - gets bandwidth data
        #  - specifying type gives a single string
        #    out of the normally returned array
        # disk([type])
        #  - gets disk data
        #  - specifying type gives a single string
        #    out of the normally returned array
        # server([type])
        #  - gets server data
        #  - specifying type gives a single string
        #    out of the normally returned array
        ###
        # Example
        # 
        # include "cpanelstats.php";
        # $stats = new cPanelStats("www.example.com", "example", "elpmaxe");
        #    echo "<pre>";
        #    print_r($stats->bandwidth());
        #    print_r($stats->disk());
        #    print_r($stats->server());
        #    echo "</pre>";
        ###
        
    function cPanelStats($url$username$password) {
            
    $this->url $url;
            
    $this->username $username;
            
    $this->password $password;
        }
        function 
    getData($file="index.html") {
            
    // Feel free to change the method it retrieves the page with.
            
    ob_start();
            
    readfile("http://{$this->username}:{$this->password}@{$this->url}:2082/frontend/x3/{$file}");
            
    $data ob_get_contents();
            
    ob_end_clean();
            return 
    $data;
        }
        function 
    bandwidth($type=NULL) {
            
    $data $this->getData();
            
    preg_match_all("/([0-9]+).([0-9]+)\/([0-9]+).([0-9]+) MB/"$data$matches);
            
    $results["Used"] = "{$matches[1][1]}.{$matches[2][1]}";
            
    $results["Free"] = "{$matches[3][1]}.{$matches[4][1]}"-$results["Used"];
            
    $results["Total"] = "{$matches[3][1]}.{$matches[4][1]}";
            
    $results["PercentUsed"] = $results["Used"]/$results["Total"]*100;
            
    $results["PercentFree"] = $results["Free"]/$results["Total"]*100;
            if(
    $type) {
                return 
    $results[$type];
            } else {
                return 
    $results;
            }
        }
        function 
    disk($type=NULL) {
            
    $data $this->getData();
            
    preg_match_all("/([0-9]+).([0-9]+)\/([0-9]+).([0-9]+) MB/"$data$matches);
            
    $results["Used"] = "{$matches[1][0]}.{$matches[2][0]}";
            
    $results["Free"] = "{$matches[3][0]}.{$matches[4][0]}"-$results["Used"];
            
    $results["Total"] = "{$matches[3][0]}.{$matches[4][0]}";
            
    $results["PercentUsed"] = $results["Used"]/$results["Total"]*100;
            
    $results["PercentFree"] = $results["Free"]/$results["Total"]*100;
            if(
    $type) {
                return 
    $results[$type];
            } else {
                return 
    $results;
            }
        }
        function 
    server($type=NULL) {
            
    $data $this->getData("status.html");
            
    preg_match_all("/<td class=\"statuscell\">(.+)<\/td>\n        <td class=\"statuscell\">(.+)<\/td>\n        <td class=\"statuscell\"><img src=\"\/(.+)-status/"$data$matches);
            for(
    $i=0;$i!=count($matches[0]);$i++) {
                
    $results[$matches[1][$i]] = array($matches[2][$i], $matches[3][$i]);
            }
            if(
    $type) {
                return 
    $results[$type];
            } else {
                return 
    $results;
            }
        }
    }
    ?>
    .. that took a while to do..
    Last edited by Penguin129; 12-26-2007 at 05:49 PM. Reason: Some corrections

  2. #2
    galaxyAbstractor's Avatar
    galaxyAbstractor is offline Community Advocate galaxyAbstractor is on a distinguished road
    Join Date
    Oct 2007
    Location
    Land of Null and Insanity
    Posts
    5,495

    Re: cPanel 11 Stats Script

    So this work on the newest skin x3?

  3. #3
    nikaashvetia26 is offline x10Hosting Member nikaashvetia26 is an unknown quantity at this point
    Join Date
    Apr 2011
    Posts
    1

    Re: cPanel 11 Stats Script


    can you pm this "last login from" code please

+ Reply to Thread

Similar Threads

  1. Any free traffic exchange script??
    By goodone in forum Scripts & 3rd Party Apps
    Replies: 2
    Last Post: 07-21-2008, 01:24 AM
  2. Replies: 8
    Last Post: 12-03-2007, 04:12 PM
  3. link cpanel with vbulletin script
    By chunsiang in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 09-10-2007, 09:20 AM
  4. [OFF] Script Instillations (Now Accepting)
    By kryptonyte in forum The Marketplace
    Replies: 0
    Last Post: 08-02-2006, 02:15 AM
  5. Just a question about my script
    By rubens in forum Free Hosting
    Replies: 11
    Last Post: 02-28-2006, 01:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers