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!

Intercept and modify data with hook

Discussion in 'cPanel Developers' started by kdub, Apr 22, 2019.

Tags:
  1. kdub

    kdub Active Member

    Joined:
    Apr 19, 2019
    Messages:
    29
    Likes Received:
    8
    Trophy Points:
    3
    Location:
    California
    cPanel Access Level:
    Root Administrator
    cPanel provides action hooks to trigger functions for cPanel events. As far as I understand, the data the system passes to the hook is essentially read-only as the hook has no way to modify values and return them to the system.

    I'm looking for filter hook functionality akin to wordpress filter hooks that will allow me to intercept and modify data as it is processed—for example to automatically append a string to a domain name when creating a zone record, before the zone is actually created.

    I suppose the alternative is to use a post action hook to go back and manually update the record through the api. But this is essentially twice the work. It would be so much easier to just hand a modified value back and let cpanel complete the task it was already doing.

    Any suggestions for accomplishing something like this are much appreciated.
     
  2. kdub

    kdub Active Member

    Joined:
    Apr 19, 2019
    Messages:
    29
    Likes Received:
    8
    Trophy Points:
    3
    Location:
    California
    cPanel Access Level:
    Root Administrator
    I guess I answered my own question. I followed the guide Tutorial - Create a Standardized Hook - Developer Documentation - cPanel Documentation to write a hook as a perl module to test. Turns out you can easily modify the existing key values or add values for unset keys that are supported by the cpanel script.
    Code:
    # $data is a referenced hash so accessing them is fairly straight forward
    # for example the key 'domain' inside the nested hash 'args' inside $data
    $data->{'args'}->{'domain'} = 'domain.tld';
    Do scripts provide the same capabilities or is it only modules?

    For some reason what's not working is the alternate_logfile so I can output logs to a file other than the default error_log. The below code should work but info is still logged only to error_log. The file exists. I don't understand.
    Code:
    my $logger = Cpanel::Logger->new( { 'alternate_logfile' => '/usr/local/cpanel/logs/myhook_log' } );
     
    cPanelLauren likes this.
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    47,555
    Likes Received:
    2,182
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @kdub,

    Our Integration Developers should be able to better answer your question about this topic. Can you send this question via email to [email protected] and let us know the outcome once you receive an answer?

    Thank you.
     
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