From d6b037d109decb9dacbc3e15806614360f55ce46 Mon Sep 17 00:00:00 2001 From: Christopher York Date: Wed, 12 Dec 2012 01:13:15 -0600 Subject: [PATCH] Added: Addon automation module / helper for automating WebsitePanel / WHMCS addons Removed: Files have been moved into their respective directories Added: readme file --- .../includes/hooks/websitepanel_addons.php | 102 ++++++++++++ .../websitepanel_addons.php | 151 ++++++++++++++++++ .../websitepanel}/websitepanel.class.php | 66 +++++++- .../websitepanel}/websitepanel.errorcodes.php | 0 .../websitepanel}/websitepanel.functions.php | 0 .../servers/websitepanel}/websitepanel.php | 0 WebsitePanel.WHMCSModule/readme.txt | 22 +++ 7 files changed, 335 insertions(+), 6 deletions(-) create mode 100644 WebsitePanel.WHMCSModule/includes/hooks/websitepanel_addons.php create mode 100644 WebsitePanel.WHMCSModule/modules/addons/websitepanel_addons/websitepanel_addons.php rename WebsitePanel.WHMCSModule/{ => modules/servers/websitepanel}/websitepanel.class.php (85%) rename WebsitePanel.WHMCSModule/{ => modules/servers/websitepanel}/websitepanel.errorcodes.php (100%) rename WebsitePanel.WHMCSModule/{ => modules/servers/websitepanel}/websitepanel.functions.php (100%) rename WebsitePanel.WHMCSModule/{ => modules/servers/websitepanel}/websitepanel.php (100%) create mode 100644 WebsitePanel.WHMCSModule/readme.txt diff --git a/WebsitePanel.WHMCSModule/includes/hooks/websitepanel_addons.php b/WebsitePanel.WHMCSModule/includes/hooks/websitepanel_addons.php new file mode 100644 index 00000000..3c9a555b --- /dev/null +++ b/WebsitePanel.WHMCSModule/includes/hooks/websitepanel_addons.php @@ -0,0 +1,102 @@ + 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; +} \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/modules/addons/websitepanel_addons/websitepanel_addons.php b/WebsitePanel.WHMCSModule/modules/addons/websitepanel_addons/websitepanel_addons.php new file mode 100644 index 00000000..5e25caf1 --- /dev/null +++ b/WebsitePanel.WHMCSModule/modules/addons/websitepanel_addons/websitepanel_addons.php @@ -0,0 +1,151 @@ + '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 '

Duplicate WHMCS Addon ID. The WHMCS Addon ID Is Assigned To Another WebsitePanel Addon.

'; + } + else + { + insert_query('tblwspaddons', array('whmcs_id' => $_POST['whmcs_id'], 'wsp_id' => $_POST['wsp_id'], 'is_ipaddress' => $_POST['is_ipaddress'])); + } + } + else + { + echo '

WHMCS Addon Not Found! Check The ID And Try Again.

'; + } + } + + // 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 '
'; + echo ''; + echo ''; + if (mysql_num_rows($results) > 0) + { + while (($row = mysql_fetch_array($results)) != false) + { + echo ""; + } + } + else + { + echo ''; + } + echo '
Addon NameWHMCS IDWebsitePanel ID
{$row['name']}{$row['whmcs_id']}{$row['wsp_id']}Delete
No Addon Data Found
'; + + // Build the add addon form + echo '

Add WebsitePanel Addon

'; + echo "
"; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
WHMCS Addon ID
WebsitePanel Addon ID
Dedicated IP Addon
'; +} \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/websitepanel.class.php b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php similarity index 85% rename from WebsitePanel.WHMCSModule/websitepanel.class.php rename to WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php index 7fdcb756..ee25020c 100644 --- a/WebsitePanel.WHMCSModule/websitepanel.class.php +++ b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.class.php @@ -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 * diff --git a/WebsitePanel.WHMCSModule/websitepanel.errorcodes.php b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.errorcodes.php similarity index 100% rename from WebsitePanel.WHMCSModule/websitepanel.errorcodes.php rename to WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.errorcodes.php diff --git a/WebsitePanel.WHMCSModule/websitepanel.functions.php b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.functions.php similarity index 100% rename from WebsitePanel.WHMCSModule/websitepanel.functions.php rename to WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.functions.php diff --git a/WebsitePanel.WHMCSModule/websitepanel.php b/WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.php similarity index 100% rename from WebsitePanel.WHMCSModule/websitepanel.php rename to WebsitePanel.WHMCSModule/modules/servers/websitepanel/websitepanel.php diff --git a/WebsitePanel.WHMCSModule/readme.txt b/WebsitePanel.WHMCSModule/readme.txt new file mode 100644 index 00000000..9da3efc4 --- /dev/null +++ b/WebsitePanel.WHMCSModule/readme.txt @@ -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. \ No newline at end of file