Writing cPanel Plugins

A big part of what we’re doing involves writing our own cPanel plugins that will then be part of our cPanel skin.  I though it be nice to quickly run through how exactly you make a cPanel plugin for anyone who is curious.  It’s actually surprisingly easy to do if you read the documentation (who does that these days?)  The first thing you want to do is generate your plugin file which you do at the cPanel site

So you visit the page http://www.cpanel.net/developer/overview.html which has a form to fill out for creating a plugin.  So in our case lets say we’re making a plugin called CPU Usage.  We’re going to make the plugin name cpuusage and then display name CPU Usage and the rest is pretty self explanatory.  Once you have your plugin then it’s time to get it to show up on the cPanel page.  You do this by doing:

cd /usr/local/cpanel/bin/
/usr/local/cpanel/bin/register_cpanelplugin cpuusage.cpanelplugin

So in our case since it’s the cpuusage plugin that’s what we’re doing but you can put whatever you’re calling your plugin.  Now in our case we’re using PHP which for the plugin portion isn’t as well documented as doing them in Perl.  So I’ll quickly run through this and how to make use of it.  The first step is putting the code into our folder the plugin is suppose to be in so lets say we’re doing it in the theme x3 we’d have our file at /usr/local/cpanel/base/frontend/x3/cpuusage/index.php .  Basically just the folder cpuusage then you can put whatever you want in it whether it’s a single file index.php or multiple files totally up to you.

PHP plugins in cPanel you can include cPanel code just like they do in the html files.  So in our case we have the default file set to index.php we could do this:

<cpanel setvar="headerimg=../images/topwebftpstats.gif">
<cpanel setvar="dprefix=../">
<cpanel Branding="include(stdheader.html)">
<div class="body-content">
<style type="text/css">
	<?cp Branding::spritelist(.spriteicon_img_mini {float:left;margin-right:5px;background: url\{leftparenthesis}%\{rightparenthesis};} %,spriteurl,images::#icon-${img}_mini {background-position\{colon}0 -${cssposition}px;width\{colon}${width}px;height\{colon}${height}px; }:) imgtype=icon,subtype=img,method=scale_60percent,format=png,img=cpuusage ?>
</style>
<div id="h1Title" class="h1Title"><div class="spriteicon_img_mini" id="icon-cpuusage_mini"></div><cpanel langprint="CPU Usage"></div>
<?php echo "This is my test page";
</div>
<cpanel Branding="include(stdfooter.html)">

You’ll notice the cPanel code in there to do the header and footer.  Then I just use PHP to echo just some random text.  So yep that’s right if you’d rather not work in perl you can do the plugin in PHP and lose nothing in terms of features that the html versions are doing when it comes to retrieving data via perl scripts in /usr/local/cpanel/Cpanel . In my case I don’t have the branding languages in at this point and I also stole the image topwebftpstats.gif you’ll notice. You can fill in the blanks by looking at the other cPanel pages as all their code will work within your php page as well. Hopefully this helps some people wishing to write plugins but to scared to write them in Perl.

This entry was posted in General. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree