summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib')
-rwxr-xr-xapps/files_external/lib/config.php564
-rw-r--r--apps/files_external/lib/ftp.php20
-rw-r--r--apps/files_external/lib/smb.php36
-rw-r--r--apps/files_external/lib/streamwrapper.php34
-rw-r--r--apps/files_external/lib/swift.php172
-rw-r--r--apps/files_external/lib/webdav.php88
6 files changed, 456 insertions, 458 deletions
diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php
index f1bc16e2537..eec31ec2ef9 100755
--- a/apps/files_external/lib/config.php
+++ b/apps/files_external/lib/config.php
@@ -1,283 +1,281 @@
-<?php
-/**
-* ownCloud
-*
-* @author Michael Gapczynski
-* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
-* License as published by the Free Software Foundation; either
-* version 3 of the License, or any later version.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
-*
-* You should have received a copy of the GNU Affero General Public
-* License along with this library. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-/**
-* Class to configure the config/mount.php and data/$user/mount.php files
-*/
-class OC_Mount_Config {
-
- const MOUNT_TYPE_GLOBAL = 'global';
- const MOUNT_TYPE_GROUP = 'group';
- const MOUNT_TYPE_USER = 'user';
-
- /**
- * Get details on each of the external storage backends, used for the mount config UI
- * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded
- * If the configuration parameter should be secret, add a '*' to the beginning of the value
- * If the configuration parameter is a boolean, add a '!' to the beginning of the value
- * If the configuration parameter is optional, add a '&' to the beginning of the value
- * If the configuration parameter is hidden, add a '#' to the begining of the value
- * @return array
- */
- public static function getBackends() {
- return array(
- 'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
- 'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
- 'OC_Filestorage_Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('configured' => '#configured','app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'),
- 'OC_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
- 'OC_Filestorage_Google' => array('backend' => 'Google Drive', 'configuration' => array('configured' => '#configured', 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
- 'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
- 'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')),
- 'OC_Filestorage_DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
- );
- }
-
- /**
- * Get the system mount points
- * The returned array is not in the same format as getUserMountPoints()
- * @return array
- */
- public static function getSystemMountPoints() {
- $mountPoints = self::readData(false);
- $backends = self::getBackends();
- $system = array();
- if (isset($mountPoints[self::MOUNT_TYPE_GROUP])) {
- foreach ($mountPoints[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
- foreach ($mounts as $mountPoint => $mount) {
- // Remove '/$user/files/' from mount point
- $mountPoint = substr($mountPoint, 13);
- // Merge the mount point into the current mount points
- if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
- $system[$mountPoint]['applicable']['groups'] = array_merge($system[$mountPoint]['applicable']['groups'], array($group));
- } else {
- $system[$mountPoint] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], 'applicable' => array('groups' => array($group), 'users' => array()));
- }
- }
- }
- }
- if (isset($mountPoints[self::MOUNT_TYPE_USER])) {
- foreach ($mountPoints[self::MOUNT_TYPE_USER] as $user => $mounts) {
- foreach ($mounts as $mountPoint => $mount) {
- // Remove '/$user/files/' from mount point
- $mountPoint = substr($mountPoint, 13);
- // Merge the mount point into the current mount points
- if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
- $system[$mountPoint]['applicable']['users'] = array_merge($system[$mountPoint]['applicable']['users'], array($user));
- } else {
- $system[$mountPoint] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], 'applicable' => array('groups' => array(), 'users' => array($user)));
- }
- }
- }
- }
- return $system;
- }
-
- /**
- * Get the personal mount points of the current user
- * The returned array is not in the same format as getUserMountPoints()
- * @return array
- */
- public static function getPersonalMountPoints() {
- $mountPoints = self::readData(true);
- $backends = self::getBackends();
- $uid = OCP\User::getUser();
- $personal = array();
- if (isset($mountPoints[self::MOUNT_TYPE_USER][$uid])) {
- foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) {
- // Remove '/uid/files/' from mount point
- $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options']);
- }
- }
- return $personal;
- }
-
-
- /**
- * Add a mount point to the filesystem
- * @param string Mount point
- * @param string Backend class
- * @param array Backend parameters for the class
- * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
- * @param string User or group to apply mount to
- * @param bool Personal or system mount point i.e. is this being called from the personal or admin page
- * @return bool
- */
- public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false) {
- if ($isPersonal) {
- // Verify that the mount point applies for the current user
- // Prevent non-admin users from mounting local storage
- if ($applicable != OCP\User::getUser() || $class == 'OC_Filestorage_Local') {
- return false;
- }
- $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/');
- } else {
- $mountPoint = '/$user/files/'.ltrim($mountPoint, '/');
- }
- $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => $classOptions)));
- $mountPoints = self::readData($isPersonal);
- // Merge the new mount point into the current mount points
- if (isset($mountPoints[$mountType])) {
- if (isset($mountPoints[$mountType][$applicable])) {
- $mountPoints[$mountType][$applicable] = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]);
- } else {
- $mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount);
- }
- } else {
- $mountPoints[$mountType] = $mount;
- }
- self::writeData($isPersonal, $mountPoints);
- return true;
- }
-
- /**
- *
- * @param string Mount point
- * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
- * @param string User or group to remove mount from
- * @param bool Personal or system mount point
- * @return bool
- */
- public static function removeMountPoint($mountPoint, $mountType, $applicable, $isPersonal = false) {
- // Verify that the mount point applies for the current user
- if ($isPersonal) {
- if ($applicable != OCP\User::getUser()) {
- return false;
- }
- $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/');
- } else {
- $mountPoint = '/$user/files/'.ltrim($mountPoint, '/');
- }
- $mountPoints = self::readData($isPersonal);
- // Remove mount point
- unset($mountPoints[$mountType][$applicable][$mountPoint]);
- // Unset parent arrays if empty
- if (empty($mountPoints[$mountType][$applicable])) {
- unset($mountPoints[$mountType][$applicable]);
- if (empty($mountPoints[$mountType])) {
- unset($mountPoints[$mountType]);
- }
- }
- self::writeData($isPersonal, $mountPoints);
- return true;
- }
-
- /**
- * Read the mount points in the config file into an array
- * @param bool Personal or system config file
- * @return array
- */
- private static function readData($isPersonal) {
- if ($isPersonal) {
- $file = OC::$SERVERROOT.'/data/'.OCP\User::getUser().'/mount.php';
- } else {
- $file = OC::$SERVERROOT.'/config/mount.php';
- }
- if (is_file($file)) {
- $mountPoints = include($file);
- if (is_array($mountPoints)) {
- return $mountPoints;
- }
- }
- return array();
- }
-
- /**
- * Write the mount points to the config file
- * @param bool Personal or system config file
- * @param array Mount points
- */
- private static function writeData($isPersonal, $data) {
- if ($isPersonal) {
- $file = OC::$SERVERROOT.'/data/'.OCP\User::getUser().'/mount.php';
- } else {
- $file = OC::$SERVERROOT.'/config/mount.php';
- }
- $content = "<?php return array (\n";
- if (isset($data[self::MOUNT_TYPE_GROUP])) {
- $content .= "\t'group' => array (\n";
- foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
- $content .= "\t\t'".$group."' => array (\n";
- foreach ($mounts as $mountPoint => $mount) {
- $content .= "\t\t\t'".$mountPoint."' => ".str_replace("\n", '', var_export($mount, true)).",\n";
-
- }
- $content .= "\t\t),\n";
- }
- $content .= "\t),\n";
- }
- if (isset($data[self::MOUNT_TYPE_USER])) {
- $content .= "\t'user' => array (\n";
- foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) {
- $content .= "\t\t'".$user."' => array (\n";
- foreach ($mounts as $mountPoint => $mount) {
- $content .= "\t\t\t'".$mountPoint."' => ".str_replace("\n", '', var_export($mount, true)).",\n";
- }
- $content .= "\t\t),\n";
- }
- $content .= "\t),\n";
- }
- $content .= ");\n?>";
- @file_put_contents($file, $content);
- }
-
- /**
- * Returns all user uploaded ssl root certificates
- * @return array
- */
- public static function getCertificates() {
- $view = \OCP\Files::getStorage('files_external');
- $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
- if (!is_dir($path)) mkdir($path);
- $result = array();
- $handle = opendir($path);
- while (false !== ($file = readdir($handle))) {
- if($file != '.' && $file != '..') $result[] = $file;
- }
- return $result;
- }
-
- /**
- * creates certificate bundle
- */
- public static function createCertificateBundle() {
- $view = \OCP\Files::getStorage("files_external");
- $path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");
-
- $certs = OC_Mount_Config::getCertificates();
- $fh_certs = fopen($path."/rootcerts.crt", 'w');
- foreach ($certs as $cert) {
- $file=$path.'/uploads/'.$cert;
- $fh = fopen($file, "r");
- $data = fread($fh, filesize($file));
- fclose($fh);
- if (strpos($data, 'BEGIN CERTIFICATE')) {
- fwrite($fh_certs, $data);
- }
- }
-
- fclose($fh_certs);
-
- return true;
- }
-
-}
-
-?> \ No newline at end of file
+<?php
+/**
+* ownCloud
+*
+* @author Michael Gapczynski
+* @copyright 2012 Michael Gapczynski mtgap@owncloud.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+* Class to configure the config/mount.php and data/$user/mount.php files
+*/
+class OC_Mount_Config {
+
+ const MOUNT_TYPE_GLOBAL = 'global';
+ const MOUNT_TYPE_GROUP = 'group';
+ const MOUNT_TYPE_USER = 'user';
+
+ /**
+ * Get details on each of the external storage backends, used for the mount config UI
+ * If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded
+ * If the configuration parameter should be secret, add a '*' to the beginning of the value
+ * If the configuration parameter is a boolean, add a '!' to the beginning of the value
+ * If the configuration parameter is optional, add a '&' to the beginning of the value
+ * If the configuration parameter is hidden, add a '#' to the begining of the value
+ * @return array
+ */
+ public static function getBackends() {
+ return array(
+ 'OC_Filestorage_Local' => array('backend' => 'Local', 'configuration' => array('datadir' => 'Location')),
+ 'OC_Filestorage_AmazonS3' => array('backend' => 'Amazon S3', 'configuration' => array('key' => 'Key', 'secret' => '*Secret', 'bucket' => 'Bucket')),
+ 'OC_Filestorage_Dropbox' => array('backend' => 'Dropbox', 'configuration' => array('configured' => '#configured','app_key' => 'App key', 'app_secret' => 'App secret', 'token' => '#token', 'token_secret' => '#token_secret'), 'custom' => 'dropbox'),
+ 'OC_Filestorage_FTP' => array('backend' => 'FTP', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure ftps://')),
+ 'OC_Filestorage_Google' => array('backend' => 'Google Drive', 'configuration' => array('configured' => '#configured', 'token' => '#token', 'token_secret' => '#token secret'), 'custom' => 'google'),
+ 'OC_Filestorage_SWIFT' => array('backend' => 'OpenStack Swift', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'token' => '*Token', 'root' => '&Root', 'secure' => '!Secure ftps://')),
+ 'OC_Filestorage_SMB' => array('backend' => 'SMB', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'share' => 'Share', 'root' => '&Root')),
+ 'OC_Filestorage_DAV' => array('backend' => 'WebDAV', 'configuration' => array('host' => 'URL', 'user' => 'Username', 'password' => '*Password', 'root' => '&Root', 'secure' => '!Secure https://'))
+ );
+ }
+
+ /**
+ * Get the system mount points
+ * The returned array is not in the same format as getUserMountPoints()
+ * @return array
+ */
+ public static function getSystemMountPoints() {
+ $mountPoints = self::readData(false);
+ $backends = self::getBackends();
+ $system = array();
+ if (isset($mountPoints[self::MOUNT_TYPE_GROUP])) {
+ foreach ($mountPoints[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
+ foreach ($mounts as $mountPoint => $mount) {
+ // Remove '/$user/files/' from mount point
+ $mountPoint = substr($mountPoint, 13);
+ // Merge the mount point into the current mount points
+ if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
+ $system[$mountPoint]['applicable']['groups'] = array_merge($system[$mountPoint]['applicable']['groups'], array($group));
+ } else {
+ $system[$mountPoint] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], 'applicable' => array('groups' => array($group), 'users' => array()));
+ }
+ }
+ }
+ }
+ if (isset($mountPoints[self::MOUNT_TYPE_USER])) {
+ foreach ($mountPoints[self::MOUNT_TYPE_USER] as $user => $mounts) {
+ foreach ($mounts as $mountPoint => $mount) {
+ // Remove '/$user/files/' from mount point
+ $mountPoint = substr($mountPoint, 13);
+ // Merge the mount point into the current mount points
+ if (isset($system[$mountPoint]) && $system[$mountPoint]['configuration'] == $mount['options']) {
+ $system[$mountPoint]['applicable']['users'] = array_merge($system[$mountPoint]['applicable']['users'], array($user));
+ } else {
+ $system[$mountPoint] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options'], 'applicable' => array('groups' => array(), 'users' => array($user)));
+ }
+ }
+ }
+ }
+ return $system;
+ }
+
+ /**
+ * Get the personal mount points of the current user
+ * The returned array is not in the same format as getUserMountPoints()
+ * @return array
+ */
+ public static function getPersonalMountPoints() {
+ $mountPoints = self::readData(true);
+ $backends = self::getBackends();
+ $uid = OCP\User::getUser();
+ $personal = array();
+ if (isset($mountPoints[self::MOUNT_TYPE_USER][$uid])) {
+ foreach ($mountPoints[self::MOUNT_TYPE_USER][$uid] as $mountPoint => $mount) {
+ // Remove '/uid/files/' from mount point
+ $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'], 'backend' => $backends[$mount['class']]['backend'], 'configuration' => $mount['options']);
+ }
+ }
+ return $personal;
+ }
+
+
+ /**
+ * Add a mount point to the filesystem
+ * @param string Mount point
+ * @param string Backend class
+ * @param array Backend parameters for the class
+ * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
+ * @param string User or group to apply mount to
+ * @param bool Personal or system mount point i.e. is this being called from the personal or admin page
+ * @return bool
+ */
+ public static function addMountPoint($mountPoint, $class, $classOptions, $mountType, $applicable, $isPersonal = false) {
+ if ($isPersonal) {
+ // Verify that the mount point applies for the current user
+ // Prevent non-admin users from mounting local storage
+ if ($applicable != OCP\User::getUser() || $class == 'OC_Filestorage_Local') {
+ return false;
+ }
+ $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/');
+ } else {
+ $mountPoint = '/$user/files/'.ltrim($mountPoint, '/');
+ }
+ $mount = array($applicable => array($mountPoint => array('class' => $class, 'options' => $classOptions)));
+ $mountPoints = self::readData($isPersonal);
+ // Merge the new mount point into the current mount points
+ if (isset($mountPoints[$mountType])) {
+ if (isset($mountPoints[$mountType][$applicable])) {
+ $mountPoints[$mountType][$applicable] = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]);
+ } else {
+ $mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount);
+ }
+ } else {
+ $mountPoints[$mountType] = $mount;
+ }
+ self::writeData($isPersonal, $mountPoints);
+ return true;
+ }
+
+ /**
+ *
+ * @param string Mount point
+ * @param string MOUNT_TYPE_GROUP | MOUNT_TYPE_USER
+ * @param string User or group to remove mount from
+ * @param bool Personal or system mount point
+ * @return bool
+ */
+ public static function removeMountPoint($mountPoint, $mountType, $applicable, $isPersonal = false) {
+ // Verify that the mount point applies for the current user
+ if ($isPersonal) {
+ if ($applicable != OCP\User::getUser()) {
+ return false;
+ }
+ $mountPoint = '/'.$applicable.'/files/'.ltrim($mountPoint, '/');
+ } else {
+ $mountPoint = '/$user/files/'.ltrim($mountPoint, '/');
+ }
+ $mountPoints = self::readData($isPersonal);
+ // Remove mount point
+ unset($mountPoints[$mountType][$applicable][$mountPoint]);
+ // Unset parent arrays if empty
+ if (empty($mountPoints[$mountType][$applicable])) {
+ unset($mountPoints[$mountType][$applicable]);
+ if (empty($mountPoints[$mountType])) {
+ unset($mountPoints[$mountType]);
+ }
+ }
+ self::writeData($isPersonal, $mountPoints);
+ return true;
+ }
+
+ /**
+ * Read the mount points in the config file into an array
+ * @param bool Personal or system config file
+ * @return array
+ */
+ private static function readData($isPersonal) {
+ if ($isPersonal) {
+ $file = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+ } else {
+ $file = OC::$SERVERROOT.'/config/mount.php';
+ }
+ if (is_file($file)) {
+ $mountPoints = include($file);
+ if (is_array($mountPoints)) {
+ return $mountPoints;
+ }
+ }
+ return array();
+ }
+
+ /**
+ * Write the mount points to the config file
+ * @param bool Personal or system config file
+ * @param array Mount points
+ */
+ private static function writeData($isPersonal, $data) {
+ if ($isPersonal) {
+ $file = OC_User::getHome(OCP\User::getUser()).'/mount.php';
+ } else {
+ $file = OC::$SERVERROOT.'/config/mount.php';
+ }
+ $content = "<?php return array (\n";
+ if (isset($data[self::MOUNT_TYPE_GROUP])) {
+ $content .= "\t'group' => array (\n";
+ foreach ($data[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
+ $content .= "\t\t'".$group."' => array (\n";
+ foreach ($mounts as $mountPoint => $mount) {
+ $content .= "\t\t\t'".$mountPoint."' => ".str_replace("\n", '', var_export($mount, true)).",\n";
+
+ }
+ $content .= "\t\t),\n";
+ }
+ $content .= "\t),\n";
+ }
+ if (isset($data[self::MOUNT_TYPE_USER])) {
+ $content .= "\t'user' => array (\n";
+ foreach ($data[self::MOUNT_TYPE_USER] as $user => $mounts) {
+ $content .= "\t\t'".$user."' => array (\n";
+ foreach ($mounts as $mountPoint => $mount) {
+ $content .= "\t\t\t'".$mountPoint."' => ".str_replace("\n", '', var_export($mount, true)).",\n";
+ }
+ $content .= "\t\t),\n";
+ }
+ $content .= "\t),\n";
+ }
+ $content .= ");\n?>";
+ @file_put_contents($file, $content);
+ }
+
+ /**
+ * Returns all user uploaded ssl root certificates
+ * @return array
+ */
+ public static function getCertificates() {
+ $view = \OCP\Files::getStorage('files_external');
+ $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/';
+ if (!is_dir($path)) mkdir($path);
+ $result = array();
+ $handle = opendir($path);
+ while (false !== ($file = readdir($handle))) {
+ if($file != '.' && $file != '..') $result[] = $file;
+ }
+ return $result;
+ }
+
+ /**
+ * creates certificate bundle
+ */
+ public static function createCertificateBundle() {
+ $view = \OCP\Files::getStorage("files_external");
+ $path = \OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("");
+
+ $certs = OC_Mount_Config::getCertificates();
+ $fh_certs = fopen($path."/rootcerts.crt", 'w');
+ foreach ($certs as $cert) {
+ $file=$path.'/uploads/'.$cert;
+ $fh = fopen($file, "r");
+ $data = fread($fh, filesize($file));
+ fclose($fh);
+ if (strpos($data, 'BEGIN CERTIFICATE')) {
+ fwrite($fh_certs, $data);
+ }
+ }
+
+ fclose($fh_certs);
+
+ return true;
+ }
+
+}
diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php
index 818273f6c2d..261141455cc 100644
--- a/apps/files_external/lib/ftp.php
+++ b/apps/files_external/lib/ftp.php
@@ -15,13 +15,13 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
private static $tempFiles=array();
- public function __construct($params){
+ public function __construct($params) {
$this->host=$params['host'];
$this->user=$params['user'];
$this->password=$params['password'];
$this->secure=isset($params['secure'])?(bool)$params['secure']:false;
$this->root=isset($params['root'])?$params['root']:'/';
- if(!$this->root || $this->root[0]!='/'){
+ if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
//create the root folder if necesary
@@ -35,16 +35,16 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
* @param string path
* @return string
*/
- public function constructUrl($path){
+ public function constructUrl($path) {
$url='ftp';
- if($this->secure){
+ if($this->secure) {
$url.='s';
}
$url.='://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path;
return $url;
}
- public function fopen($path,$mode){
- switch($mode){
+ public function fopen($path,$mode) {
+ switch($mode) {
case 'r':
case 'rb':
case 'w':
@@ -63,14 +63,14 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
case 'c':
case 'c+':
//emulate these
- if(strrpos($path,'.')!==false){
+ if(strrpos($path,'.')!==false) {
$ext=substr($path,strrpos($path,'.'));
}else{
$ext='';
}
$tmpFile=OCP\Files::tmpFile($ext);
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
- if($this->file_exists($path)){
+ if($this->file_exists($path)) {
$this->getFile($path,$tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
@@ -78,8 +78,8 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{
}
}
- public function writeBack($tmpFile){
- if(isset(self::$tempFiles[$tmpFile])){
+ public function writeBack($tmpFile) {
+ if(isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile,self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php
index 8a5e993b1d0..e5ba7a17743 100644
--- a/apps/files_external/lib/smb.php
+++ b/apps/files_external/lib/smb.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-require_once('smb4php/smb.php');
+require_once 'smb4php/smb.php';
class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
private $password;
@@ -15,40 +15,40 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
private $root;
private $share;
- public function __construct($params){
+ public function __construct($params) {
$this->host=$params['host'];
$this->user=$params['user'];
$this->password=$params['password'];
$this->share=$params['share'];
$this->root=isset($params['root'])?$params['root']:'/';
- if(!$this->root || $this->root[0]!='/'){
+ if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
- if(substr($this->root,-1,1)!='/'){
+ if(substr($this->root,-1,1)!='/') {
$this->root.='/';
}
- if(!$this->share || $this->share[0]!='/'){
+ if(!$this->share || $this->share[0]!='/') {
$this->share='/'.$this->share;
}
- if(substr($this->share,-1,1)=='/'){
+ if(substr($this->share,-1,1)=='/') {
$this->share=substr($this->share,0,-1);
}
//create the root folder if necesary
- if(!$this->is_dir('')){
+ if(!$this->is_dir('')) {
$this->mkdir('');
}
}
- public function constructUrl($path){
- if(substr($path,-1)=='/'){
+ public function constructUrl($path) {
+ if(substr($path,-1)=='/') {
$path=substr($path,0,-1);
}
return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->share.$this->root.$path;
}
- public function stat($path){
- if(!$path and $this->root=='/'){//mtime doesn't work for shares
+ public function stat($path) {
+ if(!$path and $this->root=='/') {//mtime doesn't work for shares
$mtime=$this->shareMTime();
$stat=stat($this->constructUrl($path));
$stat['mtime']=$mtime;
@@ -58,7 +58,7 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
}
}
- public function filetype($path){
+ public function filetype($path) {
return (bool)@$this->opendir($path);//using opendir causes the same amount of requests and caches the content of the folder in one go
}
@@ -67,8 +67,8 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
* @param int $time
* @return bool
*/
- public function hasUpdated($path,$time){
- if(!$path and $this->root=='/'){
+ public function hasUpdated($path,$time) {
+ if(!$path and $this->root=='/') {
//mtime doesn't work for shares, but giving the nature of the backend, doing a full update is still just fast enough
return true;
}else{
@@ -80,13 +80,13 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{
/**
* get the best guess for the modification time of the share
*/
- private function shareMTime(){
+ private function shareMTime() {
$dh=$this->opendir('');
$lastCtime=0;
- while($file=readdir($dh)){
- if($file!='.' and $file!='..'){
+ while($file=readdir($dh)) {
+ if($file!='.' and $file!='..') {
$ctime=$this->filemtime($file);
- if($ctime>$lastCtime){
+ if($ctime>$lastCtime) {
$lastCtime=$ctime;
}
}
diff --git a/apps/files_external/lib/streamwrapper.php b/apps/files_external/lib/streamwrapper.php
index 467c5a5b845..7263ef23253 100644
--- a/apps/files_external/lib/streamwrapper.php
+++ b/apps/files_external/lib/streamwrapper.php
@@ -10,12 +10,12 @@
abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
abstract public function constructUrl($path);
- public function mkdir($path){
+ public function mkdir($path) {
return mkdir($this->constructUrl($path));
}
- public function rmdir($path){
- if($this->file_exists($path)){
+ public function rmdir($path) {
+ if($this->file_exists($path)) {
$succes=rmdir($this->constructUrl($path));
clearstatcache();
return $succes;
@@ -24,42 +24,42 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
}
}
- public function opendir($path){
+ public function opendir($path) {
return opendir($this->constructUrl($path));
}
- public function filetype($path){
+ public function filetype($path) {
return filetype($this->constructUrl($path));
}
- public function isReadable($path){
+ public function isReadable($path) {
return true;//not properly supported
}
- public function isUpdatable($path){
+ public function isUpdatable($path) {
return true;//not properly supported
}
- public function file_exists($path){
+ public function file_exists($path) {
return file_exists($this->constructUrl($path));
}
- public function unlink($path){
+ public function unlink($path) {
$succes=unlink($this->constructUrl($path));
clearstatcache();
return $succes;
}
- public function fopen($path,$mode){
+ public function fopen($path,$mode) {
return fopen($this->constructUrl($path),$mode);
}
- public function free_space($path){
+ public function free_space($path) {
return 0;
}
- public function touch($path,$mtime=null){
- if(is_null($mtime)){
+ public function touch($path,$mtime=null) {
+ if(is_null($mtime)) {
$fh=$this->fopen($path,'a');
fwrite($fh,'');
fclose($fh);
@@ -68,19 +68,19 @@ abstract class OC_FileStorage_StreamWrapper extends OC_Filestorage_Common{
}
}
- public function getFile($path,$target){
+ public function getFile($path,$target) {
return copy($this->constructUrl($path),$target);
}
- public function uploadFile($path,$target){
+ public function uploadFile($path,$target) {
return copy($path,$this->constructUrl($target));
}
- public function rename($path1,$path2){
+ public function rename($path1,$path2) {
return rename($this->constructUrl($path1),$this->constructUrl($path2));
}
- public function stat($path){
+ public function stat($path) {
return stat($this->constructUrl($path));
}
diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php
index 1868bc4ba77..c29d28b44c1 100644
--- a/apps/files_external/lib/swift.php
+++ b/apps/files_external/lib/swift.php
@@ -6,7 +6,7 @@
* See the COPYING-README file.
*/
-require_once('php-cloudfiles/cloudfiles.php');
+require_once 'php-cloudfiles/cloudfiles.php';
class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
private $host;
@@ -38,7 +38,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string path
* @return string
*/
- private function getContainerName($path){
+ private function getContainerName($path) {
$path=trim($this->root.$path,'/');
return str_replace('/','\\',$path);
}
@@ -48,18 +48,18 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string path
* @return CF_Container
*/
- private function getContainer($path){
- if($path=='' or $path=='/'){
+ private function getContainer($path) {
+ if($path=='' or $path=='/') {
return $this->rootContainer;
}
- if(isset($this->containers[$path])){
+ if(isset($this->containers[$path])) {
return $this->containers[$path];
}
try{
$container=$this->conn->get_container($this->getContainerName($path));
$this->containers[$path]=$container;
return $container;
- }catch(NoSuchContainerException $e){
+ }catch(NoSuchContainerException $e) {
return null;
}
}
@@ -69,15 +69,15 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string path
* @return CF_Container
*/
- private function createContainer($path){
- if($path=='' or $path=='/'){
+ private function createContainer($path) {
+ if($path=='' or $path=='/') {
return $this->conn->create_container($this->getContainerName($path));
}
$parent=dirname($path);
- if($parent=='' or $parent=='/'){
+ if($parent=='' or $parent=='/') {
$parentContainer=$this->rootContainer;
}else{
- if(!$this->containerExists($parent)){
+ if(!$this->containerExists($parent)) {
$parentContainer=$this->createContainer($parent);
}else{
$parentContainer=$this->getContainer($parent);
@@ -92,19 +92,19 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string path
* @return CF_Object
*/
- private function getObject($path){
- if(isset($this->objects[$path])){
+ private function getObject($path) {
+ if(isset($this->objects[$path])) {
return $this->objects[$path];
}
$container=$this->getContainer(dirname($path));
- if(is_null($container)){
+ if(is_null($container)) {
return null;
}else{
try{
$obj=$container->get_object(basename($path));
$this->objects[$path]=$obj;
return $obj;
- }catch(NoSuchObjectException $e){
+ }catch(NoSuchObjectException $e) {
return null;
}
}
@@ -115,12 +115,12 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param CF_Container
* @return array
*/
- private function getObjects($container){
- if(is_null($container)){
+ private function getObjects($container) {
+ if(is_null($container)) {
return array();
}else{
$files=$container->get_objects();
- foreach($files as &$file){
+ foreach($files as &$file) {
$file=$file->name;
}
return $files;
@@ -132,9 +132,9 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string path
* @return CF_Object
*/
- private function createObject($path){
+ private function createObject($path) {
$container=$this->getContainer(dirname($path));
- if(!is_null($container)){
+ if(!is_null($container)) {
$container=$this->createContainer($path);
}
return $container->create_object(basename($path));
@@ -145,7 +145,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string
* @return bool
*/
- private function objectExists($path){
+ private function objectExists($path) {
return !is_null($this->getObject($path));
}
@@ -154,7 +154,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string path
* @return bool
*/
- private function containerExists($path){
+ private function containerExists($path) {
return !is_null($this->getContainer($path));
}
@@ -163,18 +163,18 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param CF_Container container
* @return array
*/
- private function getSubContainers($container){
+ private function getSubContainers($container) {
$tmpFile=OCP\Files::tmpFile();
$obj=$this->getSubContainerFile($container);
try{
$obj->save_to_filename($tmpFile);
- }catch(Exception $e){
+ }catch(Exception $e) {
return array();
}
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
unlink($tmpFile);
- foreach($containers as &$sub){
+ foreach($containers as &$sub) {
$sub=trim($sub);
}
return $containers;
@@ -186,8 +186,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string name
* @return bool
*/
- private function addSubContainer($container,$name){
- if(!$name){
+ private function addSubContainer($container,$name) {
+ if(!$name) {
return false;
}
$tmpFile=OCP\Files::tmpFile();
@@ -195,17 +195,17 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
try{
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
- foreach($containers as &$sub){
+ foreach($containers as &$sub) {
$sub=trim($sub);
}
- if(array_search($name,$containers)!==false){
+ if(array_search($name,$containers)!==false) {
unlink($tmpFile);
return false;
}else{
$fh=fopen($tmpFile,'a');
fwrite($fh,$name."\n");
}
- }catch(Exception $e){
+ }catch(Exception $e) {
$containers=array();
file_put_contents($tmpFile,$name."\n");
}
@@ -221,8 +221,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param string name
* @return bool
*/
- private function removeSubContainer($container,$name){
- if(!$name){
+ private function removeSubContainer($container,$name) {
+ if(!$name) {
return false;
}
$tmpFile=OCP\Files::tmpFile();
@@ -230,14 +230,14 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
try{
$obj->save_to_filename($tmpFile);
$containers=file($tmpFile);
- }catch(Exception $e){
+ }catch(Exception $e) {
return false;
}
- foreach($containers as &$sub){
+ foreach($containers as &$sub) {
$sub=trim($sub);
}
$i=array_search($name,$containers);
- if($i===false){
+ if($i===false) {
unlink($tmpFile);
return false;
}else{
@@ -255,21 +255,21 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* @param CF_Container container
* @return CF_Object
*/
- private function getSubContainerFile($container){
+ private function getSubContainerFile($container) {
try{
return $container->get_object(self::SUBCONTAINER_FILE);
- }catch(NoSuchObjectException $e){
+ }catch(NoSuchObjectException $e) {
return $container->create_object(self::SUBCONTAINER_FILE);
}
}
- public function __construct($params){
+ public function __construct($params) {
$this->token=$params['token'];
$this->host=$params['host'];
$this->user=$params['user'];
$this->root=isset($params['root'])?$params['root']:'/';
$this->secure=isset($params['secure'])?(bool)$params['secure']:true;
- if(!$this->root || $this->root[0]!='/'){
+ if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
$this->auth = new CF_Authentication($this->user, $this->token, null, $this->host);
@@ -277,7 +277,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$this->conn = new CF_Connection($this->auth);
- if(!$this->containerExists($this->root)){
+ if(!$this->containerExists($this->root)) {
$this->rootContainer=$this->createContainer('/');
}else{
$this->rootContainer=$this->getContainer('/');
@@ -285,8 +285,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
- public function mkdir($path){
- if($this->containerExists($path)){
+ public function mkdir($path) {
+ if($this->containerExists($path)) {
return false;
}else{
$this->createContainer($path);
@@ -294,12 +294,12 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
- public function rmdir($path){
- if(!$this->containerExists($path)){
+ public function rmdir($path) {
+ if(!$this->containerExists($path)) {
return false;
}else{
$this->emptyContainer($path);
- if($path!='' and $path!='/'){
+ if($path!='' and $path!='/') {
$parentContainer=$this->getContainer(dirname($path));
$this->removeSubContainer($parentContainer,basename($path));
}
@@ -310,14 +310,14 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
- private function emptyContainer($path){
+ private function emptyContainer($path) {
$container=$this->getContainer($path);
- if(is_null($container)){
+ if(is_null($container)) {
return;
}
$subContainers=$this->getSubContainers($container);
- foreach($subContainers as $sub){
- if($sub){
+ foreach($subContainers as $sub) {
+ if($sub) {
$this->emptyContainer($path.'/'.$sub);
$this->conn->delete_container($this->getContainerName($path.'/'.$sub));
unset($this->containers[$path.'/'.$sub]);
@@ -325,17 +325,17 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
$objects=$this->getObjects($container);
- foreach($objects as $object){
+ foreach($objects as $object) {
$container->delete_object($object);
unset($this->objects[$path.'/'.$object]);
}
}
- public function opendir($path){
+ public function opendir($path) {
$container=$this->getContainer($path);
$files=$this->getObjects($container);
$i=array_search(self::SUBCONTAINER_FILE,$files);
- if($i!==false){
+ if($i!==false) {
unset($files[$i]);
}
$subContainers=$this->getSubContainers($container);
@@ -345,43 +345,43 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
return opendir('fakedir://'.$id);
}
- public function filetype($path){
- if($this->containerExists($path)){
+ public function filetype($path) {
+ if($this->containerExists($path)) {
return 'dir';
}else{
return 'file';
}
}
- public function isReadable($path){
+ public function isReadable($path) {
return true;
}
- public function isUpdatable($path){
+ public function isUpdatable($path) {
return true;
}
- public function file_exists($path){
- if($this->is_dir($path)){
+ public function file_exists($path) {
+ if($this->is_dir($path)) {
return true;
}else{
return $this->objectExists($path);
}
}
- public function file_get_contents($path){
+ public function file_get_contents($path) {
$obj=$this->getObject($path);
- if(is_null($obj)){
+ if(is_null($obj)) {
return false;
}
return $obj->read();
}
- public function file_put_contents($path,$content){
+ public function file_put_contents($path,$content) {
$obj=$this->getObject($path);
- if(is_null($obj)){
+ if(is_null($obj)) {
$container=$this->getContainer(dirname($path));
- if(is_null($container)){
+ if(is_null($container)) {
return false;
}
$obj=$container->create_object(basename($path));
@@ -390,8 +390,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
return $obj->write($content);
}
- public function unlink($path){
- if($this->objectExists($path)){
+ public function unlink($path) {
+ if($this->objectExists($path)) {
$container=$this->getContainer(dirname($path));
$container->delete_object(basename($path));
unset($this->objects[$path]);
@@ -400,12 +400,12 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
- public function fopen($path,$mode){
+ public function fopen($path,$mode) {
$obj=$this->getObject($path);
- if(is_null($obj)){
+ if(is_null($obj)) {
return false;
}
- switch($mode){
+ switch($mode) {
case 'r':
case 'rb':
$fp = fopen('php://temp', 'r+');
@@ -432,23 +432,23 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
- public function writeBack($tmpFile){
- if(isset(self::$tempFiles[$tmpFile])){
+ public function writeBack($tmpFile) {
+ if(isset(self::$tempFiles[$tmpFile])) {
$this->fromTmpFile($tmpFile,self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
}
- public function free_space($path){
+ public function free_space($path) {
return 0;
}
- public function touch($path,$mtime=null){
+ public function touch($path,$mtime=null) {
$obj=$this->getObject($path);
- if(is_null($obj)){
+ if(is_null($obj)) {
return false;
}
- if(is_null($mtime)){
+ if(is_null($mtime)) {
$mtime=time();
}
@@ -457,36 +457,36 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
$obj->sync_metadata();
}
- public function rename($path1,$path2){
+ public function rename($path1,$path2) {
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
$result=$sourceContainer->move_object_to(basename($path1),$targetContainer,basename($path2));
unset($this->objects[$path1]);
- if($result){
+ if($result) {
$targetObj=$this->getObject($path2);
$this->resetMTime($targetObj);
}
return $result;
}
- public function copy($path1,$path2){
+ public function copy($path1,$path2) {
$sourceContainer=$this->getContainer(dirname($path1));
$targetContainer=$this->getContainer(dirname($path2));
$result=$sourceContainer->copy_object_to(basename($path1),$targetContainer,basename($path2));
- if($result){
+ if($result) {
$targetObj=$this->getObject($path2);
$this->resetMTime($targetObj);
}
return $result;
}
- public function stat($path){
+ public function stat($path) {
$obj=$this->getObject($path);
- if(is_null($obj)){
+ if(is_null($obj)) {
return false;
}
- if(isset($obj->metadata['Mtime']) and $obj->metadata['Mtime']>-1){
+ if(isset($obj->metadata['Mtime']) and $obj->metadata['Mtime']>-1) {
$mtime=$obj->metadata['Mtime'];
}else{
$mtime=strtotime($obj->last_modified);
@@ -498,9 +498,9 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
);
}
- private function getTmpFile($path){
+ private function getTmpFile($path) {
$obj=$this->getObject($path);
- if(!is_null($obj)){
+ if(!is_null($obj)) {
$tmpFile=OCP\Files::tmpFile();
$obj->save_to_filename($tmpFile);
return $tmpFile;
@@ -509,9 +509,9 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
}
}
- private function fromTmpFile($tmpFile,$path){
+ private function fromTmpFile($tmpFile,$path) {
$obj=$this->getObject($path);
- if(is_null($obj)){
+ if(is_null($obj)) {
$obj=$this->createObject($path);
}
$obj->load_from_filename($tmpFile);
@@ -522,8 +522,8 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{
* remove custom mtime metadata
* @param CF_Object obj
*/
- private function resetMTime($obj){
- if(isset($obj->metadata['Mtime'])){
+ private function resetMTime($obj) {
+ if(isset($obj->metadata['Mtime'])) {
$obj->metadata['Mtime']=-1;
$obj->sync_metadata();
}
diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php
index 1b9c3e3333b..3c18b227fa6 100644
--- a/apps/files_external/lib/webdav.php
+++ b/apps/files_external/lib/webdav.php
@@ -19,7 +19,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
private static $tempFiles=array();
- public function __construct($params){
+ public function __construct($params) {
$host = $params['host'];
//remove leading http[s], will be generated in createBaseUri()
if (substr($host,0,8) == "https://") $host = substr($host, 8);
@@ -29,10 +29,10 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->password=$params['password'];
$this->secure=(isset($params['secure']) && $params['secure'] == 'true')?true:false;
$this->root=isset($params['root'])?$params['root']:'/';
- if(!$this->root || $this->root[0]!='/'){
+ if(!$this->root || $this->root[0]!='/') {
$this->root='/'.$this->root;
}
- if(substr($this->root,-1,1)!='/'){
+ if(substr($this->root,-1,1)!='/') {
$this->root.='/';
}
@@ -54,26 +54,26 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
$this->mkdir('');
}
- private function createBaseUri(){
+ private function createBaseUri() {
$baseUri='http';
- if($this->secure){
+ if($this->secure) {
$baseUri.='s';
}
$baseUri.='://'.$this->host.$this->root;
return $baseUri;
}
- public function mkdir($path){
+ public function mkdir($path) {
$path=$this->cleanPath($path);
return $this->simpleResponse('MKCOL',$path,null,201);
}
- public function rmdir($path){
+ public function rmdir($path) {
$path=$this->cleanPath($path);
return $this->simpleResponse('DELETE',$path,null,204);
}
- public function opendir($path){
+ public function opendir($path) {
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array(),1);
@@ -81,54 +81,54 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
OC_FakeDirStream::$dirs[$id]=array();
$files=array_keys($response);
array_shift($files);//the first entry is the current directory
- foreach($files as $file){
+ foreach($files as $file) {
$file = urldecode(basename($file));
OC_FakeDirStream::$dirs[$id][]=$file;
}
return opendir('fakedir://'.$id);
- }catch(Exception $e){
+ }catch(Exception $e) {
return false;
}
}
- public function filetype($path){
+ public function filetype($path) {
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}resourcetype'));
$responseType=$response["{DAV:}resourcetype"]->resourceType;
return (count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file';
- }catch(Exception $e){
+ }catch(Exception $e) {
error_log($e->getMessage());
\OCP\Util::writeLog("webdav client", \OCP\Util::sanitizeHTML($e->getMessage()), \OCP\Util::ERROR);
return false;
}
}
- public function isReadable($path){
+ public function isReadable($path) {
return true;//not properly supported
}
- public function isUpdatable($path){
+ public function isUpdatable($path) {
return true;//not properly supported
}
- public function file_exists($path){
+ public function file_exists($path) {
$path=$this->cleanPath($path);
try{
$this->client->propfind($path, array('{DAV:}resourcetype'));
return true;//no 404 exception
- }catch(Exception $e){
+ }catch(Exception $e) {
return false;
}
}
- public function unlink($path){
+ public function unlink($path) {
return $this->simpleResponse('DELETE',$path,null,204);
}
- public function fopen($path,$mode){
+ public function fopen($path,$mode) {
$path=$this->cleanPath($path);
- switch($mode){
+ switch($mode) {
case 'r':
case 'rb':
//straight up curl instead of sabredav here, sabredav put's the entire get result in memory
@@ -155,14 +155,14 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
case 'c':
case 'c+':
//emulate these
- if(strrpos($path,'.')!==false){
+ if(strrpos($path,'.')!==false) {
$ext=substr($path,strrpos($path,'.'));
}else{
$ext='';
}
$tmpFile=OCP\Files::tmpFile($ext);
OC_CloseStreamWrapper::$callBacks[$tmpFile]=array($this,'writeBack');
- if($this->file_exists($path)){
+ if($this->file_exists($path)) {
$this->getFile($path,$tmpFile);
}
self::$tempFiles[$tmpFile]=$path;
@@ -170,41 +170,41 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
}
- public function writeBack($tmpFile){
- if(isset(self::$tempFiles[$tmpFile])){
+ public function writeBack($tmpFile) {
+ if(isset(self::$tempFiles[$tmpFile])) {
$this->uploadFile($tmpFile,self::$tempFiles[$tmpFile]);
unlink($tmpFile);
}
}
- public function free_space($path){
+ public function free_space($path) {
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}quota-available-bytes'));
- if(isset($response['{DAV:}quota-available-bytes'])){
+ if(isset($response['{DAV:}quota-available-bytes'])) {
return (int)$response['{DAV:}quota-available-bytes'];
}else{
return 0;
}
- }catch(Exception $e){
+ }catch(Exception $e) {
return 0;
}
}
- public function touch($path,$mtime=null){
- if(is_null($mtime)){
+ public function touch($path,$mtime=null) {
+ if(is_null($mtime)) {
$mtime=time();
}
$path=$this->cleanPath($path);
$this->client->proppatch($path, array('{DAV:}lastmodified' => $mtime));
}
- public function getFile($path,$target){
+ public function getFile($path,$target) {
$source=$this->fopen($path,'r');
file_put_contents($target,$source);
}
- public function uploadFile($path,$target){
+ public function uploadFile($path,$target) {
$source=fopen($path,'r');
$curl = curl_init();
@@ -218,13 +218,13 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
curl_close ($curl);
}
- public function rename($path1,$path2){
+ public function rename($path1,$path2) {
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
try{
$response=$this->client->request('MOVE',$path1,null,array('Destination'=>$path2));
return true;
- }catch(Exception $e){
+ }catch(Exception $e) {
echo $e;
echo 'fail';
var_dump($response);
@@ -232,13 +232,13 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
}
- public function copy($path1,$path2){
+ public function copy($path1,$path2) {
$path1=$this->cleanPath($path1);
$path2=$this->root.$this->cleanPath($path2);
try{
$response=$this->client->request('COPY',$path1,null,array('Destination'=>$path2));
return true;
- }catch(Exception $e){
+ }catch(Exception $e) {
echo $e;
echo 'fail';
var_dump($response);
@@ -246,7 +246,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
}
}
- public function stat($path){
+ public function stat($path) {
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}getlastmodified','{DAV:}getcontentlength'));
@@ -255,43 +255,43 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{
'size'=>(int)isset($response['{DAV:}getcontentlength']) ? $response['{DAV:}getcontentlength'] : 0,
'ctime'=>-1,
);
- }catch(Exception $e){
+ }catch(Exception $e) {
return array();
}
}
- public function getMimeType($path){
+ public function getMimeType($path) {
$path=$this->cleanPath($path);
try{
$response=$this->client->propfind($path, array('{DAV:}getcontenttype','{DAV:}resourcetype'));
$responseType=$response["{DAV:}resourcetype"]->resourceType;
$type=(count($responseType)>0 and $responseType[0]=="{DAV:}collection")?'dir':'file';
- if($type=='dir'){
+ if($type=='dir') {
return 'httpd/unix-directory';
- }elseif(isset($response['{DAV:}getcontenttype'])){
+ }elseif(isset($response['{DAV:}getcontenttype'])) {
return $response['{DAV:}getcontenttype'];
}else{
return false;
}
- }catch(Exception $e){
+ }catch(Exception $e) {
return false;
}
}
- private function cleanPath($path){
- if(!$path || $path[0]=='/'){
+ private function cleanPath($path) {
+ if(!$path || $path[0]=='/') {
return substr($path,1);
}else{
return $path;
}
}
- private function simpleResponse($method,$path,$body,$expected){
+ private function simpleResponse($method,$path,$body,$expected) {
$path=$this->cleanPath($path);
try{
$response=$this->client->request($method,$path,$body);
return $response['statusCode']==$expected;
- }catch(Exception $e){
+ }catch(Exception $e) {
return false;
}
}