Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Hook Script CPERROR

Discussion in 'cPanel Developers' started by moaddib, Sep 11, 2017.

Tags:
  1. moaddib

    moaddib Member

    Joined:
    Sep 11, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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.
     
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,167
    Likes Received:
    1,933
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. moaddib

    moaddib Member

    Joined:
    Sep 11, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    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
     
  4. moaddib

    moaddib Member

    Joined:
    Sep 11, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    I think main reason is that I can't connect exactly to active user session.
     
  5. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,167
    Likes Received:
    1,933
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. moaddib

    moaddib Member

    Joined:
    Sep 11, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    Yes sure,
    Please do not share this instruction.

    cPanel url: https://serverhostname:2083/cpsess[numericSessionId]/frontend/[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.
     
  7. moaddib

    moaddib Member

    Joined:
    Sep 11, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    As far as i can see i need to find out valid socket and connect to it in my perl script.
    /home/"cPanelUserHomeDir"/.cpanel/live-engine-connector-"SERIAL".sock
     
  8. moaddib

    moaddib Member

    Joined:
    Sep 11, 2017
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Ukraine
    cPanel Access Level:
    Root Administrator
    If there are any solutions for such situation ?
     
  9. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    45,167
    Likes Received:
    1,933
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello,

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

    Thank you.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice