cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
257
73
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter
Reposting snippet here from a very important blog post which plugin developers should read:

Hi Everyone, Adam here. I wanted to spend some time spelling out what’s going on in the user experience of cPanel & WHM. Plugin developers should pay close attention to the changes we’re making.

Now that we’ve fully deprecated the X3 theme, it’s time to turn our attention to WHM. We’ve got some very simple goals when it comes to WHM:

  1. Ensure a great experience for our advanced users
  2. Assist first-time users who come to WHM with no previous system administration experience
  3. Prepare for the mobile age, where laptops and desktops aren’t the only way system administration is done
Read What’s going on in WHM? | cPanel Blog for more information
 

cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
257
73
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter
For PHP plugin developers who need a temporary workaround while we make changes in WHM, here's a path you could take to bring the WHM interface chrome into your plugin.

Again, this is only a temporary workaround. We'll be expanding plugin support in WHM as a part of the WHM work. Stay tuned for those updates.

In testPlugin.html.tt

Code:
[%
USE Whostmgr;
USE JSON;

IF locale.get_html_dir_attr() == 'rtl';
SET rtl_bootstrap = Whostmgr.find_file_url('/3rdparty/bootstrap-rtl/optimized/dist/css/bootstrap-rtl.min.css');
END;

SET styleSheets = [
   rtl_bootstrap,
   '/libraries/fontawesome/css/font-awesome.min.css'
   ];

WRAPPER 'master_templates/master.tmpl'
   header = locale.maketext("WHM Example Plugin")
   stylesheets = styleSheets,
   theme='bootstrap';
%]

<iframe  frameBorder="0" scrolling="no" width=100% height=100% src="./test.php"></iframe>

[% END %]
In this example, the iframe's SRC value should point to the index page of your plugin.

NOTE: the above code snippet widget is scrollable. Remember to copy-pasta the whole thing.

In /usr/local/cpanel/whostmgr/docroot/cgi/testPlugin/index.cgi
Code:
#!/usr/local/cpanel/3rdparty/bin/perl
 use strict;
 package cgi::examplePlugin;
 use warnings;
 use Cpanel::Template                  ();

 run() unless caller();

 sub run {
    print "HTTP/1.0 200\r\n OK Content-type: text/html; charset=\"utf-8\"\r\n\r\n";
    Cpanel::Template::process_template(
        'whostmgr',
        {
            'template_file' => 'testPlugin.html.tt',
            'print'         => 1,
        }
    );
    exit;
 }
 
Last edited:

fevangelou

Member
Oct 10, 2010
24
5
53
Athens, Greece
cPanel Access Level
DataCenter Provider
Twitter
A couple of clarifications/questions if you don't mind...

a) Should the file testPlugin.html.tt be saved in the /usr/local/cpanel/whostmgr/docroot/templates/ directory?
b) You refer to an iframe's src attribute yet I don't see any iframe tag in the code above. Did you mean that in order to have the header brought into a plugin we should create an iframe tag containing the .cgi file as src?

Thank you.
 

cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
257
73
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter
a) Should the file testPlugin.html.tt be saved in the /usr/local/cpanel/whostmgr/docroot/templates/ directory?
testPlugin.html.tt should be saved in your plugin's directory inside /usr/local/cpanel/whostmgr/docroot/templates/. Additionally you can name it whatever you'd like (not just testPlugin.html.tt).

b) You refer to an iframe's src attribute yet I don't see any iframe tag in the code above. Did you mean that in order to have the header brought into a plugin we should create an iframe tag containing the .cgi file as src?
You may have to scroll within the code snippet to see it.
 

cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
257
73
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter

Dan Richert

Registered
Oct 30, 2017
1
0
1
Detroit
cPanel Access Level
Root Administrator
When I set up a PHP interface for a WHM plugin using the instructions above I'm getting this error:

Code:
Warning: file_get_contents(/var/cpanel/caches/_generated_header_files/3060838764_0_0.html): failed to open stream: No such file or directory in /usr/local/cpanel/php/WHM.php on line 50
How do properly generate the cached header and footer files?

Thanks!
 

cPanelAdamF

cPanel Product Owner
Staff member
Mar 21, 2013
257
73
153
Houston TX
cPanel Access Level
DataCenter Provider
Twitter
When I set up a PHP interface for a WHM plugin using the instructions above I'm getting this error:

Code:
Warning: file_get_contents(/var/cpanel/caches/_generated_header_files/3060838764_0_0.html): failed to open stream: No such file or directory in /usr/local/cpanel/php/WHM.php on line 50
How do properly generate the cached header and footer files?

Thanks!
Dan, what version of cpanel are you running? We've updated the caching logic in a few minor build-numbers which may solve your problem.

You can also run...

/scripts/rebuild_whm_chrome

...manually if you ever need to directly generate the cache.