MDL-22663 Repository: WebDAV supports SSL and chunked data

Conflicts:

	repository/webdav/lib.php
This commit is contained in:
Frederic Massart
2012-08-03 13:58:26 +08:00
parent f515f00aae
commit 9f412a79d0
2 changed files with 25 additions and 13 deletions
+10 -3
View File
@@ -44,6 +44,7 @@ class webdav_client {
private $_server;
private $_protocol = 'HTTP/1.1';
private $_port = 80;
private $_socket = '';
private $_path ='/';
private $_auth = false;
private $_user;
@@ -80,7 +81,7 @@ class webdav_client {
/**
* Constructor - Initialise class variables
*/
function __construct($server = '', $user = '', $pass = '', $auth = false) {
function __construct($server = '', $user = '', $pass = '', $auth = false, $socket = '') {
if (!empty($server)) {
$this->_server = $server;
}
@@ -89,6 +90,7 @@ class webdav_client {
$this->pass = $pass;
}
$this->_auth = $auth;
$this->_socket = $socket;
}
public function __set($key, $value) {
$property = '_' . $key;
@@ -155,7 +157,7 @@ class webdav_client {
function open() {
// let's try to open a socket
$this->_error_log('open a socket connection');
$this->sock = fsockopen($this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
$this->sock = fsockopen($this->_socket . $this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
set_time_limit(30);
if (is_resource($this->sock)) {
socket_set_blocking($this->sock, true);
@@ -1401,7 +1403,12 @@ EOD;
fread($this->sock, 1); // also drop off the Line Feed
$chunk_size=hexdec($chunk_size); // convert to a number in decimal system
if ($chunk_size > 0) {
$buffer .= fread($this->sock,$chunk_size);
$read = 0;
// Reading the chunk in one bite is not secure, we read it byte by byte.
while ($read < $chunk_size) {
$buffer .= fread($this->sock, 1);
$read++;
}
}
fread($this->sock, 2); // ditch the CRLF that trails the chunk
} while ($chunk_size); // till we reach the 0 length chunk (end marker)
+15 -10
View File
@@ -38,24 +38,27 @@ class repository_webdav extends repository {
if ($this->options['webdav_auth'] == 'none') {
$this->options['webdav_auth'] = false;
}
$this->dav = new webdav_client($this->options['webdav_server'], $this->options['webdav_user'], $this->options['webdav_password'], $this->options['webdav_auth']);
if (empty($this->options['webdav_type'])) {
$this->webdav_type = '';
} else {
$this->webdav_type = 'ssl://';
}
if (empty($this->options['webdav_port'])) {
if (empty($this->webdav_type)) {
$this->dav->port = 80;
} else {
$this->dav->port = 443;
}
$port = '';
if (empty($this->webdav_type)) {
$this->webdav_port = 80;
} else {
$this->webdav_port = 443;
$port = ':443';
}
} else {
$this->dav->port = $this->options['webdav_port'];
$port = ':'.$this->options['webdav_port'];
$this->webdav_port = $this->options['webdav_port'];
$port = ':' . $this->webdav_port;
}
$this->webdav_host = $this->webdav_type.$this->options['webdav_server'].$port;
$this->dav = new webdav_client($this->options['webdav_server'], $this->options['webdav_user'],
$this->options['webdav_password'], $this->options['webdav_auth'], $this->webdav_type);
$this->dav->port = $this->webdav_port;
$this->dav->debug = false;
}
public function check_login() {
@@ -103,9 +106,10 @@ class repository_webdav extends repository {
} else {
$partern = '#https://'.$this->webdav_host.'/#';
}
$path = '/'.preg_replace($partern, '', $path);
$path = '/'.preg_replace($partern, '', ltrim($path, '/'));
$dir = $this->dav->ls($path);
}
if (!is_array($dir)) {
return $ret;
}
@@ -116,9 +120,10 @@ class repository_webdav extends repository {
} else {
$filedate = '';
}
if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') {
// a folder
if (ltrim($path, '/') != ltrim($v['href'], '/')) {
if (ltrim($path, '/') != urldecode(ltrim($v['href'], '/'))) {
$matches = array();
preg_match('#(\w+)$#i', $v['href'], $matches);
if (!empty($matches[1])) {