You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

settings.php 9.5KB

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