Development of WHM Plugin in PHP

rgsites

Member
Dec 6, 2018
6
0
1
Brazail
cPanel Access Level
Root Administrator
I'm developing a WHM Plugin in PHP by following the CPanel documentation guidelines available at Guide to WHM Plugins - Interfaces - Developer Documentation - cPanel Documentation But when I access the plugin I'm getting the following error message:

Warning: file_get_contents(/var/cpanel/caches/_generated_header_files/3679936585_0_0.html): failed to open stream: No such file or directory in /usr/local/cpanel/php/WHM.php on line 71
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hello @rgsites,

Can you verify which cPanel & WHM version is installed on this system? Also, does the issue persist if you run the /scripts/rebuild_whm_chrome command?

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hello @rgsites,

Can you let me know the step-by-step instructions I can to reproduce the issue, along with the contents of the PHP plugin?

Thank you.
 

rgsites

Member
Dec 6, 2018
6
0
1
Brazail
cPanel Access Level
Root Administrator
Hello @cPanelMichael

Content is currently empty
<? php
require_once ('/ usr / local / cpanel / php / WHM.php');
WHM :: header ('Example Plugin Interface', 0,0);
?>

// Add content here.

<? php
WHM :: footer ();
?>

This is the source code for now

I registered the plugin following the guidelines of the page:
Guide to WHM Plugins - AppConfig Registration - Developer Documentation - cPanel Documentation


But when I access it through the url https://dominianserver:2087/cpsess_tokem/cgi/integrador/notificacoes.php

PHP gives me the error message:

Warning: file_get_contents(/var/cpanel/caches/_generated_header_files/170131406_0_0.html): failed to open stream: No such file or directory in /usr/local/cpanel/php/WHM.php on line 71
// Add content here. Notes:
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Content is currently empty
<? php
require_once ('/ usr / local / cpanel / php / WHM.php');
WHM :: header ('Example Plugin Interface', 0,0);
?>

// Add content here.

<? php
WHM :: footer ();
?>

This is the source code for now
Try using this code instead of leaving the content section empty:

Code:
<?php
 require_once('/usr/local/cpanel/php/WHM.php');
    WHM::header('Example Plugin Interface',0,0);
?>

<?php
Print "Hello, World!";
?>
 
<?php
    WHM::footer();
?>
This works on a test system:

Screen Shot 2018-12-12 at 11.11.44 AM.png

You may also find the following tutorial helpful as it shows a specific step-by-step real world example:

Tutorial - How to create a Plugin (WHM & cPanel)

Thank you.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hello @rgsites,

Can you open a support ticket so we can take a closer look? You can post the ticket number here and we'll update this thread with the outcome.

Thank you.
 

tizoo

Well-Known Member
Jan 6, 2004
77
3
158
cPanel Access Level
DataCenter Provider
Hi,

We are facing the same problem with our WHM plugin (WHM v76.0.14) and /script/rebuild_whm_chrome didn't fix the problem.

Do you have some news about the reason why the templates are not generated ?

Thank in advance for your information.

Philippe
 

rgsites

Member
Dec 6, 2018
6
0
1
Brazail
cPanel Access Level
Root Administrator
Hi tizoo,

Unfortunately so far I have nothing new to add.

As can be seen in the above interactions cPanelMichael recommended I open a support ticket. I have not done it yet, because at the moment the plugin I want to build is not a priority.

I recommend you not to waste time open the support ticket. I did numerous searches on the internet and could not find anything to help me.

If you can resolve update here, please.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hello @tizoo and @rgsites,

Can either of you confirm if you are using CloudLinux? Internal case CPANEL-23892 is included with cPanel & WHM version 78 to address an issue where the cache keys for WHM chrome caches are invalid on CloudLinux systems:

Fixed case CPANEL-23892: Ensure that cache keys for WHM chrome caches are valid on CloudLinux™.

The temporary workaround is to modify the below section of /usr/local/cpanel/php/WHM.php with two additional lines of code:

Code:
        if(isset($user)){
            //Get user's cache key for JSON file, based on user's name.
            $cacheKey = self::getUserCacheKey($user);

            //Load and Process selected header.
            $skipHeader=1;
            $skipSupport=1;
            $headerStr = self::loadFileToStr($cacheDir."/_generated_header_files/".$cacheKey."_".$skipSupport."_".$skipHeader.".html");
            $headerStr = self::processHeaderStrings($headerStr, $cpSession, $user, $pageTitle);

            return $headerStr;
        }else{
            throw new Exception("REMOTE_USER does not exist.");
            return false;
        }
    }
In the above code snippet, the two additional lines added for the workaround are:

Code:
$skipHeader=1;
$skipSupport=1;
Thank you.
 

tizoo

Well-Known Member
Jan 6, 2004
77
3
158
cPanel Access Level
DataCenter Provider
Hi cPanelMichael,

Thanks for your reply and your time.

I confirm that the modification fixed the problem.

But our development system is "CentOS release 6.10 (Final)" and not CL. If you need a confirmation on CL, let me know, we have production environments that run CL (6.10 and 7.6).

From what you say the bug will be fixed in v78. Do you know when v78 will reach RELEASE state ?

Philippe
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
Hi @tizoo,

But our development system is "CentOS release 6.10 (Final)" and not CL. If you need a confirmation on CL, let me know, we have production environments that run CL (6.10 and 7.6).
As part of the testing for CPANEL-23892, we manually verified the regeneration of chrome caches on both Cloudlinux and CentOS systems succeeded before publishing the case to version 78.

If you have a specific server environment you'd like me to test your plugin with, let me know the specific OS and full step-by-step instructions on how to replicate the issue you faced with your plugin prior to adding the workaround. I can replicate the specific environment internally to reproduce the error on version 76, and then update the test server to version 78 to confirm it solves the issue.

From what you say the bug will be fixed in v78. Do you know when v78 will reach RELEASE state ?
Version 78 is tentatively planned for publication to the CURRENT tier by the end of January, with the publication to the RELEASE and STABLE tiers expected before Q1 2019 ends.

Thank you.