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