Storage-as-a-Service Integration Guide
- Introduction
- Integration via Command-Line Interface (CLI)
- Integration via REST API
- Integration with WHMCS
Summary of content (76 pages)
PAGE 40
4.1. Requirements
PAGE 41
Chapter 4. Integration with WHMCS
Object Name |
’ . $s3_object . ’ |
PAGE 42
4.1. Requirements
Type | Name | Value | |||||||
’ . $s3_type . ’ | ’ . $s3_limit . ’ | ’ . $s3_value . ’ |
Type | Name | Value | |||||||
’ . $s3_type .PAGE 444.1. Requirements ’; // Show statistics for object. if (!empty($_SESSION[’s3_object_statistic’])) { // Table header. $result = $result . ’ S3 Statistics for Object: ’ . $_SESSION[’s3_object’] . PAGE 45Chapter 4. Integration with WHMCS ’ . $_SESSION[’s3_object_statistic’][’fmt_version’]. ’ | ’ . $_SESSION[’s3_object_statistic’][’service_id’]. ’ | ’ . $_SESSION[’s3_object_statistic’][’start_ts’]. ’ | ’ . $_SESSION[’s3_object_statistic’][’period’]. ’ | ’ . $s3_object[’key’][’bucket’] . ’ | ’ . $s3_object[’key’][’epoch’] . ’ | ’ . $s3_object[’key’][’user’] . ’ | ’ . $s3_object[’key’][’tag’] . ’ | ’ . | PAGE 464.1. Requirements // Modify admin area. add_hook(’AdminAreaClientSummaryPage’, 1, ”S3_adminAreaClientSummaryPage”); ?> 4.1.4 Statistics You need to have statistics collection enabled on your S3 gateway. The S3 gateway will save the statistics as regular storage objects. On each S3 storage node, create a file /var/lib/ostor/local/gw.conf with the following contents: # Enable usage statistics collection. S3_GW_COLLECT_STAT=1 Restart the S3 storage service to apply the configuration changes. PAGE 47Chapter 4. Integration with WHMCS 4.2 Managing S3 Users in WHMCS This section describes how to manage users in WHMCS in a service provider scenario. New customers will sign up for the service during purchase in your online store and you will need to create users for them in the S3 cluster. Create all files mentioned further in the directory whmcs/admin/AcronisStorage. 4.2.1 Creating S3 Users You can create a user with the ostor-users service and parameter emailAddress specifying the user email address. PAGE 484.2. Managing S3 Users in WHMCS $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-users&emailAddress=” . $s3_whmcs[’email’], ”PUT” ); // Add note with the s3 access key and s3 secret. S3_addClientNote( $s3_whmcs[’userid’], $s3_config[’whmcs_username’], $s3_client[’UserId’], $s3_client[’AWSAccessKeys’][’0’][’AWSAccessKeyId’], $s3_client[’AWSAccessKeys’][’0’][’AWSSecretAccessKey’] ); // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. PAGE 49Chapter 4. Integration with WHMCS 4.2.2 Listing S3 Users You can list information about all users with the ostor-users service. Additional rows may list S3 access key pairs associated with the user. WHMCS lists the users information fetched from S3 cluster when you click List Users (on/off). Create a file S3_listUsers.php with the following contents: PAGE 504.2. Managing S3 Users in WHMCS // Hide. $_SESSION[’s3_list_users’] = 0; // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); // Return immediately. return; } // Load configuration. $s3_config = s3_getConfig(); // Get s3 users. $s3_client = S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-users”, ”GET” ); // Store s3 result. $_SESSION[’s3_list_users’] = 1; $_SESSION[’s3_list’] = $s3_client; // Redirect back. header(’Location: ’ . PAGE 51Chapter 4. Integration with WHMCS 4.2.3 Querying S3 Users You can display information and status of a user with the ostor-users service and parameter emailAddress specifying the user email address. WHMCS displays the user information fetched from S3 cluster when you click Query User (on/off). Create a file S3_queryUser.php with the following contents: PAGE 524.2. Managing S3 Users in WHMCS if ($_SESSION[’s3_query_user’] == 1) { // Hide. $_SESSION[’s3_query_user’] = 0; // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); // Return immediately. return; } // Load configuration. $s3_config = s3_getConfig(); // Get whmcs user email. $s3_whmcs = S3_getClient($userid, $s3_config[’whmcs_username’]); // Get s3 user id. $s3_client = S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-users&emailAddress=” . PAGE 53Chapter 4. Integration with WHMCS // Call function. S3_queryUser($_GET[’userid’]); ?> 4.2.4 Disabling S3 Users You can disable users with the ostor-users service and parameter emailAddress specifying the user email address. WHMCS disables read and write access to S3 cluster when you click Disable User. Create a file S3_disableUser.php with the following contents: PAGE 544.2. Managing S3 Users in WHMCS // Disable user. function S3_disableUser($userid) { // Load configuration. $s3_config = s3_getConfig(); // Get whmcs user email. $s3_whmcs = S3_getClient($userid, $s3_config[’whmcs_username’]); // Disable user. $s3_client = S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-users&emailAddress=” . $s3_whmcs[’email’] . ”&disable”, ”POST” ); // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. PAGE 55Chapter 4. Integration with WHMCS PAGE 564.2. Managing S3 Users in WHMCS 4.2.6 Deleting S3 Users You can delete users with the ostor-users service and parameter emailAddress specifying the user email address. WHMCS removes the user from S3 cluster when you click Delete User. Create a file S3_deleteUser.php with the following contents: PAGE 57Chapter 4. Integration with WHMCS $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-users&emailAddress=” . $s3_whmcs[’email’], ”DELETE” ); // Delete note with the s3 access key and s3 secret. S3_delClientNote( $s3_whmcs[’userid’], $s3_config[’whmcs_username’], $s3_client[’UserId’], ”” ); // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. S3_deleteUser($_GET[’userid’]); ?> 4.2. PAGE 584.2. Managing S3 Users in WHMCS require(’../../includes/AcronisStorage/S3_getConfig.php’); require(’../../includes/AcronisStorage/S3_requestCurl.php’); require(’../../init.php’); // Generate s3 access key pair. function S3_generateAccessKey($userid) { // Load configuration. $s3_config = s3_getConfig(); // Get whmcs user email. $s3_whmcs = S3_getClient($userid, $s3_config[’whmcs_username’]); // Generate s3 key pair. PAGE 59Chapter 4. Integration with WHMCS // Call function. S3_generateAccessKey($_GET[’userid’]); ?> 4.2.8 Revoking S3 Access Keys You can revoke the specified access key pair of the specified user with the ostor-users service and the following parameters: emailAddress specifying the user email address, revokeKey specifying the access key in the key pair. WHMCS removes the key pair when you click Revoke Access Key. Create a file following contents: PAGE 604.2. Managing S3 Users in WHMCS require(’../../init.php’); // Revoke s3 access key pair. function S3_revokeAccessKey($userid) { // Load configuration. $s3_config = s3_getConfig(); // Get whmcs user email. $s3_whmcs = S3_getClient($userid, $s3_config[’whmcs_username’]); // Get first s3 access key. $s3_client = S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-users&emailAddress=” . $s3_whmcs[’email’], ”GET” ); // Revoke s3 access key. PAGE 61Chapter 4. Integration with WHMCS $s3_client[’AWSAccessKeys’][’0’][’AWSAccessKeyId’] ); // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. S3_revokeAccessKey($_GET[’userid’]); ?> 4.3 Managing S3 User and Bucket Limits in WHMCS This section describes limits you can define for users and buckets in WHMCS. You can apply the limits according to specific options that can be a part of your service plan. 4.3. PAGE 624.3. Managing S3 User and Bucket Limits in WHMCS // Set s3 user limits. function S3_setLimitsForUser($vars) { // Load configuration. $s3_config = s3_getConfig(); // Get whmcs user email. $s3_whmcs = S3_getClient($vars[’userid’], $s3_config[’whmcs_username’]); // Set only if value specified. if (!empty($vars[’ops-value’])) { // Set s3 bucket limits (ops). S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-limits&emailAddress=” . $s3_whmcs[’email’] . PAGE 63Chapter 4. Integration with WHMCS ’&limit-value=’ . $vars[’bandwidth-value’], ”PUT” ); } // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. S3_setLimitsForUser($_GET); ?> 4.3.2 Querying User Limits You can display the current limits with the ostor-limits service and parameter emailAddress specifying the email address. WHMCS displays the user limits in S3 cluster when you click the Get button. Create a file S3_getLimitsForUser. PAGE 644.3. Managing S3 User and Bucket Limits in WHMCS PAGE 65Chapter 4. Integration with WHMCS ?> 4.3.3 Deleting User Limits You can delete the current limits with the ostor-limits service and parameter emailAddress specifying the email address. WHMCS removes the user limits from S3 cluster when you click the Delete button. Create a file S3_deleteLimitsForUser.php with the following contents: PAGE 664.3. Managing S3 User and Bucket Limits in WHMCS // Clear array. $_SESSION[’s3_limits_user’] = null; // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. S3_getLimitsForUser($_GET[’userid’]); ?> 4.3.4 Setting Buckets Limits You can limit operations rate with the ostor-limits service and the following parameters: bucket specifying the bucket name, default=, get=, put=, list=, delete= specifying the limit value. PAGE 67Chapter 4. Integration with WHMCS if (!empty($vars[’ops-value’])) { // Set s3 bucket limits (ops). S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-limits&bucket=” . $vars[’bucket’] . ”&limit-type=ops&limit-resource=” . $vars[’ops-name’] . ’&limit-value=’ . $vars[’ops-value’], ”PUT” ); } // Set only if value specified. if (!empty($vars[’bandwidth-value’])) { // Set s3 bucket limits (bandwidth). PAGE 684.3. Managing S3 User and Bucket Limits in WHMCS ?> 4.3.5 Querying Bucket Limits You can display the current limits with the name. ostor-limits service and parameter bucket specifying the bucket WHMCS displays the bucket limits in S3 cluster when you click the Get button. S3_getLimitsForBucket.php Create a file with the following contents: PAGE 69Chapter 4. Integration with WHMCS // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. S3_getLimitsForBucket($_GET[’bucket’]); ?> 4.3.6 Deleting Bucket Limits You can delete the current limits with the ostor-limits service and parameter bucket specifying the bucket name. WHMCS removes the bucket limits from S3 cluster when you click the Delete button. Create a file S3_deleteLimitsForBucket.php with the following contents: PAGE 704.4. Obtaining Usage Statistics in WHMCS require(’../../includes/AcronisStorage/S3_requestCurl.php’); require(’../../init.php’); // Delete s3 bucket limits. function S3_deleteLimitsForBucket($bucket) { // Load configuration. $s3_config = s3_getConfig(); // Delete s3 bucket limits. S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-limits&bucket=” . $bucket, ”DELETE” ); // Clear array. $_SESSION[’s3_limits_bucket’] = null; // Redirect back. PAGE 71Chapter 4. Integration with WHMCS Note: Delete statistics objects after collecting the required data. 4.4.1 Listing Statistics Objects You can list all available statistics objects with the ostor-usage service and no parameters. IThe output only contains objects that have not been deleted. WHMCS lists the available statistics objects from S3 cluster when you click List statistics objects (on/off). Create a file S3_listStatsObjects. PAGE 724.4. Obtaining Usage Statistics in WHMCS // Get s3 statistics objects. $s3_client = S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-usage”, ”GET” ); // Store s3 result. $_SESSION[’s3_stat_objects’] = 1; $_SESSION[’s3_stat’] = $s3_client; // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. PAGE 73Chapter 4. Integration with WHMCS 4.4.2 Querying Statistics Objects You can display usage statistics with the ostor-usage service and parameter obj specifying the statistics object. WHMCS displays the accessed buckets, user ID, and counters when you click the Get button. Create a file S3_getStatsForObject.php with the following contents: PAGE 744.4. Obtaining Usage Statistics in WHMCS // Get s3 statistics object. $s3_client = S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-usage&obj=” . $object, ”GET” ); // Store s3 result. $_SESSION[’s3_object_statistic’] = $s3_client; $_SESSION[’s3_object’] = $object; // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. PAGE 75Chapter 4. Integration with WHMCS 4.4.3 Deleting Statistics Objects You can delete existing statistics objects with the ostor-usage service and parameter obj specifying the statistics object. WHMCS removes the statistics object from S3 cluster when you click the Delete button. Create a file S3_deleteStatsForObject.php with the following contents: PAGE 764.4. Obtaining Usage Statistics in WHMCS // Delete s3 statistics object. S3_requestCurl( $s3_config[’s3_key’], $s3_config[’s3_secret’], $s3_config[’s3_gateway’], ”/?ostor-usage&obj=” . $object, ”DELETE” ); // Clear array. $_SESSION[’s3_limits_bucket’] = null; // Redirect back. header(’Location: ’ . $_SERVER[’HTTP_REFERER’]); } // Call function. |