|
| 1 | +<template lang="pug"> |
| 2 | +b-modal(id="cors-config-modal" title="Security & CORS" @show="load" @ok="save" :ok-disabled="loading || !config" size="lg") |
| 3 | + div(v-if="config") |
| 4 | + b-alert(v-if="config.needs_restart" show variant="warning" class="mb-4") |
| 5 | + h5.alert-heading ⚠️ Server Restart Required |
| 6 | + p.mb-0 |
| 7 | + | CORS settings are only applied once at startup. You must <b>stop and restart the server</b> for any changes made here to take effect. |
| 8 | + |
| 9 | + b-form-group(label="Fixed CORS origins" label-cols-md=4 description="Configure general CORS origins with exact matches (e.g. http://localhost:8080). Comma-separated.") |
| 10 | + b-input(v-model="corsStr" type="text" :disabled="isFixed('cors')") |
| 11 | + small.text-warning(v-if="isFixed('cors')") |
| 12 | + | ⚠️ Fixed in <code>config.toml</code>. Settings in the configuration file take precedence and cannot be changed here. |
| 13 | + |
| 14 | + b-form-group(label="Regex CORS origins" label-cols-md=4 description="Configure CORS origins with regular expressions. Useful for browser extensions (e.g. chrome-extension://.* or moz-extension://.*). Comma-separated.") |
| 15 | + b-input(v-model="corsRegexStr" type="text" :disabled="isFixed('cors_regex')") |
| 16 | + small.text-warning(v-if="isFixed('cors_regex')") |
| 17 | + | ⚠️ Fixed in <code>config.toml</code>. Settings in the configuration file take precedence and cannot be changed here. |
| 18 | + |
| 19 | + h5.mt-4 Extensions Shortcuts |
| 20 | + b-form-group(label-cols-md=4) |
| 21 | + b-form-checkbox(v-model="editable.cors_allow_aw_chrome_extension" :disabled="isFixed('cors_allow_aw_chrome_extension')") Allow ActivityWatch extension (Chrome) |
| 22 | + template(#description) |
| 23 | + div Chrome extensions use a stable, persistent ID, so the official extension is reliably supported. |
| 24 | + small.text-warning(v-if="isFixed('cors_allow_aw_chrome_extension')") |
| 25 | + | ⚠️ Fixed in <code>config.toml</code>. Settings in the configuration file take precedence and cannot be changed here. |
| 26 | + |
| 27 | + b-form-group(label-cols-md=4) |
| 28 | + b-form-checkbox(v-model="editable.cors_allow_all_mozilla_extension" :disabled="isFixed('cors_allow_all_mozilla_extension')") Allow all Firefox extensions (DANGEROUS) |
| 29 | + template(#description) |
| 30 | + div Every version of a Mozilla extension has its own ID to avoid fingerprinting. This is why you must either allow all extensions or manually configure your specific ID. |
| 31 | + small.text-warning.mb-2.d-block(v-if="isFixed('cors_allow_all_mozilla_extension')") |
| 32 | + | ⚠️ Fixed in <code>config.toml</code>. Settings in the configuration file take precedence and cannot be changed here. |
| 33 | + div.mt-2.text-danger(v-if="editable.cors_allow_all_mozilla_extension") |
| 34 | + | ⚠️ DANGEROUS: Not recommended for security. If enabled, any installed extension can access your ActivityWatch data. Use this only if you know what extensions you have and assume full responsibility. |
| 35 | + div(v-else) |
| 36 | + | Recommended for security. To allow a specific extension safely: |
| 37 | + ol.mt-2.mb-1 |
| 38 | + li Go to <code>about:debugging#/runtime/this-firefox</code> in your browser. |
| 39 | + li Look for your extension and copy the <b>Manifest URL</b> (e.g. <code>moz-extension://4b931c07dededdedff152/manifest.json</code>). |
| 40 | + li Remove <code>manifest.json</code> from the end (to get <code>moz-extension://4b931c07dededdedff152</code>). |
| 41 | + li Paste it into the <b>Regex CORS origins</b> field above (use a comma to separate if not empty). |
| 42 | + |
| 43 | + div(v-else-if="loading") |
| 44 | + p Loading... |
| 45 | + div(v-else-if="error") |
| 46 | + b-alert(show variant="danger") Failed to load CORS configuration: {{ error }} |
| 47 | +</template> |
| 48 | + |
| 49 | +<script lang="ts"> |
| 50 | +import { useCorsStore } from '~/stores/cors'; |
| 51 | +import { mapState } from 'pinia'; |
| 52 | +
|
| 53 | +export default { |
| 54 | + name: 'CorsConfigModal', |
| 55 | + data() { |
| 56 | + return { |
| 57 | + editable: { |
| 58 | + cors: [] as string[], |
| 59 | + cors_regex: [] as string[], |
| 60 | + cors_allow_aw_chrome_extension: false, |
| 61 | + cors_allow_all_mozilla_extension: false, |
| 62 | + }, |
| 63 | + corsStr: '', |
| 64 | + corsRegexStr: '', |
| 65 | + corsStore: useCorsStore(), |
| 66 | + }; |
| 67 | + }, |
| 68 | + computed: { |
| 69 | + ...mapState(useCorsStore, ['config', 'loading', 'error']), |
| 70 | + }, |
| 71 | + watch: { |
| 72 | + config(newVal) { |
| 73 | + if (newVal) { |
| 74 | + this.editable = JSON.parse(JSON.stringify(newVal)); |
| 75 | + this.corsStr = newVal.cors.join(', '); |
| 76 | + this.corsRegexStr = newVal.cors_regex.join(', '); |
| 77 | + } |
| 78 | + }, |
| 79 | + }, |
| 80 | + methods: { |
| 81 | + isFixed(field: string): boolean { |
| 82 | + return this.config?.in_file?.includes(field) || false; |
| 83 | + }, |
| 84 | + async load() { |
| 85 | + await this.corsStore.load(); |
| 86 | + }, |
| 87 | + async save(bvModalEvt: any) { |
| 88 | + bvModalEvt.preventDefault(); |
| 89 | + |
| 90 | + // Parse comma-separated strings back to arrays |
| 91 | + this.editable.cors = this.corsStr.split(',').map(s => s.trim()).filter(s => s !== ''); |
| 92 | + this.editable.cors_regex = this.corsRegexStr.split(',').map(s => s.trim()).filter(s => s !== ''); |
| 93 | +
|
| 94 | + try { |
| 95 | + await this.corsStore.save(this.editable); |
| 96 | + (this as any).$bvModal.hide('cors-config-modal'); |
| 97 | + alert('CORS configuration saved! Please restart the server to apply changes.'); |
| 98 | + } catch (e: any) { |
| 99 | + alert('Failed to save: ' + e.message); |
| 100 | + } |
| 101 | + }, |
| 102 | + }, |
| 103 | +}; |
| 104 | +</script> |
0 commit comments