Jump to content

Hosting Usage Module - Need HELP


Recommended Posts

Hello,

Can someone PLEASE create a small module that is about the Hosting Usage?
It will only have to display the Disk Space Usage and the Bandwidth Usage. 

For example:

Disk Space: 500MB Used / 5GB Total
Bandwidth: 5GB Used / 50GB Total

That info must be grabbed directly from cPanel so the module's backend should have the ability for the user to add the cPanel username and password.

The page "Hosting Usage" should be next to Page, Setup tabs or in the mini menu of View Site, Profile, Log out.

Thanks in advance.

Link to comment
Share on other sites

  • 3 weeks later...

Here is the code to show disk usage. 
I have no idea how to convert it to PW module. Can someone do that?

<?php

// SETTINGS - START

// PUT YOUR CPANEL HOSTING USERNAME HERE:
    $username = "username";

// PUT YOUR CPANEL HOSTING PASSWORD HERE:
    $password = "password";

// MODIFY THIS PATH TO REFLECT YOUR DOMAIN, REPLACING "DOMAIN-NAME" AND "YOUR-CPANEL-USERNAME":
    $query ="http://cpanel.yoursite.com:2082/xml-api/cpanel?user=USERNAME&cpanel_xmlapi_module=StatsBar&cpanel_xmlapi_func=stat&display=diskusage";

// SETTINGS - END

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curl, CURLOPT_HEADER,0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($curl, CURLOPT_USERPWD, $username.":".$password);
    curl_setopt($curl, CURLOPT_URL, $query);
    $result = curl_exec($curl);
    curl_close($curl); 

    $xml = simpleXML_load_string($result);

    $df = $xml->data[0]->_count; // used MB
    $ds = $xml->data[0]->_max; // max MB
    $du = $ds - $df; // free MB
    if ($ds > 0) $perc = number_format(100 * $du / $ds, 2); else $perc = 0;
    $color = '#e87d7d';
    if ($perc > 50) $color = '#e8cf7d';
    if ($perc > 70) $color = '#ace97c';
    echo '<li style="font-weight:bold;padding:5px 15px;border-radius:4px;-moz-border-radius:4px;-webkit-border-radius:4px;background-color:#182227;margin-left:13px;color:#afc5cf;">'
        .'Free disk space'
        .'<div style="border:1px solid #ccc;width:100%;margin:2px 5px 2px 0;padding:1px">'
        .'<div style="width:'.$perc.'%;background-color:'.$color.';height:6px"></div></div>'
        .$du.' of '.$ds.' MB free'.'</li>';

?>

 

Link to comment
Share on other sites

You could. It would need to be a two-way encryption so you can unhash the password for the curl request. This would need an potential attacker to hack the db and the filesystem to recover the password. But I'm not very knowledgeable on what to use for that.

Link to comment
Share on other sites

I think it's "saver" in the db. File contents can easily be leaked by incorrect webserver settings, which does not happen as easily for something like module configuration. For anyone gaining access to your server it probably won't matter anyways.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...