Merge pull request #6422 from ccerrillo/fixing-6301-external-mount-webdav-blank-files

Fixing Issue #6301 on master branch
This commit is contained in:
Vincent Petry 2014-01-13 07:09:01 -08:00
commit 5e04b7f284
2 changed files with 32 additions and 16 deletions

View File

@ -392,8 +392,7 @@ class OC_Mount_Config {
* @return array * @return array
*/ */
public static function getCertificates() { public static function getCertificates() {
$view = \OCP\Files::getStorage('files_external'); $path=OC_User::getHome(OC_User::getUser()) . '/files_external/uploads/';
$path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
\OCP\Util::writeLog('files_external', 'checking path '.$path, \OCP\Util::INFO); \OCP\Util::writeLog('files_external', 'checking path '.$path, \OCP\Util::INFO);
if ( ! is_dir($path)) { if ( ! is_dir($path)) {
//path might not exist (e.g. non-standard OC_User::getHome() value) //path might not exist (e.g. non-standard OC_User::getHome() value)
@ -415,8 +414,7 @@ class OC_Mount_Config {
* creates certificate bundle * creates certificate bundle
*/ */
public static function createCertificateBundle() { public static function createCertificateBundle() {
$view = \OCP\Files::getStorage("files_external"); $path=OC_User::getHome(OC_User::getUser()) . '/files_external';
$path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");
$certs = OC_Mount_Config::getCertificates(); $certs = OC_Mount_Config::getCertificates();
$fh_certs = fopen($path."/rootcerts.crt", 'w'); $fh_certs = fopen($path."/rootcerts.crt", 'w');

View File

@ -14,6 +14,7 @@ class DAV extends \OC\Files\Storage\Common{
private $host; private $host;
private $secure; private $secure;
private $root; private $root;
private $certPath;
private $ready; private $ready;
/** /**
* @var \Sabre_DAV_Client * @var \Sabre_DAV_Client
@ -40,6 +41,12 @@ class DAV extends \OC\Files\Storage\Common{
} else { } else {
$this->secure = false; $this->secure = false;
} }
if ($this->secure === true) {
$certPath=\OC_User::getHome(\OC_User::getUser()) . '/files_external/rootcerts.crt';
if (file_exists($certPath)) {
$this->certPath=$certPath;
}
}
$this->root=isset($params['root'])?$params['root']:'/'; $this->root=isset($params['root'])?$params['root']:'/';
if ( ! $this->root || $this->root[0]!='/') { if ( ! $this->root || $this->root[0]!='/') {
$this->root='/'.$this->root; $this->root='/'.$this->root;
@ -58,20 +65,16 @@ class DAV extends \OC\Files\Storage\Common{
} }
$this->ready = true; $this->ready = true;
$settings = array( $settings = array(
'baseUri' => $this->createBaseUri(), 'baseUri' => $this->createBaseUri(),
'userName' => $this->user, 'userName' => $this->user,
'password' => $this->password, 'password' => $this->password,
); );
$this->client = new \Sabre_DAV_Client($settings); $this->client = new \Sabre_DAV_Client($settings);
$caview = \OCP\Files::getStorage('files_external'); if ($this->secure === true && $this->certPath) {
if ($caview) { $this->client->addTrustedCertificates($this->certPath);
$certPath=\OCP\Config::getSystemValue('datadirectory').$caview->getAbsolutePath("").'rootcerts.crt';
if (file_exists($certPath)) {
$this->client->addTrustedCertificates($certPath);
}
} }
} }
@ -166,7 +169,14 @@ class DAV extends \OC\Files\Storage\Common{
curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().str_replace(' ', '%20', $path)); curl_setopt($curl, CURLOPT_URL, $this->createBaseUri().str_replace(' ', '%20', $path));
curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
if ($this->secure === true) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
if($this->certPath){
curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
}
}
curl_exec ($curl); curl_exec ($curl);
curl_close ($curl); curl_close ($curl);
rewind($fp); rewind($fp);
@ -254,6 +264,13 @@ class DAV extends \OC\Files\Storage\Common{
curl_setopt($curl, CURLOPT_INFILE, $source); // file pointer curl_setopt($curl, CURLOPT_INFILE, $source); // file pointer
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($path)); curl_setopt($curl, CURLOPT_INFILESIZE, filesize($path));
curl_setopt($curl, CURLOPT_PUT, true); curl_setopt($curl, CURLOPT_PUT, true);
if ($this->secure === true) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
if($this->certPath){
curl_setopt($curl, CURLOPT_CAINFO, $this->certPath);
}
}
curl_exec ($curl); curl_exec ($curl);
curl_close ($curl); curl_close ($curl);
} }
@ -331,3 +348,4 @@ class DAV extends \OC\Files\Storage\Common{
} }
} }
} }