From 5d1c59c9fd84b161b48bbc5599742dcac0dce2d4 Mon Sep 17 00:00:00 2001 From: Virtuworks Date: Tue, 11 Dec 2012 18:30:24 -0500 Subject: [PATCH] wsp-10081 Added WHMCS Module to Source --- .../websitepanel.class.php | 332 ++++++++++++++ .../websitepanel.errorcodes.php | 25 + .../websitepanel.functions.php | 142 ++++++ WebsitePanel.WHMCSModule/websitepanel.php | 433 ++++++++++++++++++ 4 files changed, 932 insertions(+) create mode 100644 WebsitePanel.WHMCSModule/websitepanel.class.php create mode 100644 WebsitePanel.WHMCSModule/websitepanel.errorcodes.php create mode 100644 WebsitePanel.WHMCSModule/websitepanel.functions.php create mode 100644 WebsitePanel.WHMCSModule/websitepanel.php diff --git a/WebsitePanel.WHMCSModule/websitepanel.class.php b/WebsitePanel.WHMCSModule/websitepanel.class.php new file mode 100644 index 00000000..7fdcb756 --- /dev/null +++ b/WebsitePanel.WHMCSModule/websitepanel.class.php @@ -0,0 +1,332 @@ +_esUsername = $esUsername; + $this->_esPassword = $esPassword; + $this->_esServerUrl = $esServerUrl; + $this->_esServerPort = $esServerPort; + $this->_esUseSsl = $useSsl; + } + + /** + * WebsitePanel::CreateAccount() + * + * @param string $username Account username + * @param string $password Account password + * @param string $roleId Account role id + * @param string $firstName Account holders firstname + * @param string $lastName Account holders lastname + * @param string $email Account holders email address + * @param string $planId WebsitePanel plan id + * @param integer $parentPackageId Parent space / package id + * @param string $domainName Account domain name + * @param string $hostName Website hostname (if createWebsite is TRUE) + * @param bool $htmlMail Send HTML email + * @param bool $sendAccountLetter Send WebsitePanel "Account Summary" letter + * @param bool $sendPackageLetter Send WebsitePanel "Hosting Space Summary" letter + * @param bool $createPackage Create hostingspace / package on user creation + * @param bool $tempDomain Create temporary domain on hostingspace / package creation + * @param bool $createWebSite Create Website on hostingspace / package creation + * @param bool $createFtpAccount Create FTP account on hostingspace / package creation + * @param string $ftpAcountName FTP account name to create (if createFtpAccount is TRUE) + * @param bool $createMailAccount Create default mail account on hostingspace / package creation + * @param bool $createZoneRecord Create domain DNS zone record (if createMailAccount OR createWebSite are TRUE) + * @return int + */ + public function create_user_wizard($username, $password, $roleId, $firstName, $lastName, $email, $planId, $parentPackageId, $domainName, $hostName, $htmlMail = TRUE, $sendAccountLetter = TRUE, $sendPackageLetter = TRUE, $createPackage = TRUE, $tempDomain = FALSE, $createWebSite = FALSE, $createFtpAccount = FALSE, $ftpAcountName = '', $createMailAccount = FALSE, $createZoneRecord = FALSE) + { + $params = array(); + foreach (get_defined_vars() as $key => $value) + { + if ($key == 'params') + continue; + + $params[$key] = $value; + } + return $this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'CreateUserWizard', $params)->CreateUserWizardResult; + } + + /** + * WebsitePanel::UpdateUserDetails() + * + * @access public + * @param int $RoleId Account role id + * @param string $Role Account role + * @param int $StatusId Account status id + * @param string $Status Account status + * @param int $UserId Account user id + * @param int $OwnerId Account owner id + * @param string $Created Account creation date + * @param string $Changed Account changed date + * @param bool $IsDemo Demo account + * @param bool $IsPeer Peer account + * @param string $Comments Account comments + * @param string $Username Account username + * @param string $Password Account password + * @param string $FirstName Account holders firstname + * @param string $LastName Account holders lastname + * @param string $Email Account holders email address + * @param string $PrimaryPhone Account holders phone number + * @param string $Zip Account holders postal code + * @param string $InstantMessenger Account holders IM + * @param string $Fax Account holders fax number + * @param string $SecondaryPhone Account holders secondary phone number + * @param string $SecondaryEmail Account holders secondary email + * @param string $Country Account holders country + * @param string $Address Account holders physical address + * @param string $City Account holders city + * @param string $State Account holders state + * @param bool $HtmlMail Send HTML email + * @param string $CompanyName Account holders Company name + * @param bool $EcommerceEnabled Ecommerce enabled + * @return void + */ + 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) + { + if ($key == 'params') + continue; + + $params[$name] = $value; + } + return $this->execute_server_method(WebsitePanel::SERVICEFILE_USERS, 'UpdateUser', array('user' => $params))->UpdateUserResult; + } + + /** + * WebsitePanel::DeleteUser() + * + * @access public + * @param int $userid User id + * @return int + */ + public function delete_user($userId) + { + return $this->execute_server_method(WebsitePanel::SERVICEFILE_USERS, 'DeleteUser', array('userId' => $userId))->DeleteUserResult; + } + + /** + * WebsitePanel::GetUserByUsername() + * + * @access public + * @param string $username Username + * @return array + */ + public function get_user_by_username($username) + { + return (array)$this->execute_server_method(WebsitePanel::SERVICEFILE_USERS, 'GetUserByUsername', array('username' => $username))->GetUserByUsernameResult; + } + + /** + * WebsitePanel::ChangeUserStatus() + * + * @param int $userId User id + * @param string $status Account status (Active, Suspended, Cancelled, Pending) + * @return int + */ + public function change_user_status($userId, $status) + { + return $this->execute_server_method(WebsitePanel::SERVICEFILE_USERS, 'ChangeUserStatus', array('userId' => $userId, 'status' => $status))->ChangeUserStatusResult; + } + + /** + * WebsitePanel::ChangeUserPassword() + * + * @access public + * @param int $userId User id + * @param string $password New password + * @return int + */ + public function change_user_password($userId, $password) + { + return $this->execute_server_method(WebsitePanel::SERVICEFILE_USERS, 'ChangeUserPassword', array('userId' => $userId, 'password' => $password))->ChangeUserPasswordResult; + } + + /** + * WebsitePanel::GetUserPackages() + * + * @access public + * @param int $userid User id + * @return array + */ + public function get_user_packages($userid) + { + return (array)$this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'GetMyPackages', array('userId' => $userid))->GetMyPackagesResult->PackageInfo; + } + + /** + * WebsitePanel::UpdatePackageLiteral() + * + * @access public + * @param int $packageId Package id + * @param int $statusId Status id + * @param int $planId Plan id + * @param string $purchaseDate Purchase date + * @param string $packageName Package name + * @param string $packageComments Package comments + * @return array + */ + public function update_package_literal($packageId, $statusId, $planId, $purchaseDate, $packageName, $packageComments) + { + $params = array(); + foreach (get_defined_vars() as $name => $value) + { + if ($key == 'params') + continue; + + $params[$name] = $value; + } + return (array)$this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'UpdatePackageLiteral', $params)->UpdatePackageLiteralResult; + } + + /** + * WebsitePanel::GetSpaceBandwidthUsage() + * + * @access public + * @param int $packageId Package id + * @param string $startDate Start date + * @param string $endDate Ending date + * @return object + */ + public function get_space_bandwidth_usage($packageId, $startDate, $endDate) + { + return $this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'GetPackageBandwidth', array('packageId' => $packageId, 'startDate' => $startDate, 'endDate' => $endDate))->GetPackageBandwidthResult; + } + + /** + * WebsitePanel::GetSpaceDiskspaceUsage() + * + * @access private + * @param int $packageId Package Id + * @return object + */ + public function get_space_diskspace_usage($packageId) + { + return $this->execute_server_method(WebsitePanel::SERVICEFILE_PACKAGES, 'GetPackageDiskspace', array('packageId' => $packageId))->GetPackageDiskspaceResult; + } + + /** + * Executes the request Enterprise Server method / parameters and returns the results + * + * @access private + * @param string $serviceFile Enterprise Server service filename + * @param string $serviceMethod Enterprise Server service method name + * @param array $methodParameters Method parameters + * @throws Exception + * @return object + */ + private function execute_server_method($serviceFile, $serviceMethod, $methodParameters = array()) + { + $esUrl = (($this->_esUseSsl ? "https" : "http") . "://{$this->_esServerUrl}:{$this->_esServerPort}/{$serviceFile}?WSDL"); + $soapParams = array('login' => $this->_esUsername, + 'password' => $this->_esPassword, + 'cache_wsdl' => WSDL_CACHE_NONE, // WSDL caching is an annoying nightmare - we will disable it + 'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP + ); + try + { + $client = new SoapClient($esUrl, $soapParams); + $result = $client->$serviceMethod($methodParameters); + if (is_soap_fault($result)) + { + throw new Exception($result->faultstring); + } + return $result; + } + catch (Exception $e) + { + throw new Exception($e->getMessage()); + } + } +} \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/websitepanel.errorcodes.php b/WebsitePanel.WHMCSModule/websitepanel.errorcodes.php new file mode 100644 index 00000000..61d334c4 --- /dev/null +++ b/WebsitePanel.WHMCSModule/websitepanel.errorcodes.php @@ -0,0 +1,25 @@ + 'User already exists', + -101 => 'User not found', + -102 => 'User has child user accounts', + -300 => 'Hosting package could not be found', + -301 => 'Hosting package has child hosting spaces', + -501 => 'The sub-domain belongs to an existing hosting space that does not allow sub-domains to be created', + -502 => 'The domain or sub-domain exists within another hosting space', + -511 => 'Instant alias is enabled, but not configured', + -601 => 'The website already exists on the target hosting space', + -700 => 'The email domain already exists on the target hosting space', + -1100 => 'User already exists'); \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/websitepanel.functions.php b/WebsitePanel.WHMCSModule/websitepanel.functions.php new file mode 100644 index 00000000..bc5d24a6 --- /dev/null +++ b/WebsitePanel.WHMCSModule/websitepanel.functions.php @@ -0,0 +1,142 @@ +get_space_bandwidth_usage($packageId, $startDate, date('Y-m-d', time())); + return websitepanel_CalculateUsage($result, WebsitePanel::USAGE_BANDWIDTH); + } + catch (Exception $e) + { + // Do nothing, just catch the Exception to keep PHP from exploding :) + } +} + +/** + * websitepanel_CalculateDiskspaceUsage() + * + * @access public + * @param mixed $params + * @param mixed $packageId + * @return int + */ +function websitepanel_CalculateDiskspaceUsage($params, $packageId) +{ + // Create the ASPnix websitepanel_EnterpriseServer class object + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + try + { + $result = $wsp->get_space_diskspace_usage($packageId); + return websitepanel_CalculateUsage($result, WebsitePanel::USAGE_DISKSPACE); + } + catch (Exception $e) + { + // Do nothing, just catch the Exception to keep PHP from exploding :) + } +} + +/** + * websitepanel_CalculateUsage() + * + * @access public + * @param mixed $result + * @param int $usageType + * @return int + */ +function websitepanel_CalculateUsage($result, $usageType) +{ + // Process results + $xml = simplexml_load_string($result->any); + $total = 0; + if (count($xml->NewDataSet->Table) > 0) + { + foreach ($xml->NewDataSet->Table as $table) + { + switch ($usageType) + { + case WebsitePanel::USAGE_BANDWIDTH: + $total = $total + $table[0]->MegaBytesTotal; + break; + + case WebsitePanel::USAGE_DISKSPACE: + $total = $total + $table[0]->Diskspace; + break; + + default: + $total = $total + $table[0]->MegaBytesTotal; + break; + } + } + } + return $total; +} \ No newline at end of file diff --git a/WebsitePanel.WHMCSModule/websitepanel.php b/WebsitePanel.WHMCSModule/websitepanel.php new file mode 100644 index 00000000..f7807411 --- /dev/null +++ b/WebsitePanel.WHMCSModule/websitepanel.php @@ -0,0 +1,433 @@ + array( 'Type' => 'text', 'Size' => 25, 'Description' => 'Package Name'), + 'Web Space Quota' => array( 'Type' => 'text', 'Size' => 5, 'Description' => 'MB'), + 'Bandwidth Limit' => array( 'Type' => 'text', 'Size' => 5, 'Description' => 'MB'), + 'Plan ID' => array( 'Type' => 'text', 'Size' => 4, 'Description' => 'WebsitePanel hosting plan id'), + 'Parent Space ID' => array( 'Type' => 'text', 'Size' => 3, 'Description' => '* SpaceID that all accounts are created under', 'Default' => 1), + 'Enterprise Server Port' => array( 'Type' => 'text', 'Size' => 5, 'Description' => '* Required', 'Default' => 9002), + 'Different Potal URL' => array( 'Type' => 'yesno', 'Description' => 'Tick if portal address is different to server address'), + 'Portal URL' => array( 'Type' => 'text', 'Size' => 25, 'Description' => 'Portal URL, with http://, no trailing slash' ), + 'Send Account Summary Email' => array( 'Type' => 'yesno', 'Description' => 'Tick to send the "Account Summary" letter' ), + 'Send Hosting Space Summary Email' => array( 'Type' => 'yesno', 'Description' => 'Tick to send the "Hosting Space Summary" letter'), + 'Create Mail Account' => array( 'Type' => 'yesno', 'Description' => 'Tick to create mail account' ), + 'Create FTP Account' => array( 'Type' => 'yesno', 'Description' => 'Tick to create FTP account' ), + 'Create Temporary Domain' => array( 'Type' => 'yesno', 'Description' => 'Tick to create a temporary domain' ), + 'Send HTML Email' => array( 'Type' => 'yesno', 'Description' => 'Tick enable HTML email from WebsitePanel' ), + 'Create Website' => array( 'Type' => 'yesno', 'Description' => 'Tick to create Website' ), + 'Count Bandwidth / Diskspace' => array( 'Type' => 'yesno', 'Description' => 'Tick to update diskpace / bandwidth in WHMCS'), + 'Default Pointer' => array( 'Type' => 'text', 'Size' => 25, 'Description' => 'The default pointer (hostname) to use when creating a Website' ), + 'Create DNS Zone' => array( 'Type' => 'yesno', 'Description' => 'Tick to create domain DNS zone' ) + ); + return $configarray; +} + +/** + * websitepanel_CreateAccount() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_CreateAccount($params) +{ + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + // WHMCS server parameters & package parameters + $username = $params['username']; + $password = $params['password']; + $accountid = $params['accountid']; + $packageid = $params['packageid']; + $domain = $params['domain']; + $packagetype = $params['type']; + $clientsdetails = $params['clientsdetails']; + + // WebsitePanel API parameters + $planId = $params['configoption4']; + $parentPackageId = $params['configoption5']; + $roleId = ($packagetype == 'reselleraccount') ? 2 : 3; + $htmlMail = ($params['configoption14'] == 'on') ? TRUE : FALSE; + $sendAccountLetter = ($params['configoption9'] == 'on') ? TRUE : FALSE; + $sendPackageLetter = ($params['configoption10'] == 'on') ? TRUE : FALSE; + $createMailAccount = ($params['configoption11'] == 'on') ? TRUE : FALSE; + $createTempDomain = ($params['configoption13'] == 'on') ? TRUE : FALSE; + $createFtpAccount = ($params['configoption12'] == 'on') ? TRUE : FALSE; + $createWebsite = ($params['configoption15'] == 'on') ? TRUE : FALSE; + $websitePointerName = $params['configoption17']; + $createZoneRecord = ($params['configoption18'] == 'on') ? TRUE : FALSE; + + try + { + // Attempt to create the WSP user account and his / her package / hosting space + $result = $wsp->create_user_wizard($username, $password, $roleId, $clientsdetails['firstname'], $clientsdetails['lastname'], $clientsdetails['email'], $planId, $parentPackageId, $domain, $websitePointerName, $htmlMail, $sendAccountLetter, $sendPackageLetter, TRUE, $createTempDomain, $createWebsite, $createFtpAccount, $username, $createMailAccount, $createZoneRecord); + if ($result >= 0) + { + // Grab the user's details from WebsitePanel + $user = $wsp->get_user_by_username($username); + + // Update the user's account with his / her WHMCS contact details + $wsp->update_user_details($user['RoleId'], $user['Role'], $user['StatusId'], $user['Status'], $user['LoginStatusId'], $user['LoginStatus'], $user['FailedLogins'], $user['UserId'], $user['OwnerId'], $user['Created'], $user['Changed'], $user['IsDemo'], $user['IsPeer'], $user['Comments'], $username, $password, $clientsdetails['firstname'], $clientsdetails['lastname'], $clientsdetails['email'], $clientsdetails['phonenumber'], $clientsdetails['postcode'], '', '', '', '', $clientsdetails['country'], $clientsdetails['address1'], $clientsdetails['city'], $clientsdetails['state'], $htmlMail, $clientsdetails['companyname'], (($roleId == 2) ? TRUE : FALSE)); + + // Success - Alert WHMCS + return 'success'; + } + else + { + // Failed - Alert WHMCS of the returned Enterprise Server error code + return websitepanel_GetErrorMessage($result); + } + } + catch (Exception $e) + { + return $e->getMessage(); + } +} + +/** + * websitepanel_TerminateAccount() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_TerminateAccount($params) +{ + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + // WHMCS server parameters & package parameters + $username = $params['username']; + + try + { + // 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 "The specified user {$username} does not exist"; + } + else + { + // Attempt to delete the users account and package / hosting space + $result = $wsp->delete_user($user['UserId']); + if ($result >= 0) + { + // Success - Alert WHMCS + return 'success'; + } + else + { + // Failed - Alert WHMCS of the returned Enterprise Server error code + return websitepanel_GetErrorMessage($result); + } + } + } + catch (Exception $e) + { + return $e->getMessage(); + } +} + +/** + * websitepanel_SuspendAccount() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_SuspendAccount($params) +{ + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + // WHMCS server parameters & package parameters + $username = $params['username']; + + try + { + // 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 "The specified user {$username} does not exist"; + } + else + { + // Attempt to suspend the users account and package / hosting space + $result = $wsp->change_user_status($user['UserId'], WebsitePanel::USERSTATUS_SUSPENDED); + if ($result >= 0) + { + // Success - Alert WHMCS + return 'success'; + } + else + { + // Failed - Alert WHMCS of the returned Enterprise Server error code + return websitepanel_GetErrorMessage($result); + } + } + } + catch (Exception $e) + { + return $e->getMessage(); + } +} + +/** + * websitepanel_UnsuspendAccount() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_UnsuspendAccount($params) +{ + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + // WHMCS server parameters & package parameters + $username = $params['username']; + + try + { + // 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 "The specified user {$username} does not exist"; + } + else + { + // Attempt to activate the users account and package / hosting space + $result = $wsp->change_user_status($user['UserId'], WebsitePanel::USERSTATUS_ACTIVE); + if ($result >= 0) + { + // Success - Alert WHMCS + return 'success'; + } + else + { + // Failed - Alert WHMCS of the returned Enterprise Server error code + return websitepanel_GetErrorMessage($result); + } + } + } + catch (Exception $e) + { + return $e->getMessage(); + } +} + +/** + * websitepanel_ChangePassword() + * + * @access public + * @param array $params + * @return int + */ +function websitepanel_ChangePassword($params) +{ + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + // WHMCS server parameters & package parameters + $username = $params['username']; + $password = $params['password']; + + try + { + // 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 "The specified user {$username} does not exist"; + } + else + { + // Attempt to change the user's account password + $result = $wsp->change_user_password($user['UserId'], $password); + if ($result >= 0) + { + // Success - Alert WHMCS + return 'success'; + } + else + { + // Failed - Alert WHMCS of the returned Enterprise Server error code + return websitepanel_GetErrorMessage($result); + } + } + } + catch (Exception $e) + { + return $e->getMessage(); + } +} + +/** + * websitepanel_ChangePackage() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_ChangePackage($params) +{ + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $params['serverip'], $params['configoption6'], $params['serversecure']); + + // WHMCS server parameters & package parameters + $username = $params['username']; + + // WebsitePanel API parameters + $planId = $params['configoption4']; + $packageName = $params['configoption1']; + + try + { + // 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 "The specified user {$username} does not exist"; + } + else + { + // Get the user's current WebsitePanel hosting space Id (Hosting Plan) + $package = $wsp->get_user_packages($user['UserId']); + $packageId = $package['PackageId']; + + // Update the user's package + $result = $wsp->update_package_literal($packageId, $package['StatusId'], $planId, $package['PurchaseDate'], $packageName, ''); + $result = $result['Result']; + if ($result >= 0) + { + // Success - Alert WHMCS + return 'success'; + } + else + { + // Failed - Alert WHMCS of the returned Enterprise Server error code + return websitepanel_GetErrorMessage($result); + } + } + } + catch (Exception $e) + { + return $e->getMessage(); + } +} + +/** + * websitepanel_LoginLink() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_LoginLink($params) +{ + echo "Login to Control Panel (One-Click Login)"; +} + +/** + * websitepanel_ClientArea() + * + * @access public + * @param array $params + * @return string + */ +function websitepanel_ClientArea($params) +{ + return "Login to Control Panel (One-Click Login)"; +} + +/** + * websitepanel_UsageUpdate() + * + * @access public + * @param array $params + * @return void + */ +function websitepanel_UsageUpdate($params) +{ + // WHMCS server parameters & package parameters + $serverid = $params['serverid']; + $serverip = $params['serverip']; + + // Query for all active or suspended users under the specified server + $query = full_query("SELECT `username`, `packageid`, `regdate` FROM `tblhosting` WHERE `server` = {$serverid} AND `domainstatus` IN ('Active', 'Suspended') AND `username` <> ''"); + while (($row = mysql_fetch_array($query)) != false) + { + try + { + // Start processing the specified users usage + $username = $row['username']; + $packageId = $row['packageid']; + + // Get the packages ConfigOptions + $packageQuery = select_query('tblproducts', 'configoption2,configoption3,configoption6,configoption16', array('id' => $packageId, 'configoption16' => 'on')); + $cfgOptions = mysql_fetch_array($packageQuery); + $params['configoption6'] = $cfgOptions['configoption6']; + + // Diskspace and Bandwidth limits for this package + $diskLimit = $cfgOptions['configoption2']; + $bwidthLimit = $cfgOptions['configoption3']; + + // Create the WebsitePanel object instance + $wsp = new WebsitePanel($params['serverusername'], $params['serverpassword'], $serverip, $params['configoption6'], $params['serversecure']); + + // Get the specified user details + // Get the Package id of the user's package + $user = $wsp->get_user_by_username($username); + $package = $wsp->get_user_packages($user['UserId']); + + // Gather the bandwidth / diskspace usage stats + $bandwidthUsage = websitepanel_CalculateBandwidthUsage($params, $package['PackageId'], websitepanel_CreateBandwidthDate($row['regdate'])); + $diskSpaceUsage = websitepanel_CalculateDiskspaceUsage($params, $package['PackageId']); + + // Update the package details + update_query('tblhosting', array('diskusage' => $diskSpaceUsage, 'disklimit' => $diskLimit, 'bwusage' => $bandwidthUsage, 'bwlimit' => $bwidthLimit, 'lastupdate' => date('Y-m-d H:i:s')), array('username' => $username, 'server' => $serverid)); + } + catch (Exception $e) + { + // Nothing + } + } +} \ No newline at end of file