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 '
Addon Name | WHMCS ID | WebsitePanel ID | |
---|---|---|---|
{$row['name']} | {$row['whmcs_id']} | {$row['wsp_id']} | Delete |
No Addon Data Found |
Add WebsitePanel Addon
'; + echo "