PWaddict Posted July 23, 2016 Share Posted July 23, 2016 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 More sharing options...
PWaddict Posted August 13, 2016 Author Share Posted August 13, 2016 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 More sharing options...
Robin S Posted August 13, 2016 Share Posted August 13, 2016 The tabs "Pages", "Setup", etc are just pages under the Admin branch of the tree. You can add your own pages here to make new tabs. To put content on that page you can use the Admin Custom Pages module. Or it's not difficult to create your own simple ProcessModule. 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 13, 2016 Share Posted August 13, 2016 Basically go to http://modules.pw/, tick some boxes, put in your code and change the things up, which should be configurable. But this code is not too great to begin with as it'll require anyone using it to store the cpanel password unencrypted in the database or the file itself. ProcessHostingInfo.zip 5 Link to comment Share on other sites More sharing options...
PWaddict Posted August 14, 2016 Author Share Posted August 14, 2016 Thank you so much both of you Is there a way to encrypt the password? Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 14, 2016 Share Posted August 14, 2016 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 More sharing options...
PWaddict Posted August 14, 2016 Author Share Posted August 14, 2016 Do you think it's safer if I store the pass on the php file instead of db? Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 14, 2016 Share Posted August 14, 2016 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now