@@ -28,11 +28,11 @@ |
||
| 28 | 28 | * Null authentication mechanism |
| 29 | 29 | */ |
| 30 | 30 | class NullMechanism extends AuthMechanism { |
| 31 | - public function __construct(IL10N $l) { |
|
| 32 | - $this |
|
| 33 | - ->setIdentifier('null::null') |
|
| 34 | - ->setScheme(self::SCHEME_NULL) |
|
| 35 | - ->setText($l->t('None')) |
|
| 36 | - ; |
|
| 37 | - } |
|
| 31 | + public function __construct(IL10N $l) { |
|
| 32 | + $this |
|
| 33 | + ->setIdentifier('null::null') |
|
| 34 | + ->setScheme(self::SCHEME_NULL) |
|
| 35 | + ->setText($l->t('None')) |
|
| 36 | + ; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -41,48 +41,48 @@ |
||
| 41 | 41 | $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
| 42 | 42 | |
| 43 | 43 | switch ($parameter->getType()) { |
| 44 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 45 | - <?php if ($is_optional) { |
|
| 46 | - $classes[] = 'optional'; |
|
| 47 | - } ?> |
|
| 48 | - <input type="password" |
|
| 44 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 45 | + <?php if ($is_optional) { |
|
| 46 | + $classes[] = 'optional'; |
|
| 47 | + } ?> |
|
| 48 | + <input type="password" |
|
| 49 | 49 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 50 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 50 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 51 | 51 | value="<?php p($value); ?>" |
| 52 | 52 | placeholder="<?php p($placeholder); ?>" |
| 53 | 53 | /> |
| 54 | 54 | <?php |
| 55 | - break; |
|
| 56 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 57 | - <?php $checkboxId = uniqid("checkbox_"); ?> |
|
| 55 | + break; |
|
| 56 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 57 | + <?php $checkboxId = uniqid("checkbox_"); ?> |
|
| 58 | 58 | <div> |
| 59 | 59 | <label> |
| 60 | 60 | <input type="checkbox" |
| 61 | 61 | id="<?php p($checkboxId); ?>" |
| 62 | 62 | <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 63 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 63 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 64 | 64 | <?php if ($value === true): ?> checked="checked"<?php endif; ?> |
| 65 | - /> |
|
| 65 | + /> |
|
| 66 | 66 | <?php p($placeholder); ?> |
| 67 | 67 | </label> |
| 68 | 68 | </div> |
| 69 | 69 | <?php |
| 70 | - break; |
|
| 71 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 72 | - <input type="hidden" |
|
| 70 | + break; |
|
| 71 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 72 | + <input type="hidden" |
|
| 73 | 73 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 74 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 74 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 75 | 75 | value="<?php p($value); ?>" |
| 76 | 76 | /> |
| 77 | 77 | <?php |
| 78 | - break; |
|
| 79 | - default: ?> |
|
| 80 | - <?php if ($is_optional) { |
|
| 81 | - $classes[] = 'optional'; |
|
| 82 | - } ?> |
|
| 83 | - <input type="text" |
|
| 78 | + break; |
|
| 79 | + default: ?> |
|
| 80 | + <?php if ($is_optional) { |
|
| 81 | + $classes[] = 'optional'; |
|
| 82 | + } ?> |
|
| 83 | + <input type="text" |
|
| 84 | 84 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 85 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 85 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 86 | 86 | value="<?php p($value); ?>" |
| 87 | 87 | placeholder="<?php p($placeholder); ?>" |
| 88 | 88 | /> |
@@ -194,8 +194,11 @@ |
||
| 194 | 194 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
| 195 | 195 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
| 196 | 196 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
| 197 | - <?php else: ?> |
|
| 198 | - <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
| 197 | + <?php else { |
|
| 198 | + : ?> |
|
| 199 | + <input type="checkbox" id="allowUserMountingBackends<?php p($i); |
|
| 200 | +} |
|
| 201 | +?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
| 199 | 202 | print_unescaped(' checked="checked"'); |
| 200 | 203 | } ?> /> |
| 201 | 204 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
@@ -1,54 +1,54 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - use \OCA\Files_External\Lib\Backend\Backend; |
|
| 2 | + use \OCA\Files_External\Lib\Backend\Backend; |
|
| 3 | 3 | use \OCA\Files_External\Lib\Auth\AuthMechanism; |
| 4 | 4 | use \OCA\Files_External\Lib\DefinitionParameter; |
| 5 | 5 | use \OCA\Files_External\Service\BackendService; |
| 6 | 6 | |
| 7 | 7 | $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
| 8 | 8 | |
| 9 | - $l->t("Enable encryption"); |
|
| 10 | - $l->t("Enable previews"); |
|
| 11 | - $l->t("Enable sharing"); |
|
| 12 | - $l->t("Check for changes"); |
|
| 13 | - $l->t("Never"); |
|
| 14 | - $l->t("Once every direct access"); |
|
| 15 | - $l->t('Read only'); |
|
| 9 | + $l->t("Enable encryption"); |
|
| 10 | + $l->t("Enable previews"); |
|
| 11 | + $l->t("Enable sharing"); |
|
| 12 | + $l->t("Check for changes"); |
|
| 13 | + $l->t("Never"); |
|
| 14 | + $l->t("Once every direct access"); |
|
| 15 | + $l->t('Read only'); |
|
| 16 | 16 | |
| 17 | - script('files_external', [ |
|
| 18 | - 'settings', |
|
| 19 | - 'templates' |
|
| 20 | - ]); |
|
| 21 | - style('files_external', 'settings'); |
|
| 17 | + script('files_external', [ |
|
| 18 | + 'settings', |
|
| 19 | + 'templates' |
|
| 20 | + ]); |
|
| 21 | + style('files_external', 'settings'); |
|
| 22 | 22 | |
| 23 | - // load custom JS |
|
| 24 | - foreach ($_['backends'] as $backend) { |
|
| 25 | - /** @var Backend $backend */ |
|
| 26 | - $scripts = $backend->getCustomJs(); |
|
| 27 | - foreach ($scripts as $script) { |
|
| 28 | - script('files_external', $script); |
|
| 29 | - } |
|
| 30 | - } |
|
| 31 | - foreach ($_['authMechanisms'] as $authMechanism) { |
|
| 32 | - /** @var AuthMechanism $authMechanism */ |
|
| 33 | - $scripts = $authMechanism->getCustomJs(); |
|
| 34 | - foreach ($scripts as $script) { |
|
| 35 | - script('files_external', $script); |
|
| 36 | - } |
|
| 37 | - } |
|
| 23 | + // load custom JS |
|
| 24 | + foreach ($_['backends'] as $backend) { |
|
| 25 | + /** @var Backend $backend */ |
|
| 26 | + $scripts = $backend->getCustomJs(); |
|
| 27 | + foreach ($scripts as $script) { |
|
| 28 | + script('files_external', $script); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | + foreach ($_['authMechanisms'] as $authMechanism) { |
|
| 32 | + /** @var AuthMechanism $authMechanism */ |
|
| 33 | + $scripts = $authMechanism->getCustomJs(); |
|
| 34 | + foreach ($scripts as $script) { |
|
| 35 | + script('files_external', $script); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - function writeParameterInput($parameter, $options, $classes = []) { |
|
| 40 | - $value = ''; |
|
| 41 | - if (isset($options[$parameter->getName()])) { |
|
| 42 | - $value = $options[$parameter->getName()]; |
|
| 43 | - } |
|
| 44 | - $placeholder = $parameter->getText(); |
|
| 45 | - $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
| 39 | + function writeParameterInput($parameter, $options, $classes = []) { |
|
| 40 | + $value = ''; |
|
| 41 | + if (isset($options[$parameter->getName()])) { |
|
| 42 | + $value = $options[$parameter->getName()]; |
|
| 43 | + } |
|
| 44 | + $placeholder = $parameter->getText(); |
|
| 45 | + $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
| 46 | 46 | |
| 47 | - switch ($parameter->getType()) { |
|
| 48 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 47 | + switch ($parameter->getType()) { |
|
| 48 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 49 | 49 | <?php if ($is_optional) { |
| 50 | - $classes[] = 'optional'; |
|
| 51 | - } ?> |
|
| 50 | + $classes[] = 'optional'; |
|
| 51 | + } ?> |
|
| 52 | 52 | <input type="password" |
| 53 | 53 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 54 | 54 | data-parameter="<?php p($parameter->getName()); ?>" |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | placeholder="<?php p($placeholder); ?>" |
| 57 | 57 | /> |
| 58 | 58 | <?php |
| 59 | - break; |
|
| 60 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 59 | + break; |
|
| 60 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 61 | 61 | <?php $checkboxId = uniqid("checkbox_"); ?> |
| 62 | 62 | <div> |
| 63 | 63 | <label> |
@@ -71,19 +71,19 @@ discard block |
||
| 71 | 71 | </label> |
| 72 | 72 | </div> |
| 73 | 73 | <?php |
| 74 | - break; |
|
| 75 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 74 | + break; |
|
| 75 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 76 | 76 | <input type="hidden" |
| 77 | 77 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 78 | 78 | data-parameter="<?php p($parameter->getName()); ?>" |
| 79 | 79 | value="<?php p($value); ?>" |
| 80 | 80 | /> |
| 81 | 81 | <?php |
| 82 | - break; |
|
| 83 | - default: ?> |
|
| 82 | + break; |
|
| 83 | + default: ?> |
|
| 84 | 84 | <?php if ($is_optional) { |
| 85 | - $classes[] = 'optional'; |
|
| 86 | - } ?> |
|
| 85 | + $classes[] = 'optional'; |
|
| 86 | + } ?> |
|
| 87 | 87 | <input type="text" |
| 88 | 88 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 89 | 89 | data-parameter="<?php p($parameter->getName()); ?>" |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | placeholder="<?php p($placeholder); ?>" |
| 92 | 92 | /> |
| 93 | 93 | <?php |
| 94 | - } |
|
| 95 | - } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | 96 | ?> |
| 97 | 97 | |
| 98 | 98 | <div id="emptycontent" class="hidden"> |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | </div> |
| 102 | 102 | |
| 103 | 103 | <?php |
| 104 | - $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true); |
|
| 104 | + $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true); |
|
| 105 | 105 | ?> |
| 106 | 106 | <form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" data-can-create-local="<?php echo $canCreateNewLocalStorage?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
| 107 | 107 | <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2> |
| 108 | 108 | <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
| 109 | 109 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
| 110 | 110 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
| 111 | - print_unescaped(''.$_['dependencies'].''); |
|
| 111 | + print_unescaped(''.$_['dependencies'].''); |
|
| 112 | 112 | } ?> |
| 113 | 113 | <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'> |
| 114 | 114 | <thead> |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | <th><?php p($l->t('Authentication')); ?></th> |
| 120 | 120 | <th><?php p($l->t('Configuration')); ?></th> |
| 121 | 121 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) { |
| 122 | - print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
| 122 | + print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
| 123 | 123 | } ?> |
| 124 | 124 | <th> </th> |
| 125 | 125 | <th> </th> |
@@ -150,17 +150,17 @@ discard block |
||
| 150 | 150 | <?php p($l->t('Add storage')); ?> |
| 151 | 151 | </option> |
| 152 | 152 | <?php |
| 153 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
| 154 | - return $backend->isVisibleFor($_['visibilityType']); |
|
| 155 | - }); |
|
| 156 | - uasort($sortedBackends, function ($a, $b) { |
|
| 157 | - return strcasecmp($a->getText(), $b->getText()); |
|
| 158 | - }); |
|
| 159 | - ?> |
|
| 153 | + $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
| 154 | + return $backend->isVisibleFor($_['visibilityType']); |
|
| 155 | + }); |
|
| 156 | + uasort($sortedBackends, function ($a, $b) { |
|
| 157 | + return strcasecmp($a->getText(), $b->getText()); |
|
| 158 | + }); |
|
| 159 | + ?> |
|
| 160 | 160 | <?php foreach ($sortedBackends as $backend): ?> |
| 161 | 161 | <?php if ($backend->getDeprecateTo() || (!$canCreateNewLocalStorage && $backend->getIdentifier() == "local")) { |
| 162 | - continue; |
|
| 163 | - } // ignore deprecated backends?> |
|
| 162 | + continue; |
|
| 163 | + } // ignore deprecated backends?> |
|
| 164 | 164 | <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
| 165 | 165 | <?php endforeach; ?> |
| 166 | 166 | </select> |
@@ -186,23 +186,23 @@ discard block |
||
| 186 | 186 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?> |
| 187 | 187 | <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox" |
| 188 | 188 | value="1" <?php if ($_['allowUserMounting']) { |
| 189 | - print_unescaped(' checked="checked"'); |
|
| 190 | - } ?> /> |
|
| 189 | + print_unescaped(' checked="checked"'); |
|
| 190 | + } ?> /> |
|
| 191 | 191 | <label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span> |
| 192 | 192 | |
| 193 | 193 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
| 194 | 194 | <?php |
| 195 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
| 196 | - return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
| 197 | - }); |
|
| 198 | - ?> |
|
| 195 | + $userBackends = array_filter($_['backends'], function ($backend) { |
|
| 196 | + return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
| 197 | + }); |
|
| 198 | + ?> |
|
| 199 | 199 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
| 200 | 200 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
| 201 | 201 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
| 202 | 202 | <?php else: ?> |
| 203 | 203 | <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
| 204 | - print_unescaped(' checked="checked"'); |
|
| 205 | - } ?> /> |
|
| 204 | + print_unescaped(' checked="checked"'); |
|
| 205 | + } ?> /> |
|
| 206 | 206 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
| 207 | 207 | <?php endif; ?> |
| 208 | 208 | <?php $i++; ?> |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | <?php |
| 104 | 104 | $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true); |
| 105 | 105 | ?> |
| 106 | -<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" data-can-create-local="<?php echo $canCreateNewLocalStorage?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
|
| 106 | +<form data-can-create="<?php echo $canCreateMounts ? 'true' : 'false' ?>" data-can-create-local="<?php echo $canCreateNewLocalStorage ? 'true' : 'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled'] ? 'true' : 'false'; ?>"> |
|
| 107 | 107 | <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2> |
| 108 | - <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation'));?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
| 108 | + <a target="_blank" rel="noreferrer" class="icon-info" title="<?php p($l->t('Open documentation')); ?>" href="<?php p(link_to_docs('admin-external-storage')); ?>"></a> |
|
| 109 | 109 | <p class="settings-hint"><?php p($l->t('External storage enables you to mount external storage services and devices as secondary Nextcloud storage devices. You may also allow users to mount their own external storage services.')); ?></p> |
| 110 | 110 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
| 111 | 111 | print_unescaped(''.$_['dependencies'].''); |
@@ -150,10 +150,10 @@ discard block |
||
| 150 | 150 | <?php p($l->t('Add storage')); ?> |
| 151 | 151 | </option> |
| 152 | 152 | <?php |
| 153 | - $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) { |
|
| 153 | + $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
| 154 | 154 | return $backend->isVisibleFor($_['visibilityType']); |
| 155 | 155 | }); |
| 156 | - uasort($sortedBackends, function ($a, $b) { |
|
| 156 | + uasort($sortedBackends, function($a, $b) { |
|
| 157 | 157 | return strcasecmp($a->getText(), $b->getText()); |
| 158 | 158 | }); |
| 159 | 159 | ?> |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
| 194 | 194 | <?php |
| 195 | - $userBackends = array_filter($_['backends'], function ($backend) { |
|
| 195 | + $userBackends = array_filter($_['backends'], function($backend) { |
|
| 196 | 196 | return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
| 197 | 197 | }); |
| 198 | 198 | ?> |
@@ -29,40 +29,40 @@ |
||
| 29 | 29 | |
| 30 | 30 | class FedAuth extends AbstractBasic { |
| 31 | 31 | |
| 32 | - /** @var DbHandler */ |
|
| 33 | - private $db; |
|
| 32 | + /** @var DbHandler */ |
|
| 33 | + private $db; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * FedAuth constructor. |
|
| 37 | - * |
|
| 38 | - * @param DbHandler $db |
|
| 39 | - */ |
|
| 40 | - public function __construct(DbHandler $db) { |
|
| 41 | - $this->db = $db; |
|
| 42 | - $this->principalPrefix = 'principals/system/'; |
|
| 35 | + /** |
|
| 36 | + * FedAuth constructor. |
|
| 37 | + * |
|
| 38 | + * @param DbHandler $db |
|
| 39 | + */ |
|
| 40 | + public function __construct(DbHandler $db) { |
|
| 41 | + $this->db = $db; |
|
| 42 | + $this->principalPrefix = 'principals/system/'; |
|
| 43 | 43 | |
| 44 | - // setup realm |
|
| 45 | - $defaults = new \OCP\Defaults(); |
|
| 46 | - $this->realm = $defaults->getName(); |
|
| 47 | - } |
|
| 44 | + // setup realm |
|
| 45 | + $defaults = new \OCP\Defaults(); |
|
| 46 | + $this->realm = $defaults->getName(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Validates a username and password |
|
| 51 | - * |
|
| 52 | - * This method should return true or false depending on if login |
|
| 53 | - * succeeded. |
|
| 54 | - * |
|
| 55 | - * @param string $username |
|
| 56 | - * @param string $password |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - protected function validateUserPass($username, $password) { |
|
| 60 | - return $this->db->auth($username, $password); |
|
| 61 | - } |
|
| 49 | + /** |
|
| 50 | + * Validates a username and password |
|
| 51 | + * |
|
| 52 | + * This method should return true or false depending on if login |
|
| 53 | + * succeeded. |
|
| 54 | + * |
|
| 55 | + * @param string $username |
|
| 56 | + * @param string $password |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + protected function validateUserPass($username, $password) { |
|
| 60 | + return $this->db->auth($username, $password); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @inheritdoc |
|
| 65 | - */ |
|
| 66 | - public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
| 67 | - } |
|
| 63 | + /** |
|
| 64 | + * @inheritdoc |
|
| 65 | + */ |
|
| 66 | + public function challenge(RequestInterface $request, ResponseInterface $response) { |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | */ |
| 135 | 135 | public function requestSharedSecret($url, $token) { |
| 136 | 136 | if ($this->trustedServers->isTrustedServer($url) === false) { |
| 137 | - $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
| 137 | + $this->logger->error('remote server not trusted ('.$url.') while requesting shared secret', ['app' => 'federation']); |
|
| 138 | 138 | throw new OCSForbiddenException(); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | $localToken = $this->dbHandler->getToken($url); |
| 144 | 144 | if (strcmp($localToken, $token) > 0) { |
| 145 | 145 | $this->logger->info( |
| 146 | - 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
| 146 | + 'remote server ('.$url.') presented lower token. We will initiate the exchange of the shared secret.', |
|
| 147 | 147 | ['app' => 'federation'] |
| 148 | 148 | ); |
| 149 | 149 | throw new OCSForbiddenException(); |
@@ -183,14 +183,14 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function getSharedSecret($url, $token) { |
| 185 | 185 | if ($this->trustedServers->isTrustedServer($url) === false) { |
| 186 | - $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
| 186 | + $this->logger->error('remote server not trusted ('.$url.') while getting shared secret', ['app' => 'federation']); |
|
| 187 | 187 | throw new OCSForbiddenException(); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | if ($this->isValidToken($url, $token) === false) { |
| 191 | 191 | $expectedToken = $this->dbHandler->getToken($url); |
| 192 | 192 | $this->logger->error( |
| 193 | - 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
| 193 | + 'remote server ('.$url.') didn\'t send a valid token (got "'.$token.'" but expected "'.$expectedToken.'") while getting shared secret', |
|
| 194 | 194 | ['app' => 'federation'] |
| 195 | 195 | ); |
| 196 | 196 | throw new OCSForbiddenException(); |
@@ -48,164 +48,164 @@ |
||
| 48 | 48 | */ |
| 49 | 49 | class OCSAuthAPIController extends OCSController { |
| 50 | 50 | |
| 51 | - /** @var ISecureRandom */ |
|
| 52 | - private $secureRandom; |
|
| 53 | - |
|
| 54 | - /** @var IJobList */ |
|
| 55 | - private $jobList; |
|
| 56 | - |
|
| 57 | - /** @var TrustedServers */ |
|
| 58 | - private $trustedServers; |
|
| 59 | - |
|
| 60 | - /** @var DbHandler */ |
|
| 61 | - private $dbHandler; |
|
| 62 | - |
|
| 63 | - /** @var ILogger */ |
|
| 64 | - private $logger; |
|
| 65 | - |
|
| 66 | - /** @var ITimeFactory */ |
|
| 67 | - private $timeFactory; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * OCSAuthAPI constructor. |
|
| 71 | - * |
|
| 72 | - * @param string $appName |
|
| 73 | - * @param IRequest $request |
|
| 74 | - * @param ISecureRandom $secureRandom |
|
| 75 | - * @param IJobList $jobList |
|
| 76 | - * @param TrustedServers $trustedServers |
|
| 77 | - * @param DbHandler $dbHandler |
|
| 78 | - * @param ILogger $logger |
|
| 79 | - * @param ITimeFactory $timeFactory |
|
| 80 | - */ |
|
| 81 | - public function __construct( |
|
| 82 | - $appName, |
|
| 83 | - IRequest $request, |
|
| 84 | - ISecureRandom $secureRandom, |
|
| 85 | - IJobList $jobList, |
|
| 86 | - TrustedServers $trustedServers, |
|
| 87 | - DbHandler $dbHandler, |
|
| 88 | - ILogger $logger, |
|
| 89 | - ITimeFactory $timeFactory |
|
| 90 | - ) { |
|
| 91 | - parent::__construct($appName, $request); |
|
| 92 | - |
|
| 93 | - $this->secureRandom = $secureRandom; |
|
| 94 | - $this->jobList = $jobList; |
|
| 95 | - $this->trustedServers = $trustedServers; |
|
| 96 | - $this->dbHandler = $dbHandler; |
|
| 97 | - $this->logger = $logger; |
|
| 98 | - $this->timeFactory = $timeFactory; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @NoCSRFRequired |
|
| 103 | - * @PublicPage |
|
| 104 | - * |
|
| 105 | - * request received to ask remote server for a shared secret, for legacy end-points |
|
| 106 | - * |
|
| 107 | - * @param string $url |
|
| 108 | - * @param string $token |
|
| 109 | - * @return Http\DataResponse |
|
| 110 | - * @throws OCSForbiddenException |
|
| 111 | - */ |
|
| 112 | - public function requestSharedSecretLegacy($url, $token) { |
|
| 113 | - return $this->requestSharedSecret($url, $token); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * @NoCSRFRequired |
|
| 119 | - * @PublicPage |
|
| 120 | - * |
|
| 121 | - * create shared secret and return it, for legacy end-points |
|
| 122 | - * |
|
| 123 | - * @param string $url |
|
| 124 | - * @param string $token |
|
| 125 | - * @return Http\DataResponse |
|
| 126 | - * @throws OCSForbiddenException |
|
| 127 | - */ |
|
| 128 | - public function getSharedSecretLegacy($url, $token) { |
|
| 129 | - return $this->getSharedSecret($url, $token); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @NoCSRFRequired |
|
| 134 | - * @PublicPage |
|
| 135 | - * |
|
| 136 | - * request received to ask remote server for a shared secret |
|
| 137 | - * |
|
| 138 | - * @param string $url |
|
| 139 | - * @param string $token |
|
| 140 | - * @return Http\DataResponse |
|
| 141 | - * @throws OCSForbiddenException |
|
| 142 | - */ |
|
| 143 | - public function requestSharedSecret($url, $token) { |
|
| 144 | - if ($this->trustedServers->isTrustedServer($url) === false) { |
|
| 145 | - $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
| 146 | - throw new OCSForbiddenException(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // if both server initiated the exchange of the shared secret the greater |
|
| 150 | - // token wins |
|
| 151 | - $localToken = $this->dbHandler->getToken($url); |
|
| 152 | - if (strcmp($localToken, $token) > 0) { |
|
| 153 | - $this->logger->info( |
|
| 154 | - 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
| 155 | - ['app' => 'federation'] |
|
| 156 | - ); |
|
| 157 | - throw new OCSForbiddenException(); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $this->jobList->add( |
|
| 161 | - 'OCA\Federation\BackgroundJob\GetSharedSecret', |
|
| 162 | - [ |
|
| 163 | - 'url' => $url, |
|
| 164 | - 'token' => $token, |
|
| 165 | - 'created' => $this->timeFactory->getTime() |
|
| 166 | - ] |
|
| 167 | - ); |
|
| 168 | - |
|
| 169 | - return new Http\DataResponse(); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - /** |
|
| 173 | - * @NoCSRFRequired |
|
| 174 | - * @PublicPage |
|
| 175 | - * |
|
| 176 | - * create shared secret and return it |
|
| 177 | - * |
|
| 178 | - * @param string $url |
|
| 179 | - * @param string $token |
|
| 180 | - * @return Http\DataResponse |
|
| 181 | - * @throws OCSForbiddenException |
|
| 182 | - */ |
|
| 183 | - public function getSharedSecret($url, $token) { |
|
| 184 | - if ($this->trustedServers->isTrustedServer($url) === false) { |
|
| 185 | - $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
| 186 | - throw new OCSForbiddenException(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if ($this->isValidToken($url, $token) === false) { |
|
| 190 | - $expectedToken = $this->dbHandler->getToken($url); |
|
| 191 | - $this->logger->error( |
|
| 192 | - 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
| 193 | - ['app' => 'federation'] |
|
| 194 | - ); |
|
| 195 | - throw new OCSForbiddenException(); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - $sharedSecret = $this->secureRandom->generate(32); |
|
| 199 | - |
|
| 200 | - $this->trustedServers->addSharedSecret($url, $sharedSecret); |
|
| 201 | - |
|
| 202 | - return new Http\DataResponse([ |
|
| 203 | - 'sharedSecret' => $sharedSecret |
|
| 204 | - ]); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - protected function isValidToken($url, $token) { |
|
| 208 | - $storedToken = $this->dbHandler->getToken($url); |
|
| 209 | - return hash_equals($storedToken, $token); |
|
| 210 | - } |
|
| 51 | + /** @var ISecureRandom */ |
|
| 52 | + private $secureRandom; |
|
| 53 | + |
|
| 54 | + /** @var IJobList */ |
|
| 55 | + private $jobList; |
|
| 56 | + |
|
| 57 | + /** @var TrustedServers */ |
|
| 58 | + private $trustedServers; |
|
| 59 | + |
|
| 60 | + /** @var DbHandler */ |
|
| 61 | + private $dbHandler; |
|
| 62 | + |
|
| 63 | + /** @var ILogger */ |
|
| 64 | + private $logger; |
|
| 65 | + |
|
| 66 | + /** @var ITimeFactory */ |
|
| 67 | + private $timeFactory; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * OCSAuthAPI constructor. |
|
| 71 | + * |
|
| 72 | + * @param string $appName |
|
| 73 | + * @param IRequest $request |
|
| 74 | + * @param ISecureRandom $secureRandom |
|
| 75 | + * @param IJobList $jobList |
|
| 76 | + * @param TrustedServers $trustedServers |
|
| 77 | + * @param DbHandler $dbHandler |
|
| 78 | + * @param ILogger $logger |
|
| 79 | + * @param ITimeFactory $timeFactory |
|
| 80 | + */ |
|
| 81 | + public function __construct( |
|
| 82 | + $appName, |
|
| 83 | + IRequest $request, |
|
| 84 | + ISecureRandom $secureRandom, |
|
| 85 | + IJobList $jobList, |
|
| 86 | + TrustedServers $trustedServers, |
|
| 87 | + DbHandler $dbHandler, |
|
| 88 | + ILogger $logger, |
|
| 89 | + ITimeFactory $timeFactory |
|
| 90 | + ) { |
|
| 91 | + parent::__construct($appName, $request); |
|
| 92 | + |
|
| 93 | + $this->secureRandom = $secureRandom; |
|
| 94 | + $this->jobList = $jobList; |
|
| 95 | + $this->trustedServers = $trustedServers; |
|
| 96 | + $this->dbHandler = $dbHandler; |
|
| 97 | + $this->logger = $logger; |
|
| 98 | + $this->timeFactory = $timeFactory; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @NoCSRFRequired |
|
| 103 | + * @PublicPage |
|
| 104 | + * |
|
| 105 | + * request received to ask remote server for a shared secret, for legacy end-points |
|
| 106 | + * |
|
| 107 | + * @param string $url |
|
| 108 | + * @param string $token |
|
| 109 | + * @return Http\DataResponse |
|
| 110 | + * @throws OCSForbiddenException |
|
| 111 | + */ |
|
| 112 | + public function requestSharedSecretLegacy($url, $token) { |
|
| 113 | + return $this->requestSharedSecret($url, $token); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * @NoCSRFRequired |
|
| 119 | + * @PublicPage |
|
| 120 | + * |
|
| 121 | + * create shared secret and return it, for legacy end-points |
|
| 122 | + * |
|
| 123 | + * @param string $url |
|
| 124 | + * @param string $token |
|
| 125 | + * @return Http\DataResponse |
|
| 126 | + * @throws OCSForbiddenException |
|
| 127 | + */ |
|
| 128 | + public function getSharedSecretLegacy($url, $token) { |
|
| 129 | + return $this->getSharedSecret($url, $token); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @NoCSRFRequired |
|
| 134 | + * @PublicPage |
|
| 135 | + * |
|
| 136 | + * request received to ask remote server for a shared secret |
|
| 137 | + * |
|
| 138 | + * @param string $url |
|
| 139 | + * @param string $token |
|
| 140 | + * @return Http\DataResponse |
|
| 141 | + * @throws OCSForbiddenException |
|
| 142 | + */ |
|
| 143 | + public function requestSharedSecret($url, $token) { |
|
| 144 | + if ($this->trustedServers->isTrustedServer($url) === false) { |
|
| 145 | + $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']); |
|
| 146 | + throw new OCSForbiddenException(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // if both server initiated the exchange of the shared secret the greater |
|
| 150 | + // token wins |
|
| 151 | + $localToken = $this->dbHandler->getToken($url); |
|
| 152 | + if (strcmp($localToken, $token) > 0) { |
|
| 153 | + $this->logger->info( |
|
| 154 | + 'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.', |
|
| 155 | + ['app' => 'federation'] |
|
| 156 | + ); |
|
| 157 | + throw new OCSForbiddenException(); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $this->jobList->add( |
|
| 161 | + 'OCA\Federation\BackgroundJob\GetSharedSecret', |
|
| 162 | + [ |
|
| 163 | + 'url' => $url, |
|
| 164 | + 'token' => $token, |
|
| 165 | + 'created' => $this->timeFactory->getTime() |
|
| 166 | + ] |
|
| 167 | + ); |
|
| 168 | + |
|
| 169 | + return new Http\DataResponse(); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + /** |
|
| 173 | + * @NoCSRFRequired |
|
| 174 | + * @PublicPage |
|
| 175 | + * |
|
| 176 | + * create shared secret and return it |
|
| 177 | + * |
|
| 178 | + * @param string $url |
|
| 179 | + * @param string $token |
|
| 180 | + * @return Http\DataResponse |
|
| 181 | + * @throws OCSForbiddenException |
|
| 182 | + */ |
|
| 183 | + public function getSharedSecret($url, $token) { |
|
| 184 | + if ($this->trustedServers->isTrustedServer($url) === false) { |
|
| 185 | + $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']); |
|
| 186 | + throw new OCSForbiddenException(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if ($this->isValidToken($url, $token) === false) { |
|
| 190 | + $expectedToken = $this->dbHandler->getToken($url); |
|
| 191 | + $this->logger->error( |
|
| 192 | + 'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret', |
|
| 193 | + ['app' => 'federation'] |
|
| 194 | + ); |
|
| 195 | + throw new OCSForbiddenException(); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + $sharedSecret = $this->secureRandom->generate(32); |
|
| 199 | + |
|
| 200 | + $this->trustedServers->addSharedSecret($url, $sharedSecret); |
|
| 201 | + |
|
| 202 | + return new Http\DataResponse([ |
|
| 203 | + 'sharedSecret' => $sharedSecret |
|
| 204 | + ]); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + protected function isValidToken($url, $token) { |
|
| 208 | + $storedToken = $this->dbHandler->getToken($url); |
|
| 209 | + return hash_equals($storedToken, $token); |
|
| 210 | + } |
|
| 211 | 211 | } |
@@ -29,32 +29,32 @@ |
||
| 29 | 29 | |
| 30 | 30 | class LastUsedController extends Controller { |
| 31 | 31 | |
| 32 | - /** @var IConfig */ |
|
| 33 | - protected $config; |
|
| 32 | + /** @var IConfig */ |
|
| 33 | + protected $config; |
|
| 34 | 34 | |
| 35 | - /** @var IUserSession */ |
|
| 36 | - protected $userSession; |
|
| 35 | + /** @var IUserSession */ |
|
| 36 | + protected $userSession; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param string $appName |
|
| 40 | - * @param IRequest $request |
|
| 41 | - * @param IConfig $config |
|
| 42 | - * @param IUserSession $userSession |
|
| 43 | - */ |
|
| 44 | - public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
| 45 | - parent::__construct($appName, $request); |
|
| 46 | - $this->config = $config; |
|
| 47 | - $this->userSession = $userSession; |
|
| 48 | - } |
|
| 38 | + /** |
|
| 39 | + * @param string $appName |
|
| 40 | + * @param IRequest $request |
|
| 41 | + * @param IConfig $config |
|
| 42 | + * @param IUserSession $userSession |
|
| 43 | + */ |
|
| 44 | + public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) { |
|
| 45 | + parent::__construct($appName, $request); |
|
| 46 | + $this->config = $config; |
|
| 47 | + $this->userSession = $userSession; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @NoAdminRequired |
|
| 52 | - */ |
|
| 53 | - public function getLastUsedTagIds() { |
|
| 54 | - $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
| 55 | - $tagIds = json_decode($lastUsed, true); |
|
| 56 | - return new DataResponse(array_map(function ($id) { |
|
| 57 | - return (string) $id; |
|
| 58 | - }, $tagIds)); |
|
| 59 | - } |
|
| 50 | + /** |
|
| 51 | + * @NoAdminRequired |
|
| 52 | + */ |
|
| 53 | + public function getLastUsedTagIds() { |
|
| 54 | + $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
|
| 55 | + $tagIds = json_decode($lastUsed, true); |
|
| 56 | + return new DataResponse(array_map(function ($id) { |
|
| 57 | + return (string) $id; |
|
| 58 | + }, $tagIds)); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | public function getLastUsedTagIds() { |
| 54 | 54 | $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]'); |
| 55 | 55 | $tagIds = json_decode($lastUsed, true); |
| 56 | - return new DataResponse(array_map(function ($id) { |
|
| 56 | + return new DataResponse(array_map(function($id) { |
|
| 57 | 57 | return (string) $id; |
| 58 | 58 | }, $tagIds)); |
| 59 | 59 | } |
@@ -31,30 +31,30 @@ |
||
| 31 | 31 | use OCP\Command\ICommand; |
| 32 | 32 | |
| 33 | 33 | class Expire implements ICommand { |
| 34 | - use FileAccess; |
|
| 34 | + use FileAccess; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private $user; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private $user; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $user |
|
| 43 | - */ |
|
| 44 | - public function __construct($user) { |
|
| 45 | - $this->user = $user; |
|
| 46 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $user |
|
| 43 | + */ |
|
| 44 | + public function __construct($user) { |
|
| 45 | + $this->user = $user; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - public function handle() { |
|
| 49 | - $userManager = \OC::$server->getUserManager(); |
|
| 50 | - if (!$userManager->userExists($this->user)) { |
|
| 51 | - // User has been deleted already |
|
| 52 | - return; |
|
| 53 | - } |
|
| 48 | + public function handle() { |
|
| 49 | + $userManager = \OC::$server->getUserManager(); |
|
| 50 | + if (!$userManager->userExists($this->user)) { |
|
| 51 | + // User has been deleted already |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - \OC_Util::tearDownFS(); |
|
| 56 | - \OC_Util::setupFS($this->user); |
|
| 57 | - Trashbin::expire($this->user); |
|
| 58 | - \OC_Util::tearDownFS(); |
|
| 59 | - } |
|
| 55 | + \OC_Util::tearDownFS(); |
|
| 56 | + \OC_Util::setupFS($this->user); |
|
| 57 | + Trashbin::expire($this->user); |
|
| 58 | + \OC_Util::tearDownFS(); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | } else { |
| 91 | 91 | $p = new ProgressBar($output); |
| 92 | 92 | $p->start(); |
| 93 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
| 93 | + $this->userManager->callForSeenUsers(function(IUser $user) use ($p) { |
|
| 94 | 94 | $p->advance(); |
| 95 | 95 | $this->expireTrashForUser($user); |
| 96 | 96 | }); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | \OC_Util::setupFS($user); |
| 119 | 119 | |
| 120 | 120 | // Check if this user has a trashbin directory |
| 121 | - $view = new \OC\Files\View('/' . $user); |
|
| 121 | + $view = new \OC\Files\View('/'.$user); |
|
| 122 | 122 | if (!$view->is_dir('/files_trashbin/files')) { |
| 123 | 123 | return false; |
| 124 | 124 | } |
@@ -38,95 +38,95 @@ |
||
| 38 | 38 | |
| 39 | 39 | class ExpireTrash extends Command { |
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var Expiration |
|
| 43 | - */ |
|
| 44 | - private $expiration; |
|
| 41 | + /** |
|
| 42 | + * @var Expiration |
|
| 43 | + */ |
|
| 44 | + private $expiration; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var IUserManager |
|
| 48 | - */ |
|
| 49 | - private $userManager; |
|
| 46 | + /** |
|
| 47 | + * @var IUserManager |
|
| 48 | + */ |
|
| 49 | + private $userManager; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @param IUserManager|null $userManager |
|
| 53 | - * @param Expiration|null $expiration |
|
| 54 | - */ |
|
| 55 | - public function __construct(IUserManager $userManager = null, |
|
| 56 | - Expiration $expiration = null) { |
|
| 57 | - parent::__construct(); |
|
| 51 | + /** |
|
| 52 | + * @param IUserManager|null $userManager |
|
| 53 | + * @param Expiration|null $expiration |
|
| 54 | + */ |
|
| 55 | + public function __construct(IUserManager $userManager = null, |
|
| 56 | + Expiration $expiration = null) { |
|
| 57 | + parent::__construct(); |
|
| 58 | 58 | |
| 59 | - $this->userManager = $userManager; |
|
| 60 | - $this->expiration = $expiration; |
|
| 61 | - } |
|
| 59 | + $this->userManager = $userManager; |
|
| 60 | + $this->expiration = $expiration; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - protected function configure() { |
|
| 64 | - $this |
|
| 65 | - ->setName('trashbin:expire') |
|
| 66 | - ->setDescription('Expires the users trashbin') |
|
| 67 | - ->addArgument( |
|
| 68 | - 'user_id', |
|
| 69 | - InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 70 | - 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
| 71 | - ); |
|
| 72 | - } |
|
| 63 | + protected function configure() { |
|
| 64 | + $this |
|
| 65 | + ->setName('trashbin:expire') |
|
| 66 | + ->setDescription('Expires the users trashbin') |
|
| 67 | + ->addArgument( |
|
| 68 | + 'user_id', |
|
| 69 | + InputArgument::OPTIONAL | InputArgument::IS_ARRAY, |
|
| 70 | + 'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired' |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 75 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 76 | - if (!$maxAge) { |
|
| 77 | - $output->writeln("Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)"); |
|
| 78 | - return 1; |
|
| 79 | - } |
|
| 74 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 75 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 76 | + if (!$maxAge) { |
|
| 77 | + $output->writeln("Auto expiration is configured - keeps files and folders in the trash bin for 30 days and automatically deletes anytime after that if space is needed (note: files may not be deleted if space is not needed)"); |
|
| 78 | + return 1; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - $users = $input->getArgument('user_id'); |
|
| 82 | - if (!empty($users)) { |
|
| 83 | - foreach ($users as $user) { |
|
| 84 | - if ($this->userManager->userExists($user)) { |
|
| 85 | - $output->writeln("Remove deleted files of <info>$user</info>"); |
|
| 86 | - $userObject = $this->userManager->get($user); |
|
| 87 | - $this->expireTrashForUser($userObject); |
|
| 88 | - } else { |
|
| 89 | - $output->writeln("<error>Unknown user $user</error>"); |
|
| 90 | - return 1; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - } else { |
|
| 94 | - $p = new ProgressBar($output); |
|
| 95 | - $p->start(); |
|
| 96 | - $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
| 97 | - $p->advance(); |
|
| 98 | - $this->expireTrashForUser($user); |
|
| 99 | - }); |
|
| 100 | - $p->finish(); |
|
| 101 | - $output->writeln(''); |
|
| 102 | - } |
|
| 103 | - return 0; |
|
| 104 | - } |
|
| 81 | + $users = $input->getArgument('user_id'); |
|
| 82 | + if (!empty($users)) { |
|
| 83 | + foreach ($users as $user) { |
|
| 84 | + if ($this->userManager->userExists($user)) { |
|
| 85 | + $output->writeln("Remove deleted files of <info>$user</info>"); |
|
| 86 | + $userObject = $this->userManager->get($user); |
|
| 87 | + $this->expireTrashForUser($userObject); |
|
| 88 | + } else { |
|
| 89 | + $output->writeln("<error>Unknown user $user</error>"); |
|
| 90 | + return 1; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + } else { |
|
| 94 | + $p = new ProgressBar($output); |
|
| 95 | + $p->start(); |
|
| 96 | + $this->userManager->callForSeenUsers(function (IUser $user) use ($p) { |
|
| 97 | + $p->advance(); |
|
| 98 | + $this->expireTrashForUser($user); |
|
| 99 | + }); |
|
| 100 | + $p->finish(); |
|
| 101 | + $output->writeln(''); |
|
| 102 | + } |
|
| 103 | + return 0; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - public function expireTrashForUser(IUser $user) { |
|
| 107 | - $uid = $user->getUID(); |
|
| 108 | - if (!$this->setupFS($uid)) { |
|
| 109 | - return; |
|
| 110 | - } |
|
| 111 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 112 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 113 | - } |
|
| 106 | + public function expireTrashForUser(IUser $user) { |
|
| 107 | + $uid = $user->getUID(); |
|
| 108 | + if (!$this->setupFS($uid)) { |
|
| 109 | + return; |
|
| 110 | + } |
|
| 111 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 112 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Act on behalf on trash item owner |
|
| 117 | - * @param string $user |
|
| 118 | - * @return boolean |
|
| 119 | - */ |
|
| 120 | - protected function setupFS($user) { |
|
| 121 | - \OC_Util::tearDownFS(); |
|
| 122 | - \OC_Util::setupFS($user); |
|
| 115 | + /** |
|
| 116 | + * Act on behalf on trash item owner |
|
| 117 | + * @param string $user |
|
| 118 | + * @return boolean |
|
| 119 | + */ |
|
| 120 | + protected function setupFS($user) { |
|
| 121 | + \OC_Util::tearDownFS(); |
|
| 122 | + \OC_Util::setupFS($user); |
|
| 123 | 123 | |
| 124 | - // Check if this user has a trashbin directory |
|
| 125 | - $view = new \OC\Files\View('/' . $user); |
|
| 126 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
| 127 | - return false; |
|
| 128 | - } |
|
| 124 | + // Check if this user has a trashbin directory |
|
| 125 | + $view = new \OC\Files\View('/' . $user); |
|
| 126 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
| 127 | + return false; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - return true; |
|
| 131 | - } |
|
| 130 | + return true; |
|
| 131 | + } |
|
| 132 | 132 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | return; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 81 | + $this->userManager->callForSeenUsers(function(IUser $user) { |
|
| 82 | 82 | $uid = $user->getUID(); |
| 83 | 83 | if (!$this->setupFS($uid)) { |
| 84 | 84 | return; |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | \OC_Util::setupFS($user); |
| 101 | 101 | |
| 102 | 102 | // Check if this user has a trashbin directory |
| 103 | - $view = new \OC\Files\View('/' . $user); |
|
| 103 | + $view = new \OC\Files\View('/'.$user); |
|
| 104 | 104 | if (!$view->is_dir('/files_trashbin/files')) { |
| 105 | 105 | return false; |
| 106 | 106 | } |
@@ -36,84 +36,84 @@ |
||
| 36 | 36 | |
| 37 | 37 | class ExpireTrash extends \OC\BackgroundJob\TimedJob { |
| 38 | 38 | |
| 39 | - /** @var IConfig */ |
|
| 40 | - private $config; |
|
| 39 | + /** @var IConfig */ |
|
| 40 | + private $config; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var Expiration |
|
| 44 | - */ |
|
| 45 | - private $expiration; |
|
| 42 | + /** |
|
| 43 | + * @var Expiration |
|
| 44 | + */ |
|
| 45 | + private $expiration; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var IUserManager |
|
| 49 | - */ |
|
| 50 | - private $userManager; |
|
| 47 | + /** |
|
| 48 | + * @var IUserManager |
|
| 49 | + */ |
|
| 50 | + private $userManager; |
|
| 51 | 51 | |
| 52 | - public function __construct(IConfig $config = null, |
|
| 53 | - IUserManager $userManager = null, |
|
| 54 | - Expiration $expiration = null) { |
|
| 55 | - // Run once per 30 minutes |
|
| 56 | - $this->setInterval(60 * 30); |
|
| 52 | + public function __construct(IConfig $config = null, |
|
| 53 | + IUserManager $userManager = null, |
|
| 54 | + Expiration $expiration = null) { |
|
| 55 | + // Run once per 30 minutes |
|
| 56 | + $this->setInterval(60 * 30); |
|
| 57 | 57 | |
| 58 | - if ($config === null || $expiration === null || $userManager === null) { |
|
| 59 | - $this->fixDIForJobs(); |
|
| 60 | - } else { |
|
| 61 | - $this->config = $config; |
|
| 62 | - $this->userManager = $userManager; |
|
| 63 | - $this->expiration = $expiration; |
|
| 64 | - } |
|
| 65 | - } |
|
| 58 | + if ($config === null || $expiration === null || $userManager === null) { |
|
| 59 | + $this->fixDIForJobs(); |
|
| 60 | + } else { |
|
| 61 | + $this->config = $config; |
|
| 62 | + $this->userManager = $userManager; |
|
| 63 | + $this->expiration = $expiration; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - protected function fixDIForJobs() { |
|
| 68 | - /** @var Application $application */ |
|
| 69 | - $application = \OC::$server->query(Application::class); |
|
| 70 | - $this->config = $application->getContainer()->get(IConfig::class); |
|
| 71 | - $this->userManager = \OC::$server->getUserManager(); |
|
| 72 | - $this->expiration = $application->getContainer()->query('Expiration'); |
|
| 73 | - } |
|
| 67 | + protected function fixDIForJobs() { |
|
| 68 | + /** @var Application $application */ |
|
| 69 | + $application = \OC::$server->query(Application::class); |
|
| 70 | + $this->config = $application->getContainer()->get(IConfig::class); |
|
| 71 | + $this->userManager = \OC::$server->getUserManager(); |
|
| 72 | + $this->expiration = $application->getContainer()->query('Expiration'); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param $argument |
|
| 77 | - * @throws \Exception |
|
| 78 | - */ |
|
| 79 | - protected function run($argument) { |
|
| 80 | - $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); |
|
| 81 | - if ($backgroundJob === 'no') { |
|
| 82 | - return; |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * @param $argument |
|
| 77 | + * @throws \Exception |
|
| 78 | + */ |
|
| 79 | + protected function run($argument) { |
|
| 80 | + $backgroundJob = $this->config->getAppValue('files_trashbin', 'background_job_expire_trash', 'yes'); |
|
| 81 | + if ($backgroundJob === 'no') { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 86 | - if (!$maxAge) { |
|
| 87 | - return; |
|
| 88 | - } |
|
| 85 | + $maxAge = $this->expiration->getMaxAgeAsTimestamp(); |
|
| 86 | + if (!$maxAge) { |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 91 | - $uid = $user->getUID(); |
|
| 92 | - if (!$this->setupFS($uid)) { |
|
| 93 | - return; |
|
| 94 | - } |
|
| 95 | - $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 96 | - Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 97 | - }); |
|
| 90 | + $this->userManager->callForSeenUsers(function (IUser $user) { |
|
| 91 | + $uid = $user->getUID(); |
|
| 92 | + if (!$this->setupFS($uid)) { |
|
| 93 | + return; |
|
| 94 | + } |
|
| 95 | + $dirContent = Helper::getTrashFiles('/', $uid, 'mtime'); |
|
| 96 | + Trashbin::deleteExpiredFiles($dirContent, $uid); |
|
| 97 | + }); |
|
| 98 | 98 | |
| 99 | - \OC_Util::tearDownFS(); |
|
| 100 | - } |
|
| 99 | + \OC_Util::tearDownFS(); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Act on behalf on trash item owner |
|
| 104 | - * @param string $user |
|
| 105 | - * @return boolean |
|
| 106 | - */ |
|
| 107 | - protected function setupFS($user) { |
|
| 108 | - \OC_Util::tearDownFS(); |
|
| 109 | - \OC_Util::setupFS($user); |
|
| 102 | + /** |
|
| 103 | + * Act on behalf on trash item owner |
|
| 104 | + * @param string $user |
|
| 105 | + * @return boolean |
|
| 106 | + */ |
|
| 107 | + protected function setupFS($user) { |
|
| 108 | + \OC_Util::tearDownFS(); |
|
| 109 | + \OC_Util::setupFS($user); |
|
| 110 | 110 | |
| 111 | - // Check if this user has a trashbin directory |
|
| 112 | - $view = new \OC\Files\View('/' . $user); |
|
| 113 | - if (!$view->is_dir('/files_trashbin/files')) { |
|
| 114 | - return false; |
|
| 115 | - } |
|
| 111 | + // Check if this user has a trashbin directory |
|
| 112 | + $view = new \OC\Files\View('/' . $user); |
|
| 113 | + if (!$view->is_dir('/files_trashbin/files')) { |
|
| 114 | + return false; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return true; |
|
| 118 | - } |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $result = []; |
| 45 | 45 | $timestamp = null; |
| 46 | 46 | |
| 47 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 47 | + $view = new \OC\Files\View('/'.$user.'/files_trashbin/files'); |
|
| 48 | 48 | |
| 49 | 49 | if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
| 50 | 50 | throw new \Exception('Directory does not exists'); |
@@ -91,12 +91,12 @@ discard block |
||
| 91 | 91 | ]; |
| 92 | 92 | if ($originalPath) { |
| 93 | 93 | if ($originalPath !== '.') { |
| 94 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 94 | + $i['extraData'] = $originalPath.'/'.$originalName; |
|
| 95 | 95 | } else { |
| 96 | 96 | $i['extraData'] = $originalName; |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 99 | + $result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | if ($sortAttribute !== '') { |
@@ -36,95 +36,95 @@ |
||
| 36 | 36 | use OCP\Files\Cache\ICacheEntry; |
| 37 | 37 | |
| 38 | 38 | class Helper { |
| 39 | - /** |
|
| 40 | - * Retrieves the contents of a trash bin directory. |
|
| 41 | - * |
|
| 42 | - * @param string $dir path to the directory inside the trashbin |
|
| 43 | - * or empty to retrieve the root of the trashbin |
|
| 44 | - * @param string $user |
|
| 45 | - * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 46 | - * @param bool $sortDescending true for descending sort, false otherwise |
|
| 47 | - * @return \OCP\Files\FileInfo[] |
|
| 48 | - */ |
|
| 49 | - public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 50 | - $result = []; |
|
| 51 | - $timestamp = null; |
|
| 39 | + /** |
|
| 40 | + * Retrieves the contents of a trash bin directory. |
|
| 41 | + * |
|
| 42 | + * @param string $dir path to the directory inside the trashbin |
|
| 43 | + * or empty to retrieve the root of the trashbin |
|
| 44 | + * @param string $user |
|
| 45 | + * @param string $sortAttribute attribute to sort on or empty to disable sorting |
|
| 46 | + * @param bool $sortDescending true for descending sort, false otherwise |
|
| 47 | + * @return \OCP\Files\FileInfo[] |
|
| 48 | + */ |
|
| 49 | + public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) { |
|
| 50 | + $result = []; |
|
| 51 | + $timestamp = null; |
|
| 52 | 52 | |
| 53 | - $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 53 | + $view = new \OC\Files\View('/' . $user . '/files_trashbin/files'); |
|
| 54 | 54 | |
| 55 | - if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 56 | - throw new \Exception('Directory does not exists'); |
|
| 57 | - } |
|
| 55 | + if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) { |
|
| 56 | + throw new \Exception('Directory does not exists'); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - $mount = $view->getMount($dir); |
|
| 60 | - $storage = $mount->getStorage(); |
|
| 61 | - $absoluteDir = $view->getAbsolutePath($dir); |
|
| 62 | - $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 59 | + $mount = $view->getMount($dir); |
|
| 60 | + $storage = $mount->getStorage(); |
|
| 61 | + $absoluteDir = $view->getAbsolutePath($dir); |
|
| 62 | + $internalPath = $mount->getInternalPath($absoluteDir); |
|
| 63 | 63 | |
| 64 | - $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 65 | - $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 66 | - foreach ($dirContent as $entry) { |
|
| 67 | - $entryName = $entry->getName(); |
|
| 68 | - $name = $entryName; |
|
| 69 | - if ($dir === '' || $dir === '/') { |
|
| 70 | - $pathparts = pathinfo($entryName); |
|
| 71 | - $timestamp = substr($pathparts['extension'], 1); |
|
| 72 | - $name = $pathparts['filename']; |
|
| 73 | - } elseif ($timestamp === null) { |
|
| 74 | - // for subfolders we need to calculate the timestamp only once |
|
| 75 | - $parts = explode('/', ltrim($dir, '/')); |
|
| 76 | - $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 77 | - } |
|
| 78 | - $originalPath = ''; |
|
| 79 | - $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
| 80 | - if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 81 | - $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 82 | - if (substr($originalPath, -1) === '/') { |
|
| 83 | - $originalPath = substr($originalPath, 0, -1); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 87 | - $i = [ |
|
| 88 | - 'name' => $name, |
|
| 89 | - 'mtime' => $timestamp, |
|
| 90 | - 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 91 | - 'type' => $type, |
|
| 92 | - 'directory' => ($dir === '/') ? '' : $dir, |
|
| 93 | - 'size' => $entry->getSize(), |
|
| 94 | - 'etag' => '', |
|
| 95 | - 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 96 | - 'fileid' => $entry->getId(), |
|
| 97 | - ]; |
|
| 98 | - if ($originalPath) { |
|
| 99 | - if ($originalPath !== '.') { |
|
| 100 | - $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 101 | - } else { |
|
| 102 | - $i['extraData'] = $originalName; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 106 | - } |
|
| 64 | + $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user); |
|
| 65 | + $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir))); |
|
| 66 | + foreach ($dirContent as $entry) { |
|
| 67 | + $entryName = $entry->getName(); |
|
| 68 | + $name = $entryName; |
|
| 69 | + if ($dir === '' || $dir === '/') { |
|
| 70 | + $pathparts = pathinfo($entryName); |
|
| 71 | + $timestamp = substr($pathparts['extension'], 1); |
|
| 72 | + $name = $pathparts['filename']; |
|
| 73 | + } elseif ($timestamp === null) { |
|
| 74 | + // for subfolders we need to calculate the timestamp only once |
|
| 75 | + $parts = explode('/', ltrim($dir, '/')); |
|
| 76 | + $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1); |
|
| 77 | + } |
|
| 78 | + $originalPath = ''; |
|
| 79 | + $originalName = substr($entryName, 0, -strlen($timestamp) - 2); |
|
| 80 | + if (isset($originalLocations[$originalName][$timestamp])) { |
|
| 81 | + $originalPath = $originalLocations[$originalName][$timestamp]; |
|
| 82 | + if (substr($originalPath, -1) === '/') { |
|
| 83 | + $originalPath = substr($originalPath, 0, -1); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file'; |
|
| 87 | + $i = [ |
|
| 88 | + 'name' => $name, |
|
| 89 | + 'mtime' => $timestamp, |
|
| 90 | + 'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name), |
|
| 91 | + 'type' => $type, |
|
| 92 | + 'directory' => ($dir === '/') ? '' : $dir, |
|
| 93 | + 'size' => $entry->getSize(), |
|
| 94 | + 'etag' => '', |
|
| 95 | + 'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE, |
|
| 96 | + 'fileid' => $entry->getId(), |
|
| 97 | + ]; |
|
| 98 | + if ($originalPath) { |
|
| 99 | + if ($originalPath !== '.') { |
|
| 100 | + $i['extraData'] = $originalPath . '/' . $originalName; |
|
| 101 | + } else { |
|
| 102 | + $i['extraData'] = $originalName; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - if ($sortAttribute !== '') { |
|
| 109 | - return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 110 | - } |
|
| 111 | - return $result; |
|
| 112 | - } |
|
| 108 | + if ($sortAttribute !== '') { |
|
| 109 | + return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending); |
|
| 110 | + } |
|
| 111 | + return $result; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Format file infos for JSON |
|
| 116 | - * |
|
| 117 | - * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 118 | - */ |
|
| 119 | - public static function formatFileInfos($fileInfos) { |
|
| 120 | - $files = []; |
|
| 121 | - foreach ($fileInfos as $i) { |
|
| 122 | - $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 123 | - $entry['id'] = $i->getId(); |
|
| 124 | - $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 125 | - $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 126 | - $files[] = $entry; |
|
| 127 | - } |
|
| 128 | - return $files; |
|
| 129 | - } |
|
| 114 | + /** |
|
| 115 | + * Format file infos for JSON |
|
| 116 | + * |
|
| 117 | + * @param \OCP\Files\FileInfo[] $fileInfos file infos |
|
| 118 | + */ |
|
| 119 | + public static function formatFileInfos($fileInfos) { |
|
| 120 | + $files = []; |
|
| 121 | + foreach ($fileInfos as $i) { |
|
| 122 | + $entry = \OCA\Files\Helper::formatFileInfo($i); |
|
| 123 | + $entry['id'] = $i->getId(); |
|
| 124 | + $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image |
|
| 125 | + $entry['permissions'] = \OCP\Constants::PERMISSION_READ; |
|
| 126 | + $files[] = $entry; |
|
| 127 | + } |
|
| 128 | + return $files; |
|
| 129 | + } |
|
| 130 | 130 | } |