DiagnosticsView.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <template>
  2. <Section
  3. :title="t('diagnostics.config-issues')"
  4. :icon="AlertCircleIcon"
  5. >
  6. <p>{{ t('diagnostics.config-issues-description') }}</p>
  7. <p v-if="!loading && configIssues.length === 0">
  8. {{ t('diagnostics.config-issues-none') }}
  9. </p>
  10. <Table
  11. v-else
  12. :data="configIssueRows"
  13. :headers="configIssueHeaders"
  14. :show-pagination="false"
  15. >
  16. <template #cell-severity="{ value }">
  17. <span
  18. class="tag"
  19. :class="value"
  20. >{{ value }}</span>
  21. </template>
  22. </Table>
  23. </Section>
  24. <Section
  25. :title="t('diagnostics.get-support')"
  26. :icon="CustomerSupportIcon"
  27. >
  28. <p>
  29. {{ t('diagnostics.get-support-description') }}
  30. </p>
  31. <ul>
  32. <li>
  33. <a
  34. href="https://docs.olivetin.app/troubleshooting/wheretofindhelp.html"
  35. target="_blank"
  36. >{{ t('diagnostics.where-to-find-help') }}</a>
  37. </li>
  38. </ul>
  39. </Section>
  40. <Section
  41. :title="t('diagnostics.ssh')"
  42. :icon="ComputerTerminal01Icon"
  43. >
  44. <dl>
  45. <dt>{{ t('diagnostics.found-key') }}</dt>
  46. <dd>{{ diagnostics.sshFoundKey || '?' }}</dd>
  47. <dt>{{ t('diagnostics.found-config') }}</dt>
  48. <dd>{{ diagnostics.sshFoundConfig || '?' }}</dd>
  49. </dl>
  50. </Section>
  51. <Section
  52. :title="t('diagnostics.server-diagnostics')"
  53. :icon="CloudServerIcon"
  54. >
  55. <p>{{ t('diagnostics.server-diagnostics-description') }}</p>
  56. <p>
  57. <a
  58. href="https://docs.olivetin.app/troubleshooting/server-diagnostics.html"
  59. target="_blank"
  60. >{{ t('diagnostics.server-diagnostics-docs') }}</a>
  61. </p>
  62. <ReadOnlyTextArea
  63. v-model="serverDiagnostics"
  64. :rows="10"
  65. markdown-ticks
  66. :copy-label="t('diagnostics.copy-to-clipboard')"
  67. :copied-label="t('diagnostics.copied')"
  68. >
  69. <template #actions>
  70. <button
  71. type="button"
  72. :disabled="loading"
  73. class="good"
  74. @click="generateServerDiagnostics"
  75. >
  76. {{ t('diagnostics.generate-server-diagnostics') }}
  77. </button>
  78. </template>
  79. </ReadOnlyTextArea>
  80. </Section>
  81. <Section
  82. :title="t('diagnostics.browser-info')"
  83. :icon="BrowserIcon"
  84. >
  85. <p>{{ t('diagnostics.browser-info-description') }}</p>
  86. <ReadOnlyTextArea
  87. v-model="browserInfo"
  88. :rows="10"
  89. markdown-ticks
  90. :copy-label="t('diagnostics.copy-to-clipboard')"
  91. :copied-label="t('diagnostics.copied')"
  92. >
  93. <template #actions>
  94. <button
  95. type="button"
  96. :disabled="loading"
  97. class="good"
  98. @click="generateBrowserInfo"
  99. >
  100. {{ t('diagnostics.generate-browser-info') }}
  101. </button>
  102. </template>
  103. </ReadOnlyTextArea>
  104. </Section>
  105. </template>
  106. <script setup>
  107. import { ref, computed, onMounted, onUnmounted } from 'vue'
  108. import {
  109. AlertCircleIcon,
  110. BrowserIcon,
  111. CloudServerIcon,
  112. ComputerTerminal01Icon,
  113. CustomerSupportIcon
  114. } from '@hugeicons/core-free-icons'
  115. import ReadOnlyTextArea from 'picocrank/vue/components/ReadOnlyTextArea.vue'
  116. import Section from 'picocrank/vue/components/Section.vue'
  117. import Table from 'picocrank/vue/components/Table.vue'
  118. import { useI18n } from 'vue-i18n'
  119. const { t, locale } = useI18n()
  120. const diagnostics = ref({})
  121. const configIssues = ref([])
  122. const loading = ref(false)
  123. const serverDiagnostics = ref('')
  124. const browserInfo = ref('')
  125. const configIssueHeaders = computed(() => [
  126. { key: 'severity', label: t('diagnostics.config-issue-severity'), sortable: true, width: '7rem' },
  127. { key: 'configFile', label: t('diagnostics.config-issue-config-file'), sortable: true, width: '14rem' },
  128. { key: 'code', label: t('diagnostics.config-issue-code'), sortable: true, width: '12rem' },
  129. { key: 'message', label: t('diagnostics.config-issue-message'), sortable: false },
  130. { key: 'actionTitle', label: t('diagnostics.config-issue-action'), sortable: true, width: '10rem' },
  131. { key: 'argumentName', label: t('diagnostics.config-issue-argument'), sortable: true, width: '8rem' },
  132. { key: 'source', label: t('diagnostics.config-issue-source'), sortable: false, width: '12rem' }
  133. ])
  134. const configIssueRows = computed(() => configIssues.value.map((issue) => ({
  135. severity: issue.severity || '',
  136. code: issue.code || '',
  137. message: issue.message || '',
  138. actionTitle: issue.actionTitle || '',
  139. argumentName: issue.argumentName || '',
  140. configFile: issue.configFile || '',
  141. source: issue.source || ''
  142. })))
  143. async function fetchDiagnostics () {
  144. loading.value = true
  145. try {
  146. const response = await window.client.getDiagnostics()
  147. diagnostics.value = {
  148. sshFoundKey: response.SshFoundKey,
  149. sshFoundConfig: response.SshFoundConfig
  150. }
  151. configIssues.value = response.configIssues || []
  152. } catch (err) {
  153. console.error('Failed to fetch diagnostics:', err)
  154. diagnostics.value = {
  155. sshFoundKey: t('diagnostics.unknown'),
  156. sshFoundConfig: t('diagnostics.unknown')
  157. }
  158. configIssues.value = []
  159. }
  160. loading.value = false
  161. }
  162. async function generateServerDiagnostics () {
  163. loading.value = true
  164. try {
  165. const response = await window.client.serverDiagnostics()
  166. console.log('response', response)
  167. serverDiagnostics.value = response.alert
  168. } catch (err) {
  169. console.error('Failed to generate server diagnostics:', err)
  170. serverDiagnostics.value = ''
  171. } finally {
  172. loading.value = false
  173. }
  174. }
  175. async function generateBrowserInfo () {
  176. loading.value = true
  177. try {
  178. let userAgentData = 'N/A'
  179. if (navigator.userAgentData) {
  180. try {
  181. const uaData = await navigator.userAgentData.getHighEntropyValues([
  182. 'platform',
  183. 'platformVersion',
  184. 'architecture',
  185. 'model',
  186. 'uaFullVersion',
  187. 'bitness',
  188. 'fullVersionList'
  189. ])
  190. userAgentData = JSON.stringify(uaData, null, 2)
  191. } catch (err) {
  192. userAgentData = `${t('diagnostics.useragent-data-error')}: ${err.message}`
  193. }
  194. }
  195. const info = {
  196. userAgent: navigator.userAgent,
  197. platform: navigator.platform,
  198. language: navigator.language,
  199. languages: navigator.languages?.join(', ') || 'N/A',
  200. cookieEnabled: navigator.cookieEnabled,
  201. onLine: navigator.onLine,
  202. screenWidth: screen.width,
  203. screenHeight: screen.height,
  204. screenColorDepth: screen.colorDepth,
  205. screenPixelDepth: screen.pixelDepth,
  206. viewportWidth: window.innerWidth,
  207. viewportHeight: window.innerHeight,
  208. devicePixelRatio: window.devicePixelRatio || 'N/A',
  209. timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
  210. timezoneOffset: new Date().getTimezoneOffset(),
  211. localStorageEnabled: (() => {
  212. try {
  213. localStorage.setItem('test', 'test')
  214. localStorage.removeItem('test')
  215. return true
  216. } catch {
  217. return false
  218. }
  219. })(),
  220. sessionStorageEnabled: (() => {
  221. try {
  222. sessionStorage.setItem('test', 'test')
  223. sessionStorage.removeItem('test')
  224. return true
  225. } catch {
  226. return false
  227. }
  228. })(),
  229. hardwareConcurrency: navigator.hardwareConcurrency || 'N/A',
  230. maxTouchPoints: navigator.maxTouchPoints || 'N/A',
  231. userAgentData
  232. }
  233. const showVersionNumber = window.initResponse?.effectivePolicy?.showVersionNumber ?? true
  234. const olivetinVersion = showVersionNumber
  235. ? (window.initResponse?.currentVersion || t('diagnostics.unknown'))
  236. : '[hidden]'
  237. const currentLanguage = locale.value || t('diagnostics.unknown')
  238. let output = ''
  239. output += '### BROWSER INFO START (copy all text to BROWSER INFO END)\n'
  240. output += '# OliveTin Information\n'
  241. output += `olivetinVersion: ${olivetinVersion}\n`
  242. output += `currentLanguage: ${currentLanguage}\n`
  243. output += '\n# Browser Information\n'
  244. output += `userAgent: ${info.userAgent}\n`
  245. output += `platform: ${info.platform}\n`
  246. output += `language: ${info.language}\n`
  247. output += `languages: ${info.languages}\n`
  248. output += '\n# User Agent Data\n'
  249. output += `userAgentData:\n${info.userAgentData}\n`
  250. output += '\n# Display Information\n'
  251. output += `screenWidth: ${info.screenWidth}\n`
  252. output += `screenHeight: ${info.screenHeight}\n`
  253. output += `screenColorDepth: ${info.screenColorDepth}\n`
  254. output += `screenPixelDepth: ${info.screenPixelDepth}\n`
  255. output += `viewportWidth: ${info.viewportWidth}\n`
  256. output += `viewportHeight: ${info.viewportHeight}\n`
  257. output += `devicePixelRatio: ${info.devicePixelRatio}\n`
  258. output += '\n# Feature Support\n'
  259. output += `cookieEnabled: ${info.cookieEnabled}\n`
  260. output += `localStorageEnabled: ${info.localStorageEnabled}\n`
  261. output += `sessionStorageEnabled: ${info.sessionStorageEnabled}\n`
  262. output += `onLine: ${info.onLine}\n`
  263. output += `hardwareConcurrency: ${info.hardwareConcurrency}\n`
  264. output += `maxTouchPoints: ${info.maxTouchPoints}\n`
  265. output += '\n# Location & Time\n'
  266. output += `timezone: ${info.timezone}\n`
  267. output += `timezoneOffset: ${info.timezoneOffset}\n`
  268. output += '\n### BROWSER INFO END (copy all text from BROWSER INFO START)'
  269. browserInfo.value = output
  270. } finally {
  271. loading.value = false
  272. }
  273. }
  274. onMounted(() => {
  275. fetchDiagnostics()
  276. window.addEventListener('EventConfigChanged', fetchDiagnostics)
  277. window.addEventListener('EventEntityChanged', fetchDiagnostics)
  278. })
  279. onUnmounted(() => {
  280. window.removeEventListener('EventConfigChanged', fetchDiagnostics)
  281. window.removeEventListener('EventEntityChanged', fetchDiagnostics)
  282. })
  283. </script>