AppSetup.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <script setup>
  2. import AdminTabs from '@/layouts/AdminTabs.vue'
  3. import systemService from '@/services/systemService'
  4. import { useAppSettingsUpdater } from '@/composables/appSettingsUpdater'
  5. import { useAppSettingsStore } from '@/stores/appSettings'
  6. import { useNotifyStore } from '@/stores/notify'
  7. import { useUserStore } from '@/stores/user'
  8. import VersionChecker from '@/components/VersionChecker.vue'
  9. import CopyButton from '@/components/CopyButton.vue'
  10. const $2fauth = inject('2fauth')
  11. const user = useUserStore()
  12. const notify = useNotifyStore()
  13. const appSettings = useAppSettingsStore()
  14. const returnTo = useStorage($2fauth.prefix + 'returnTo', 'accounts')
  15. const infos = ref()
  16. const listInfos = ref(null)
  17. const isSendingTestEmail = ref(false)
  18. const isClearingCache = ref(false)
  19. const healthEndPoint = $2fauth.config.subdirectory + '/up'
  20. const healthEndPointFullPath = location.hostname + $2fauth.config.subdirectory + '/up'
  21. /**
  22. * Sends a test email
  23. */
  24. function sendTestEmail() {
  25. isSendingTestEmail.value = true;
  26. systemService.sendTestEmail()
  27. .finally(() => {
  28. isSendingTestEmail.value = false;
  29. })
  30. }
  31. /**
  32. * clears app cache
  33. */
  34. function clearCache() {
  35. isClearingCache.value = true;
  36. systemService.clearCache().then(response => {
  37. useNotifyStore().success({ type: 'is-success', text: trans('admin.cache_cleared') })
  38. })
  39. .finally(() => {
  40. isClearingCache.value = false;
  41. })
  42. }
  43. onBeforeRouteLeave((to) => {
  44. if (! to.name.startsWith('admin.')) {
  45. notify.clear()
  46. }
  47. })
  48. onMounted(async () => {
  49. await appSettings.fetch()
  50. systemService.getSystemInfos({returnError: true}).then(response => {
  51. infos.value = response.data.common
  52. })
  53. .catch(() => {
  54. infos.value = null
  55. })
  56. })
  57. </script>
  58. <template>
  59. <div>
  60. <AdminTabs activeTab="admin.appSetup" />
  61. <div class="options-tabs">
  62. <FormWrapper>
  63. <form>
  64. <h4 class="title is-4 pt-4 has-text-grey-light">{{ $t('settings.general') }}</h4>
  65. <!-- Check for update -->
  66. <FormCheckbox v-model="appSettings.checkForUpdate" @update:model-value="val => useAppSettingsUpdater('checkForUpdate', val)" fieldName="checkForUpdate" label="commons.check_for_update" help="commons.check_for_update_help" />
  67. <VersionChecker />
  68. <!-- email config test -->
  69. <div class="field">
  70. <label class="label" for="btnTestEmail" v-html="$t('admin.forms.test_email.label')" />
  71. <p class="help" v-html="$t('admin.forms.test_email.help')" />
  72. <p class="help" v-html="$t('admin.forms.test_email.email_will_be_send_to_x', { email: user.email })" />
  73. </div>
  74. <div class="columns is-mobile is-vcentered">
  75. <div class="column is-narrow">
  76. <button id="btnTestEmail" type="button" :class="isSendingTestEmail ? 'is-loading' : ''" class="button is-link is-rounded is-small" @click="sendTestEmail" >
  77. <span class="icon is-small">
  78. <FontAwesomeIcon :icon="['far', 'paper-plane']" />
  79. </span>
  80. <span>{{ $t('commons.send') }}</span>
  81. </button>
  82. </div>
  83. </div>
  84. <!-- healthcheck -->
  85. <div class="field">
  86. <label class="label" for="lnkHealthCheck" v-html="$t('admin.forms.health_endpoint.label')" />
  87. <p class="help" v-html="$t('admin.forms.health_endpoint.help')" />
  88. </div>
  89. <div class="field mb-5">
  90. <a id="lnkHealthCheck" target="_blank" :href="healthEndPoint">{{ healthEndPointFullPath }}</a>
  91. </div>
  92. <h4 class="title is-4 pt-5 has-text-grey-light">{{ $t('admin.storage') }}</h4>
  93. <!-- store icons in database -->
  94. <FormCheckbox v-model="appSettings.storeIconsInDatabase" @update:model-value="val => useAppSettingsUpdater('storeIconsInDatabase', val)" fieldName="storeIconsInDatabase" label="admin.forms.store_icon_to_database.label" help="admin.forms.store_icon_to_database.help" />
  95. <h4 class="title is-4 pt-5 has-text-grey-light">{{ $t('settings.security') }}</h4>
  96. <!-- protect db -->
  97. <FormCheckbox v-model="appSettings.useEncryption" @update:model-value="val => useAppSettingsUpdater('useEncryption', val)" fieldName="useEncryption" label="admin.forms.use_encryption.label" help="admin.forms.use_encryption.help" />
  98. </form>
  99. <h4 class="title is-4 pt-5 has-text-grey-light">{{ $t('commons.environment') }}</h4>
  100. <!-- cache management -->
  101. <div class="field">
  102. <!-- <h5 class="title is-5">{{ $t('settings.security') }}</h5> -->
  103. <label for="btnClearCache" class="label" v-html="$t('admin.forms.cache_management.label')" />
  104. <p class="help" v-html="$t('admin.forms.cache_management.help')" />
  105. </div>
  106. <div class="field mb-5 is-grouped">
  107. <p class="control">
  108. <button id="btnClearCache" type="button" :class="isClearingCache ? 'is-loading' : ''" class="button is-link is-rounded is-small" @click="clearCache">
  109. {{ $t('commons.clear') }}
  110. </button>
  111. </p>
  112. </div>
  113. <!-- env vars -->
  114. <div class="field">
  115. <label for="btnCopyEnvVars" class="label" v-html="$t('admin.variables')" />
  116. </div>
  117. <div v-if="infos" class="about-debug box is-family-monospace is-size-7">
  118. <CopyButton id="btnCopyEnvVars" :token="listInfos?.innerText" />
  119. <ul ref="listInfos" id="listInfos">
  120. <li v-for="(value, preference) in infos" :value="value" :key="preference">
  121. <b>{{ preference }}</b>: <span class="has-text-grey">{{ value }}</span>
  122. </li>
  123. </ul>
  124. </div>
  125. <div v-else-if="infos === null" class="about-debug box is-family-monospace is-size-7 has-text-warning-dark">
  126. {{ $t('errors.error_during_data_fetching') }}
  127. </div>
  128. </FormWrapper>
  129. </div>
  130. <VueFooter :showButtons="true">
  131. <ButtonBackCloseCancel :returnTo="{ name: returnTo }" action="close" />
  132. </VueFooter>
  133. </div>
  134. </template>