settings.php 8.7 KB

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