diff --git a/apps/files_encryption/appinfo/app.php b/apps/files_encryption/appinfo/app.php index 3f76e910a5..2a30d0beb6 100644 --- a/apps/files_encryption/appinfo/app.php +++ b/apps/files_encryption/appinfo/app.php @@ -10,10 +10,12 @@ OCP\Util::connectHook('OC_User', 'post_login', 'OC_Crypt', 'loginListener'); stream_wrapper_register('crypt', 'OC_CryptStream'); -if(!isset($_SESSION['enckey']) and OCP\User::isLoggedIn()) {//force the user to re-loggin if the encryption key isn't unlocked (happens when a user is logged in before the encryption app is enabled) +// force the user to re-loggin if the encryption key isn't unlocked +// (happens when a user is logged in before the encryption app is enabled) +if ( ! isset($_SESSION['enckey']) and OCP\User::isLoggedIn()) { OCP\User::logout(); header("Location: ".OC::$WEBROOT.'/'); exit(); } -OCP\App::registerAdmin('files_encryption', 'settings'); +OCP\App::registerAdmin('files_encryption', 'settings'); \ No newline at end of file diff --git a/apps/files_encryption/lib/crypt.php b/apps/files_encryption/lib/crypt.php index 5ff3f57838..666fedb4e1 100644 --- a/apps/files_encryption/lib/crypt.php +++ b/apps/files_encryption/lib/crypt.php @@ -27,7 +27,8 @@ // - Setting if crypto should be on by default // - Add a setting "DonĀ“t encrypt files larger than xx because of performance reasons" // - Transparent decrypt/encrypt in filesystem.php. Autodetect if a file is encrypted (.encrypted extension) -// - Don't use a password directly as encryption key. but a key which is stored on the server and encrypted with the user password. -> password change faster +// - Don't use a password directly as encryption key, but a key which is stored on the server and encrypted with the +// user password. -> password change faster // - IMPORTANT! Check if the block lenght of the encrypted data stays the same @@ -45,12 +46,12 @@ class OC_Crypt { public static function init($login, $password) { $view=new OC_FilesystemView('/'); - if(!$view->file_exists('/'.$login)) { + if ( ! $view->file_exists('/'.$login)) { $view->mkdir('/'.$login); } OC_FileProxy::$enabled=false; - if(!$view->file_exists('/'.$login.'/encryption.key')) {// does key exist? + if ( ! $view->file_exists('/'.$login.'/encryption.key')) {// does key exist? OC_Crypt::createkey($login, $password); } $key=$view->file_get_contents('/'.$login.'/encryption.key'); @@ -67,13 +68,13 @@ class OC_Crypt { * if the key is left out, the default handeler will be used */ public static function getBlowfish($key='') { - if($key) { + if ($key) { return new Crypt_Blowfish($key); - }else{ - if(!isset($_SESSION['enckey'])) { + } else { + if ( ! isset($_SESSION['enckey'])) { return false; } - if(!self::$bf) { + if ( ! self::$bf) { self::$bf=new Crypt_Blowfish($_SESSION['enckey']); } return self::$bf; @@ -96,7 +97,7 @@ class OC_Crypt { } public static function changekeypasscode($oldPassword, $newPassword) { - if(OCP\User::isLoggedIn()) { + if (OCP\User::isLoggedIn()) { $username=OCP\USER::getUser(); $view=new OC_FilesystemView('/'.$username); @@ -151,7 +152,7 @@ class OC_Crypt { */ public static function encryptFile( $source, $target, $key='') { $handleread = fopen($source, "rb"); - if($handleread!=false) { + if ($handleread!=false) { $handlewrite = fopen($target, "wb"); while (!feof($handleread)) { $content = fread($handleread, 8192); @@ -174,12 +175,12 @@ class OC_Crypt { */ public static function decryptFile( $source, $target, $key='') { $handleread = fopen($source, "rb"); - if($handleread!=false) { + if ($handleread!=false) { $handlewrite = fopen($target, "wb"); while (!feof($handleread)) { $content = fread($handleread, 8192); $enccontent=OC_CRYPT::decrypt( $content, $key); - if(feof($handleread)) { + if (feof($handleread)) { $enccontent=rtrim($enccontent, "\0"); } fwrite($handlewrite, $enccontent); @@ -194,7 +195,7 @@ class OC_Crypt { */ public static function blockEncrypt($data, $key='') { $result=''; - while(strlen($data)) { + while (strlen($data)) { $result.=self::encrypt(substr($data, 0, 8192), $key); $data=substr($data, 8192); } @@ -206,13 +207,13 @@ class OC_Crypt { */ public static function blockDecrypt($data, $key='', $maxLength=0) { $result=''; - while(strlen($data)) { + while (strlen($data)) { $result.=self::decrypt(substr($data, 0, 8192), $key); $data=substr($data, 8192); } - if($maxLength>0) { + if ($maxLength>0) { return substr($result, 0, $maxLength); - }else{ + } else { return rtrim($result, "\0"); } } diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php index 8b05560050..d516c0c21b 100644 --- a/apps/files_encryption/lib/cryptstream.php +++ b/apps/files_encryption/lib/cryptstream.php @@ -23,8 +23,9 @@ /** * transparently encrypted filestream * - * you can use it as wrapper around an existing stream by setting OC_CryptStream::$sourceStreams['foo']=array('path'=>$path, 'stream'=>$stream) - * and then fopen('crypt://streams/foo'); + * you can use it as wrapper around an existing stream by setting + * OC_CryptStream::$sourceStreams['foo']=array('path'=>$path, 'stream'=>$stream) + * and then fopen('crypt://streams/foo'); */ class OC_CryptStream{ @@ -37,29 +38,29 @@ class OC_CryptStream{ private static $rootView; public function stream_open($path, $mode, $options, &$opened_path) { - if(!self::$rootView) { + if ( ! self::$rootView) { self::$rootView=new OC_FilesystemView(''); } $path=str_replace('crypt://', '', $path); - if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) { + if (dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])) { $this->source=self::$sourceStreams[basename($path)]['stream']; $this->path=self::$sourceStreams[basename($path)]['path']; $this->size=self::$sourceStreams[basename($path)]['size']; - }else{ + } else { $this->path=$path; - if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+') { + if ($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+') { $this->size=0; - }else{ + } else { $this->size=self::$rootView->filesize($path, $mode); } OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file $this->source=self::$rootView->fopen($path, $mode); OC_FileProxy::$enabled=true; - if(!is_resource($this->source)) { + if ( ! is_resource($this->source)) { OCP\Util::writeLog('files_encryption', 'failed to open '.$path, OCP\Util::ERROR); } } - if(is_resource($this->source)) { + if (is_resource($this->source)) { $this->meta=stream_get_meta_data($this->source); } return is_resource($this->source); @@ -78,19 +79,21 @@ class OC_CryptStream{ //$count will always be 8192 https://bugs.php.net/bug.php?id=21641 //This makes this function a lot simpler but will breake everything the moment it's fixed $this->writeCache=''; - if($count!=8192) { - OCP\Util::writeLog('files_encryption', 'php bug 21641 no longer holds, decryption will not work', OCP\Util::FATAL); + if ($count!=8192) { + OCP\Util::writeLog('files_encryption', + 'php bug 21641 no longer holds, decryption will not work', + OCP\Util::FATAL); die(); } $pos=ftell($this->source); $data=fread($this->source, 8192); - if(strlen($data)) { + if (strlen($data)) { $result=OC_Crypt::decrypt($data); - }else{ + } else { $result=''; } $length=$this->size-$pos; - if($length<8192) { + if ($length<8192) { $result=substr($result, 0, $length); } return $result; @@ -99,11 +102,11 @@ class OC_CryptStream{ public function stream_write($data) { $length=strlen($data); $currentPos=ftell($this->source); - if($this->writeCache) { + if ($this->writeCache) { $data=$this->writeCache.$data; $this->writeCache=''; } - if($currentPos%8192!=0) { + if ($currentPos%8192!=0) { //make sure we always start on a block start fseek($this->source, -($currentPos%8192), SEEK_CUR); $encryptedBlock=fread($this->source, 8192); @@ -113,11 +116,11 @@ class OC_CryptStream{ fseek($this->source, -($currentPos%8192), SEEK_CUR); } $currentPos=ftell($this->source); - while($remainingLength=strlen($data)>0) { - if($remainingLength<8192) { + while ($remainingLength=strlen($data)>0) { + if ($remainingLength<8192) { $this->writeCache=$data; $data=''; - }else{ + } else { $encrypted=OC_Crypt::encrypt(substr($data, 0, 8192)); fwrite($this->source, $encrypted); $data=substr($data, 8192); @@ -157,7 +160,7 @@ class OC_CryptStream{ } private function flush() { - if($this->writeCache) { + if ($this->writeCache) { $encrypted=OC_Crypt::encrypt($this->writeCache); fwrite($this->source, $encrypted); $this->writeCache=''; @@ -166,7 +169,7 @@ class OC_CryptStream{ public function stream_close() { $this->flush(); - if($this->meta['mode']!='r' and $this->meta['mode']!='rb') { + if ($this->meta['mode']!='r' and $this->meta['mode']!='rb') { OC_FileCache::put($this->path, array('encrypted'=>true, 'size'=>$this->size), ''); } return fclose($this->source); diff --git a/apps/files_encryption/lib/proxy.php b/apps/files_encryption/lib/proxy.php index 4a390013d2..e8dbd95c29 100644 --- a/apps/files_encryption/lib/proxy.php +++ b/apps/files_encryption/lib/proxy.php @@ -35,20 +35,22 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ * @return bool */ private static function shouldEncrypt($path) { - if(is_null(self::$enableEncryption)) { + if (is_null(self::$enableEncryption)) { self::$enableEncryption=(OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true')=='true'); } - if(!self::$enableEncryption) { + if ( ! self::$enableEncryption) { return false; } - if(is_null(self::$blackList)) { - self::$blackList=explode(',', OCP\Config::getAppValue('files_encryption', 'type_blacklist', 'jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); + if (is_null(self::$blackList)) { + self::$blackList=explode(',', OCP\Config::getAppValue('files_encryption', + 'type_blacklist', + 'jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); } - if(self::isEncrypted($path)) { + if (self::isEncrypted($path)) { return true; } $extension=substr($path, strrpos($path, '.')+1); - if(array_search($extension, self::$blackList)===false) { + if (array_search($extension, self::$blackList)===false) { return true; } } @@ -64,8 +66,8 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ } public function preFile_put_contents($path,&$data) { - if(self::shouldEncrypt($path)) { - if (!is_resource($data)) {//stream put contents should have been converter to fopen + if (self::shouldEncrypt($path)) { + if ( ! is_resource($data)) {//stream put contents should have been converter to fopen $size=strlen($data); $data=OC_Crypt::blockEncrypt($data); OC_FileCache::put($path, array('encrypted'=>true,'size'=>$size), ''); @@ -74,7 +76,7 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ } public function postFile_get_contents($path, $data) { - if(self::isEncrypted($path)) { + if (self::isEncrypted($path)) { $cached=OC_FileCache_Cached::get($path, ''); $data=OC_Crypt::blockDecrypt($data, '', $cached['size']); } @@ -82,15 +84,15 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ } public function postFopen($path,&$result) { - if(!$result) { + if ( ! $result) { return $result; } $meta=stream_get_meta_data($result); - if(self::isEncrypted($path)) { + if (self::isEncrypted($path)) { fclose($result); $result=fopen('crypt://'.$path, $meta['mode']); - }elseif(self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') { - if(OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0) { + } elseif (self::shouldEncrypt($path) and $meta['mode']!='r' and $meta['mode']!='rb') { + if (OC_Filesystem::file_exists($path) and OC_Filesystem::filesize($path)>0) { //first encrypt the target file so we don't end up with a half encrypted file OCP\Util::writeLog('files_encryption', 'Decrypting '.$path.' before writing', OCP\Util::DEBUG); $tmp=fopen('php://temp'); @@ -105,14 +107,14 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ } public function postGetMimeType($path, $mime) { - if(self::isEncrypted($path)) { + if (self::isEncrypted($path)) { $mime=OCP\Files::getMimeType('crypt://'.$path, 'w'); } return $mime; } public function postStat($path, $data) { - if(self::isEncrypted($path)) { + if (self::isEncrypted($path)) { $cached=OC_FileCache_Cached::get($path, ''); $data['size']=$cached['size']; } @@ -120,10 +122,10 @@ class OC_FileProxy_Encryption extends OC_FileProxy{ } public function postFileSize($path, $size) { - if(self::isEncrypted($path)) { + if (self::isEncrypted($path)) { $cached=OC_FileCache_Cached::get($path, ''); return $cached['size']; - }else{ + } else { return $size; } } diff --git a/apps/files_encryption/settings.php b/apps/files_encryption/settings.php index ae28b088cd..6b2b03211e 100644 --- a/apps/files_encryption/settings.php +++ b/apps/files_encryption/settings.php @@ -7,7 +7,9 @@ */ $tmpl = new OCP\Template( 'files_encryption', 'settings'); -$blackList=explode(',', OCP\Config::getAppValue('files_encryption', 'type_blacklist', 'jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); +$blackList=explode(',', OCP\Config::getAppValue('files_encryption', + 'type_blacklist', + 'jpg,png,jpeg,avi,mpg,mpeg,mkv,mp3,oga,ogv,ogg')); $enabled=(OCP\Config::getAppValue('files_encryption', 'enable_encryption', 'true')=='true'); $tmpl->assign('blacklist', $blackList); $tmpl->assign('encryption_enabled', $enabled); @@ -15,4 +17,4 @@ $tmpl->assign('encryption_enabled', $enabled); OCP\Util::addscript('files_encryption', 'settings'); OCP\Util::addscript('core', 'multiselect'); -return $tmpl->fetchPage(); +return $tmpl->fetchPage(); \ No newline at end of file diff --git a/apps/files_encryption/templates/settings.php b/apps/files_encryption/templates/settings.php index 55e8cf1542..75df784e39 100644 --- a/apps/files_encryption/templates/settings.php +++ b/apps/files_encryption/templates/settings.php @@ -1,12 +1,14 @@
diff --git a/apps/files_encryption/tests/proxy.php b/apps/files_encryption/tests/proxy.php index 1c800bbc5f..5aa617e747 100644 --- a/apps/files_encryption/tests/proxy.php +++ b/apps/files_encryption/tests/proxy.php @@ -42,7 +42,7 @@ class Test_CryptProxy extends UnitTestCase { public function tearDown() { OCP\Config::setAppValue('files_encryption', 'enable_encryption', $this->oldConfig); - if(!is_null($this->oldKey)) { + if ( ! is_null($this->oldKey)) { $_SESSION['enckey']=$this->oldKey; } } diff --git a/apps/files_encryption/tests/stream.php b/apps/files_encryption/tests/stream.php index 67b5e98ae6..e4af17d47b 100644 --- a/apps/files_encryption/tests/stream.php +++ b/apps/files_encryption/tests/stream.php @@ -41,13 +41,13 @@ class Test_CryptStream extends UnitTestCase { * @return resource */ function getStream($id, $mode, $size) { - if($id==='') { + if ($id==='') { $id=uniqid(); } - if(!isset($this->tmpFiles[$id])) { + if ( ! isset($this->tmpFiles[$id])) { $file=OCP\Files::tmpFile(); $this->tmpFiles[$id]=$file; - }else{ + } else { $file=$this->tmpFiles[$id]; } $stream=fopen($file, $mode); diff --git a/apps/files_external/ajax/addMountPoint.php b/apps/files_external/ajax/addMountPoint.php index e08f805942..4cd8871b31 100644 --- a/apps/files_external/ajax/addMountPoint.php +++ b/apps/files_external/ajax/addMountPoint.php @@ -10,4 +10,9 @@ if ($_POST['isPersonal'] == 'true') { OCP\JSON::checkAdminUser(); $isPersonal = false; } -OC_Mount_Config::addMountPoint($_POST['mountPoint'], $_POST['class'], $_POST['classOptions'], $_POST['mountType'], $_POST['applicable'], $isPersonal); +OC_Mount_Config::addMountPoint($_POST['mountPoint'], + $_POST['class'], + $_POST['classOptions'], + $_POST['mountType'], + $_POST['applicable'], + $isPersonal); \ No newline at end of file diff --git a/apps/files_external/ajax/addRootCertificate.php b/apps/files_external/ajax/addRootCertificate.php index 72eb30009d..be60b415e1 100644 --- a/apps/files_external/ajax/addRootCertificate.php +++ b/apps/files_external/ajax/addRootCertificate.php @@ -2,7 +2,7 @@ OCP\JSON::checkAppEnabled('files_external'); -if ( !($filename = $_FILES['rootcert_import']['name']) ) { +if ( ! ($filename = $_FILES['rootcert_import']['name']) ) { header("Location: settings/personal.php"); exit; } @@ -13,7 +13,7 @@ fclose($fh); $filename = $_FILES['rootcert_import']['name']; $view = new \OC_FilesystemView('/'.\OCP\User::getUser().'/files_external/uploads'); -if (!$view->file_exists('')) $view->mkdir(''); +if ( ! $view->file_exists('')) $view->mkdir(''); $isValid = openssl_pkey_get_public($data); @@ -29,8 +29,10 @@ if ( $isValid ) { $view->file_put_contents($filename, $data); OC_Mount_Config::createCertificateBundle(); } else { - OCP\Util::writeLog("files_external", "Couldn't import SSL root certificate ($filename), allowed formats: PEM and DER", OCP\Util::WARN); + OCP\Util::writeLog('files_external', + 'Couldn\'t import SSL root certificate ('.$filename.'), allowed formats: PEM and DER', + OCP\Util::WARN); } -header("Location: settings/personal.php"); +header('Location: settings/personal.php'); exit; diff --git a/apps/files_external/ajax/dropbox.php b/apps/files_external/ajax/dropbox.php index f5923940dc..58c41d6906 100644 --- a/apps/files_external/ajax/dropbox.php +++ b/apps/files_external/ajax/dropbox.php @@ -16,9 +16,13 @@ if (isset($_POST['app_key']) && isset($_POST['app_secret'])) { $callback = null; } $token = $oauth->getRequestToken(); - OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), 'request_token' => $token['token'], 'request_token_secret' => $token['token_secret']))); + OCP\JSON::success(array('data' => array('url' => $oauth->getAuthorizeUrl($callback), + 'request_token' => $token['token'], + 'request_token_secret' => $token['token_secret']))); } catch (Exception $exception) { - OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.'))); + OCP\JSON::error(array('data' => array('message' => + 'Fetching request tokens failed. Verify that your Dropbox app key and secret are correct.') + )); } break; case 2: @@ -26,9 +30,12 @@ if (isset($_POST['app_key']) && isset($_POST['app_secret'])) { try { $oauth->setToken($_POST['request_token'], $_POST['request_token_secret']); $token = $oauth->getAccessToken(); - OCP\JSON::success(array('access_token' => $token['token'], 'access_token_secret' => $token['token_secret'])); + OCP\JSON::success(array('access_token' => $token['token'], + 'access_token_secret' => $token['token_secret'])); } catch (Exception $exception) { - OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.'))); + OCP\JSON::error(array('data' => array('message' => + 'Fetching access tokens failed. Verify that your Dropbox app key and secret are correct.') + )); } } break; diff --git a/apps/files_external/ajax/google.php b/apps/files_external/ajax/google.php index 4cd01c06cc..c76c7618e4 100644 --- a/apps/files_external/ajax/google.php +++ b/apps/files_external/ajax/google.php @@ -14,7 +14,9 @@ if (isset($_POST['step'])) { } else { $callback = null; } - $scope = 'https://docs.google.com/feeds/ https://docs.googleusercontent.com/ https://spreadsheets.google.com/feeds/'; + $scope = 'https://docs.google.com/feeds/' + .' https://docs.googleusercontent.com/' + .' https://spreadsheets.google.com/feeds/'; $url = 'https://www.google.com/accounts/OAuthGetRequestToken?scope='.urlencode($scope); $params = array('scope' => $scope, 'oauth_callback' => $callback); $request = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $url, $params); @@ -24,24 +26,35 @@ if (isset($_POST['step'])) { parse_str($response, $token); if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) { $authUrl = 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token='.$token['oauth_token']; - OCP\JSON::success(array('data' => array('url' => $authUrl, 'request_token' => $token['oauth_token'], 'request_token_secret' => $token['oauth_token_secret']))); + OCP\JSON::success(array('data' => array('url' => $authUrl, + 'request_token' => $token['oauth_token'], + 'request_token_secret' => $token['oauth_token_secret']))); } else { - OCP\JSON::error(array('data' => array('message' => 'Fetching request tokens failed. Error: '.$response))); + OCP\JSON::error(array('data' => array( + 'message' => 'Fetching request tokens failed. Error: '.$response + ))); } break; case 2: - if (isset($_POST['oauth_verifier']) && isset($_POST['request_token']) && isset($_POST['request_token_secret'])) { + if (isset($_POST['oauth_verifier']) + && isset($_POST['request_token']) + && isset($_POST['request_token_secret']) + ) { $token = new OAuthToken($_POST['request_token'], $_POST['request_token_secret']); $url = 'https://www.google.com/accounts/OAuthGetAccessToken'; - $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, array('oauth_verifier' => $_POST['oauth_verifier'])); + $request = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $url, + array('oauth_verifier' => $_POST['oauth_verifier'])); $request->sign_request($sigMethod, $consumer, $token); $response = send_signed_request('GET', $url, array($request->to_header()), null, false); $token = array(); parse_str($response, $token); if (isset($token['oauth_token']) && isset($token['oauth_token_secret'])) { - OCP\JSON::success(array('access_token' => $token['oauth_token'], 'access_token_secret' => $token['oauth_token_secret'])); + OCP\JSON::success(array('access_token' => $token['oauth_token'], + 'access_token_secret' => $token['oauth_token_secret'])); } else { - OCP\JSON::error(array('data' => array('message' => 'Fetching access tokens failed. Error: '.$response))); + OCP\JSON::error(array('data' => array( + 'message' => 'Fetching access tokens failed. Error: '.$response + ))); } } break; diff --git a/apps/files_external/js/settings.js b/apps/files_external/js/settings.js index 89f346574e..0dc983ca8a 100644 --- a/apps/files_external/js/settings.js +++ b/apps/files_external/js/settings.js @@ -142,7 +142,7 @@ $(document).ready(function() { $('td.remove>img').live('click', function() { var tr = $(this).parent().parent(); var mountPoint = $(tr).find('.mountPoint input').val(); - if (!mountPoint) { + if ( ! mountPoint) { var row=this.parentNode.parentNode; $.post(OC.filePath('files_external', 'ajax', 'removeRootCertificate.php'), { cert: row.id }); $(tr).remove(); diff --git a/apps/files_external/lib/amazons3.php b/apps/files_external/lib/amazons3.php index 41ec3c70b4..235ade06db 100644 --- a/apps/files_external/lib/amazons3.php +++ b/apps/files_external/lib/amazons3.php @@ -45,7 +45,7 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { if ($response) { $this->objects[$path] = $response; return $response; - // This object could be a folder, a '/' must be at the end of the path + // This object could be a folder, a '/' must be at the end of the path } else if (substr($path, -1) != '/') { $response = $this->s3->get_object_metadata($this->bucket, $path.'/'); if ($response) { @@ -108,11 +108,14 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { $stat['atime'] = time(); $stat['mtime'] = $stat['atime']; $stat['ctime'] = $stat['atime']; - } else if ($object = $this->getObject($path)) { - $stat['size'] = $object['Size']; - $stat['atime'] = time(); - $stat['mtime'] = strtotime($object['LastModified']); - $stat['ctime'] = $stat['mtime']; + } else { + $object = $this->getObject($path); + if ($object) { + $stat['size'] = $object['Size']; + $stat['atime'] = time(); + $stat['mtime'] = strtotime($object['LastModified']); + $stat['ctime'] = $stat['mtime']; + } } if (isset($stat)) { return $stat; @@ -123,12 +126,15 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { public function filetype($path) { if ($path == '' || $path == '/') { return 'dir'; - } else if ($object = $this->getObject($path)) { - // Amazon S3 doesn't have typical folders, this is an alternative method to detect a folder - if (substr($object['Key'], -1) == '/' && $object['Size'] == 0) { - return 'dir'; - } else { - return 'file'; + } else { + $object = $this->getObject($path); + if ($object) { + // Amazon S3 doesn't have typical folders, this is an alternative method to detect a folder + if (substr($object['Key'], -1) == '/' && $object['Size'] == 0) { + return 'dir'; + } else { + return 'file'; + } } } return false; @@ -199,7 +205,9 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { public function writeBack($tmpFile) { if (isset(self::$tempFiles[$tmpFile])) { $handle = fopen($tmpFile, 'r'); - $response = $this->s3->create_object($this->bucket, self::$tempFiles[$tmpFile], array('fileUpload' => $handle)); + $response = $this->s3->create_object($this->bucket, + self::$tempFiles[$tmpFile], + array('fileUpload' => $handle)); if ($response->isOK()) { unlink($tmpFile); } @@ -209,8 +217,11 @@ class OC_Filestorage_AmazonS3 extends OC_Filestorage_Common { public function getMimeType($path) { if ($this->filetype($path) == 'dir') { return 'httpd/unix-directory'; - } else if ($object = $this->getObject($path)) { - return $object['ContentType']; + } else { + $object = $this->getObject($path); + if ($object) { + return $object['ContentType']; + } } return false; } diff --git a/apps/files_external/lib/config.php b/apps/files_external/lib/config.php index fdc847fcf2..87d6886c51 100755 --- a/apps/files_external/lib/config.php +++ b/apps/files_external/lib/config.php @@ -39,14 +39,64 @@ class OC_Mount_Config { */ 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://')) + '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://')) ); } @@ -66,9 +116,14 @@ class OC_Mount_Config { $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)); + $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())); + $system[$mountPoint] = array( + 'class' => $mount['class'], + 'backend' => $backends[$mount['class']]['backend'], + 'configuration' => $mount['options'], + 'applicable' => array('groups' => array($group), 'users' => array())); } } } @@ -80,9 +135,13 @@ class OC_Mount_Config { $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)); + $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))); + $system[$mountPoint] = array('class' => $mount['class'], + 'backend' => $backends[$mount['class']]['backend'], + 'configuration' => $mount['options'], + 'applicable' => array('groups' => array(), 'users' => array($user))); } } } @@ -103,7 +162,9 @@ class OC_Mount_Config { 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']); + $personal[substr($mountPoint, strlen($uid) + 8)] = array('class' => $mount['class'], + 'backend' => $backends[$mount['class']]['backend'], + 'configuration' => $mount['options']); } } return $personal; @@ -135,7 +196,12 @@ class OC_Mount_Config { * @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) { + 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 @@ -176,7 +242,8 @@ class OC_Mount_Config { // 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]); + $mountPoints[$mountType][$applicable] + = array_merge($mountPoints[$mountType][$applicable], $mount[$applicable]); } else { $mountPoints[$mountType] = array_merge($mountPoints[$mountType], $mount); } @@ -286,18 +353,18 @@ class OC_Mount_Config { $view = \OCP\Files::getStorage('files_external'); $path=\OCP\Config::getSystemValue('datadirectory').$view->getAbsolutePath("").'uploads/'; \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) //in this case create full path using 3rd (recursive=true) parameter. mkdir($path, 0777, true); } $result = array(); $handle = opendir($path); - if (!$handle) { + if ( ! $handle) { return array(); } while (false !== ($file = readdir($handle))) { - if($file != '.' && $file != '..') $result[] = $file; + if ($file != '.' && $file != '..') $result[] = $file; } return $result; } diff --git a/apps/files_external/lib/dropbox.php b/apps/files_external/lib/dropbox.php index c822083270..33ca14cab1 100755 --- a/apps/files_external/lib/dropbox.php +++ b/apps/files_external/lib/dropbox.php @@ -31,7 +31,12 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { private static $tempFiles = array(); public function __construct($params) { - if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['app_key']) && isset($params['app_secret']) && isset($params['token']) && isset($params['token_secret'])) { + if (isset($params['configured']) && $params['configured'] == 'true' + && isset($params['app_key']) + && isset($params['app_secret']) + && isset($params['token']) + && isset($params['token_secret']) + ) { $this->root=isset($params['root'])?$params['root']:''; $oauth = new Dropbox_OAuth_Curl($params['app_key'], $params['app_secret']); $oauth->setToken($params['token'], $params['token_secret']); @@ -44,7 +49,7 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { private function getMetaData($path, $list = false) { $path = $this->root.$path; - if (!$list && isset($this->metaData[$path])) { + if ( ! $list && isset($this->metaData[$path])) { return $this->metaData[$path]; } else { if ($list) { @@ -95,7 +100,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { } public function opendir($path) { - if ($contents = $this->getMetaData($path, true)) { + $contents = $this->getMetaData($path, true); + if ($contents) { $files = array(); foreach ($contents as $file) { $files[] = basename($file['path']); @@ -107,7 +113,8 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { } public function stat($path) { - if ($metaData = $this->getMetaData($path)) { + $metaData = $this->getMetaData($path); + if ($metaData) { $stat['size'] = $metaData['bytes']; $stat['atime'] = time(); $stat['mtime'] = (isset($metaData['modified'])) ? strtotime($metaData['modified']) : time(); @@ -120,11 +127,14 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { 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'; + } else { + $metaData = $this->getMetaData($path); + if ($metaData) { + if ($metaData['is_dir'] == 'true') { + return 'dir'; + } else { + return 'file'; + } } } return false; @@ -241,8 +251,11 @@ class OC_Filestorage_Dropbox extends OC_Filestorage_Common { public function getMimeType($path) { if ($this->filetype($path) == 'dir') { return 'httpd/unix-directory'; - } else if ($metaData = $this->getMetaData($path)) { - return $metaData['mime_type']; + } else { + $metaData = $this->getMetaData($path); + if ($metaData) { + return $metaData['mime_type']; + } } return false; } diff --git a/apps/files_external/lib/ftp.php b/apps/files_external/lib/ftp.php index 5b90e3049b..e796ae446b 100644 --- a/apps/files_external/lib/ftp.php +++ b/apps/files_external/lib/ftp.php @@ -19,21 +19,21 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ $this->host=$params['host']; $this->user=$params['user']; $this->password=$params['password']; - if(isset($params['secure'])) { - if(is_string($params['secure'])) { + if (isset($params['secure'])) { + if (is_string($params['secure'])) { $this->secure = ($params['secure'] === 'true'); - }else{ + } else { $this->secure = (bool)$params['secure']; } - }else{ + } else { $this->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 - if (!$this->is_dir('')) { + if ( ! $this->is_dir('')) { $this->mkdir(''); } } @@ -45,7 +45,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ */ public function constructUrl($path) { $url='ftp'; - if($this->secure) { + if ($this->secure) { $url.='s'; } $url.='://'.$this->user.':'.$this->password.'@'.$this->host.$this->root.$path; @@ -71,14 +71,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{ + } 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; @@ -87,7 +87,7 @@ class OC_FileStorage_FTP extends OC_FileStorage_StreamWrapper{ } public function writeBack($tmpFile) { - if(isset(self::$tempFiles[$tmpFile])) { + if (isset(self::$tempFiles[$tmpFile])) { $this->uploadFile($tmpFile, self::$tempFiles[$tmpFile]); unlink($tmpFile); } diff --git a/apps/files_external/lib/google.php b/apps/files_external/lib/google.php index e5de81280a..c836a5a07c 100644 --- a/apps/files_external/lib/google.php +++ b/apps/files_external/lib/google.php @@ -32,7 +32,10 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { private static $tempFiles = array(); public function __construct($params) { - if (isset($params['configured']) && $params['configured'] == 'true' && isset($params['token']) && isset($params['token_secret'])) { + if (isset($params['configured']) && $params['configured'] == 'true' + && isset($params['token']) + && isset($params['token_secret']) + ) { $consumer_key = isset($params['consumer_key']) ? $params['consumer_key'] : 'anonymous'; $consumer_secret = isset($params['consumer_secret']) ? $params['consumer_secret'] : 'anonymous'; $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret); @@ -44,7 +47,14 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { } } - private function sendRequest($uri, $httpMethod, $postData = null, $extraHeaders = null, $isDownload = false, $returnHeaders = false, $isContentXML = true, $returnHTTPCode = false) { + private function sendRequest($uri, + $httpMethod, + $postData = null, + $extraHeaders = null, + $isDownload = false, + $returnHeaders = false, + $isContentXML = true, + $returnHTTPCode = false) { $uri = trim($uri); // create an associative array from each key/value url query param pair. $params = array(); @@ -58,7 +68,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { $tempStr .= '&' . urlencode($key) . '=' . urlencode($value); } $uri = preg_replace('/&/', '?', $tempStr, 1); - $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->oauth_token, $httpMethod, $uri, $params); + $request = OAuthRequest::from_consumer_and_token($this->consumer, + $this->oauth_token, + $httpMethod, + $uri, + $params); $request->sign_request($this->sig_method, $this->consumer, $this->oauth_token); $auth_header = $request->to_header(); $headers = array($auth_header, 'GData-Version: 3.0'); @@ -132,6 +146,11 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { return false; } + /** + * Base url for google docs feeds + */ + const BASE_URI='https://docs.google.com/feeds'; + private function getResource($path) { $file = basename($path); if (array_key_exists($file, $this->entries)) { @@ -140,14 +159,14 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { // Strip the file extension; file could be a native Google Docs resource if ($pos = strpos($file, '.')) { $title = substr($file, 0, $pos); - $dom = $this->getFeed('https://docs.google.com/feeds/default/private/full?showfolders=true&title='.$title, 'GET'); + $dom = $this->getFeed(self::BASE_URI.'/default/private/full?showfolders=true&title='.$title, 'GET'); // Check if request was successful and entry exists if ($dom && $entry = $dom->getElementsByTagName('entry')->item(0)) { $this->entries[$file] = $entry; return $entry; } } - $dom = $this->getFeed('https://docs.google.com/feeds/default/private/full?showfolders=true&title='.$file, 'GET'); + $dom = $this->getFeed(self::BASE_URI.'/default/private/full?showfolders=true&title='.$file, 'GET'); // Check if request was successful and entry exists if ($dom && $entry = $dom->getElementsByTagName('entry')->item(0)) { $this->entries[$file] = $entry; @@ -180,20 +199,25 @@ class OC_Filestorage_Google extends OC_Filestorage_Common { $collection = dirname($path); // Check if path parent is root directory if ($collection == '/' || $collection == '\.' || $collection == '.') { - $uri = 'https://docs.google.com/feeds/default/private/full'; - // Get parent content link - } else if ($dom = $this->getResource(basename($collection))) { - $uri = $dom->getElementsByTagName('content')->item(0)->getAttribute('src'); + $uri = self::BASE_URI.'/default/private/full'; + } else { + // Get parent content link + $dom = $this->getResource(basename($collection)); + if ($dom) { + $uri = $dom->getElementsByTagName('content')->item(0)->getAttribute('src'); + } } if (isset($uri)) { $title = basename($path); // Construct post data $postData = ''; $postData .= '