1
0

settings.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2012-2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. use OCA\Files_External\Lib\Auth\AuthMechanism;
  8. use OCA\Files_External\Lib\Backend\Backend;
  9. use OCA\Files_External\Lib\DefinitionParameter;
  10. use OCA\Files_External\Service\BackendService;
  11. /** @var array $_ */
  12. $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting'];
  13. $l->t("Enable encryption");
  14. $l->t("Enable previews");
  15. $l->t("Enable sharing");
  16. $l->t("Check for changes");
  17. $l->t("Never");
  18. $l->t("Once every direct access");
  19. $l->t('Read only');
  20. script('files_external', [
  21. 'settings',
  22. 'templates'
  23. ]);
  24. style('files_external', 'settings');
  25. // load custom JS
  26. foreach ($_['backends'] as $backend) {
  27. /** @var Backend $backend */
  28. $scripts = $backend->getCustomJs();
  29. foreach ($scripts as $script) {
  30. script('files_external', $script);
  31. }
  32. }
  33. foreach ($_['authMechanisms'] as $authMechanism) {
  34. /** @var AuthMechanism $authMechanism */
  35. $scripts = $authMechanism->getCustomJs();
  36. foreach ($scripts as $script) {
  37. script('files_external', $script);
  38. }
  39. }
  40. function writeParameterInput($parameter, $options, $classes = []) {
  41. $value = '';
  42. if (isset($options[$parameter->getName()])) {
  43. $value = $options[$parameter->getName()];
  44. }
  45. $placeholder = $parameter->getText();
  46. $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL);
  47. switch ($parameter->getType()) {
  48. case DefinitionParameter::VALUE_PASSWORD: ?>
  49. <?php if ($is_optional) {
  50. $classes[] = 'optional';
  51. } ?>
  52. <input type="password"
  53. <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  54. data-parameter="<?php p($parameter->getName()); ?>"
  55. value="<?php p($value); ?>"
  56. placeholder="<?php p($placeholder); ?>"
  57. />
  58. <?php
  59. break;
  60. case DefinitionParameter::VALUE_BOOLEAN: ?>
  61. <?php $checkboxId = uniqid("checkbox_"); ?>
  62. <div>
  63. <label>
  64. <input type="checkbox"
  65. id="<?php p($checkboxId); ?>"
  66. <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  67. data-parameter="<?php p($parameter->getName()); ?>"
  68. <?php if ($value === true): ?> checked="checked"<?php endif; ?>
  69. />
  70. <?php p($placeholder); ?>
  71. </label>
  72. </div>
  73. <?php
  74. break;
  75. case DefinitionParameter::VALUE_HIDDEN: ?>
  76. <input type="hidden"
  77. <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  78. data-parameter="<?php p($parameter->getName()); ?>"
  79. value="<?php p($value); ?>"
  80. />
  81. <?php
  82. break;
  83. default: ?>
  84. <?php if ($is_optional) {
  85. $classes[] = 'optional';
  86. } ?>
  87. <input type="text"
  88. <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?>
  89. data-parameter="<?php p($parameter->getName()); ?>"
  90. value="<?php p($value); ?>"
  91. placeholder="<?php p($placeholder); ?>"
  92. />
  93. <?php
  94. }
  95. }
  96. ?>
  97. <div class="emptyfilelist emptycontent hidden">
  98. <div class="icon-external"></div>
  99. <h2><?php p($l->t('No external storage configured or you don\'t have the permission to configure them')); ?></h2>
  100. </div>
  101. <?php
  102. $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true);
  103. ?>
  104. <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'; ?>">
  105. <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2>
  106. <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>
  107. <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 people to mount their own external storage services.')); ?></p>
  108. <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) {
  109. print_unescaped(''.$_['dependencies'].'');
  110. } ?>
  111. <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
  112. <thead>
  113. <tr>
  114. <th></th>
  115. <th><?php p($l->t('Folder name')); ?></th>
  116. <th><?php p($l->t('External storage')); ?></th>
  117. <th><?php p($l->t('Authentication')); ?></th>
  118. <th><?php p($l->t('Configuration')); ?></th>
  119. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) {
  120. print_unescaped('<th>'.$l->t('Available for').'</th>');
  121. } ?>
  122. <th>&nbsp;</th>
  123. <th>&nbsp;</th>
  124. <th>&nbsp;</th>
  125. </tr>
  126. </thead>
  127. <tbody>
  128. <tr class="externalStorageLoading">
  129. <td colspan="8">
  130. <span id="externalStorageLoading" class="icon icon-loading"></span>
  131. </td>
  132. </tr>
  133. <tr id="addMountPoint"
  134. <?php if (!$canCreateMounts): ?>
  135. style="display: none;"
  136. <?php endif; ?>
  137. >
  138. <td class="status">
  139. <span data-placement="right" title="<?php p($l->t('Click to recheck the configuration')); ?>"></span>
  140. </td>
  141. <td class="mountPoint"><input type="text" name="mountPoint" value=""
  142. placeholder="<?php p($l->t('Folder name')); ?>">
  143. </td>
  144. <td class="backend">
  145. <select id="selectBackend" class="selectBackend" data-configurations='<?php p(json_encode($_['backends'])); ?>'>
  146. <option value="" disabled selected
  147. style="display:none;">
  148. <?php p($l->t('Add storage')); ?>
  149. </option>
  150. <?php
  151. $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) {
  152. return $backend->isVisibleFor($_['visibilityType']);
  153. });
  154. uasort($sortedBackends, function ($a, $b) {
  155. return strcasecmp($a->getText(), $b->getText());
  156. });
  157. ?>
  158. <?php foreach ($sortedBackends as $backend): ?>
  159. <?php if ($backend->getDeprecateTo() || (!$canCreateNewLocalStorage && $backend->getIdentifier() == "local")) {
  160. continue;
  161. } // ignore deprecated backends?>
  162. <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option>
  163. <?php endforeach; ?>
  164. </select>
  165. </td>
  166. <td class="authentication" data-mechanisms='<?php p(json_encode($_['authMechanisms'])); ?>'></td>
  167. <td class="configuration"></td>
  168. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
  169. <td class="applicable" align="right">
  170. <label><input type="checkbox" class="applicableToAllUsers" checked="" /><?php p($l->t('All people')); ?></label>
  171. <div class="applicableUsersContainer">
  172. <input type="hidden" class="applicableUsers" style="width:20em;" value="" />
  173. </div>
  174. </td>
  175. <?php endif; ?>
  176. <td class="mountOptionsToggle hidden">
  177. <button type="button" class="icon-more" aria-expanded="false" title="<?php p($l->t('Advanced settings')); ?>"></button>
  178. <input type="hidden" class="mountOptions" value="" />
  179. </td>
  180. <td class="save hidden">
  181. <button type="button" class="icon-checkmark" title="<?php p($l->t('Save')); ?>"></button>
  182. </td>
  183. </tr>
  184. </tbody>
  185. </table>
  186. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
  187. <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox"
  188. value="1" <?php if ($_['allowUserMounting']) {
  189. print_unescaped(' checked="checked"');
  190. } ?> />
  191. <label for="allowUserMounting"><?php p($l->t('Allow people to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span>
  192. <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>>
  193. <?php
  194. $userBackends = array_filter($_['backends'], function ($backend) {
  195. return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
  196. });
  197. ?>
  198. <?php $i = 0;
  199. foreach ($userBackends as $backend): ?>
  200. <?php if ($deprecateTo = $backend->getDeprecateTo()): ?>
  201. <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" />
  202. <?php else: ?>
  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. } ?> />
  206. <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br />
  207. <?php endif; ?>
  208. <?php $i++; ?>
  209. <?php endforeach; ?>
  210. </p>
  211. <?php endif; ?>
  212. </form>
  213. <div class="followupsection">
  214. <form autocomplete="false" action="#"
  215. id="global_credentials" method="post"
  216. class="<?php if (isset($_['visibilityType']) && $_['visibilityType'] === BackendService::VISIBILITY_PERSONAL) {
  217. print_unescaped("global_credentials__personal");
  218. } ?>">
  219. <h2><?php p($l->t('Global credentials')); ?></h2>
  220. <p class="settings-hint"><?php p($l->t('Global credentials can be used to authenticate with multiple external storages that have the same credentials.')); ?></p>
  221. <input type="text" name="username"
  222. autocomplete="false"
  223. value="<?php p($_['globalCredentials']['user']); ?>"
  224. placeholder="<?php p($l->t('Login')) ?>"/>
  225. <input type="password" name="password"
  226. autocomplete="false"
  227. value="<?php p($_['globalCredentials']['password']); ?>"
  228. placeholder="<?php p($l->t('Password')) ?>"/>
  229. <input type="hidden" name="uid"
  230. value="<?php p($_['globalCredentialsUid']); ?>"/>
  231. <input type="submit" value="<?php p($l->t('Save')) ?>"/>
  232. </form>
  233. </div>