1
0

settings.php 8.5 KB

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