SMB.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Robin McCorkell <robin@mccorkell.me.uk>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCA\Files_External\Lib\Backend;
  23. use \OCP\IL10N;
  24. use \OCA\Files_External\Lib\Backend\Backend;
  25. use \OCA\Files_External\Lib\DefinitionParameter;
  26. use \OCA\Files_External\Lib\Auth\AuthMechanism;
  27. use \OCA\Files_External\Service\BackendService;
  28. use \OCA\Files_External\Lib\StorageConfig;
  29. use \OCA\Files_External\Lib\LegacyDependencyCheckPolyfill;
  30. use \OCA\Files_External\Lib\Auth\Password\Password;
  31. use OCP\IUser;
  32. class SMB extends Backend {
  33. use LegacyDependencyCheckPolyfill;
  34. public function __construct(IL10N $l, Password $legacyAuth) {
  35. $this
  36. ->setIdentifier('smb')
  37. ->addIdentifierAlias('\OC\Files\Storage\SMB') // legacy compat
  38. ->setStorageClass('\OCA\Files_External\Lib\Storage\SMB')
  39. ->setText($l->t('SMB / CIFS'))
  40. ->addParameters([
  41. (new DefinitionParameter('host', $l->t('Host'))),
  42. (new DefinitionParameter('share', $l->t('Share'))),
  43. (new DefinitionParameter('root', $l->t('Remote subfolder')))
  44. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  45. (new DefinitionParameter('domain', $l->t('Domain')))
  46. ->setFlag(DefinitionParameter::FLAG_OPTIONAL),
  47. ])
  48. ->addAuthScheme(AuthMechanism::SCHEME_PASSWORD)
  49. ->setLegacyAuthMechanism($legacyAuth)
  50. ;
  51. }
  52. /**
  53. * @param StorageConfig $storage
  54. * @param IUser $user
  55. */
  56. public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
  57. $user = $storage->getBackendOption('user');
  58. if ($domain = $storage->getBackendOption('domain')) {
  59. $storage->setBackendOption('user', $domain.'\\'.$user);
  60. }
  61. }
  62. }