Esempio n. 1
0
/**
 * 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);
        }
    }
}
Esempio n. 2
0
/**
 * Updates the WHMCS service's usage details from WebsitePanel
 * 
 * @param aray $params WHMCS parameters
 * @throws Exception
 */
function websitepanel_UsageUpdate($params)
{
    // WHMCS server parameters & package parameters
    $serverUsername = $params['serverusername'];
    $serverPassword = $params['serverpassword'];
    $serverHost = empty($params['serverhostname']) ? $params['serverip'] : $params['serverhostname'];
    $serverSecure = $params['serversecure'];
    $serverId = $params['serverid'];
    $userId = 0;
    $serviceId = 0;
    // Query for WebsitePanel user accounts assigned to this server
    // Only services that have packages that have "Tick to update diskpace / bandwidth in WHMCS" enabled
    $result = full_query("SELECT h.id AS serviceid, h.userid AS userid, h.username AS username, h.regdate AS regdate, p.configoption2 AS configoption2, p.configoption3 AS configoption3, p.configoption6 AS configoption6 FROM `tblhosting` AS h, `tblproducts` AS p WHERE h.server = {$serverId} AND h.packageid = p.id AND p.configoption16 = 'on' AND h.domainstatus IN ('Active', 'Suspended')");
    while (($row = mysql_fetch_array($result)) != false) {
        // Start processing the users usage
        $username = $row['username'];
        $userId = $row['userid'];
        $serviceId = $row['serviceid'];
        $serverPort = $row['configoption6'];
        // Diskspace and Bandwidth limits for this package
        $diskLimit = $row['configoption2'];
        $bwidthLimit = $row['configoption3'];
        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 calculate usage for unknown user");
            }
            // Get the user's package details from WebsitePanel - We need the PackageId
            $package = $wsp->getUserPackages($user['UserId']);
            // Gather the bandwidth / diskspace usage stats
            $bwidthUsage = websitepanel_CalculateUsage($wsp->getPackageBandwidthUsage($package['PackageId'], websitepanel_CreateBandwidthDate($row['regdate']), date('Y-m-d', time())), websitepanel_EnterpriseServer::USAGE_BANDWIDTH);
            $diskUsage = websitepanel_CalculateUsage($wsp->getPackageDiskspaceUsage($package['PackageId']), websitepanel_EnterpriseServer::USAGE_DISKSPACE);
            // Update WHMCS's service details
            update_query('tblhosting', array('diskusage' => $diskUsage, 'disklimit' => $diskLimit, 'bwusage' => $bwidthUsage, 'bwlimit' => $bwidthLimit, 'lastupdate' => 'now()'), array('id' => $serviceId));
            // Log the module call
            websitepanel_logModuleCall(__FUNCTION__, $params, $package);
        } catch (Exception $e) {
            // Error message to log / return
            $errorMessage = "UsageUpdate Fault: (Code: {$e->getCode()}, Message: {$e->getMessage()}, Service ID: {$serviceId})";
            // Log the module call
            websitepanel_logModuleCall(__FUNCTION__, $params, $e->getMessage());
            // Log to WHMCS
            logactivity($errorMessage, $userId);
        }
    }
}