mirror of
https://github.com/moodle/moodle.git
synced 2025-08-07 09:56:38 +02:00
MDL-22663 Repository: WebDAV supports SSL and chunked data
This commit is contained in:
parent
3f995bef7a
commit
85a9d23d91
2 changed files with 31 additions and 16 deletions
|
@ -44,6 +44,7 @@ class webdav_client {
|
||||||
private $_server;
|
private $_server;
|
||||||
private $_protocol = 'HTTP/1.1';
|
private $_protocol = 'HTTP/1.1';
|
||||||
private $_port = 80;
|
private $_port = 80;
|
||||||
|
private $_socket = '';
|
||||||
private $_path ='/';
|
private $_path ='/';
|
||||||
private $_auth = false;
|
private $_auth = false;
|
||||||
private $_user;
|
private $_user;
|
||||||
|
@ -80,7 +81,7 @@ class webdav_client {
|
||||||
/**
|
/**
|
||||||
* Constructor - Initialise class variables
|
* Constructor - Initialise class variables
|
||||||
*/
|
*/
|
||||||
function __construct($server = '', $user = '', $pass = '', $auth = false) {
|
function __construct($server = '', $user = '', $pass = '', $auth = false, $socket = '') {
|
||||||
if (!empty($server)) {
|
if (!empty($server)) {
|
||||||
$this->_server = $server;
|
$this->_server = $server;
|
||||||
}
|
}
|
||||||
|
@ -89,6 +90,7 @@ class webdav_client {
|
||||||
$this->pass = $pass;
|
$this->pass = $pass;
|
||||||
}
|
}
|
||||||
$this->_auth = $auth;
|
$this->_auth = $auth;
|
||||||
|
$this->_socket = $socket;
|
||||||
}
|
}
|
||||||
public function __set($key, $value) {
|
public function __set($key, $value) {
|
||||||
$property = '_' . $key;
|
$property = '_' . $key;
|
||||||
|
@ -155,7 +157,7 @@ class webdav_client {
|
||||||
function open() {
|
function open() {
|
||||||
// let's try to open a socket
|
// let's try to open a socket
|
||||||
$this->_error_log('open a socket connection');
|
$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);
|
set_time_limit(30);
|
||||||
if (is_resource($this->sock)) {
|
if (is_resource($this->sock)) {
|
||||||
socket_set_blocking($this->sock, true);
|
socket_set_blocking($this->sock, true);
|
||||||
|
@ -1404,7 +1406,12 @@ EOD;
|
||||||
fread($this->sock, 1); // also drop off the Line Feed
|
fread($this->sock, 1); // also drop off the Line Feed
|
||||||
$chunk_size=hexdec($chunk_size); // convert to a number in decimal system
|
$chunk_size=hexdec($chunk_size); // convert to a number in decimal system
|
||||||
if ($chunk_size > 0) {
|
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
|
fread($this->sock, 2); // ditch the CRLF that trails the chunk
|
||||||
} while ($chunk_size); // till we reach the 0 length chunk (end marker)
|
} while ($chunk_size); // till we reach the 0 length chunk (end marker)
|
||||||
|
|
|
@ -44,24 +44,27 @@ class repository_webdav extends repository {
|
||||||
if ($this->options['webdav_auth'] == 'none') {
|
if ($this->options['webdav_auth'] == 'none') {
|
||||||
$this->options['webdav_auth'] = false;
|
$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'])) {
|
if (empty($this->options['webdav_type'])) {
|
||||||
$this->webdav_type = '';
|
$this->webdav_type = '';
|
||||||
} else {
|
} else {
|
||||||
$this->webdav_type = 'ssl://';
|
$this->webdav_type = 'ssl://';
|
||||||
}
|
}
|
||||||
if (empty($this->options['webdav_port'])) {
|
if (empty($this->options['webdav_port'])) {
|
||||||
if (empty($this->webdav_type)) {
|
|
||||||
$this->dav->port = 80;
|
|
||||||
} else {
|
|
||||||
$this->dav->port = 443;
|
|
||||||
}
|
|
||||||
$port = '';
|
$port = '';
|
||||||
|
if (empty($this->webdav_type)) {
|
||||||
|
$this->webdav_port = 80;
|
||||||
|
} else {
|
||||||
|
$this->webdav_port = 443;
|
||||||
|
$port = ':443';
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->dav->port = $this->options['webdav_port'];
|
$this->webdav_port = $this->options['webdav_port'];
|
||||||
$port = ':'.$this->options['webdav_port'];
|
$port = ':' . $this->webdav_port;
|
||||||
}
|
}
|
||||||
$this->webdav_host = $this->webdav_type.$this->options['webdav_server'].$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;
|
$this->dav->debug = false;
|
||||||
}
|
}
|
||||||
public function check_login() {
|
public function check_login() {
|
||||||
|
@ -120,13 +123,16 @@ class repository_webdav extends repository {
|
||||||
} else {
|
} else {
|
||||||
$v['lastmodified'] = null;
|
$v['lastmodified'] = null;
|
||||||
}
|
}
|
||||||
$v['href'] = substr($v['href'], strlen(urlencode($webdavpath)));
|
|
||||||
$title = urldecode(substr($v['href'], strlen($path)));
|
// Extracting object title from absolute path
|
||||||
|
$v['href'] = substr(urldecode($v['href']), strlen($webdavpath));
|
||||||
|
$title = substr($v['href'], strlen($path));
|
||||||
|
|
||||||
if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') {
|
if (!empty($v['resourcetype']) && $v['resourcetype'] == 'collection') {
|
||||||
// a folder
|
// a folder
|
||||||
if ($path != $v['href']) {
|
if ($path != $v['href']) {
|
||||||
$folders[] = array(
|
$folders[strtoupper($title)] = array(
|
||||||
'title'=>$title,
|
'title'=>rtrim($title, '/'),
|
||||||
'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
|
'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
|
||||||
'children'=>array(),
|
'children'=>array(),
|
||||||
'datemodified'=>$v['lastmodified'],
|
'datemodified'=>$v['lastmodified'],
|
||||||
|
@ -136,7 +142,7 @@ class repository_webdav extends repository {
|
||||||
}else{
|
}else{
|
||||||
// a file
|
// a file
|
||||||
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';
|
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';
|
||||||
$files[] = array(
|
$files[strtoupper($title)] = array(
|
||||||
'title'=>$title,
|
'title'=>$title,
|
||||||
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false),
|
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false),
|
||||||
'size'=>$size,
|
'size'=>$size,
|
||||||
|
@ -145,6 +151,8 @@ class repository_webdav extends repository {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ksort($files);
|
||||||
|
ksort($folders);
|
||||||
$ret['list'] = array_merge($folders, $files);
|
$ret['list'] = array_merge($folders, $files);
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue