1
0

settings.php 9.8 KB

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