settings.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 class="emptyfilelist emptycontent 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. <?php
  96. $canCreateNewLocalStorage = \OC::$server->getConfig()->getSystemValue('files_external_allow_create_new_local', true);
  97. ?>
  98. <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'; ?>">
  99. <h2 class="inlineblock" data-anchor-name="external-storage"><?php p($l->t('External storage')); ?></h2>
  100. <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>
  101. <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>
  102. <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) {
  103. print_unescaped(''.$_['dependencies'].'');
  104. } ?>
  105. <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
  106. <thead>
  107. <tr>
  108. <th></th>
  109. <th><?php p($l->t('Folder name')); ?></th>
  110. <th><?php p($l->t('External storage')); ?></th>
  111. <th><?php p($l->t('Authentication')); ?></th>
  112. <th><?php p($l->t('Configuration')); ?></th>
  113. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) {
  114. print_unescaped('<th>'.$l->t('Available for').'</th>');
  115. } ?>
  116. <th>&nbsp;</th>
  117. <th>&nbsp;</th>
  118. <th>&nbsp;</th>
  119. </tr>
  120. </thead>
  121. <tbody>
  122. <tr class="externalStorageLoading">
  123. <td colspan="8">
  124. <span id="externalStorageLoading" class="icon icon-loading"></span>
  125. </td>
  126. </tr>
  127. <tr id="addMountPoint"
  128. <?php if (!$canCreateMounts): ?>
  129. style="display: none;"
  130. <?php endif; ?>
  131. >
  132. <td class="status">
  133. <span data-placement="right" title="<?php p($l->t('Click to recheck the configuration')); ?>"></span>
  134. </td>
  135. <td class="mountPoint"><input type="text" name="mountPoint" value=""
  136. placeholder="<?php p($l->t('Folder name')); ?>">
  137. </td>
  138. <td class="backend">
  139. <select id="selectBackend" class="selectBackend" data-configurations='<?php p(json_encode($_['backends'])); ?>'>
  140. <option value="" disabled selected
  141. style="display:none;">
  142. <?php p($l->t('Add storage')); ?>
  143. </option>
  144. <?php
  145. $sortedBackends = array_filter($_['backends'], function ($backend) use ($_) {
  146. return $backend->isVisibleFor($_['visibilityType']);
  147. });
  148. uasort($sortedBackends, function ($a, $b) {
  149. return strcasecmp($a->getText(), $b->getText());
  150. });
  151. ?>
  152. <?php foreach ($sortedBackends as $backend): ?>
  153. <?php if ($backend->getDeprecateTo() || (!$canCreateNewLocalStorage && $backend->getIdentifier() == "local")) {
  154. continue;
  155. } // ignore deprecated backends?>
  156. <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option>
  157. <?php endforeach; ?>
  158. </select>
  159. </td>
  160. <td class="authentication" data-mechanisms='<?php p(json_encode($_['authMechanisms'])); ?>'></td>
  161. <td class="configuration"></td>
  162. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
  163. <td class="applicable" align="right">
  164. <label><input type="checkbox" class="applicableToAllUsers" checked="" /><?php p($l->t('All users')); ?></label>
  165. <div class="applicableUsersContainer">
  166. <input type="hidden" class="applicableUsers" style="width:20em;" value="" />
  167. </div>
  168. </td>
  169. <?php endif; ?>
  170. <td class="mountOptionsToggle hidden">
  171. <button type="button" class="icon-more" aria-expanded="false" title="<?php p($l->t('Advanced settings')); ?>"></button>
  172. <input type="hidden" class="mountOptions" value="" />
  173. </td>
  174. <td class="save hidden">
  175. <button type="button" class="icon-checkmark" title="<?php p($l->t('Save')); ?>"></button>
  176. </td>
  177. </tr>
  178. </tbody>
  179. </table>
  180. <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
  181. <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox"
  182. value="1" <?php if ($_['allowUserMounting']) {
  183. print_unescaped(' checked="checked"');
  184. } ?> />
  185. <label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span>
  186. <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>>
  187. <?php
  188. $userBackends = array_filter($_['backends'], function ($backend) {
  189. return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
  190. });
  191. ?>
  192. <?php $i = 0; foreach ($userBackends as $backend): ?>
  193. <?php if ($deprecateTo = $backend->getDeprecateTo()): ?>
  194. <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" />
  195. <?php else: ?>
  196. <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) {
  197. print_unescaped(' checked="checked"');
  198. } ?> />
  199. <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br />
  200. <?php endif; ?>
  201. <?php $i++; ?>
  202. <?php endforeach; ?>
  203. </p>
  204. <?php endif; ?>
  205. </form>
  206. <div class="followupsection">
  207. <form autocomplete="false" action="#"
  208. id="global_credentials" method="post">
  209. <h2><?php p($l->t('Global credentials')); ?></h2>
  210. <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>
  211. <input type="text" name="username"
  212. autocomplete="false"
  213. value="<?php p($_['globalCredentials']['user']); ?>"
  214. placeholder="<?php p($l->t('Username')) ?>"/>
  215. <input type="password" name="password"
  216. autocomplete="false"
  217. value="<?php p($_['globalCredentials']['password']); ?>"
  218. placeholder="<?php p($l->t('Password')) ?>"/>
  219. <input type="hidden" name="uid"
  220. value="<?php p($_['globalCredentialsUid']); ?>"/>
  221. <input type="submit" value="<?php p($l->t('Save')) ?>"/>
  222. </form>
  223. </div>