Run Script on Subdomain Creation via cPanel
I'd like to hook into the subdomain creation process (when done via cPanel) to run a bash (or perl) script. I successfully added one by creating a WHM module for account creation, but it seems like cPanel hooks don't work the same way.
WHM::Accounts::Create can be done via a module which I created, put in /usr/local/cpanel/MyPackage, and registered via bin/manage_hooks. That perl module calls a script and runs the tasks during the account creation process. Easy, once I figured it out!
Api2::SubDomain::addsubdomain doesn't seem to have modules the way WHM does, and I can't wrap my head around the process. Do I create a perl module and put it in /usr/local/cpanel/MyPackage, and then register it the same way via bin/manage_hooks? Does it go somewhere else? Or is it NOT a module and I have to create a perl script (in which case, where does it have to go and CAN it go in the MyPackage dir)?
The docs are great in terms of what can be done, but they're lacking in how to do it.
To clarify - I want to put this on my server, not call something externally via an API call. This is to run a script during the process when a user creates a subdomain through his/her cPanel.
Thanks!
-
I'd like to hook into the subdomain creation process (when done via cPanel) to run a bash (or perl) script. I successfully added one by creating a WHM module for account creation, but it seems like cPanel hooks don't work the same way.
Hello :) Please let us know if this thread is helpful: Hook to add addon domain. It's for addon domain names, but you could apply it to subdomains as well. Thank you.0 -
That definitely sent me down the right path and got it registered. It runs, but using the exact script here (Guide to Standardized Hooks - Hook Action Code - Software Development Kit - cPanel Documentation) along with some printing in do_something to figure out how data is being passed, but I'm getting nothing for $json: my $json = JSON::Syck::Dump($input); my $filename = '/home/test.txt'; open(my $fh, '>', $filename); print $fh "My json: $json"; close $fh;
$input is supposed to have the data from get_passed_data() which is supposed to return JSON...but I get nothing. (Note - the file IS being created and its contents are: My json: null0 -
Have you enabled debug mode? It's documented at: Guide to Standardized Hooks - Debug Mode - Software Development Kit - cPanel Documentation It will print debug data into the /usr/local/cpanel/logs/error_log file. Thank you. 0 -
Debug saved me. Thanks! I got it all working after much trial, error, and printing to the log. 0 -
I am happy to see you were able to address the issue. Thank you for updating us with the outcome. 0
Please sign in to leave a comment.
Comments
5 comments