moaddib

Member
Sep 11, 2017
6
0
1
Ukraine
cPanel Access Level
Root Administrator
Hi to avery one.
I work with Hook script that was added to event Api2::AddonDomain::addaddondomain
I used to use Cpanel::CPERROR function in my hooks modules but now I need script with escalated privileges.
In fact, I need to push Custom CPERROR to UI (page addon_domains_page_footer.html.tt or etc.)

How know how exactly works function Cpanel::CPERROR i need to reproduce it.
 

cPanelMichael

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

moaddib

Member
Sep 11, 2017
6
0
1
Ukraine
cPanel Access Level
Root Administrator
Yes sure. I already read this article, but i did not found any info about cperrors at hook script not module !!
/usr/local/cpanel/bin/manage_hooks add script ~/my-error-script.pm --category=Cpanel --event=Api2::AddonDomain::addaddondomain --stage=pre --manual --escalateprivs
I know that we can create cpsession by
#!/usr/local/cpanel/3rdparty/bin/perl
use Cpanel;
my $user="some_cp_user";
Cpanel->new->initcp($user);
#or
Cpanel->initcp($user);
Cpanel::CPERROR{'addondomain'} = "Done";

And I have not received any error at web UI.

As was mentioned earlier it works fine at my cPanel modules.
Like /usr/local/cpanel/bin/manage_hooks add Cpanel::MyError
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,884
2,254
463
I think main reason is that I can't connect exactly to active user session.
Could you provide us with the specific steps you are taking to reproduce this issue? Also, could you provide an example of the custom script you are using?

Thank you.
 

moaddib

Member
Sep 11, 2017
6
0
1
Ukraine
cPanel Access Level
Root Administrator
Yes sure,
Please do not share this instruction.

cPanel url: https://serverhostname:2083/cpsess[...ntend/[cPanelTemplate]/addon/doadddomain.html

1st way that works fine

cd /usr/local/cpanel/Cpanel/
vim SomeModule.pm
cat /usr/local/cpanel/Cpanel/SomeModule.pm

I
Code:
#!/usr/local/cpanel/3rdparty/bin/perl
package Cpanel::SomeModule;
use strict;
use warnings;
sub describe {
    my $hooks = [
        {
            'category' => 'Cpanel',
            'event'    => 'Api2::AddonDomain::addaddondomain',
            'stage'    => 'pre',
            'hook'     => 'Cpanel::SomeModule::SomeFunction',
            'exectype' => 'module',
        }

    ];
    return $hooks;
}

sub SomeFunction {

    my $return_value = {
        'status'     => 0,
        'status_msg' => undef
    };
  $Cpanel::CPERROR{'addondomain'} = "Fail to do SomeAction";
  return $return_value;
};

1;
/usr/local/cpanel/bin/manage_hooks add module Cpanel::SomeModule
These actions return to User Web Interface Error with following text "Fail to do SomeAction".

In my case i need to use Script not module.
2nd Way.

cd /my_folder/customPath/
vim SomeScript.pl

Code:
#!/usr/local/cpanel/3rdparty/bin/perl
package Cpanel::SomeScript;
use strict;
use warnings;
use Cpanel;

my $user="cPanelUser";
my @Cpanel = Cpanel->initcp($user);
# or my @Cpanel = Cpanel->new->initcp($user);
@Cpanel->set_api_error("Fail to do SomeAction");
# or @Cpanel::CPERROR{'addondomain'} = "Fail to do SomeAction";

my $result  = 0;                            
my $message = 'This is an error message.';

print "$result $message";
exit;

/usr/local/cpanel/bin/manage_hooks add script /my_folder/customPath/SomeScript.pl --category=Cpanel --event=Api2::AddonDomain::addaddondomain --stage=pre --manual --escalateprivs

No result in cPanel Web interface.
 

cPanelMichael

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

It looks like we are assisting you with this topic as part of ticket number 8880093.

Thank you.