logo
About Us Hosting Servers Docs Login





Hosting Account Order Code Explained

Three files are included with the sample code:

  • process-hosting.cgi -- performs the account addition
  • ServerConfig.pm -- Contains your login information
  • XMLAPIRequest.pm -- Functions for interacting with the XML API

The first file we are going to discuss is XMLAPIRequest.pm. This file simply contains code used to create functions for accessing the XML API. YOu won't need to change this code:

All you need to get from the above is that the methods for interacting with the XML API are new and dispatch where new creates a new XML API object and dispatch sends an XML API request. You might note that we are using Net::SSLeay so your data is traveling encrypted.

Next, we'll look at ServerConfig.pm, here you simply need to put in the username and password of root or the reseller that will be making the XML API requests. You'll also need to note the location of XMLAPIRequest.pm:

We separated out this code so that you can put it in /home/username and not within a web readable directory. You don't want t your WHM password available to the web. This file also creates a new XMLAPI Request called $xmlapi_object for you to work with.

The real meat of the code is within process-hosting.cgi. This is where the hosting order is processed, credit cards are checked, etc. Noting that a lot of the functions in this file are simply dummy functions that you'll have to fill in (i.e. interfacing with your credit card processor, billing system, etc). First, you'll note that we have to pull in the configuration info:

Then, we're gathering the info passed from our HTML order page:

There's some logic to worry about credit cards and other things but what we're really worried about are 4 functions, the first being checkUserExists:

You'll notice that what we're doing is simply looking up whether or not the user exists on the server with the listaccts XML API call:

We then want to make sure the Net::SSLeay request succeeded:

If the request succeeded, we look for a XML object called acct. If one exists, we know one or more accounts matched our search so we should send that the function failed since the user exists (we use failure as it is an easy way to halt the process with an if statement):

Next is the createAccount function:

You'll notice that this is just a call to /xml-api/createacct with some error checking:

We check to see which plan the user chose when they signed up. If they chose the reseller plan we add some logic to make them a reseller and setting their hosting plan correctly. First we'll add the reseller=1 variable to the xml-api request if they are a reseller:

Later we'll set the reseller's ACL. We'll get to the setResellerACL function later:

After we send the XML API request, we simply check to make sure the Net::SSLeay request succeeded

If it did, we get the result by creating a XML::Simple object and placing the Net::SSLeay request result in it:

Then we check the XML API statusmsg to make sure the account creation was sucessful:

If it was successful, we can send an email with the account details:

You remember that we need to know whether or not the user is going to be a reseller so we'll use isReseller to check and see if their package matches a package that is a reseller package, and return 1 (true) if it does:

If they are a reseller, we need to set their reseller privileges. We'll do this with a reseller ACL we created in the Reseller Center in WHM. Where our acl list is called reseller1:

To put everything together, we need the HTML from the form used to gather the data:

We also need some JavaScript to validate the form. Noting that you need to improve upon this JavaScript in order to validate the specific data you need. This JavaScript only ensures that the form field are not blank when the for is submitted:



Home   |    About us   |    Hosting   |    Servers   |    Docs   |    Login

MyBrandedHOST.com © 2007.  cPanel is a registered trademark of cPanel, Inc.