settings.php 7.8 KB

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