Edit File by line
/home/barbar84/www/wp-conte.../plugins/updraftp.../includes
File: S3.php
[1000] Fix | Delete
$rest = new UpdraftPlus_S3Request('PUT', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[1001] Fix | Delete
$rest->setParameter('logging', null);
[1002] Fix | Delete
$rest->data = $dom->saveXML();
[1003] Fix | Delete
$rest->size = strlen($rest->data);
[1004] Fix | Delete
$rest->setHeader('Content-Type', 'application/xml');
[1005] Fix | Delete
$rest = $rest->getResponse();
[1006] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[1007] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[1008] Fix | Delete
}
[1009] Fix | Delete
[1010] Fix | Delete
if (false !== $rest->error) {
[1011] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::setBucketLogging({$bucket}, {$targetBucket}): [%s] %s",
[1012] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[1013] Fix | Delete
return false;
[1014] Fix | Delete
}
[1015] Fix | Delete
return true;
[1016] Fix | Delete
}
[1017] Fix | Delete
[1018] Fix | Delete
[1019] Fix | Delete
/**
[1020] Fix | Delete
* Get logging status for a bucket
[1021] Fix | Delete
*
[1022] Fix | Delete
* This will return false if logging is not enabled.
[1023] Fix | Delete
* Note: To enable logging, you also need to grant write access to the log group
[1024] Fix | Delete
*
[1025] Fix | Delete
* @param string $bucket Bucket name
[1026] Fix | Delete
*
[1027] Fix | Delete
* @return array | false
[1028] Fix | Delete
*/
[1029] Fix | Delete
public function getBucketLogging($bucket) {
[1030] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[1031] Fix | Delete
$rest->setParameter('logging', null);
[1032] Fix | Delete
$rest = $rest->getResponse();
[1033] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[1034] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[1035] Fix | Delete
}
[1036] Fix | Delete
[1037] Fix | Delete
if (false !== $rest->error) {
[1038] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::getBucketLogging({$bucket}): [%s] %s",
[1039] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[1040] Fix | Delete
return false;
[1041] Fix | Delete
}
[1042] Fix | Delete
if (!isset($rest->body->LoggingEnabled)) return false; // No logging
[1043] Fix | Delete
return array(
[1044] Fix | Delete
'targetBucket' => (string)$rest->body->LoggingEnabled->TargetBucket,
[1045] Fix | Delete
'targetPrefix' => (string)$rest->body->LoggingEnabled->TargetPrefix,
[1046] Fix | Delete
);
[1047] Fix | Delete
}
[1048] Fix | Delete
[1049] Fix | Delete
[1050] Fix | Delete
/**
[1051] Fix | Delete
* Disable bucket logging
[1052] Fix | Delete
*
[1053] Fix | Delete
* @param string $bucket Bucket name
[1054] Fix | Delete
*
[1055] Fix | Delete
* @return boolean
[1056] Fix | Delete
*/
[1057] Fix | Delete
public function disableBucketLogging($bucket) {
[1058] Fix | Delete
return $this->setBucketLogging($bucket, null);
[1059] Fix | Delete
}
[1060] Fix | Delete
[1061] Fix | Delete
/**
[1062] Fix | Delete
* Get a bucket's location
[1063] Fix | Delete
*
[1064] Fix | Delete
* @param string $bucket Bucket name
[1065] Fix | Delete
*
[1066] Fix | Delete
* @return string | false
[1067] Fix | Delete
*/
[1068] Fix | Delete
public function getBucketLocation($bucket) {
[1069] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', $bucket, '', $this->endpoint, $this->use_dns_bucket_name, $this);
[1070] Fix | Delete
$rest->setParameter('location', null);
[1071] Fix | Delete
$rest = $rest->getResponse();
[1072] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[1073] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[1074] Fix | Delete
}
[1075] Fix | Delete
if (false !== $rest->error) {
[1076] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::getBucketLocation({$bucket}): [%s] %s",
[1077] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[1078] Fix | Delete
return false;
[1079] Fix | Delete
}
[1080] Fix | Delete
[1081] Fix | Delete
return (isset($rest->body[0]) && (string)$rest->body[0] !== '') ? (string)$rest->body[0] : 'US';
[1082] Fix | Delete
}
[1083] Fix | Delete
[1084] Fix | Delete
/**
[1085] Fix | Delete
* Set object or bucket Access Control Policy
[1086] Fix | Delete
*
[1087] Fix | Delete
* @param string $bucket Bucket name
[1088] Fix | Delete
* @param string $uri Object URI
[1089] Fix | Delete
* @param array $acp Access Control Policy Data (same as the data returned from getAccessControlPolicy)
[1090] Fix | Delete
*
[1091] Fix | Delete
* @return boolean
[1092] Fix | Delete
*/
[1093] Fix | Delete
public function setAccessControlPolicy($bucket, $uri = '', $acp = array()) {
[1094] Fix | Delete
$dom = new DOMDocument;
[1095] Fix | Delete
$dom->formatOutput = true;
[1096] Fix | Delete
$accessControlPolicy = $dom->createElement('AccessControlPolicy');
[1097] Fix | Delete
$accessControlList = $dom->createElement('AccessControlList');
[1098] Fix | Delete
[1099] Fix | Delete
// It seems the owner has to be passed along too
[1100] Fix | Delete
$owner = $dom->createElement('Owner');
[1101] Fix | Delete
$owner->appendChild($dom->createElement('ID', $acp['owner']['id']));
[1102] Fix | Delete
$owner->appendChild($dom->createElement('DisplayName', $acp['owner']['name']));
[1103] Fix | Delete
$accessControlPolicy->appendChild($owner);
[1104] Fix | Delete
[1105] Fix | Delete
foreach ($acp['acl'] as $g) {
[1106] Fix | Delete
$grant = $dom->createElement('Grant');
[1107] Fix | Delete
$grantee = $dom->createElement('Grantee');
[1108] Fix | Delete
$grantee->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
[1109] Fix | Delete
if (isset($g['id'])) {
[1110] Fix | Delete
// CanonicalUser (DisplayName is omitted)
[1111] Fix | Delete
$grantee->setAttribute('xsi:type', 'CanonicalUser');
[1112] Fix | Delete
$grantee->appendChild($dom->createElement('ID', $g['id']));
[1113] Fix | Delete
} elseif (isset($g['email'])) {
[1114] Fix | Delete
// AmazonCustomerByEmail
[1115] Fix | Delete
$grantee->setAttribute('xsi:type', 'AmazonCustomerByEmail');
[1116] Fix | Delete
$grantee->appendChild($dom->createElement('EmailAddress', $g['email']));
[1117] Fix | Delete
} elseif ('Group' == $g['type']) {
[1118] Fix | Delete
// Group
[1119] Fix | Delete
$grantee->setAttribute('xsi:type', 'Group');
[1120] Fix | Delete
$grantee->appendChild($dom->createElement('URI', $g['uri']));
[1121] Fix | Delete
}
[1122] Fix | Delete
$grant->appendChild($grantee);
[1123] Fix | Delete
$grant->appendChild($dom->createElement('Permission', $g['permission']));
[1124] Fix | Delete
$accessControlList->appendChild($grant);
[1125] Fix | Delete
}
[1126] Fix | Delete
[1127] Fix | Delete
$accessControlPolicy->appendChild($accessControlList);
[1128] Fix | Delete
$dom->appendChild($accessControlPolicy);
[1129] Fix | Delete
[1130] Fix | Delete
$rest = new UpdraftPlus_S3Request('PUT', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[1131] Fix | Delete
$rest->setParameter('acl', null);
[1132] Fix | Delete
$rest->data = $dom->saveXML();
[1133] Fix | Delete
$rest->size = strlen($rest->data);
[1134] Fix | Delete
$rest->setHeader('Content-Type', 'application/xml');
[1135] Fix | Delete
$rest = $rest->getResponse();
[1136] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[1137] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[1138] Fix | Delete
}
[1139] Fix | Delete
[1140] Fix | Delete
if (false !== $rest->error) {
[1141] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::setAccessControlPolicy({$bucket}, {$uri}): [%s] %s",
[1142] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[1143] Fix | Delete
return false;
[1144] Fix | Delete
}
[1145] Fix | Delete
return true;
[1146] Fix | Delete
}
[1147] Fix | Delete
[1148] Fix | Delete
[1149] Fix | Delete
/**
[1150] Fix | Delete
* Get object or bucket Access Control Policy
[1151] Fix | Delete
*
[1152] Fix | Delete
* @param string $bucket Bucket name
[1153] Fix | Delete
* @param string $uri Object URI
[1154] Fix | Delete
* @return mixed | false
[1155] Fix | Delete
*/
[1156] Fix | Delete
public function getAccessControlPolicy($bucket, $uri = '') {
[1157] Fix | Delete
$rest = new UpdraftPlus_S3Request('GET', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[1158] Fix | Delete
$rest->setParameter('acl', null);
[1159] Fix | Delete
$rest = $rest->getResponse();
[1160] Fix | Delete
if (false === $rest->error && 200 !== $rest->code) {
[1161] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[1162] Fix | Delete
}
[1163] Fix | Delete
[1164] Fix | Delete
if (false !== $rest->error) {
[1165] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::getAccessControlPolicy({$bucket}, {$uri}): [%s] %s",
[1166] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[1167] Fix | Delete
return false;
[1168] Fix | Delete
}
[1169] Fix | Delete
[1170] Fix | Delete
$acp = array();
[1171] Fix | Delete
if (isset($rest->body->Owner, $rest->body->Owner->ID, $rest->body->Owner->DisplayName))
[1172] Fix | Delete
$acp['owner'] = array(
[1173] Fix | Delete
'id' => (string)$rest->body->Owner->ID, 'name' => (string)$rest->body->Owner->DisplayName
[1174] Fix | Delete
);
[1175] Fix | Delete
[1176] Fix | Delete
if (isset($rest->body->AccessControlList)) {
[1177] Fix | Delete
$acp['acl'] = array();
[1178] Fix | Delete
foreach ($rest->body->AccessControlList->Grant as $grant) {
[1179] Fix | Delete
foreach ($grant->Grantee as $grantee) {
[1180] Fix | Delete
if (isset($grantee->ID, $grantee->DisplayName)) // CanonicalUser
[1181] Fix | Delete
$acp['acl'][] = array(
[1182] Fix | Delete
'type' => 'CanonicalUser',
[1183] Fix | Delete
'id' => (string)$grantee->ID,
[1184] Fix | Delete
'name' => (string)$grantee->DisplayName,
[1185] Fix | Delete
'permission' => (string)$grant->Permission
[1186] Fix | Delete
);
[1187] Fix | Delete
elseif (isset($grantee->EmailAddress)) // AmazonCustomerByEmail
[1188] Fix | Delete
$acp['acl'][] = array(
[1189] Fix | Delete
'type' => 'AmazonCustomerByEmail',
[1190] Fix | Delete
'email' => (string)$grantee->EmailAddress,
[1191] Fix | Delete
'permission' => (string)$grant->Permission
[1192] Fix | Delete
);
[1193] Fix | Delete
elseif (isset($grantee->URI)) // Group
[1194] Fix | Delete
$acp['acl'][] = array(
[1195] Fix | Delete
'type' => 'Group',
[1196] Fix | Delete
'uri' => (string)$grantee->URI,
[1197] Fix | Delete
'permission' => (string)$grant->Permission
[1198] Fix | Delete
);
[1199] Fix | Delete
else continue;
[1200] Fix | Delete
}
[1201] Fix | Delete
}
[1202] Fix | Delete
}
[1203] Fix | Delete
return $acp;
[1204] Fix | Delete
}
[1205] Fix | Delete
[1206] Fix | Delete
/**
[1207] Fix | Delete
* Delete an object
[1208] Fix | Delete
*
[1209] Fix | Delete
* @param string $bucket Bucket name
[1210] Fix | Delete
* @param string $uri Object URI
[1211] Fix | Delete
*
[1212] Fix | Delete
* @return boolean
[1213] Fix | Delete
*/
[1214] Fix | Delete
public function deleteObject($bucket, $uri) {
[1215] Fix | Delete
$rest = new UpdraftPlus_S3Request('DELETE', $bucket, $uri, $this->endpoint, $this->use_dns_bucket_name, $this);
[1216] Fix | Delete
$rest = $rest->getResponse();
[1217] Fix | Delete
if (false === $rest->error && 204 !== $rest->code) {
[1218] Fix | Delete
$rest->error = array('code' => $rest->code, 'message' => 'Unexpected HTTP status');
[1219] Fix | Delete
}
[1220] Fix | Delete
[1221] Fix | Delete
if (false !== $rest->error) {
[1222] Fix | Delete
$this->__triggerError(sprintf("UpdraftPlus_S3::deleteObject(): [%s] %s",
[1223] Fix | Delete
$rest->error['code'], $rest->error['message']), __FILE__, __LINE__);
[1224] Fix | Delete
return false;
[1225] Fix | Delete
}
[1226] Fix | Delete
return true;
[1227] Fix | Delete
}
[1228] Fix | Delete
[1229] Fix | Delete
/**
[1230] Fix | Delete
* Get a query string authenticated URL
[1231] Fix | Delete
*
[1232] Fix | Delete
* @param string $bucket Bucket name
[1233] Fix | Delete
* @param string $uri Object URI
[1234] Fix | Delete
* @param integer $lifetime Lifetime in seconds
[1235] Fix | Delete
* @param boolean $hostBucket Use the bucket name as the hostname
[1236] Fix | Delete
* @param boolean $https Use HTTPS ($hostBucket should be false for SSL verification)
[1237] Fix | Delete
*
[1238] Fix | Delete
* @return string
[1239] Fix | Delete
*/
[1240] Fix | Delete
public function getAuthenticatedURL($bucket, $uri, $lifetime, $hostBucket = false, $https = false) {
[1241] Fix | Delete
$expires = time() + $lifetime;
[1242] Fix | Delete
$uri = str_replace(array('%2F', '%2B'), array('/', '+'), rawurlencode($uri));
[1243] Fix | Delete
return sprintf(($https ? 'https' : 'http').'://%s/%s?AWSAccessKeyId=%s&Expires=%u&Signature=%s',
[1244] Fix | Delete
// $hostBucket ? $bucket : $bucket.'.s3.amazonaws.com', $uri, $this->__accessKey, $expires,
[1245] Fix | Delete
$hostBucket ? $bucket : 's3.amazonaws.com/'.$bucket, $uri, $this->__accessKey, $expires,
[1246] Fix | Delete
urlencode($this->__getHash("GET\n\n\n{$expires}\n/{$bucket}/{$uri}")));
[1247] Fix | Delete
}
[1248] Fix | Delete
[1249] Fix | Delete
/**
[1250] Fix | Delete
* Get upload POST parameters for form uploads
[1251] Fix | Delete
*
[1252] Fix | Delete
* @param string $bucket Bucket name
[1253] Fix | Delete
* @param string $uriPrefix Object URI prefix
[1254] Fix | Delete
* @param string $acl ACL constant
[1255] Fix | Delete
* @param integer $lifetime Lifetime in seconds
[1256] Fix | Delete
* @param integer $maxFileSize Maximum file size in bytes (default 5MB)
[1257] Fix | Delete
* @param string $successRedirect Redirect URL or 200 / 201 status code
[1258] Fix | Delete
* @param array $amzHeaders Array of x-amz-meta-* headers
[1259] Fix | Delete
* @param array $headers Array of request headers or content type as a string
[1260] Fix | Delete
* @param boolean $flashVars Includes additional "Filename" variable posted by Flash
[1261] Fix | Delete
*
[1262] Fix | Delete
* @return object
[1263] Fix | Delete
*/
[1264] Fix | Delete
public function getHttpUploadPostParams($bucket, $uriPrefix = '', $acl = self::ACL_PRIVATE, $lifetime = 3600,
[1265] Fix | Delete
$maxFileSize = 5242880, $successRedirect = "201", $amzHeaders = array(), $headers = array(), $flashVars = false) {
[1266] Fix | Delete
// Create policy object
[1267] Fix | Delete
$policy = new stdClass;
[1268] Fix | Delete
$policy->expiration = gmdate('Y-m-d\TH:i:s\Z', (time() + $lifetime));
[1269] Fix | Delete
$policy->conditions = array();
[1270] Fix | Delete
$obj = new stdClass; $obj->bucket = $bucket; array_push($policy->conditions, $obj);
[1271] Fix | Delete
$obj = new stdClass; $obj->acl = $acl; array_push($policy->conditions, $obj);
[1272] Fix | Delete
[1273] Fix | Delete
$obj = new stdClass; // 200 for non-redirect uploads
[1274] Fix | Delete
if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201)))
[1275] Fix | Delete
$obj->success_action_status = (string)$successRedirect;
[1276] Fix | Delete
else // URL
[1277] Fix | Delete
$obj->success_action_redirect = $successRedirect;
[1278] Fix | Delete
array_push($policy->conditions, $obj);
[1279] Fix | Delete
[1280] Fix | Delete
if (self::ACL_PUBLIC_READ !== $acl)
[1281] Fix | Delete
array_push($policy->conditions, array('eq', '$acl', $acl));
[1282] Fix | Delete
[1283] Fix | Delete
array_push($policy->conditions, array('starts-with', '$key', $uriPrefix));
[1284] Fix | Delete
if ($flashVars) array_push($policy->conditions, array('starts-with', '$Filename', ''));
[1285] Fix | Delete
foreach (array_keys($headers) as $headerKey)
[1286] Fix | Delete
array_push($policy->conditions, array('starts-with', '$'.$headerKey, ''));
[1287] Fix | Delete
foreach ($amzHeaders as $headerKey => $headerVal) {
[1288] Fix | Delete
$obj = new stdClass;
[1289] Fix | Delete
$obj->{$headerKey} = (string)$headerVal;
[1290] Fix | Delete
array_push($policy->conditions, $obj);
[1291] Fix | Delete
}
[1292] Fix | Delete
array_push($policy->conditions, array('content-length-range', 0, $maxFileSize));
[1293] Fix | Delete
$policy = base64_encode(str_replace('\/', '/', json_encode($policy)));
[1294] Fix | Delete
[1295] Fix | Delete
// Create parameters
[1296] Fix | Delete
$params = new stdClass;
[1297] Fix | Delete
$params->AWSAccessKeyId = $this->__accessKey;
[1298] Fix | Delete
$params->key = $uriPrefix.'${filename}';
[1299] Fix | Delete
$params->acl = $acl;
[1300] Fix | Delete
$params->policy = $policy; unset($policy);
[1301] Fix | Delete
$params->signature = $this->__getHash($params->policy);
[1302] Fix | Delete
if (is_numeric($successRedirect) && in_array((int)$successRedirect, array(200, 201)))
[1303] Fix | Delete
$params->success_action_status = (string)$successRedirect;
[1304] Fix | Delete
else
[1305] Fix | Delete
$params->success_action_redirect = $successRedirect;
[1306] Fix | Delete
foreach ($headers as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal;
[1307] Fix | Delete
foreach ($amzHeaders as $headerKey => $headerVal) $params->{$headerKey} = (string)$headerVal;
[1308] Fix | Delete
return $params;
[1309] Fix | Delete
}
[1310] Fix | Delete
[1311] Fix | Delete
/**
[1312] Fix | Delete
* Get MIME type for file
[1313] Fix | Delete
*
[1314] Fix | Delete
* @internal Used to get mime types
[1315] Fix | Delete
*
[1316] Fix | Delete
* @param string &$file File path
[1317] Fix | Delete
*
[1318] Fix | Delete
* @return string
[1319] Fix | Delete
*/
[1320] Fix | Delete
public function __getMimeType(&$file) {// phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore -- Method name "UpdraftPlus_S3Request::__responseHeaderCallback" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.
[1321] Fix | Delete
$type = false;
[1322] Fix | Delete
// Fileinfo documentation says fileinfo_open() will use the
[1323] Fix | Delete
// MAGIC env var for the magic file
[1324] Fix | Delete
if (extension_loaded('fileinfo') && isset($_ENV['MAGIC']) &&
[1325] Fix | Delete
false !== ($finfo = finfo_open(FILEINFO_MIME, $_ENV['MAGIC']))) {// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.finfo_openFound -- The function finfo_open() is not present in PHP version 5.2 or earlier
[1326] Fix | Delete
if (false !== ($type = finfo_file($finfo, $file))) {// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.finfo_fileFound -- The function finfo_file() is not present in PHP version 5.2 or earlier
[1327] Fix | Delete
// Remove the charset and grab the last content-type
[1328] Fix | Delete
$type = explode(' ', str_replace('; charset=', ';charset=', $type));
[1329] Fix | Delete
$type = array_pop($type);
[1330] Fix | Delete
$type = explode(';', $type);
[1331] Fix | Delete
$type = trim(array_shift($type));
[1332] Fix | Delete
}
[1333] Fix | Delete
finfo_close($finfo);// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.finfo_closeFound -- The function finfo_close() is not present in PHP version 5.2 or earlier
[1334] Fix | Delete
[1335] Fix | Delete
// If anyone is still using mime_content_type()
[1336] Fix | Delete
} elseif (function_exists('mime_content_type')) {
[1337] Fix | Delete
$type = trim(mime_content_type($file));
[1338] Fix | Delete
}
[1339] Fix | Delete
[1340] Fix | Delete
if (false !== $type && strlen($type) > 0) return $type;
[1341] Fix | Delete
[1342] Fix | Delete
// Otherwise do it the old fashioned way
[1343] Fix | Delete
static $exts = array(
[1344] Fix | Delete
'jpg' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png',
[1345] Fix | Delete
'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ico' => 'image/x-icon',
[1346] Fix | Delete
'swf' => 'application/x-shockwave-flash', 'pdf' => 'application/pdf',
[1347] Fix | Delete
'zip' => 'application/zip', 'gz' => 'application/x-gzip',
[1348] Fix | Delete
'tar' => 'application/x-tar', 'bz' => 'application/x-bzip',
[1349] Fix | Delete
'bz2' => 'application/x-bzip2', 'txt' => 'text/plain',
[1350] Fix | Delete
'asc' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html',
[1351] Fix | Delete
'css' => 'text/css', 'js' => 'text/javascript',
[1352] Fix | Delete
'xml' => 'text/xml', 'xsl' => 'application/xsl+xml',
[1353] Fix | Delete
'ogg' => 'application/ogg', 'mp3' => 'audio/mpeg', 'wav' => 'audio/x-wav',
[1354] Fix | Delete
'avi' => 'video/x-msvideo', 'mpg' => 'video/mpeg', 'mpeg' => 'video/mpeg',
[1355] Fix | Delete
'mov' => 'video/quicktime', 'flv' => 'video/x-flv', 'php' => 'text/x-php'
[1356] Fix | Delete
);
[1357] Fix | Delete
$ext = strtolower(pathInfo($file, PATHINFO_EXTENSION));
[1358] Fix | Delete
return isset($exts[$ext]) ? $exts[$ext] : 'application/octet-stream';
[1359] Fix | Delete
}
[1360] Fix | Delete
[1361] Fix | Delete
[1362] Fix | Delete
/**
[1363] Fix | Delete
* Generate the auth string: "AWS AccessKey:Signature"
[1364] Fix | Delete
*
[1365] Fix | Delete
* @internal Used by UpdraftPlus_S3Request::getResponse()
[1366] Fix | Delete
*
[1367] Fix | Delete
* @param string $string String to sign
[1368] Fix | Delete
*
[1369] Fix | Delete
* @return string
[1370] Fix | Delete
*/
[1371] Fix | Delete
public function __getSignature($string) {// phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore -- Method name "UpdraftPlus_S3Request::__responseHeaderCallback" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.
[1372] Fix | Delete
return 'AWS '.$this->__accessKey.':'.$this->__getHash($string);
[1373] Fix | Delete
}
[1374] Fix | Delete
[1375] Fix | Delete
[1376] Fix | Delete
/**
[1377] Fix | Delete
* Creates a HMAC-SHA1 hash
[1378] Fix | Delete
*
[1379] Fix | Delete
* This uses the hash extension if loaded
[1380] Fix | Delete
*
[1381] Fix | Delete
* @internal Used by __getSignature()
[1382] Fix | Delete
*
[1383] Fix | Delete
* @param string $string String to sign
[1384] Fix | Delete
*
[1385] Fix | Delete
* @return string
[1386] Fix | Delete
*/
[1387] Fix | Delete
private function __getHash($string) {// phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore -- Method name "UpdraftPlus_S3Request::__responseHeaderCallback" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.
[1388] Fix | Delete
return base64_encode(extension_loaded('hash') ?
[1389] Fix | Delete
hash_hmac('sha1', $string, $this->__secretKey, true) : pack('H*', sha1(
[1390] Fix | Delete
(str_pad($this->__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) .
[1391] Fix | Delete
pack('H*', sha1((str_pad($this->__secretKey, 64, chr(0x00)) ^
[1392] Fix | Delete
(str_repeat(chr(0x36), 64))) . $string)))));
[1393] Fix | Delete
}
[1394] Fix | Delete
[1395] Fix | Delete
/**
[1396] Fix | Delete
* Generate the headers for AWS Signature V4
[1397] Fix | Delete
*
[1398] Fix | Delete
* @internal Used by UpdraftPlus_S3Request::getResponse()
[1399] Fix | Delete
* @param array $aHeaders amzHeaders
[1400] Fix | Delete
* @param array $headers
[1401] Fix | Delete
* @param string $method
[1402] Fix | Delete
* @param string $uri
[1403] Fix | Delete
* @param string $data
[1404] Fix | Delete
*
[1405] Fix | Delete
* @return array $headers
[1406] Fix | Delete
*/
[1407] Fix | Delete
public function __getSignatureV4($aHeaders, $headers, $method = 'GET', $uri = '', $data = '') {// phpcs:ignore PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames.MethodDoubleUnderscore -- Method name "UpdraftPlus_S3Request::__responseHeaderCallback" is discouraged; PHP has reserved all method names with a double underscore prefix for future use.
[1408] Fix | Delete
$service = 's3';
[1409] Fix | Delete
$region = $this->getRegion();
[1410] Fix | Delete
[1411] Fix | Delete
$algorithm = 'AWS4-HMAC-SHA256';
[1412] Fix | Delete
$amzHeaders = array();
[1413] Fix | Delete
$amzRequests = array();
[1414] Fix | Delete
[1415] Fix | Delete
$amzDate = gmdate('Ymd\THis\Z');
[1416] Fix | Delete
$amzDateStamp = gmdate('Ymd');
[1417] Fix | Delete
[1418] Fix | Delete
// amz-date ISO8601 format? for aws request
[1419] Fix | Delete
$amzHeaders['x-amz-date'] = $amzDate;
[1420] Fix | Delete
[1421] Fix | Delete
// CanonicalHeaders
[1422] Fix | Delete
foreach ($headers as $k => $v) {
[1423] Fix | Delete
$amzHeaders[strtolower($k)] = trim($v);
[1424] Fix | Delete
}
[1425] Fix | Delete
[1426] Fix | Delete
foreach ($aHeaders as $k => $v) {
[1427] Fix | Delete
$amzHeaders[strtolower($k)] = trim($v);
[1428] Fix | Delete
}
[1429] Fix | Delete
uksort($amzHeaders, 'strcmp');
[1430] Fix | Delete
[1431] Fix | Delete
// payload
[1432] Fix | Delete
$payloadHash = isset($amzHeaders['x-amz-content-sha256']) ? $amzHeaders['x-amz-content-sha256'] : hash('sha256', $data);
[1433] Fix | Delete
[1434] Fix | Delete
// parameters
[1435] Fix | Delete
$parameters = array();
[1436] Fix | Delete
if (strpos($uri, '?')) {
[1437] Fix | Delete
list($uri, $query_str) = @explode('?', $uri);
[1438] Fix | Delete
parse_str($query_str, $parameters);
[1439] Fix | Delete
}
[1440] Fix | Delete
[1441] Fix | Delete
// Canonical Requests
[1442] Fix | Delete
$amzRequests[] = $method;
[1443] Fix | Delete
$uriQmPos = strpos($uri, '?');
[1444] Fix | Delete
$amzRequests[] = (false === $uriQmPos ? $uri : substr($uri, 0, $uriQmPos));
[1445] Fix | Delete
$amzRequests[] = http_build_query($parameters);
[1446] Fix | Delete
[1447] Fix | Delete
// add headers as string to requests
[1448] Fix | Delete
foreach ($amzHeaders as $k => $v) {
[1449] Fix | Delete
$amzRequests[] = $k . ':' . $v;
[1450] Fix | Delete
}
[1451] Fix | Delete
[1452] Fix | Delete
// add a blank entry so we end up with an extra line break
[1453] Fix | Delete
$amzRequests[] = '';
[1454] Fix | Delete
[1455] Fix | Delete
// SignedHeaders
[1456] Fix | Delete
$amzRequests[] = implode(';', array_keys($amzHeaders));
[1457] Fix | Delete
[1458] Fix | Delete
// payload hash
[1459] Fix | Delete
$amzRequests[] = $payloadHash;
[1460] Fix | Delete
[1461] Fix | Delete
// request as string
[1462] Fix | Delete
$amzRequestStr = implode("\n", $amzRequests);
[1463] Fix | Delete
[1464] Fix | Delete
// CredentialScope
[1465] Fix | Delete
$credentialScope = array();
[1466] Fix | Delete
$credentialScope[] = $amzDateStamp;
[1467] Fix | Delete
$credentialScope[] = $region;
[1468] Fix | Delete
$credentialScope[] = $service;
[1469] Fix | Delete
$credentialScope[] = 'aws4_request';
[1470] Fix | Delete
[1471] Fix | Delete
// stringToSign
[1472] Fix | Delete
$stringToSign = array();
[1473] Fix | Delete
$stringToSign[] = $algorithm;
[1474] Fix | Delete
$stringToSign[] = $amzDate;
[1475] Fix | Delete
$stringToSign[] = implode('/', $credentialScope);
[1476] Fix | Delete
$stringToSign[] = hash('sha256', $amzRequestStr);
[1477] Fix | Delete
[1478] Fix | Delete
// as string
[1479] Fix | Delete
$stringToSignStr = implode("\n", $stringToSign);
[1480] Fix | Delete
[1481] Fix | Delete
// Make Signature
[1482] Fix | Delete
$kSecret = 'AWS4' . $this->__secretKey;
[1483] Fix | Delete
$kDate = hash_hmac('sha256', $amzDateStamp, $kSecret, true);
[1484] Fix | Delete
$kRegion = hash_hmac('sha256', $region, $kDate, true);
[1485] Fix | Delete
$kService = hash_hmac('sha256', $service, $kRegion, true);
[1486] Fix | Delete
$kSigning = hash_hmac('sha256', 'aws4_request', $kService, true);
[1487] Fix | Delete
$signature = hash_hmac('sha256', $stringToSignStr, $kSigning);
[1488] Fix | Delete
[1489] Fix | Delete
$authorization = array(
[1490] Fix | Delete
'Credential=' . $this->__accessKey . '/' . implode('/', $credentialScope),
[1491] Fix | Delete
'SignedHeaders=' . implode(';', array_keys($amzHeaders)),
[1492] Fix | Delete
'Signature=' . $signature,
[1493] Fix | Delete
);
[1494] Fix | Delete
$authorizationStr = $algorithm . ' ' . implode(',', $authorization);
[1495] Fix | Delete
[1496] Fix | Delete
$resultHeaders = array(
[1497] Fix | Delete
'X-AMZ-DATE' => $amzDate,
[1498] Fix | Delete
'Authorization' => $authorizationStr
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function