Ejemplo n.º 1
0
 /**
  * Builds and handles the Download Options page.
  *
  * @package s2Member\Menu_Pages
  * @since 3.5
  */
 public static function down_ops_page()
 {
     do_action('ws_plugin__s2member_before_down_ops_page', get_defined_vars());
     c_ws_plugin__s2member_menu_pages::update_all_options();
     if (!empty($_REQUEST['ws_plugin__s2member_cf_options_reset']) && wp_verify_nonce($_REQUEST['ws_plugin__s2member_cf_options_reset'], 'ws-plugin--s2member-cf-options-reset')) {
         c_ws_plugin__s2member_files_in::reset_aws_cf_config_values();
         // A full CloudFront reset.
         c_ws_plugin__s2member_admin_notices::display_admin_notice('Amazon CloudFront configuration reset successfully.');
     }
     $files_dir = $GLOBALS['WS_PLUGIN__']['s2member']['c']['files_dir'];
     $htaccess = $GLOBALS['WS_PLUGIN__']['s2member']['c']['files_dir'] . '/.htaccess';
     $htaccess_contents = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents($GLOBALS['WS_PLUGIN__']['s2member']['c']['files_dir_htaccess'])));
     $no_gzip_htaccess = ABSPATH . '.htaccess';
     // Always located in the absolute root path for WordPress.
     $no_gzip_htaccess_contents = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents($GLOBALS['WS_PLUGIN__']['s2member']['c']['files_no_gzip_htaccess'])));
     if (!c_ws_plugin__s2member_files::no_gzip_rules_in_root_htaccess()) {
         // If s2Member's GZIP exclusions do NOT yet exist in the root `.htaccess` file.
         c_ws_plugin__s2member_files::write_no_gzip_into_root_htaccess() . clearstatcache();
     }
     // Handle the root `.htaccess` file now.
     if (!is_dir($files_dir) && is_writable(dirname(c_ws_plugin__s2member_utils_dirs::strip_dir_app_data($files_dir)))) {
         mkdir($files_dir, 0777, TRUE) . clearstatcache();
     }
     // Create this directory structure now.
     if (is_dir($files_dir) && is_writable($files_dir) && !file_exists($htaccess)) {
         // This file does NOT exist yet?
         file_put_contents($htaccess, $htaccess_contents) . clearstatcache();
     }
     // Create the `.htaccess` file now.
     if (!c_ws_plugin__s2member_files::no_gzip_rules_in_root_htaccess()) {
         // If s2Member's GZIP exclusions do NOT yet exist in the root `.htaccess` file.
         c_ws_plugin__s2member_admin_notices::display_admin_notice('Possible GZIP conflict on server. Unable to write GZIP exclusions into root .htaccess file (<code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($no_gzip_htaccess)) . '</code>). Please read the panel below: <strong>Preventing GZIP Conflicts</strong>, and add this section yourself:<br /><pre>' . esc_html($no_gzip_htaccess_contents) . '</pre>', TRUE);
     }
     if (!is_dir($files_dir)) {
         // If the security-enabled files directory does not exist yet.
         c_ws_plugin__s2member_admin_notices::display_admin_notice('The security-enabled files directory (<code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($files_dir)) . '</code>) does not exist. Please create this directory manually.', TRUE);
     }
     if (!file_exists($htaccess)) {
         // If the `.htaccess` file has not been created yet.
         c_ws_plugin__s2member_admin_notices::display_admin_notice('The .htaccess protection file (<code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($htaccess)) . '</code>) does not exist. Please create this file manually. Inside your .htaccess file, add this:<br /><pre>' . esc_html($htaccess_contents) . '</pre>', TRUE);
     } else {
         if (!preg_match('/deny from all/i', file_get_contents($htaccess))) {
             // Else if the `.htaccess` file does not offer the required protection.
             c_ws_plugin__s2member_admin_notices::display_admin_notice('Unprotected. The .htaccess protection file (<code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($htaccess)) . '</code>) does not contain <code>deny from all</code>. Inside your .htaccess file, add this:<br /><pre>' . esc_html($htaccess_contents) . '</pre>', TRUE);
         }
     }
     if (!empty($_POST['ws_plugin__s2member_amazon_cf_files_auto_configure_distros']) && ($nonce = $_POST['ws_plugin__s2member_amazon_cf_files_auto_configure_distros']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-amazon-cf-files-auto-configure-distros')) {
         if (($amazon_cf_auto_configure_distros = c_ws_plugin__s2member_files_in::amazon_cf_auto_configure_distros()) && $amazon_cf_auto_configure_distros['success']) {
             c_ws_plugin__s2member_admin_notices::display_admin_notice('Amazon CloudFront Distributions auto-configured successfully. Please allow 30 minutes for initial propagation. <strong>Tip:</strong> If you try to stream over the RTMP protocol using something like the <code>[s2Stream /]</code> shortcode, and you keep getting an "ID Not Found" error while using JW Player; please note that it can <em>sometimes</em> take a full 24 hours for RTMP (i.e., streaming distributions) to begin working properly. This is because there are a few initialization routines that must complete on the AWS side when you first integrate with CloudFront. Please be patient.' . ($GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_cf_files_distro_downloads_cname'] ? '<br /><em>Downloads Distribution CNAME: <code>' . esc_html($GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_cf_files_distro_downloads_cname']) . ' &mdash;&raquo; ' . esc_html($GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_cf_files_distro_downloads_dname']) . '</code></em>' : '') . ($GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_cf_files_distro_streaming_cname'] ? '<br /><em>Streaming Distribution CNAME: <code>' . esc_html($GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_cf_files_distro_streaming_cname']) . ' &mdash;&raquo; ' . esc_html($GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_cf_files_distro_streaming_dname']) . '</code></em>' : ''));
         } else {
             // Else there was an error. We need to report this back to the site owner so they can understand what's going on.
             (c_ws_plugin__s2member_menu_pages::$pre_display_errors['cf_files_auto_configure_distros'] = TRUE) . c_ws_plugin__s2member_admin_notices::display_admin_notice('Unable to auto-configure Amazon CloudFront Distributions.<br />Error code: <code>' . esc_html($amazon_cf_auto_configure_distros['code']) . '</code>. Error Message: <code>' . esc_html($amazon_cf_auto_configure_distros['message']) . '</code>', TRUE);
         }
     }
     if (!empty($_POST['ws_plugin__s2member_amazon_s3_files_auto_configure_acls']) && ($nonce = $_POST['ws_plugin__s2member_amazon_s3_files_auto_configure_acls']) && wp_verify_nonce($nonce, 'ws-plugin--s2member-amazon-s3-files-auto-configure-acls')) {
         if (($amazon_s3_auto_configure_acls = c_ws_plugin__s2member_files_in::amazon_s3_auto_configure_acls()) && $amazon_s3_auto_configure_acls['success']) {
             c_ws_plugin__s2member_admin_notices::display_admin_notice('Amazon S3 ACLs auto-configured successfully.');
         } else {
             // Else there was an error. We need to report this back to the site owner so they can understand what's going on.
             (c_ws_plugin__s2member_menu_pages::$pre_display_errors['s3_files_auto_configure_acls'] = TRUE) . c_ws_plugin__s2member_admin_notices::display_admin_notice('Unable to auto-configure Amazon S3 ACLs.<br />Error code: <code>' . esc_html($amazon_s3_auto_configure_acls['code']) . '</code>. Error Message: <code>' . esc_html($amazon_s3_auto_configure_acls['message']) . '</code>', TRUE);
         }
     }
     include_once dirname(dirname(__FILE__)) . '/menu-pages/down-ops.inc.php';
     do_action('ws_plugin__s2member_after_down_ops_page', get_defined_vars());
 }
Ejemplo n.º 2
0
 /**
  * Auto-configures Amazon CloudFront distros.
  *
  * @package s2Member\Files
  * @since 130209
  *
  * @return bool|array True on success, else array on failure.
  *   Failure array will contain a failure `code`, and a failure `message`.
  */
 public static function amazon_cf_auto_configure_distros()
 {
     return c_ws_plugin__s2member_files_in::amazon_cf_auto_configure_distros();
 }
 /**
  * Builds and handles the Download Options page.
  * 
  * @package s2Member\Menu_Pages
  * @since 3.5
  * 
  * @return null
  */
 public static function down_ops_page()
 {
     do_action("ws_plugin__s2member_before_down_ops_page", get_defined_vars());
     /**/
     c_ws_plugin__s2member_menu_pages::update_all_options();
     /**/
     $files_dir = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"];
     /**/
     if (!is_dir($files_dir) && is_writable(dirname(c_ws_plugin__s2member_utils_dirs::strip_dir_app_data($files_dir)))) {
         mkdir($files_dir, 0777, true) . clearstatcache();
     }
     /**/
     $htaccess = $GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir"] . "/.htaccess";
     $htaccess_contents = trim(c_ws_plugin__s2member_utilities::evl(file_get_contents($GLOBALS["WS_PLUGIN__"]["s2member"]["c"]["files_dir_htaccess"])));
     /**/
     if (is_dir($files_dir) && is_writable($files_dir) && !file_exists($htaccess)) {
         file_put_contents($htaccess, $htaccess_contents) . clearstatcache();
     }
     /**/
     if (!is_dir($files_dir)) {
         /* If the security-enabled files directory does not exist yet. */
         c_ws_plugin__s2member_admin_notices::display_admin_notice('The security-enabled files directory ( <code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($files_dir)) . '</code> ) does not exist. Please create this directory manually.', true);
     }
     /**/
     if (!file_exists($htaccess)) {
         /* If the .htaccess file has not been created yet. */
         c_ws_plugin__s2member_admin_notices::display_admin_notice('The .htaccess protection file ( <code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($htaccess)) . '</code> ) does not exist. Please create this file manually. Inside your .htaccess file, add this:<br /><pre>' . esc_html($htaccess_contents) . '</pre>', true);
     } else {
         if (!preg_match("/deny from all/i", file_get_contents($htaccess))) {
             /* Else if the .htaccess file does not offer the required protection. */
             c_ws_plugin__s2member_admin_notices::display_admin_notice('Unprotected. The .htaccess protection file ( <code>' . esc_html(c_ws_plugin__s2member_utils_dirs::doc_root_path($htaccess)) . '</code> ) does not contain <code>deny from all</code>. Inside your .htaccess file, add this:<br /><pre>' . esc_html($htaccess_contents) . '</pre>', true);
         }
     }
     /**/
     if (!empty($_POST["ws_plugin__s2member_amazon_cf_files_auto_configure_distros"]) && ($nonce = $_POST["ws_plugin__s2member_amazon_cf_files_auto_configure_distros"]) && wp_verify_nonce($nonce, "ws-plugin--s2member-amazon-cf-files-auto-configure-distros")) {
         if (($amazon_cf_auto_configure_distros = c_ws_plugin__s2member_files_in::amazon_cf_auto_configure_distros()) && $amazon_cf_auto_configure_distros["success"]) {
             c_ws_plugin__s2member_admin_notices::display_admin_notice('Amazon® CloudFront Distributions auto-configured successfully. Please allow 30 minutes for propagation.' . ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distro_downloads_cname"] ? '<br /><em>Downloads Distribution CNAME: <code>' . esc_html($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distro_downloads_cname"]) . ' &mdash;&raquo; ' . esc_html($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distro_downloads_dname"]) . '</code></em>' : '') . ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distro_streaming_cname"] ? '<br /><em>Streaming Distribution CNAME: <code>' . esc_html($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distro_streaming_cname"]) . ' &mdash;&raquo; ' . esc_html($GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_cf_files_distro_streaming_dname"]) . '</code></em>' : ''));
         } else {
             /* Else there was an error. We need to report this back to the site owner so they can understand what's going on. */
             (c_ws_plugin__s2member_menu_pages::$pre_display_errors["cf_files_auto_configure_distros"] = true) . c_ws_plugin__s2member_admin_notices::display_admin_notice('Unable to auto-configure Amazon® CloudFront Distributions.<br />Error code: <code>' . esc_html($amazon_cf_auto_configure_distros["code"]) . '</code>. Error Message: <code>' . esc_html($amazon_cf_auto_configure_distros["message"]) . '</code>', true);
         }
     }
     /**/
     if (!empty($_POST["ws_plugin__s2member_amazon_s3_files_auto_configure_acls"]) && ($nonce = $_POST["ws_plugin__s2member_amazon_s3_files_auto_configure_acls"]) && wp_verify_nonce($nonce, "ws-plugin--s2member-amazon-s3-files-auto-configure-acls")) {
         if (($amazon_s3_auto_configure_acls = c_ws_plugin__s2member_files_in::amazon_s3_auto_configure_acls()) && $amazon_s3_auto_configure_acls["success"]) {
             c_ws_plugin__s2member_admin_notices::display_admin_notice('Amazon® S3 ACLs auto-configured successfully.');
         } else {
             /* Else there was an error. We need to report this back to the site owner so they can understand what's going on. */
             (c_ws_plugin__s2member_menu_pages::$pre_display_errors["s3_files_auto_configure_acls"] = true) . c_ws_plugin__s2member_admin_notices::display_admin_notice('Unable to auto-configure Amazon® S3 ACLs.<br />Error code: <code>' . esc_html($amazon_s3_auto_configure_acls["code"]) . '</code>. Error Message: <code>' . esc_html($amazon_s3_auto_configure_acls["message"]) . '</code>', true);
         }
     }
     /**/
     include_once dirname(dirname(__FILE__)) . "/menu-pages/down-ops.inc.php";
     /**/
     do_action("ws_plugin__s2member_after_down_ops_page", get_defined_vars());
     /**/
     return;
     /* Return for uniformity. */
 }
Ejemplo n.º 4
0
 /**
  * Creates an Amazon S3/CloudFront Distro.
  *
  * @package s2Member\Files
  * @since 110926
  *
  * @param string $distro_type Required: `downloads|streaming`.
  *
  * @return array Array containing a true `success` and `distro_[distro_type]_id`, `distro_[distro_type]_dname` elements on success, else a failure array.
  *   Failure array will contain a failure `code`, and a failure `message`.
  */
 public static function amazon_cf_create_distro($distro_type = '')
 {
     if ($distro_type && is_string($distro_type) && in_array($distro_type, array('downloads', 'streaming'))) {
         foreach ($GLOBALS['WS_PLUGIN__']['s2member']['o'] as $option => $option_value) {
             if (preg_match('/^amazon_cf_files_/', $option) && ($option = preg_replace('/^amazon_cf_files_/', '', $option))) {
                 $cfc[$option] = $option_value;
             }
         }
         $s3c['bucket'] = $GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_s3_files_bucket'];
         $cfc['access_key'] = $s3c['access_key'] = $GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_s3_files_access_key'];
         $cfc['secret_key'] = $s3c['secret_key'] = $GLOBALS['WS_PLUGIN__']['s2member']['o']['amazon_s3_files_secret_key'];
         $cf_domain = 'cloudfront.amazonaws.com';
         $cf_date = gmdate('D, d M Y H:i:s') . ' GMT';
         $cf_signature = base64_encode(c_ws_plugin__s2member_files_in::amazon_cf_sign($cf_date));
         if ($distro_type === 'downloads') {
             $cf_location = '/2010-11-01/distribution';
             // Create distro.
             $cf_distro_downloads_reference = time() . '.' . md5('downloads' . $s3c['bucket'] . $s3c['access_key'] . $s3c['secret_key'] . $cfc['private_key'] . $cfc['private_key_id'] . $cfc['distro_downloads_cname']);
             $cf_distro_downloads_xml = '<?xml version="1.0" encoding="UTF-8"?><DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"><S3Origin><DNSName>' . esc_html($s3c['bucket']) . '.s3.amazonaws.com</DNSName><OriginAccessIdentity>origin-access-identity/cloudfront/' . esc_html($cfc['distros_access_id']) . '</OriginAccessIdentity></S3Origin><CallerReference>' . esc_html($cf_distro_downloads_reference) . '</CallerReference>' . ($cfc['distro_downloads_cname'] ? '<CNAME>' . esc_html($cfc['distro_downloads_cname']) . '</CNAME>' : '') . '<Comment>' . esc_html(sprintf(_x('Created by s2Member, for S3 Bucket: %s.', 's2member-admin', 's2member'), $s3c['bucket'])) . '</Comment><Enabled>true</Enabled><DefaultRootObject>index.html</DefaultRootObject><TrustedSigners><Self/></TrustedSigners></DistributionConfig>';
             $cf_args = array('method' => 'POST', 'redirection' => 5, 'body' => $cf_distro_downloads_xml, 'headers' => array('Host' => $cf_domain, 'Content-Type' => 'application/xml', 'Date' => $cf_date, 'Authorization' => 'AWS ' . $cfc['access_key'] . ':' . $cf_signature));
             if (($cf_response = c_ws_plugin__s2member_utils_urls::remote('https://' . $cf_domain . $cf_location, FALSE, array_merge($cf_args, array('timeout' => 20)), 'array')) && ($cf_response['code'] === 200 || $cf_response['code'] === 201)) {
                 if (preg_match('/\\<Distribution.*?\\>(.+?)\\<\\/Distribution\\>/is', $cf_response['body'], $cf_distro_downloads_tag) && preg_match('/\\<Id\\>(.+?)\\<\\/Id\\>/is', $cf_distro_downloads_tag[1], $cf_distro_downloads_id_tag) && preg_match('/\\<DomainName\\>(.+?)\\<\\/DomainName\\>/is', $cf_distro_downloads_tag[1], $cf_distro_downloads_dname_tag)) {
                     return array('success' => TRUE, 'code' => NULL, 'message' => NULL, 'distro_downloads_id' => trim($cf_distro_downloads_id_tag[1]), 'distro_downloads_dname' => trim($cf_distro_downloads_dname_tag[1]));
                 } else {
                     // Else, we use a default error code and message.
                     return array('success' => FALSE, 'code' => -97, 'message' => _x('Unable to create/read Amazon CloudFront Downloads Distro. Unexpected response.', 's2member-admin', 's2member'));
                 }
             } else {
                 if (isset($cf_response['code'], $cf_response['message'])) {
                     /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon CloudFront API call. Feel free to exclude `%s` if you like. */
                     return array('success' => FALSE, 'code' => $cf_response['code'], 'message' => sprintf(_x('Unable to create Amazon CloudFront Downloads Distro. %s', 's2member-admin', 's2member'), $cf_response['message']));
                 } else {
                     // Else, we use a default error code and message.
                     return array('success' => FALSE, 'code' => -98, 'message' => _x('Unable to create Amazon CloudFront Downloads Distro. Connection failed.', 's2member-admin', 's2member'));
                 }
             }
         } else {
             if ($distro_type === 'streaming') {
                 $cf_location = '/2010-11-01/streaming-distribution';
                 // Create streaming distro.
                 $cf_distro_streaming_reference = time() . '.' . md5('streaming' . $s3c['bucket'] . $s3c['access_key'] . $s3c['secret_key'] . $cfc['private_key'] . $cfc['private_key_id'] . $cfc['distro_streaming_cname']);
                 $cf_distro_streaming_xml = '<?xml version="1.0" encoding="UTF-8"?><StreamingDistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"><S3Origin><DNSName>' . esc_html($s3c['bucket']) . '.s3.amazonaws.com</DNSName><OriginAccessIdentity>origin-access-identity/cloudfront/' . esc_html($cfc['distros_access_id']) . '</OriginAccessIdentity></S3Origin><CallerReference>' . esc_html($cf_distro_streaming_reference) . '</CallerReference>' . ($cfc['distro_streaming_cname'] ? '<CNAME>' . esc_html($cfc['distro_streaming_cname']) . '</CNAME>' : '') . '<Comment>' . esc_html(sprintf(_x('Created by s2Member, for S3 Bucket: %s.', 's2member-admin', 's2member'), $s3c['bucket'])) . '</Comment><Enabled>true</Enabled><DefaultRootObject>index.html</DefaultRootObject><TrustedSigners><Self/></TrustedSigners></StreamingDistributionConfig>';
                 $cf_args = array('method' => 'POST', 'redirection' => 5, 'body' => $cf_distro_streaming_xml, 'headers' => array('Host' => $cf_domain, 'Content-Type' => 'application/xml', 'Date' => $cf_date, 'Authorization' => 'AWS ' . $cfc['access_key'] . ':' . $cf_signature));
                 if (($cf_response = c_ws_plugin__s2member_utils_urls::remote('https://' . $cf_domain . $cf_location, FALSE, array_merge($cf_args, array('timeout' => 20)), 'array')) && ($cf_response['code'] === 200 || $cf_response['code'] === 201)) {
                     if (preg_match('/\\<StreamingDistribution.*?\\>(.+?)\\<\\/StreamingDistribution\\>/is', $cf_response['body'], $cf_distro_streaming_tag) && preg_match('/\\<Id\\>(.+?)\\<\\/Id\\>/is', $cf_distro_streaming_tag[1], $cf_distro_streaming_id_tag) && preg_match('/\\<DomainName\\>(.+?)\\<\\/DomainName\\>/is', $cf_distro_streaming_tag[1], $cf_distro_streaming_dname_tag)) {
                         return array('success' => TRUE, 'code' => NULL, 'message' => NULL, 'distro_streaming_id' => trim($cf_distro_streaming_id_tag[1]), 'distro_streaming_dname' => trim($cf_distro_streaming_dname_tag[1]));
                     } else {
                         // Else, we use a default error code and message.
                         return array('success' => FALSE, 'code' => -97, 'message' => _x('Unable to create/read Amazon CloudFront Streaming Distro. Unexpected response.', 's2member-admin', 's2member'));
                     }
                 } else {
                     if (isset($cf_response['code'], $cf_response['message'])) {
                         /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon CloudFront API call. Feel free to exclude `%s` if you like. */
                         return array('success' => FALSE, 'code' => $cf_response['code'], 'message' => sprintf(_x('Unable to create Amazon CloudFront Streaming Distro. %s', 's2member-admin', 's2member'), $cf_response['message']));
                     } else {
                         // Else, we use a default error code and message.
                         return array('success' => FALSE, 'code' => -98, 'message' => _x('Unable to create Amazon CloudFront Streaming Distro. Connection failed.', 's2member-admin', 's2member'));
                     }
                 }
             }
         }
     }
     // Else, we use a default error code and message (default behavior).
     return array('success' => FALSE, 'code' => -99, 'message' => _x('Unable to create Amazon CloudFront Distro. Invalid Distro type.', 's2member-admin', 's2member'));
 }
Ejemplo n.º 5
0
 /**
  * Creates an Amazon S3/CloudFront Distro.
  *
  * @package s2Member\Files
  * @since 110926
  *
  * @param str $distro_type Required: `downloads|streaming`.
  * @return array Array containing a true `success` and `distro_[distro_type]_id`, `distro_[distro_type]_dname` elements on success, else a failure array.
  * 	Failure array will contain a failure `code`, and a failure `message`.
  */
 public static function amazon_cf_create_distro($distro_type = FALSE)
 {
     if ($distro_type && is_string($distro_type) && in_array($distro_type, array("downloads", "streaming"))) {
         foreach ($GLOBALS["WS_PLUGIN__"]["s2member"]["o"] as $option => $option_value) {
             if (preg_match("/^amazon_cf_files_/", $option) && ($option = preg_replace("/^amazon_cf_files_/", "", $option))) {
                 $cfc[$option] = $option_value;
             }
         }
         $s3c["bucket"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_bucket"];
         $cfc["access_key"] = $s3c["access_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_access_key"];
         $cfc["secret_key"] = $s3c["secret_key"] = $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["amazon_s3_files_secret_key"];
         $cf_domain = "cloudfront.amazonaws.com";
         $cf_date = gmdate("D, d M Y H:i:s") . " GMT";
         $cf_signature = base64_encode(c_ws_plugin__s2member_files_in::amazon_cf_sign($cf_date));
         if ($distro_type === "downloads") {
             $cf_location = "/2010-11-01/distribution";
             $cf_distro_downloads_reference = time() . "." . md5("downloads" . $s3c["bucket"] . $s3c["access_key"] . $s3c["secret_key"] . $cfc["private_key"] . $cfc["private_key_id"] . $cfc["distro_downloads_cname"]);
             $cf_distro_downloads_xml = '<?xml version="1.0" encoding="UTF-8"?><DistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"><S3Origin><DNSName>' . esc_html($s3c["bucket"]) . '.s3.amazonaws.com</DNSName><OriginAccessIdentity>origin-access-identity/cloudfront/' . esc_html($cfc["distros_access_id"]) . '</OriginAccessIdentity></S3Origin><CallerReference>' . esc_html($cf_distro_downloads_reference) . '</CallerReference>' . ($cfc["distro_downloads_cname"] ? '<CNAME>' . esc_html($cfc["distro_downloads_cname"]) . '</CNAME>' : '') . '<Comment>' . esc_html(sprintf(_x("Created by s2Member, for S3 Bucket: %s.", "s2member-admin", "s2member"), $s3c["bucket"])) . '</Comment><Enabled>true</Enabled><DefaultRootObject>index.html</DefaultRootObject><TrustedSigners><Self/></TrustedSigners></DistributionConfig>';
             $cf_args = array("method" => "POST", "redirection" => 0, "body" => $cf_distro_downloads_xml, "headers" => array("Host" => $cf_domain, "Content-Type" => "application/xml", "Date" => $cf_date, "Authorization" => "AWS " . $cfc["access_key"] . ":" . $cf_signature));
             if (($cf_response = c_ws_plugin__s2member_utils_urls::remote("https://" . $cf_domain . $cf_location, false, array_merge($cf_args, array("timeout" => 20)), "array")) && ($cf_response["code"] === 200 || $cf_response["code"] === 201)) {
                 if (preg_match("/\\<Distribution.*?\\>(.+?)\\<\\/Distribution\\>/is", $cf_response["body"], $cf_distro_downloads_tag) && preg_match("/\\<Id\\>(.+?)\\<\\/Id\\>/is", $cf_distro_downloads_tag[1], $cf_distro_downloads_id_tag) && preg_match("/\\<DomainName\\>(.+?)\\<\\/DomainName\\>/is", $cf_distro_downloads_tag[1], $cf_distro_downloads_dname_tag)) {
                     return array("success" => true, "code" => null, "message" => null, "distro_downloads_id" => trim($cf_distro_downloads_id_tag[1]), "distro_downloads_dname" => trim($cf_distro_downloads_dname_tag[1]));
                 } else {
                     // Else, we use a default error code and message.
                     return array("success" => false, "code" => -97, "message" => _x("Unable to create/read Amazon CloudFront Downloads Distro. Unexpected response.", "s2member-admin", "s2member"));
                 }
             } else {
                 if (isset($cf_response["code"], $cf_response["message"])) {
                     /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon CloudFront API call. Feel free to exclude `%s` if you like. */
                     return array("success" => false, "code" => $cf_response["code"], "message" => sprintf(_x("Unable to create Amazon CloudFront Downloads Distro. %s", "s2member-admin", "s2member"), $cf_response["message"]));
                 } else {
                     // Else, we use a default error code and message.
                     return array("success" => false, "code" => -98, "message" => _x("Unable to create Amazon CloudFront Downloads Distro. Connection failed.", "s2member-admin", "s2member"));
                 }
             }
         } else {
             if ($distro_type === "streaming") {
                 $cf_location = "/2010-11-01/streaming-distribution";
                 $cf_distro_streaming_reference = time() . "." . md5("streaming" . $s3c["bucket"] . $s3c["access_key"] . $s3c["secret_key"] . $cfc["private_key"] . $cfc["private_key_id"] . $cfc["distro_streaming_cname"]);
                 $cf_distro_streaming_xml = '<?xml version="1.0" encoding="UTF-8"?><StreamingDistributionConfig xmlns="http://cloudfront.amazonaws.com/doc/2010-11-01/"><S3Origin><DNSName>' . esc_html($s3c["bucket"]) . '.s3.amazonaws.com</DNSName><OriginAccessIdentity>origin-access-identity/cloudfront/' . esc_html($cfc["distros_access_id"]) . '</OriginAccessIdentity></S3Origin><CallerReference>' . esc_html($cf_distro_streaming_reference) . '</CallerReference>' . ($cfc["distro_streaming_cname"] ? '<CNAME>' . esc_html($cfc["distro_streaming_cname"]) . '</CNAME>' : '') . '<Comment>' . esc_html(sprintf(_x("Created by s2Member, for S3 Bucket: %s.", "s2member-admin", "s2member"), $s3c["bucket"])) . '</Comment><Enabled>true</Enabled><DefaultRootObject>index.html</DefaultRootObject><TrustedSigners><Self/></TrustedSigners></StreamingDistributionConfig>';
                 $cf_args = array("method" => "POST", "redirection" => 0, "body" => $cf_distro_streaming_xml, "headers" => array("Host" => $cf_domain, "Content-Type" => "application/xml", "Date" => $cf_date, "Authorization" => "AWS " . $cfc["access_key"] . ":" . $cf_signature));
                 if (($cf_response = c_ws_plugin__s2member_utils_urls::remote("https://" . $cf_domain . $cf_location, false, array_merge($cf_args, array("timeout" => 20)), "array")) && ($cf_response["code"] === 200 || $cf_response["code"] === 201)) {
                     if (preg_match("/\\<StreamingDistribution.*?\\>(.+?)\\<\\/StreamingDistribution\\>/is", $cf_response["body"], $cf_distro_streaming_tag) && preg_match("/\\<Id\\>(.+?)\\<\\/Id\\>/is", $cf_distro_streaming_tag[1], $cf_distro_streaming_id_tag) && preg_match("/\\<DomainName\\>(.+?)\\<\\/DomainName\\>/is", $cf_distro_streaming_tag[1], $cf_distro_streaming_dname_tag)) {
                         return array("success" => true, "code" => null, "message" => null, "distro_streaming_id" => trim($cf_distro_streaming_id_tag[1]), "distro_streaming_dname" => trim($cf_distro_streaming_dname_tag[1]));
                     } else {
                         // Else, we use a default error code and message.
                         return array("success" => false, "code" => -97, "message" => _x("Unable to create/read Amazon CloudFront Streaming Distro. Unexpected response.", "s2member-admin", "s2member"));
                     }
                 } else {
                     if (isset($cf_response["code"], $cf_response["message"])) {
                         /* translators: In this translation, `%s` may be filled with an English message, which comes from the Amazon CloudFront API call. Feel free to exclude `%s` if you like. */
                         return array("success" => false, "code" => $cf_response["code"], "message" => sprintf(_x("Unable to create Amazon CloudFront Streaming Distro. %s", "s2member-admin", "s2member"), $cf_response["message"]));
                     } else {
                         // Else, we use a default error code and message.
                         return array("success" => false, "code" => -98, "message" => _x("Unable to create Amazon CloudFront Streaming Distro. Connection failed.", "s2member-admin", "s2member"));
                     }
                 }
             }
         }
     } else {
         // Else, we use a default error code and message.
         return array("success" => false, "code" => -99, "message" => _x("Unable to create Amazon CloudFront Distro. Invalid Distro type.", "s2member-admin", "s2member"));
     }
 }