Cockpit Add-on Module Code
The code for the WHMCS Cockpit Add-on Module is available on GitHub: https://github.com/0-complexity/whmcs-cockpit-module
Also see the GitBook for this module: https://www.gitbook.com/book/gig/whmcs-cockpit-module/
Two main files are involved here:
hook_cockpit.php
- Located in the in the
includes/hooks
directory - This is where the first step is implemented, compiling the URL to request the authorization code
- Located in the in the
cockpit.php
- Located in the
modules/servers/cockpit
directory
- Located in the
Two other files that are important:
vdc.php
- Located in root of the WHMCS directory
vdc.tpl
is the template file used byvdc.php
- Located in the
templates/itsyouonline
directory
- Located in the
All for files are discussed below.
- hook_cockpit.php
Two hooks are implemented here, as registered at the botton of the code:
add_hook('ClientAreaPage', 1, 'hook_template_variables');
add_hook('ShoppingCartValidateProductUpdate', 1, 'validate_product');
The first hook, function hook_template_variables()
, as documented in the WHMCS Documentation, is called every time the client area page loads and can accept a return of values to be included as additional smarty fields.
Here we just return the value of the session variable "jwt" in an array of field => value combinations, using "jwt" as the field name.
This session variable was set previously when the user authenticated successfully against ItsYou.online, see the implementation of "step 6" in the OAuth 2.0 Add-on Module Code section.
This always us to pass the JWT value as a querry string field value of the iframe that embeds the VDC Control Panel, as explained in the VDC Control Panel Code section.
The second hook, validate_product()
, as documented in the WHMCS Documentation, is called as the product configuration is being completed.
Here we make sure that the name specified by the user for the new virtual datacenter is not yet used.
Another JWT is involved here, a JWT needed to talk to the Cockpit on behalf of the logged in Moehaha.com reseller organization. The other JWT, discussed above, allows the VDC Control Panel to connect to the G8 node on behalf of the end user.
- cockpit.php
In this file following functions implemented:
cockpit_ConfigOptions()
- Sets up the Module *Settings tab of the Product/Services configuration in the WHMCS Admin Portal
- Also see Provisioning Module Developer Docs in the WHMCS documentation
cockpit_ClientAreaCustomButtonArray()
- Here we create the "Control Panel" button that will call the
cockpit_vdc()
function when clicked - Also see Provisioning Module Developer Docs in the WHMCS documentation
- Here we create the "Control Panel" button that will call the
cockpit_vdc()
- Redirects the user to the
vdc.php
page that embeds the VDC Control Panel as an iframe, as documented in VDC Control Panel Code for more details - For compiling the redirect URL:
- A JWT is requested from ItsYou.online for talking to the Cockpit on behalf of the Moehaha.com reseller organization
- Using this JWT we get the id of the virtual datacenter and the domain URL for the G8 node hosting it the from the Cockpit
- This id and the domain URL is passed to the redirect URL
- Also see Provisioning Module SDK Parameters in the WHMCS documentation
- Redirects the user to the
cockpit_TerminateAccount()
cockpit_CreateAccount()
this is where the actual deployment is implemented- Also here a JWT is requested from ItsYou.online for talking to the Cockpit on behalf of the Moehaha.com reseller organization
- Using this JWT we get the id of the virtual datacenter and the domain URL for the G8 node hosting it the from the Cockpit
- Through the
deploy()
function the deployment is done 4 steps, all implemented inCockpitApi.php
, one of the files in themodules/servers/cockpit/lib
directory:create_repository()
create_blueprint()
execute_blueprint()
install_service_vdc()
- Also here a JWT is requested from ItsYou.online for talking to the Cockpit on behalf of the Moehaha.com reseller organization
cockpit_ChangePackage()