Cpanel::App - should it be used to check which app user is in?
Cpanel::App
appears to do what I want (with methods such as
is_cpanel
,
is_webmail
,
is_whm
and with a POD which says: [QUOTE]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:
#!/usr/local/cpanel/3rdparty/bin/perl
# 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() . "
\n";
print 'Are we whm? ' . ( Cpanel::App::is_whm() ? 'yes' : 'no' ) . "
\n";
print 'Are we cpanel? ' . ( Cpanel::App::is_cpanel() ? 'yes' : 'no' ) . "
\n";
print 'Are we webmail? ' . ( Cpanel::App::is_webmail() ? 'yes' : 'no' ) . "
\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
,...
-
Maybe Andy Baugh has some ideas on this one?
0 -
Depends on what you mean by developers. Developers working at cPanel? Yes. Integrators? No.
This is why we do not mention use of this module in our online documentation (last I checked anyways).
When you are using Cpanel::App, it is autoritative *if* your code's execution context is already inside of a compiled binary. This is useful if say, your context is a "module" hook, but not if you are a "script" hook. Similarly, custom CGIs in whostmgr (for example) will never have $Cpanel::appname set, so this module will as well be "at a loss" as to what the app actually is (and thus assume the "default" of cpanel), as this CGI is ran via fork+exec, so it retains no prior memory of what was in the compiled binary.
You might be tempted to reference ENV to see if we put something useful in there for you, but as far as the app goes, you'd be out of luck here too.
Your best bet is either to:
a) Check the URL in your code, which usually is different enough to use as a semaphore for "what app am I in"
b) Already know "what app you'll be" by coding it into your custom CGI script before install. Since the way to install whostmgr, cpanel and webmail plugin CGIs are all slightly different, whatever install script you use to install this CGI to the various cPanel "apps" can always just echo in "what app we are" to a __DATA__ block at the end of the file and then reference it above in your CGI.
0
Please sign in to leave a comment.
Comments
2 comments