How to add scripts before a user is created in WHM

louisliu

Registered
Oct 1, 2010
4
0
51
I want to add some scripts when i create a new account in WHM:
Once all data is submitted in that page, the new user is created and the required changes are made.
The processing script should be altered, having it FIRST register the domain via the third party's API.
If the domain can not be registered, the script should fail and the some errors should be displayed.

Thanks!
 

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
Hi louisliu,

Let me first outline your requirements to ensure I fully understand.

1) The root or a reseller user use WHM to create an account.
2) Account creation is dependent on registering the new account's intended domain with a Registar (via their API)
3) If the domain registration is not successful, then account creation is unsuccessful. An error should be displayed within WHM stating the specific reason.


Well, short answer is that the various hooks systems either spawn separate processes (which couldn't preempt account creation, ie Function Hooks, Script Hooks) or receives their information on a level that WHM don't report, ( cPanel API level, ie CustomEventHandler). Your real option will require some significate coding.

I think the best opinion for you would be a WHM Plugin. WHM Plugins are CGI scripts, so is can be Perl or PHP. Your plugin would be a wrapper of sorts; maybe more like a mini application. You'd present a New Account form, similar to the one under Account Functions, but when the form is submitted it first attempts to register the domain, then tries to create the new account locally (either by executing /scripts/wwwacct or via the XML-API).

Even if there was a way to accomplish the 'do other stuff first and possibly fail' scenario with one of our hooks, I think you're best served doing a plugin if only for the reason that domain registration could be a rather lengthy and sophisticated bit of code. If you're customization was more application like, then you could actually do some very useful things, like besides just say there was a problem. For instance you could fully leverage either the domain registar's API or a payment gateway to ensure secure and PCI compliant transactions for the new domain.


Take a look at that stuff and post back if you have any questions,
-DavidN
 

louisliu

Registered
Oct 1, 2010
4
0
51
Thanks cPanelDavidN!

Your outline is correct.

WHM plugins may be the best solution, but i think your short answer is what i want to find, do you give me more informations to solve my question?

Thanks!
 

brianoz

Well-Known Member
Mar 13, 2004
1,146
7
168
Melbourne, Australia
cPanel Access Level
Root Administrator
Normally this is all done by a billing solution that sits above WHM/cpanel - one very good such solution is WHMCS. The billing system collects payment, creates invoice and payment audit trails, and then registers the domain and creates the account in WHM [via cPanel API]. In other words, you're kind of doing it backwards!

What are the reasons you need to do it this way? Not to say there might not be very good reasons, but understanding them in this point is key to providing reasoned advice.
 
Last edited:

cPanelDavidN

Well-Known Member
Staff member
Dec 17, 2009
571
3
68
Houston, TX
cPanel Access Level
Root Administrator
I think Brian has a very good point. Normally, a billing solution that can talk to the registar's APIs and the WHM/cPanel's APIs is what people use.

I think that any 'short answer' solution that I could dream up would be too fragile and overly complicated. A WHM Plugin, or some third party billing solution would work much better in the long term (and maybe short term too).

Regards,
-DavidN