Added: Addon automation module / helper for automating WebsitePanel / WHMCS addons

Removed: Files have been moved into their respective directories
Added: readme file
This commit is contained in:
Christopher York 2012-12-12 01:13:15 -06:00
parent 701d58049b
commit d6b037d109
7 changed files with 335 additions and 6 deletions

View file

@ -0,0 +1,102 @@
<?php if (!defined('WHMCS')) exit('ACCESS DENIED');
/**
* WebsitePanel Addons Hook
*
* @author Christopher York
* @package WebsitePanel Addons Hook
* @version v1.0
* @link http://www.websitepanel.net/
*/
/**
* websitepanel_addons_AddonActivation
*
* @access public
* @return array
*/
function websitepanel_addons_AddonActivation($params)
{
// Sanity check to make sure the associated service is WebsitePanel based product
// And that the addon purchased has an associated WebsitePanel addon
$results = full_query("SELECT h.id AS `id` FROM `tblhosting` AS h, `tblwspaddons` AS w, `tblservers` AS s WHERE h.id = {$params['serviceid']} AND h.server = s.id AND s.type = 'websitepanel' AND w.whmcs_id = {$params['addonid']}");
if (mysql_num_rows($results) > 0)
{
// Include the WebsitePanel ES Class
require_once(ROOTDIR . '/modules/servers/websitepanel/websitepanel.class.php');
// Retrieve the WebsitePanel Addons module settings
$modSettings = websitepanel_addons_GetSettings();
// Get the associated WebsitePanel username from WHMCS
$results = select_query('tblhosting', 'username', array('id' => $params['serviceid']));
$username = mysql_fetch_array($results);
$username = $username['username'];
if (empty($username))
{
// The username is required - if missing we cannot continue
return;
}
// Create the WebsitePanel object instance
$wsp = new WebsitePanel($modSettings['username'], $modSettings['password'], $modSettings['serverhost'], $modSettings['serverport'], (($modSettings['serversecured']) == 'on' ? TRUE : FALSE));
// Grab the user's details from WebsitePanel in order to get the user's id
$user = $wsp->get_user_by_username($username);
if (empty($user))
{
return;
}
// Get the user's current WebsitePanel hosting space Id (Hosting Plan)
$package = $wsp->get_user_packages($user['UserId']);
$packageId = $package['PackageId'];
if (empty($packageId))
{
return;
}
// Get the associated WebsitePanel addon id
$results = select_query('tblwspaddons', 'wsp_id,is_ipaddress', array('whmcs_id' => $params['addonid']));
$addon = mysql_fetch_array($results);
$addonPlanId = $addon['wsp_id'];
$addonIsIpAddress = $addon['is_ipaddress'];
// Add the Addon Plan to the customer's WebsitePanel package / hosting space
$results = $wsp->add_package_addon_by_id($packageId, $addonPlanId);
// Check the results to verify that the addon has been successfully allocated
if ($results['Result'] > 0)
{
// If this addon is an IP address addon - attempt to randomly allocate an IP address to the customer's hosting space
if ($addonIsIpAddress)
{
$wsp->package_allocate_ipaddress($packageId);
}
}
}
}
/* Addon Activation - WebsitePanel */
add_hook('AddonActivation', 1, 'websitepanel_addons_AddonActivation');
/* Addon Activation - WebsitePanel */
add_hook('AddonActivated', 1, 'websitepanel_addons_AddonActivation');
/**
* websitepanel_addons_GetSettings
*
* @access public
* @return array
*/
function websitepanel_addons_GetSettings()
{
$settings = array();
// Retrieve the settings from the modules configuration table
$results = select_query('tbladdonmodules', 'setting,value', array('module' => 'websitepanel_addons'));
while (($row = mysql_fetch_array($results)) != false)
{
$settings[$row['setting']] = $row['value'];
}
return $settings;
}

View file

@ -0,0 +1,151 @@
<?php if (!defined('WHMCS')) exit('ACCESS DENIED');
/**
* WebsitePanel Addons Addon Module
*
* @author Christopher York
* @package WebsitePanel Addons Addon Module
* @version v1.0
* @link http://www.websitepanel.net/
*/
/**
* websitepanel_addons_config
*
* @access public
* @return array
*/
function websitepanel_addons_config()
{
$configarray = array('name' => 'WebsitePanel Addons Automation',
'description' => 'Automates WHMCS product addons with WebsitePanel',
'version' => '1.0',
'author' => 'Christopher York',
'fields' => array('serverhost' => array('FriendlyName', 'Enterprise Server Host', 'Type' => 'text', 'Size' => 25, 'Description' => 'Enterprise Server hostname / IP address', 'Default' => '127.0.0.1'),
'serverport' => array('FriendlyName', 'Enterprise Server Port', 'Type' => 'text', 'Size' => 4, 'Description' => 'Enterprise Server port', 'Default' => 9002),
'serversecured' => array('FriendlyName', 'Use Secured Connection', 'Type' => 'yesno', 'Description' => 'Tick to use SSL secured connection'),
'username' => array('FriendlyName', 'Username', 'Type' => 'text', 'Size' => 25, 'Description' => 'Enterprise Server username', 'Default' => 'serveradmin'),
'password' => array('FriendlyName', 'Password', 'Type' => 'password', 'Size' => 25, 'Description' => 'Enterprise Server password')
)
);
return $configarray;
}
/**
* websitepanel_addons_activate
*
* @access public
* @return array
*/
function websitepanel_addons_activate()
{
// Create the WebsitePanel Addons table
$query = "CREATE TABLE `tblwspaddons` (
`whmcs_id` int(11) NOT NULL,
`wsp_id` int(11) NOT NULL,
`is_ipaddress` bit(1) NOT NULL DEFAULT b'0',
PRIMARY KEY (`whmcs_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
$result = full_query($query);
// Check the results to verify that the table has been created properly
if (!$result)
{
return array('status' => 'error', 'description' => 'There was an error while activating the module');
}
else
{
return array('status' => 'success', 'description' => 'The module has been activated successfully');
}
}
/**
* websitepanel_addons_deactivate
*
* @access public
* @return array
*/
function websitepanel_addons_deactivate()
{
// Create the WebsitePanel Addons table
$query = 'DROP TABLE `tblwspaddons`';
$result = full_query($query);
// Check the results to verify that the table has been created properly
if (!$result)
{
return array('status' => 'error', 'description' => 'There was an error while deactiviting the module');
}
else
{
return array('status' => 'success', 'description' => 'The module has been deactivated successfully');
}
}
/**
* websitepanel_addons_output
*
* @access public
* @return mixed
*/
function websitepanel_addons_output($params)
{
// Delete the requested WebsitePanel addon
if (isset($_GET['action']) && $_GET['action'] == 'delete')
{
delete_query('tblwspaddons', array('whmcs_id' => $_GET['id']));
}
// Add the requested WebsitePanel addon
if ($_POST && isset($_POST['action']) && $_POST['action'] == 'add')
{
// Sanity check to make sure the WHMCS addon ID exists
$results = select_query('tbladdons', 'id', array('id' => $_POST['whmcs_id']));
if (mysql_num_rows($results) > 0)
{
$results = select_query('tblwspaddons', 'whmcs_id', array('whmcs_id' => $_POST['whmcs_id']));
if (mysql_num_rows($results) > 0)
{
echo '<p><div style="margin:0 0 -5px 0;padding: 10px;background-color: #FBEEEB;border: 1px dashed #cc0000;font-weight: bold;color: #cc0000;font-size:14px;text-align: center;-moz-border-radius: 10px;-webkit-border-radius: 10px;-o-border-radius: 10px;border-radius: 10px;">Duplicate WHMCS Addon ID. The WHMCS Addon ID Is Assigned To Another WebsitePanel Addon.</div></p>';
}
else
{
insert_query('tblwspaddons', array('whmcs_id' => $_POST['whmcs_id'], 'wsp_id' => $_POST['wsp_id'], 'is_ipaddress' => $_POST['is_ipaddress']));
}
}
else
{
echo '<p><div style="margin:0 0 -5px 0;padding: 10px;background-color: #FBEEEB;border: 1px dashed #cc0000;font-weight: bold;color: #cc0000;font-size:14px;text-align: center;-moz-border-radius: 10px;-webkit-border-radius: 10px;-o-border-radius: 10px;border-radius: 10px;">WHMCS Addon Not Found! Check The ID And Try Again.</div></p>';
}
}
// Get all the assigned addons and display them to the user
$results = full_query('SELECT a.name AS `name`, a.id AS `whmcs_id`, w.wsp_id AS `wsp_id` FROM `tbladdons` AS a, `tblwspaddons` AS w WHERE w.whmcs_id = a.id');
// Build the table / data grid
echo '<div class="tablebg">';
echo '<table class="datatable" width="100%" border="0" cellspacing="1" cellpadding="3">';
echo '<tr><th>Addon Name</th><th>WHMCS ID</th><th>WebsitePanel ID</th><th></th></tr>';
if (mysql_num_rows($results) > 0)
{
while (($row = mysql_fetch_array($results)) != false)
{
echo "<tr><td>{$row['name']}</td><td>{$row['whmcs_id']}</td><td>{$row['wsp_id']}</td><td><a href=\"{$params['modulelink']}&action=delete&id={$row['whmcs_id']}\" onclick=\"return confirm('Are you sure you want to delete this addon?');\">Delete</td></td></tr>";
}
}
else
{
echo '<tr><td colspan="4">No Addon Data Found</td></tr>';
}
echo '</table></div>';
// Build the add addon form
echo '<p><strong>Add WebsitePanel Addon</strong></p>';
echo "<form action=\"{$params['modulelink']}\" method=\"POST\">";
echo '<input type="hidden" name="action" id="action" value="add">';
echo '<table class="form" "width="100%" border="0" cellspacing="2" cellpadding="3">';
echo '<tr><td class="fieldlabel">WHMCS Addon ID</td><td class="fieldarea"><input type="text" name="whmcs_id" id="whmcs_id"></td></tr>';
echo '<tr><td class="fieldlabel">WebsitePanel Addon ID</td><td class="fieldarea"><input type="text" name="wsp_id" id="wsp_id"></td></tr>';
echo '<tr><td class="fieldlabel">Dedicated IP Addon</td><td class="fieldarea"><input type="checkbox" name="is_ipaddress" id="is_ipaddress" value="1"></td></tr>';
echo '<tr><td colspan="2" class="fieldarea"><input type="submit" name="submit" id="submit" value="Submit"></td></tr>';
echo '</form></table>';
}

View file

@ -18,11 +18,12 @@ class WebsitePanel
*/
const SERVICEFILE_PACKAGES = 'esPackages.asmx';
const SERVICEFILE_USERS = 'esUsers.asmx';
const SERVICEFILE_SERVERS = 'esServers.asmx';
/**
* WebsitePanel account states
*
* @access private
* @access public
* @var string
*/
const USERSTATUS_ACTIVE = 'Active';
@ -33,12 +34,28 @@ class WebsitePanel
/**
* WebsitePanel usage calculation
*
* @access private
* @access public
* @var int
*/
const USAGE_DISKSPACE = 0;
const USAGE_BANDWIDTH = 1;
/**
* WebsitePanel IP address pools
*
* @access public
* @var string
*/
const IPADDRESS_POOL_WEB = 'Web';
/**
* WebsitePanel IP address groups
*
* @access public
* @var string
*/
const IPADDRESS_GROUP_WEBSITES = 'WebSites';
/**
* Enterprise Server username
*
@ -174,12 +191,12 @@ class WebsitePanel
public function update_user_details($RoleId, $Role, $StatusId, $Status, $LoginStatusId, $LoginStatus, $FailedLogins, $UserId, $OwnerId, $Created, $Changed, $IsDemo, $IsPeer, $Comments, $Username, $Password, $FirstName, $LastName, $Email, $PrimaryPhone, $Zip, $InstantMessenger, $Fax, $SecondaryPhone, $SecondaryEmail, $Country, $Address, $City, $State, $HtmlMail, $CompanyName, $EcommerceEnabled)
{
$params = array();
foreach (get_defined_vars() as $name => $value)
foreach (get_defined_vars() as $key => $value)
{
if ($key == 'params')
continue;
$params[$name] = $value;
$params[$key] = $value;
}
return $this->execute_server_method(WebsitePanel::SERVICEFILE_USERS, 'UpdateUser', array('user' => $params))->UpdateUserResult;
}
@ -260,16 +277,30 @@ class WebsitePanel
public function update_package_literal($packageId, $statusId, $planId, $purchaseDate, $packageName, $packageComments)
{
$params = array();
foreach (get_defined_vars() as $name => $value)
foreach (get_defined_vars() as $key => $value)
{
if ($key == 'params')
continue;
$params[$name] = $value;
$params[$key] = $value;
}
return (array)$this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'UpdatePackageLiteral', $params)->UpdatePackageLiteralResult;
}
/**
* WebsitePanel::add_package_addon_by_id()
*
* @access public
* @param mixed $packageId Package id
* @param mixed $addonPlanId Addon plan od
* @param integer $quantity Quantity
* @return array
*/
public function add_package_addon_by_id($packageId, $addonPlanId, $quantity = 1)
{
return (array)$this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'AddPackageAddonById', array('packageId' => $packageId, 'addonPlanId' => $addonPlanId, 'quantity' => $quantity))->AddPackageAddonByIdResult;
}
/**
* WebsitePanel::GetSpaceBandwidthUsage()
*
@ -296,6 +327,29 @@ class WebsitePanel
return $this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'GetPackageDiskspace', array('packageId' => $packageId))->GetPackageDiskspaceResult;
}
/**
* WebsitePanel::package_allocate_ipaddress()
*
* @param mixed $packageId Package id
* @param mixed $groupName Group name
* @param mixed $pool Address pool
* @param integer $addressesNumber Number of IP addresses
* @param bool $allocateRandom Allocate IP addresses randomly
* @return object
*/
public function package_allocate_ipaddress($packageId, $groupName = WebsitePanel::IPADDRESS_POOL_WEB, $pool = WebsitePanel::IPADDRESS_GROUP_WEBSITES, $addressesNumber = 1, $allocateRandom = TRUE)
{
$params = array();
foreach (get_defined_vars() as $key => $value)
{
if ($key == 'params')
continue;
$params[$key] = $value;
}
return $this->execute_server_method(WebsitePanel::SERVICEFILE_SERVERS, 'AllocatePackageIPAddresses', $params)->AllocatePackageIPAddressesResult;
}
/**
* Executes the request Enterprise Server method / parameters and returns the results
*

View file

@ -0,0 +1,22 @@
Extract the "includes" and "modules" directories into the root of your WHMCS installation
Overwrite any files that already exists
To enable addon automation...
1. WHMCS Admin -> Setup -> Addon Modules -> "WebsitePanel Addons Automation" -> Activate
2. Select "Configure"
3. Enter your WebsitePanel Enterprise Server details
4. WHMCS Admin -> Addons -> "WebsitePanel Addons"
5. Enter your addons here. You can get the WHMCS addon ID by clicking the edit icon on the addon and extracting the &id=x from the URL (x being the WHMCS Addon ID)
You can retrieve your WebsitePanel addon ID by editing the addon and extracting the PlanID=x from the URL (x being the WebsitePanel Addon ID)
6. If this is a Dedicated IP address addon, check the Dedicated IP Address box to allow the module to auto-allocate an IP address.
What does not work?
- Quantities, only a single addon => addon can be allocated
- Terminating / Suspending Addons, I've ran out of time on what I can do currently
- When an IP address is allocated WebsitePanel does not return back what IP was allocated, so WHMCS is not updated which what IP has been allocated to
his / her package at this time.
- A single user => single package is the only way the WebsitePanel server module works. I have no plans on making this work any other way.
- Users who use empty pointers when creating websites (domain.com instead of www.domain.com), websites are not created automatically even if the "Create Website"
option is selected. I have provided a patch to the websitepanel developers, should be fixed in a later release.
- The "Enable DNS Zone" option does not currently work - I have provided a patch to the websitepanel developers, should be fixed in a later release.
- Instant aliases / Temp domain are not properly created for websites, I have provided a patch to the websitepanel developers, should be fixed in a later release.