kUdtiHaEX

Member
May 15, 2008
9
17
53
Belgrade, Serbia
cPanel Access Level
DataCenter Provider
Twitter
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.
 

CharlesBoyd

Member
May 29, 2012
10
0
51
cPanel Access Level
Root Administrator
You can write standardized hooks for the following API2 function calls:

Api2::AddonDomain::addaddondomain()

Api2::SubDomain::addsubdomain()

Api2::Park::park()


#!/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: YourAddonDomain.pm

Save this as: /var/cpanel/perl5/lib/YourAddonModule.pm

(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 YourAddonModule.pm'

Subdomain and Parked domain hooks will follow similarly, you may refer to the documentation for further information.
 
Last edited: