Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-22663 Repository: WebDAV supports SSL and chunked data

  • Loading branch information...
commit 85a9d23d916a540331a599acc64a05b28f7bae68 1 parent 3f995be
@FMCorz FMCorz authored
Showing with 29 additions and 14 deletions.
  1. +10 −3 lib/webdavlib.php
  2. +19 −11 repository/webdav/lib.php
View
13 lib/webdavlib.php
@@ -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 @@ function __construct($server = '', $user = '', $pass = '', $auth = false) {
$this->pass = $pass;
}
$this->_auth = $auth;
+ $this->_socket = $socket;
}
public function __set($key, $value) {
$property = '_' . $key;
@@ -155,7 +157,7 @@ function iso8601totime($iso8601) {
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);
@@ -1404,7 +1406,12 @@ private function get_respond() {
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)
View
30 repository/webdav/lib.php
@@ -44,24 +44,27 @@ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = a
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'])) {
+ $port = '';
if (empty($this->webdav_type)) {
- $this->dav->port = 80;
+ $this->webdav_port = 80;
} else {
- $this->dav->port = 443;
+ $this->webdav_port = 443;
+ $port = ':443';
}
- $port = '';
} 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() {
@@ -120,13 +123,16 @@ public function get_listing($path='', $page = '') {
} else {
$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') {
// a folder
if ($path != $v['href']) {
- $folders[] = array(
- 'title'=>$title,
+ $folders[strtoupper($title)] = array(
+ 'title'=>rtrim($title, '/'),
'thumbnail'=>$OUTPUT->pix_url(file_folder_icon(90))->out(false),
'children'=>array(),
'datemodified'=>$v['lastmodified'],
@@ -136,7 +142,7 @@ public function get_listing($path='', $page = '') {
}else{
// a file
$size = !empty($v['getcontentlength'])? $v['getcontentlength']:'';
- $files[] = array(
+ $files[strtoupper($title)] = array(
'title'=>$title,
'thumbnail' => $OUTPUT->pix_url(file_extension_icon($title, 90))->out(false),
'size'=>$size,
@@ -145,6 +151,8 @@ public function get_listing($path='', $page = '') {
);
}
}
+ ksort($files);
+ ksort($folders);
$ret['list'] = array_merge($folders, $files);
return $ret;
}
Please sign in to comment.
Something went wrong with that request. Please try again.