/** * Handles activating and adding client addons to WebsitePanel * * @access public * @param array $params WHMCS parameters * @throws Exception */ function websitepanel_addons_AddonActivation($params) { // WHMCS server parameters & package parameters $userId = $params['userid']; $serviceId = $params['serviceid']; $addonId = $params['addonid']; $result = full_query("SELECT h.username AS username, s.ipaddress AS serverip, s.hostname AS serverhostname, s.secure AS serversecure, s.username AS serverusername, s.password AS serverpassword, p.configoption6 AS configoption6, h.id AS serviceid FROM `tblhosting` AS h, `tblservers` AS s, `tblproducts` AS p, `mod_wspaddons` AS w WHERE h.packageid = p.id AND w.whmcs_id = {$addonId} AND h.id = {$serviceId} AND h.server = s.id AND s.type = 'websitepanel'"); if (mysql_num_rows($result) > 0) { // Get the results of the query $row = mysql_fetch_assoc($result); // Start processing the users addon $username = $row['username']; $serverUsername = $row['serverusername']; $serverPassword = decrypt($row['serverpassword']); $serverPort = $row['configoption6']; $serverHost = empty($row['serverhostname']) ? $row['serverip'] : $row['serverhostname']; $serverSecure = $row['serversecure'] == 'on' ? TRUE : FALSE; try { // Create the WebsitePanel Enterprise Server Client object instance $wsp = new websitepanel_EnterpriseServer($serverUsername, $serverPassword, $serverHost, $serverPort, $serverSecure); // Get the user's details from WebsitePanel - We need the UserId $user = $wsp->getUserByUsername($username); if (empty($user)) { throw new Exception("User {$username} does not exist - Cannot allocate addon for unknown user"); } // Get the user's package details from WebsitePanel - We need the PackageId $package = $wsp->getUserPackages($user['UserId']); $packageId = $package['PackageId']; // Get the associated WebsitePanel addon id $results = select_query('mod_wspaddons', 'wsp_id,is_ipaddress', array('whmcs_id' => $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->addPackageAddonById($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->allocatePackageIPAddresses($packageId); } // Add log entry to client log logactivity("WebsitePanel Addon - Account {$username} addon successfully completed - Addon ID: {$addonId}", $userId); } else { // Add log entry to client log throw new Exception("Unknown", $results['Result']); } } catch (Exception $e) { // Error message to log / return $errorMessage = "websitepanel_addons_AddonActivation Fault: (Code: {$e->getCode()}, Message: {$e->getMessage()}, Service ID: {$serviceId})"; // Log to WHMCS logactivity($errorMessage, $userId); } } }
/** * Handles updating WebsitePanel account details when a client or administrator updates a client's details * * @access public * @param array $params WHMCS parameters * @throws Exception */ function websitepanel_sync_ClientEdit($params) { // WHMCS server parameters & package parameters $userId = $params['userid']; $serviceId = 0; // Query for the users WebsitePanel accounts - If they do not have any, just ignore the request $result = full_query("SELECT h.username AS username, s.ipaddress AS serverip, s.hostname AS serverhostname, s.secure AS serversecure, s.username AS serverusername, s.password AS serverpassword, p.configoption6 AS configoption6, h.id AS serviceid FROM `tblhosting` AS h, `tblservers` AS s, `tblproducts` AS p WHERE h.userid = {$userId} AND h.packageid = p.id AND h.server = s.id AND s.type = 'websitepanel' AND h.domainstatus IN ('Active', 'Suspended')"); while (($row = mysql_fetch_array($result)) != false) { // Start updating the users account details $serviceId = $row['serviceid']; $username = $row['username']; $serverUsername = $row['serverusername']; $serverPassword = decrypt($row['serverpassword']); $serverPort = $row['configoption6']; $serverHost = empty($row['serverhostname']) ? $row['serverip'] : $row['serverhostname']; $serverSecure = $row['serversecure'] == 'on' ? TRUE : FALSE; $clientsDetails = $params; try { // Create the WebsitePanel Enterprise Server Client object instance $wsp = new websitepanel_EnterpriseServer($serverUsername, $serverPassword, $serverHost, $serverPort, $serverSecure); // Get the user's details from WebsitePanel - We need the username $user = $wsp->getUserByUsername($username); if (empty($user)) { throw new Exception("User {$username} does not exist - Cannot update account details for unknown user"); } // Update the user's account details using the previous details + WHMCS's details (address, city, state etc.) $userParams = array('RoleId' => $user['RoleId'], 'Role' => $user['Role'], 'StatusId' => $user['StatusId'], 'Status' => $user['Status'], 'LoginStatusId' => $user['LoginStatusId'], 'LoginStatus' => $user['LoginStatus'], 'FailedLogins' => $user['FailedLogins'], 'UserId' => $user['UserId'], 'OwnerId' => $user['OwnerId'], 'IsPeer' => $user['IsPeer'], 'Created' => $user['Created'], 'Changed' => $user['Changed'], 'IsDemo' => $user['IsDemo'], 'Comments' => $user['Comments'], 'LastName' => $clientsDetails['lastname'], 'Username' => $user['Username'], 'Password' => $user['Password'], 'FirstName' => $clientsDetails['firstname'], 'Email' => $clientsDetails['email'], 'PrimaryPhone' => $clientsDetails['phonenumber'], 'Zip' => $clientsDetails['postcode'], 'InstantMessenger' => '', 'Fax' => '', 'SecondaryPhone' => '', 'SecondaryEmail' => '', 'Country' => $clientsDetails['country'], 'Address' => $clientsDetails['address1'], 'City' => $clientsDetails['city'], 'State' => $clientsDetails['state'], 'HtmlMail' => $user['HtmlMail'], 'CompanyName' => $clientsDetails['companyname'], 'EcommerceEnabled' => $user['EcommerceEnabled'], 'SubscriberNumber' => ''); // Execute the UpdateUserDetails method $wsp->updateUserDetails($userParams); // Add log entry to client log logactivity("WebsitePanel Sync - Account {$username} contact details updated successfully", $userId); } catch (Exception $e) { // Error message to log / return $errorMessage = "websitepanel_sync_ClientEdit Fault: (Code: {$e->getCode()}, Message: {$e->getMessage()}, Service ID: {$serviceId})"; // Log to WHMCS logactivity($errorMessage, $userId); } } }
/** * Returns the WebsitePanel one-click login link * * @param array $params WHMCS parameters * @throws Exception * @return string */ function websitepanel_LoginLink($params) { // WHMCS does not return the full hosting account details, we will query for what we need $result = select_query('tblhosting', 'domainstatus', array('id' => $params['serviceid'])); $results = mysql_fetch_array($result); $params['domainstatus'] = $results['domainstatus']; // Display the link only if the account is Active or Suspended if (in_array($params['domainstatus'], array('Active', 'Suspended'))) { // WHMCS server parameters & package parameters $serverUsername = $params['serverusername']; $serverPassword = $params['serverpassword']; $serverPort = $params['configoption6']; $serverHost = empty($params['serverhostname']) ? $params['serverip'] : $params['serverhostname']; $serverSecure = $params['serversecure']; $username = $params['username']; $serviceId = $params['serviceid']; $clientsDetails = $params['clientsdetails']; $userId = $clientsDetails['userid']; try { // Create the WebsitePanel Enterprise Server Client object instance $wsp = new websitepanel_EnterpriseServer($serverUsername, $serverPassword, $serverHost, $serverPort, $serverSecure); // Get the user's details from WebsitePanel - We need the userid $user = $wsp->getUserByUsername($username); if (empty($user)) { throw new Exception("User {$username} does not exist - Cannot display account link for unknown user"); } // Load the client area language file $LANG = websitepanel_LoadClientLanguage(); // Print the link echo "<a href=\"{$params['configoption8']}/Default.aspx?pid=Home&UserID={$user['UserId']}\" target=\"_blank\" title=\"{$LANG['websitepanel_adminarea_gotowebsitepanelaccount']}\">{$LANG['websitepanel_adminarea_gotowebsitepanelaccount']}</a><br />"; // Log the module call websitepanel_logModuleCall(__FUNCTION__, $params, $user); } catch (Exception $e) { // Error message to log / return $errorMessage = "LoginLink Fault: (Code: {$e->getCode()}, Message: {$e->getMessage()}, Service ID: {$serviceId})"; // Log to WHMCS logactivity($errorMessage, $userId); // Log the module call websitepanel_logModuleCall(__FUNCTION__, $params, $e->getMessage()); } } }