Cpanel::App - should it be used to check which app user is in?

Operating System & Version
almalinux 8
cPanel & WHM Version


Well-Known Member
May 28, 2022
Mansfield, Nottingham, UK
cPanel Access Level
Root Administrator

Are developers meant to use the methods in Cpanel::App to determine which environment/application their plugin is running in?

Longer -

I'm (slowly) developing a cPanel plugin and wanting to check which "application" the user is in (cpanel, whm, etc) - and the Perl package Cpanel::App appears to do what I want (with methods such as is_cpanel , is_webmail, is_whm and with a POD which says:

This module provides authoritative logic for determining whether the
running cpsrvd application is cPanel, WHM, or Webmail.

You should NOT access global scalars like $Cpanel::appname to
discern this information; use this module’s functions instead.
However, whenever I load the Cpanel::App package, it sets the internal variable $appname to "cpanel" and so only is_cpanel comes back true no matter which application is running.

Here's my test code:

# File location: /usr/local/cpanel/whostmgr/docroot/cgi/test.cgi
use strict;
use warnings;
use Cpanel::App();
print "Content-type: text/html; charset=utf-8\r\n\r\n";
print 'App name normalised: ' . Cpanel::App::get_normalized_name() . "<br>\n";
print 'Are we whm? ' .     ( Cpanel::App::is_whm()     ? 'yes' : 'no' ) . "<br>\n";
print 'Are we cpanel? ' .  ( Cpanel::App::is_cpanel()  ? 'yes' : 'no' ) . "<br>\n";
print 'Are we webmail? ' . ( Cpanel::App::is_webmail() ? 'yes' : 'no' ) . "<br>\n";
exit 0;
I did try accessing $Cpanel::App::appname directly without loading Cpanel::App , but then it was empty. Quite a lot of Cpanel provided code accesses $Cpanel::appname (114 mentions) and $Cpanel::App::appname (84 mentions) - with only 13 mentions of Cpanel::App::is_whm and 5 mentions of Cpanel::App::is_cpanel ,...


Feb 16, 2023
cPanel Access Level
Root Administrator
In a plugin CGI context, Cpanel::App is not going to function properly. The default app in that module is cPanel. The whostmgr and cpsrvd binaries set the variable inside their context, but you won't have that set in a plugin CGI's context. As such it will *always* report back that it is cpanel.

With that in mind, this isn't to say that you can't know what is executing your plugin CGI. The simplest way to check this during *runtime* would be a check on the URL string, as these will look different in each of these contexts.
  • Like
Reactions: cPRex