| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * @copyright Copyright (c) 2016, ownCloud, Inc. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @author Arthur Schiwon <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @author Christoph Wurst <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author Joas Schilling <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * @author Morris Jobke <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * @author Robin Appelman <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @author Robin McCorkell <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @author Roeland Jago Douma <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @author Ross Nicoll <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author Vincent Petry <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @license AGPL-3.0 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * This code is free software: you can redistribute it and/or modify | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * it under the terms of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * as published by the Free Software Foundation. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * GNU Affero General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * You should have received a copy of the GNU Affero General Public License, version 3, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * along with this program. If not, see <http://www.gnu.org/licenses/> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | namespace OCA\Files_External\AppInfo; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | use OCA\Files_External\Config\ConfigAdapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | use OCA\Files_External\Config\UserPlaceholderHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | use OCA\Files_External\Listener\GroupDeletedListener; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | use OCA\Files_External\Listener\UserDeletedListener; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | use OCA\Files_External\Lib\Auth\AmazonS3\AccessKey; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | use OCA\Files_External\Lib\Auth\Builtin; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | use OCA\Files_External\Lib\Auth\NullMechanism; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | use OCA\Files_External\Lib\Auth\OAuth1\OAuth1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | use OCA\Files_External\Lib\Auth\OAuth2\OAuth2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV2; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | use OCA\Files_External\Lib\Auth\OpenStack\OpenStackV3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  | use OCA\Files_External\Lib\Auth\OpenStack\Rackspace; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | use OCA\Files_External\Lib\Auth\Password\GlobalAuth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | use OCA\Files_External\Lib\Auth\Password\LoginCredentials; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | use OCA\Files_External\Lib\Auth\Password\Password; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | use OCA\Files_External\Lib\Auth\Password\SessionCredentials; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | use OCA\Files_External\Lib\Auth\Password\UserGlobalAuth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | use OCA\Files_External\Lib\Auth\Password\UserProvided; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | use OCA\Files_External\Lib\Auth\PublicKey\RSA; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  | use OCA\Files_External\Lib\Auth\PublicKey\RSAPrivateKey; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  | use OCA\Files_External\Lib\Auth\SMB\KerberosAuth; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | use OCA\Files_External\Lib\Backend\AmazonS3; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  | use OCA\Files_External\Lib\Backend\DAV; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | use OCA\Files_External\Lib\Backend\FTP; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  | use OCA\Files_External\Lib\Backend\Local; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  | use OCA\Files_External\Lib\Backend\OwnCloud; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  | use OCA\Files_External\Lib\Backend\SFTP; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  | use OCA\Files_External\Lib\Backend\SFTP_Key; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  | use OCA\Files_External\Lib\Backend\SMB; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | use OCA\Files_External\Lib\Backend\SMB_OC; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | use OCA\Files_External\Lib\Backend\Swift; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | use OCA\Files_External\Lib\Config\IAuthMechanismProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | use OCA\Files_External\Lib\Config\IBackendProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | use OCA\Files_External\Service\BackendService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | use OCP\AppFramework\App; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | use OCP\AppFramework\Bootstrap\IBootContext; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | use OCP\AppFramework\Bootstrap\IBootstrap; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | use OCP\AppFramework\Bootstrap\IRegistrationContext; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | use OCP\Files\Config\IMountProviderCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  | use OCP\Group\Events\GroupDeletedEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | use OCP\User\Events\UserDeletedEvent; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  | require_once __DIR__ . '/../../3rdparty/autoload.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  * @package OCA\Files_External\AppInfo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | class Application extends App implements IBackendProvider, IAuthMechanismProvider, IBootstrap { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 * Application constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	 * @throws \OCP\AppFramework\QueryException | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 85 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  | 	public function __construct(array $urlParams = []) { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  | 		parent::__construct('files_external', $urlParams); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	public function register(IRegistrationContext $context): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | 		$context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 		$context->registerEventListener(GroupDeletedEvent::class, GroupDeletedListener::class); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	public function boot(IBootContext $context): void { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 		$context->injectFn(function (IMountProviderCollection $mountProviderCollection, ConfigAdapter $configAdapter) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 			$mountProviderCollection->registerProvider($configAdapter); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 		\OCA\Files\App::getNavigationManager()->add(function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 			$l = \OC::$server->getL10N('files_external'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 			return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  | 				'id' => 'extstoragemounts', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 				'appname' => 'files_external', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 				'script' => 'list.php', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  | 				'order' => 30, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | 				'name' => $l->t('External storage'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  | 			]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  | 		$context->injectFn(function (BackendService $backendService, UserPlaceholderHandler $userConfigHandler) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  | 			$backendService->registerBackendProvider($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  | 			$backendService->registerAuthMechanismProvider($this); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  | 			$backendService->registerConfigHandler('user', function () use ($userConfigHandler) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | 				return $userConfigHandler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  | 			}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | 		}); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  | 		// force-load auth mechanisms since some will register hooks | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  | 		// TODO: obsolete these and use the TokenProvider to get the user's password from the session | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  | 		$this->getAuthMechanisms(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  | 	 * @{inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  | 	public function getBackends() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | 		$container = $this->getContainer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  | 		$backends = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | 			$container->query(Local::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | 			$container->query(FTP::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | 			$container->query(DAV::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | 			$container->query(OwnCloud::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  | 			$container->query(SFTP::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  | 			$container->query(AmazonS3::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  | 			$container->query(Swift::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  | 			$container->query(SFTP_Key::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  | 			$container->query(SMB::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  | 			$container->query(SMB_OC::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  | 		return $backends; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  | 	 * @{inheritdoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  | 	public function getAuthMechanisms() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  | 		$container = $this->getContainer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  | 		return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  | 			// AuthMechanism::SCHEME_NULL mechanism | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  | 			$container->query(NullMechanism::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  | 			// AuthMechanism::SCHEME_BUILTIN mechanism | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  | 			$container->query(Builtin::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  | 			// AuthMechanism::SCHEME_PASSWORD mechanisms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  | 			$container->query(Password::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  | 			$container->query(SessionCredentials::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  | 			$container->query(LoginCredentials::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  | 			$container->query(UserProvided::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  | 			$container->query(GlobalAuth::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  | 			$container->query(UserGlobalAuth::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  | 			// AuthMechanism::SCHEME_OAUTH1 mechanisms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  | 			$container->query(OAuth1::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  | 			// AuthMechanism::SCHEME_OAUTH2 mechanisms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  | 			$container->query(OAuth2::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  | 			// AuthMechanism::SCHEME_PUBLICKEY mechanisms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  | 			$container->query(RSA::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | 			$container->query(RSAPrivateKey::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  | 			// AuthMechanism::SCHEME_OPENSTACK mechanisms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  | 			$container->query(OpenStackV2::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  | 			$container->query(OpenStackV3::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  | 			$container->query(Rackspace::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  | 			// Specialized mechanisms | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  | 			$container->query(AccessKey::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  | 			$container->query(KerberosAuth::class), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  | 		]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 185 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 186 |  |  |  |