1
0

settings.php 8.4 KB

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