mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'wip-MDL-53467-master' of git://github.com/abgreeve/moodle
This commit is contained in:
commit
ae2d413b2c
@ -3,7 +3,6 @@
|
||||
Amazon S3 PHP Class
|
||||
|
||||
Cloned from git://github.com/tpyo/amazon-s3-php-class.git
|
||||
At commit 8413f6f70ad3bb79ae756958d4ba2238514b00af
|
||||
|
||||
https://github.com/tpyo/amazon-s3-php-class
|
||||
http://undesigned.org.za/2007/10/22/amazon-s3-php-class
|
||||
|
@ -32,7 +32,7 @@
|
||||
* Amazon S3 PHP class
|
||||
*
|
||||
* @link http://undesigned.org.za/2007/10/22/amazon-s3-php-class
|
||||
* @version 0.5.1-dev
|
||||
* @version 0.5.1
|
||||
*/
|
||||
class S3
|
||||
{
|
||||
@ -75,6 +75,14 @@ class S3
|
||||
*/
|
||||
private static $__sslKey = null;
|
||||
|
||||
/**
|
||||
* Default delimiter to be used, for example while getBucket().
|
||||
* @var string
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static $defDelimiter = null;
|
||||
|
||||
/**
|
||||
* AWS URI
|
||||
*
|
||||
@ -111,6 +119,15 @@ class S3
|
||||
*/
|
||||
public static $useSSLValidation = true;
|
||||
|
||||
/**
|
||||
* Use SSL version
|
||||
*
|
||||
* @var const
|
||||
* @access public
|
||||
* @static
|
||||
*/
|
||||
public static $useSSLVersion = CURL_SSLVERSION_TLSv1;
|
||||
|
||||
/**
|
||||
* Use PHP exceptions?
|
||||
*
|
||||
@ -202,6 +219,7 @@ class S3
|
||||
self::$endpoint = $host;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set AWS access key and secret key
|
||||
*
|
||||
@ -416,6 +434,7 @@ class S3
|
||||
if ($marker !== null && $marker !== '') $rest->setParameter('marker', $marker);
|
||||
if ($maxKeys !== null && $maxKeys !== '') $rest->setParameter('max-keys', $maxKeys);
|
||||
if ($delimiter !== null && $delimiter !== '') $rest->setParameter('delimiter', $delimiter);
|
||||
else if (!empty(self::$defDelimiter)) $rest->setParameter('delimiter', self::$defDelimiter);
|
||||
$response = $rest->getResponse();
|
||||
if ($response->error === false && $response->code !== 200)
|
||||
$response->error = array('code' => $response->code, 'message' => 'Unexpected HTTP status');
|
||||
@ -561,6 +580,7 @@ class S3
|
||||
self::__triggerError('S3::inputFile(): Unable to open input file: '.$file, __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
clearstatcache(false, $file);
|
||||
return array('file' => $file, 'size' => filesize($file), 'md5sum' => $md5sum !== false ?
|
||||
(is_string($md5sum) ? $md5sum : base64_encode(md5_file($file, true))) : '');
|
||||
}
|
||||
@ -634,15 +654,18 @@ class S3
|
||||
if (isset($input['size']) && $input['size'] >= 0)
|
||||
$rest->size = $input['size'];
|
||||
else {
|
||||
if (isset($input['file']))
|
||||
if (isset($input['file'])) {
|
||||
clearstatcache(false, $input['file']);
|
||||
$rest->size = filesize($input['file']);
|
||||
}
|
||||
elseif (isset($input['data']))
|
||||
$rest->size = strlen($input['data']);
|
||||
}
|
||||
|
||||
// Custom request headers (Content-Type, Content-Disposition, Content-Encoding)
|
||||
if (is_array($requestHeaders))
|
||||
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
|
||||
foreach ($requestHeaders as $h => $v)
|
||||
strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v);
|
||||
elseif (is_string($requestHeaders)) // Support for legacy contentType parameter
|
||||
$input['type'] = $requestHeaders;
|
||||
|
||||
@ -797,7 +820,8 @@ class S3
|
||||
{
|
||||
$rest = new S3Request('PUT', $bucket, $uri, self::$endpoint);
|
||||
$rest->setHeader('Content-Length', 0);
|
||||
foreach ($requestHeaders as $h => $v) $rest->setHeader($h, $v);
|
||||
foreach ($requestHeaders as $h => $v)
|
||||
strpos($h, 'x-amz-') === 0 ? $rest->setAmzHeader($h, $v) : $rest->setHeader($h, $v);
|
||||
foreach ($metaHeaders as $h => $v) $rest->setAmzHeader('x-amz-meta-'.$h, $v);
|
||||
if ($storageClass !== self::STORAGE_CLASS_STANDARD) // Storage class
|
||||
$rest->setAmzHeader('x-amz-storage-class', $storageClass);
|
||||
@ -2117,6 +2141,9 @@ final class S3Request
|
||||
|
||||
if (S3::$useSSL)
|
||||
{
|
||||
// Set protocol version
|
||||
curl_setopt($curl, CURLOPT_SSLVERSION, S3::$useSSLVersion);
|
||||
|
||||
// SSL Validation can now be optional for those with broken OpenSSL installations
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, S3::$useSSLValidation ? 2 : 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, S3::$useSSLValidation ? 1 : 0);
|
||||
@ -2292,6 +2319,7 @@ final class S3Request
|
||||
private function __dnsBucketName($bucket)
|
||||
{
|
||||
if (strlen($bucket) > 63 || preg_match("/[^a-z0-9\.-]/", $bucket) > 0) return false;
|
||||
if (S3::$useSSL && strstr($bucket, '.') !== false) return false;
|
||||
if (strstr($bucket, '-.') !== false) return false;
|
||||
if (strstr($bucket, '..') !== false) return false;
|
||||
if (!preg_match("/^[0-9a-z]/", $bucket)) return false;
|
||||
|
@ -26,6 +26,11 @@
|
||||
require_once($CFG->dirroot . '/repository/lib.php');
|
||||
require_once($CFG->dirroot . '/repository/s3/S3.php');
|
||||
|
||||
// This constant is not defined in php 5.4. Set it to avoid errors.
|
||||
if (!defined('CURL_SSLVERSION_TLSv1')) {
|
||||
define('CURL_SSLVERSION_TLSv1', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a repository class used to browse Amazon S3 content.
|
||||
*
|
||||
|
@ -4,7 +4,7 @@
|
||||
<location>S3.php</location>
|
||||
<name>S3</name>
|
||||
<license>BSD</license>
|
||||
<version>0.5.1-dev</version>
|
||||
<version>0.5.1</version>
|
||||
<licenseversion></licenseversion>
|
||||
</library>
|
||||
</libraries>
|
||||
|
@ -26,6 +26,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2015111600; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2015111601; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2015111000; // Requires this Moodle version
|
||||
$plugin->component = 'repository_s3'; // Full name of the plugin (used for diagnostics)
|
||||
|
Loading…
x
Reference in New Issue
Block a user