/** * Deletes an Amazon S3/CloudFront Distro. * * @package s2Member\Files * @since 110926 * * @param string $distro_id Required. A Distro ID. * @param string $distro_id_etag Required. A Distro ETag header. * @param string $distro_id_xml Required. A Distro's XML configuration. * * @return array Array containing a true `success` element on success, else a failure array. * Failure array will contain a failure `code`, and a failure `message`. */ public static function amazon_cf_del_distro($distro_id = '', $distro_id_etag = '', $distro_id_xml = '') { if ($distro_id && is_string($distro_id) && $distro_id_etag && is_string($distro_id_etag) && $distro_id_xml && is_string($distro_id_xml) && ($distro_id_type = stripos($distro_id_xml, '<StreamingDistribution') !== FALSE ? 'streaming' : (stripos($distro_id_xml, '<Distribution') !== FALSE ? 'downloads' : FALSE)) && preg_match('/\\<CallerReference\\>(.+?)\\<\\/CallerReference\\>/is', $distro_id_xml, $distro_id_reference_tag) && ($distro_id_reference = $distro_id_reference_tag[1])) { if (stripos($distro_id_xml, '<Status>Deployed</Status>') !== FALSE) { if (($cf_response = c_ws_plugin__s2member_files_in::amazon_cf_disable_distro($distro_id, $distro_id_etag, $distro_id_xml)) && $cf_response['success']) { if (($cf_response = c_ws_plugin__s2member_files_in::amazon_cf_get_distro($distro_id, $distro_id_type)) && $cf_response['success'] && $cf_response['deployed']) { 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)); $cf_location = $distro_id_type === 'streaming' ? '/2010-11-01/streaming-distribution/' . $distro_id : '/2010-11-01/distribution/' . $distro_id; $cf_args = array('method' => 'DELETE', 'redirection' => 5, 'headers' => array('Host' => $cf_domain, 'Date' => $cf_date, 'If-Match' => $cf_response['etag'], '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'] === 204)) { return array('success' => TRUE, 'code' => NULL, 'message' => NULL); } 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 delete existing Amazon CloudFront Distro. %s', 's2member-admin', 's2member'), $cf_response['message'])); } else { // Else, we use a default error code and message. return array('success' => FALSE, 'code' => -94, 'message' => _x('Unable to delete existing Amazon CloudFront Distro. Connection failed.', 's2member-admin', 's2member')); } } } else { if (isset($cf_response['success'], $cf_response['deployed']) && $cf_response['success'] && !$cf_response['deployed']) { /* 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' => -95, 'message' => _x('Existing Amazon CloudFront Distro cannot be deleted at this time. Still in a `pending` state after having been disabled by s2Member. Please wait 15 minutes, then try again. There is a certain process that s2Member must strictly adhere to when re-configuring your Amazon CloudFront Distros. You may have to tick the auto-configure checkbox again, and re-run s2Member\'s auto-configuration routine many times, because s2Member will likely run into several `pending` challenges, as it works to completely re-configure your Amazon CloudFront Distros for you. Thanks for your patience. Please wait 15 minutes, then try again.', '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 check status of existing Amazon CloudFront Distro. %s', 's2member-admin', 's2member'), $cf_response['message'])); } else { // Else, we use a default error code and message. return array('success' => FALSE, 'code' => -96, 'message' => _x('Unable to check status of existing Amazon CloudFront Distro. Connection failed.', '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 disable existing Amazon CloudFront Distro. %s', 's2member-admin', 's2member'), $cf_response['message'])); } else { // Else, we use a default error code and message. return array('success' => FALSE, 'code' => -97, 'message' => _x('Unable to disable existing Amazon CloudFront Distro. Connection failed.', 's2member-admin', 's2member')); } } } else { // Else, we use a default error code and message. return array('success' => FALSE, 'code' => -98, 'message' => _x('Existing Amazon CloudFront Distro cannot be deleted at this time. Still in a `pending` state. Please wait 15 minutes, then try again. There is a certain process that s2Member must strictly adhere to when re-configuring your Amazon CloudFront Distros. You may have to tick the auto-configure checkbox again, and re-run s2Member\'s auto-configuration routine many times, because s2Member will likely run into several `pending` challenges, as it works to completely re-configure your Amazon CloudFront Distros for you. Thanks for your patience. Please wait 15 minutes, then try again.', 's2member-admin', 's2member')); } } else { // Else, we use a default error code and message. return array('success' => FALSE, 'code' => -99, 'message' => _x('Unable to delete existing Amazon CloudFront Distro. Invalid Distro ID or ETag.', 's2member-admin', 's2member')); } }
/** * Deletes an Amazon S3/CloudFront Distro. * * @package s2Member\Files * @since 110926 * * @param str $distro_id Required. A Distro ID. * @param str $distro_id_etag Required. A Distro ETag header. * @param str $distro_id_xml Required. A Distro's XML configuration. * @return array Array containing a true `success` element on success, else a failure array. * Failure array will contain a failure `code`, and a failure `message`. */ public static function amazon_cf_del_distro($distro_id = FALSE, $distro_id_etag = FALSE, $distro_id_xml = FALSE) { if ($distro_id && is_string($distro_id) && $distro_id_etag && is_string($distro_id_etag) && $distro_id_xml && is_string($distro_id_xml) && ($distro_id_type = stripos($distro_id_xml, "<StreamingDistribution") !== false ? "streaming" : (stripos($distro_id_xml, "<Distribution") !== false ? "downloads" : false)) && preg_match("/\\<CallerReference\\>(.+?)\\<\\/CallerReference\\>/is", $distro_id_xml, $distro_id_reference_tag) && ($distro_id_reference = $distro_id_reference_tag[1])) { if (stripos($distro_id_xml, "<Status>Deployed</Status>") !== false) { if (($cf_response = c_ws_plugin__s2member_files_in::amazon_cf_disable_distro($distro_id, $distro_id_etag, $distro_id_xml)) && $cf_response["success"]) { if (($cf_response = c_ws_plugin__s2member_files_in::amazon_cf_get_distro($distro_id, $distro_id_type)) && $cf_response["success"] && $cf_response["deployed"]) { 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)); $cf_location = $distro_id_type === "streaming" ? "/2010-11-01/streaming-distribution/" . $distro_id : "/2010-11-01/distribution/" . $distro_id; $cf_args = array("method" => "DELETE", "redirection" => 0, "headers" => array("Host" => $cf_domain, "Date" => $cf_date, "If-Match" => $cf_response["etag"], "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"] === 204)) { return array("success" => true, "code" => null, "message" => null); } 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 delete existing Amazon CloudFront Distro. %s", "s2member-admin", "s2member"), $cf_response["message"])); } else { // Else, we use a default error code and message. return array("success" => false, "code" => -94, "message" => _x("Unable to delete existing Amazon CloudFront Distro. Connection failed.", "s2member-admin", "s2member")); } } } else { if (isset($cf_response["success"], $cf_response["deployed"]) && $cf_response["success"] && !$cf_response["deployed"]) { /* 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" => -95, "message" => _x("Existing Amazon CloudFront Distro cannot be deleted at this time. Still in a `pending` state after having been disabled by s2Member. Please wait 15 minutes, then try again. There is a certain process that s2Member must strictly adhere to when re-configuring your Amazon CloudFront Distros. You may have to tick the auto-configure checkbox again, and re-run s2Member's auto-configuration routine many times, because s2Member will likely run into several `pending` challenges, as it works to completely re-configure your Amazon CloudFront Distros for you. Thanks for your patience. Please wait 15 minutes, then try again.", "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 check status of existing Amazon CloudFront Distro. %s", "s2member-admin", "s2member"), $cf_response["message"])); } else { // Else, we use a default error code and message. return array("success" => false, "code" => -96, "message" => _x("Unable to check status of existing Amazon CloudFront Distro. Connection failed.", "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 disable existing Amazon CloudFront Distro. %s", "s2member-admin", "s2member"), $cf_response["message"])); } else { // Else, we use a default error code and message. return array("success" => false, "code" => -97, "message" => _x("Unable to disable existing Amazon CloudFront Distro. Connection failed.", "s2member-admin", "s2member")); } } } else { // Else, we use a default error code and message. return array("success" => false, "code" => -98, "message" => _x("Existing Amazon CloudFront Distro cannot be deleted at this time. Still in a `pending` state. Please wait 15 minutes, then try again. There is a certain process that s2Member must strictly adhere to when re-configuring your Amazon CloudFront Distros. You may have to tick the auto-configure checkbox again, and re-run s2Member's auto-configuration routine many times, because s2Member will likely run into several `pending` challenges, as it works to completely re-configure your Amazon CloudFront Distros for you. Thanks for your patience. Please wait 15 minutes, then try again.", "s2member-admin", "s2member")); } } else { // Else, we use a default error code and message. return array("success" => false, "code" => -99, "message" => _x("Unable to delete existing Amazon CloudFront Distro. Invalid Distro ID or ETag.", "s2member-admin", "s2member")); } }