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!

Hooking into domain processes

Discussion in 'cPanel Developers' started by kUdtiHaEX, Mar 16, 2013.

  1. kUdtiHaEX

    kUdtiHaEX Member

    May 15, 2008
    Likes Received:
    Trophy Points:
    I'm trying to write a hook for these cases:
    1. Addon domain add
    2. Subdomain add
    3. Parked domain add

    After searching through Google and cPanel Docs, I have found that I should place some file in appropriate directory here /usr/local/cpanel/hooks/park (for parked domains) and /usr/local/cpanel/hooks/subdomain (for subdomains).

    My questions are:
    1. If this course of action is correct, where should I put a script for addon domains?
    2. How should I name these files - addaddondomain, addsubdomain etc? What are correct answers?
    3. Are they executable scripts and in which language I can write them - Python, shell, PHP, Perl?
    4. Are they executed before or after the action?

    What I want to do is just to write something into file / do a search&replace every time someone does some of these 3 actions.
  2. CharlesBoyd

    CharlesBoyd Member

    May 29, 2012
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    You can write standardized hooks for the following API2 function calls:




    #!/usr/bin/env perl

    package YourAddonModule;

    use warnings;
    use strict;

    sub describe {
    my $create_addon_hook = {
    'category' => 'Cpanel',
    'event' => 'Api2::AddonDomain::addaddondomain',
    'stage' => 'pre', # or post
    'hook' => 'YourAddonModule::your_hook_subroutine',
    'exectype' => 'module',
    return [$create_addon_hook];

    sub your_addon_hook {
    my ( $context, $data ) = @_;
    my $args = $data->{'args'};
    my ( $dir, $newdomain, $subdomain ) = ( $args->{'dir'}, $args->{'newdomain'}, $args->{'subdomain'} );
    print "HOOK TEST : Created $newdomain with dir = $dir and subdomain = $subdomain","\n";

    Here's a link to more readable version of the code:

    Save this as: /var/cpanel/perl5/lib/

    (Note that you may have to create that directory with 'mkdir -p /var/cpanel/perl5/lib')

    Then you can register the hook with:

    '/usr/local/cpanel/bin/manage_hooks add module'

    Subdomain and Parked domain hooks will follow similarly, you may refer to the documentation for further information.
    #2 CharlesBoyd, Mar 19, 2013
    Last edited: Mar 19, 2013

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