diff options
Diffstat (limited to 'apps/files_external/lib')
-rw-r--r-- | apps/files_external/lib/amazons3.php | 2 | ||||
-rwxr-xr-x | apps/files_external/lib/config.php | 238 | ||||
-rwxr-xr-x | apps/files_external/lib/dropbox.php | 203 | ||||
-rw-r--r-- | apps/files_external/lib/ftp.php | 2 | ||||
-rw-r--r-- | apps/files_external/lib/google.php | 2 | ||||
-rw-r--r-- | apps/files_external/lib/smb.php | 20 | ||||
-rw-r--r-- | apps/files_external/lib/swift.php | 2 | ||||
-rw-r--r-- | apps/files_external/lib/webdav.php | 4 |
8 files changed, 465 insertions, 8 deletions
diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index e847ef143c3..b8e5b9b079b 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -20,7 +20,7 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ -require_once 'aws-sdk-1.5.5/sdk.class.php'; +require_once 'aws-sdk/sdk.class.php'; class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php new file mode 100755 index 00000000000..870c13b5aed --- /dev/null +++ b/apps/files_external/lib/config.php @@ -0,0 +1,238 @@ +<?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('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('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', '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 && $applicable != OCP\User::getUser()) { + return false; + } + $mountPoints = self::readData($isPersonal); + // Remove mount point + unset($mountPoints[$mountType][$applicable]['/$user/files/'.$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); + } + +} + +?>
\ No newline at end of file diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php new file mode 100755 index 00000000000..5e94277c6d4 --- /dev/null +++ b/apps/files_external/lib/dropbox.php @@ -0,0 +1,203 @@ +<?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/>. +*/ + +require_once 'Dropbox/autoload.php'; + +class OC_Filestorage_Dropbox extends OC_Filestorage_Common { + + private $dropbox; + private $metaData = array(); + + private static $tempFiles = array(); + + public function __construct($params) { + $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']); + $oauth->setToken($params['token'], $params['token_secret']); + $this->dropbox = new Dropbox_API($oauth, 'dropbox'); + + } + + private function getMetaData($path, $list = false) { + if (!$list && isset($this->metaData[$path])) { + return $this->metaData[$path]; + } else { + if ($list) { + $response = $this->dropbox->getMetaData($path); + if ($response && isset($response['contents'])) { + $contents = $response['contents']; + // Cache folder's contents + foreach ($contents as $file) { + $this->metaData[$path.'/'.basename($file['path'])] = $file; + } + unset($response['contents']); + $this->metaData[$path] = $response; + } + $this->metaData[$path] = $response; + // Return contents of folder only + return $contents; + } else { + try { + $response = $this->dropbox->getMetaData($path, 'false'); + $this->metaData[$path] = $response; + return $response; + } catch (Exception $exception) { + return false; + } + } + } + } + + public function mkdir($path) { + return $this->dropbox->createFolder($path); + } + + public function rmdir($path) { + return $this->dropbox->delete($path); + } + + public function opendir($path) { + if ($contents = $this->getMetaData($path, true)) { + $files = array(); + foreach ($contents as $file) { + $files[] = basename($file['path']); + } + OC_FakeDirStream::$dirs['dropbox'] = $files; + return opendir('fakedir://dropbox'); + } + return false; + } + + public function stat($path) { + if ($metaData = $this->getMetaData($path)) { + $stat['size'] = $metaData['bytes']; + $stat['atime'] = time(); + $stat['mtime'] = strtotime($metaData['modified']); + $stat['ctime'] = $stat['mtime']; + return $stat; + } + return false; + } + + public function filetype($path) { + if ($path == '' || $path == '/') { + return 'dir'; + } else if ($metaData = $this->getMetaData($path)) { + if ($metaData['is_dir'] == 'true') { + return 'dir'; + } else { + return 'file'; + } + } + return false; + } + + public function is_readable($path) { + return true; + } + + public function is_writable($path) { + return true; + } + + public function file_exists($path) { + if ($path == '' || $path == '/') { + return true; + } + if ($this->getMetaData($path)) { + return true; + } + return false; + } + + public function unlink($path) { + return $this->dropbox->delete($path); + } + + public function fopen($path, $mode) { + switch ($mode) { + case 'r': + case 'rb': + $tmpFile = OC_Helper::tmpFile(); + file_put_contents($tmpFile, $this->dropbox->getFile($path)); + return fopen($tmpFile, 'r'); + case 'w': + case 'wb': + case 'a': + case 'ab': + case 'r+': + case 'w+': + case 'wb+': + case 'a+': + case 'x': + case 'x+': + case 'c': + case 'c+': + if (strrpos($path, '.') !== false) { + $ext = substr($path, strrpos($path, '.')); + } else { + $ext = ''; + } + $tmpFile = OC_Helper::tmpFile($ext); + OC_CloseStreamWrapper::$callBacks[$tmpFile] = array($this, 'writeBack'); + if ($this->file_exists($path)) { + $source = $this->fopen($path, 'r'); + file_put_contents($tmpFile, $source); + } + self::$tempFiles[$tmpFile] = $path; + return fopen('close://'.$tmpFile, $mode); + } + return false; + } + + public function writeBack($tmpFile) { + if (isset(self::$tempFiles[$tmpFile])) { + $handle = fopen($tmpFile, 'r'); + $response = $this->dropbox->putFile(self::$tempFiles[$tmpFile], $handle); + if ($response) { + unlink($tmpFile); + } + } + } + + public function getMimeType($path) { + if ($this->filetype($path) == 'dir') { + return 'httpd/unix-directory'; + } else if ($metaData = $this->getMetaData($path)) { + return $metaData['mime_type']; + } + return false; + } + + public function free_space($path) { + if ($info = $this->dropbox->getAccountInfo()) { + return $info['quota_info']['quota'] - $info['quota_info']['normal']; + } + return false; + } + + public function touch($path, $mtime = null) { + return false; + } + +} + +?>
\ No newline at end of file diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index e9655ebf3a5..4d5ae670de5 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -21,7 +21,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index d2285a6d82c..c2a4af0ff8a 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -20,7 +20,7 @@ * License along with this library. If not, see <http://www.gnu.org/licenses/>. */ -require_once 'common.inc.php'; +require_once 'Google/common.inc.php'; class OC_Filestorage_Google extends OC_Filestorage_Common { diff --git a/apps/files_external/lib/smb.php b/apps/files_external/lib/smb.php index f5e6d78e776..9112655194a 100644 --- a/apps/files_external/lib/smb.php +++ b/apps/files_external/lib/smb.php @@ -13,6 +13,7 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ private $user; private $host; private $root; + private $share; private static $tempFiles=array(); @@ -20,17 +21,32 @@ class OC_FileStorage_SMB extends OC_FileStorage_StreamWrapper{ $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]!='/'){ + $this->root='/'.$this->root; + } + if(substr($this->root,-1,1)!='/'){ + $this->root.='/'; + } + if(!$this->share || $this->share[0]!='/'){ + $this->share='/'.$this->share; + } + if(substr($this->share,-1,1)=='/'){ + $this->share=substr($this->share,0,-1); + } //create the root folder if necesary - $this->mkdir(''); + if(!$this->is_dir('')){ + $this->mkdir(''); + } } public function constructUrl($path){ if(substr($path,-1)=='/'){ $path=substr($path,0,-1); } - return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path; + return 'smb://'.$this->user.':'.$this->password.'@'.$this->host.$this->share.$this->root.$path; } } diff --git a/apps/files_external/lib/swift.php b/apps/files_external/lib/swift.php index e3ba9c240cf..58b95a6ae01 100644 --- a/apps/files_external/lib/swift.php +++ b/apps/files_external/lib/swift.php @@ -269,7 +269,7 @@ class OC_FileStorage_SWIFT extends OC_Filestorage_Common{ $this->user=$params['user']; $this->root=isset($params['root'])?$params['root']:'/'; $this->secure=isset($params['secure'])?(bool)$params['secure']:true; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } $this->auth = new CF_Authentication($this->user, $this->token, null, $this->host); diff --git a/apps/files_external/lib/webdav.php b/apps/files_external/lib/webdav.php index 07c90d4878e..d136f04f3eb 100644 --- a/apps/files_external/lib/webdav.php +++ b/apps/files_external/lib/webdav.php @@ -25,7 +25,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ $this->password=$params['password']; $this->secure=isset($params['secure'])?(bool)$params['secure']:false; $this->root=isset($params['root'])?$params['root']:'/'; - if(substr($this->root,0,1)!='/'){ + if(!$this->root || $this->root[0]!='/'){ $this->root='/'.$this->root; } if(substr($this->root,-1,1)!='/'){ @@ -273,7 +273,7 @@ class OC_FileStorage_DAV extends OC_Filestorage_Common{ } private function cleanPath($path){ - if(substr($path,0,1)=='/'){ + if(!$path || $path[0]=='/'){ return substr($path,1); }else{ return $path; |