2019-05-10 21:12:00 +00:00
|
|
|
<template>
|
|
|
|
<div id="app">
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-navbar
|
|
|
|
toggleable="lg"
|
|
|
|
type="dark"
|
|
|
|
variant="primary"
|
|
|
|
>
|
|
|
|
<b-navbar-brand
|
|
|
|
href="#"
|
|
|
|
@click="newSecret"
|
|
|
|
>
|
|
|
|
<i class="fas fa-user-secret" /> OTS - One Time Secrets
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-navbar-brand>
|
|
|
|
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-navbar-toggle target="nav-collapse" />
|
2019-05-10 21:12:00 +00:00
|
|
|
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-collapse
|
|
|
|
id="nav-collapse"
|
|
|
|
is-nav
|
|
|
|
>
|
2019-05-10 21:12:00 +00:00
|
|
|
<b-navbar-nav class="ml-auto">
|
2019-07-14 19:21:18 +00:00
|
|
|
<b-nav-item @click="explanationShown = !explanationShown">
|
|
|
|
<i class="fas fa-question" /> {{ $t('btn-show-explanation') }}
|
|
|
|
</b-nav-item>
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-nav-item @click="newSecret">
|
|
|
|
<i class="fas fa-plus" /> {{ $t('btn-new-secret') }}
|
|
|
|
</b-nav-item>
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-navbar-nav>
|
|
|
|
</b-collapse>
|
|
|
|
</b-navbar>
|
|
|
|
|
|
|
|
<b-container class="mt-4">
|
|
|
|
<b-row class="justify-content-center">
|
|
|
|
<b-col md="8">
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-alert
|
|
|
|
v-model="showError"
|
|
|
|
variant="danger"
|
|
|
|
dismissible
|
|
|
|
v-html="error"
|
|
|
|
/>
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
|
|
|
|
<b-row>
|
|
|
|
<b-col>
|
2019-07-14 19:21:18 +00:00
|
|
|
<!-- Explanation -->
|
|
|
|
<b-card
|
|
|
|
v-if="explanationShown"
|
|
|
|
class="mb-3"
|
|
|
|
border-variant="primary"
|
|
|
|
header-bg-variant="primary"
|
|
|
|
header-text-variant="white"
|
|
|
|
>
|
|
|
|
<span
|
|
|
|
slot="header"
|
|
|
|
v-html="$t('title-explanation')"
|
|
|
|
/>
|
|
|
|
<ul>
|
|
|
|
<li v-for="explanation in $t('items-explanation')">
|
|
|
|
{{ explanation }}
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</b-card>
|
|
|
|
|
|
|
|
<!-- Creation dialog -->
|
2019-05-10 21:12:00 +00:00
|
|
|
<b-card
|
2019-07-14 16:00:47 +00:00
|
|
|
v-if="mode == 'create' && !secretId"
|
2019-05-10 21:12:00 +00:00
|
|
|
border-variant="primary"
|
|
|
|
header-bg-variant="primary"
|
|
|
|
header-text-variant="white"
|
2019-07-14 16:00:47 +00:00
|
|
|
>
|
|
|
|
<span
|
|
|
|
slot="header"
|
|
|
|
v-html="$t('title-new-secret')"
|
|
|
|
/>
|
2019-05-10 21:12:00 +00:00
|
|
|
<b-form-group :label="$t('label-secret-data')">
|
|
|
|
<b-form-textarea
|
|
|
|
id="secret"
|
2019-07-14 16:00:47 +00:00
|
|
|
v-model="secret"
|
2019-05-10 21:12:00 +00:00
|
|
|
max-rows="25"
|
|
|
|
rows="5"
|
2019-07-14 16:00:47 +00:00
|
|
|
/>
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-form-group>
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-button
|
|
|
|
variant="success"
|
|
|
|
@click="createSecret"
|
|
|
|
>
|
|
|
|
{{ $t('btn-create-secret') }}
|
|
|
|
</b-button>
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-card>
|
|
|
|
|
2019-07-14 19:21:18 +00:00
|
|
|
<!-- Secret created, show secret URL -->
|
2019-05-10 21:12:00 +00:00
|
|
|
<b-card
|
2019-07-14 16:00:47 +00:00
|
|
|
v-if="mode == 'create' && secretId"
|
2019-05-10 21:12:00 +00:00
|
|
|
border-variant="success"
|
|
|
|
header-bg-variant="success"
|
|
|
|
header-text-variant="white"
|
2019-07-14 16:00:47 +00:00
|
|
|
>
|
|
|
|
<span
|
|
|
|
slot="header"
|
|
|
|
v-html="$t('title-secret-created')"
|
|
|
|
/>
|
|
|
|
<p v-html="$t('text-pre-url')" />
|
2019-05-10 21:12:00 +00:00
|
|
|
<b-form-group>
|
2019-07-14 16:00:47 +00:00
|
|
|
<b-form-input
|
2019-07-14 16:20:16 +00:00
|
|
|
ref="secretUrl"
|
2019-07-14 16:00:47 +00:00
|
|
|
:value="secretUrl"
|
|
|
|
readonly
|
2019-07-14 16:20:16 +00:00
|
|
|
@focus="$refs.secretUrl.select()"
|
2019-07-14 16:00:47 +00:00
|
|
|
/>
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-form-group>
|
2019-07-14 16:00:47 +00:00
|
|
|
<p v-html="$t('text-burn-hint')" />
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-card>
|
|
|
|
|
2019-07-14 19:21:18 +00:00
|
|
|
<!-- Display secret -->
|
2019-05-10 21:12:00 +00:00
|
|
|
<b-card
|
2019-07-14 16:00:47 +00:00
|
|
|
v-if="mode == 'view'"
|
2019-05-10 21:12:00 +00:00
|
|
|
border-variant="primary"
|
|
|
|
header-bg-variant="primary"
|
|
|
|
header-text-variant="white"
|
2019-07-14 16:00:47 +00:00
|
|
|
>
|
|
|
|
<span
|
|
|
|
slot="header"
|
|
|
|
v-html="$t('title-reading-secret')"
|
|
|
|
/>
|
2019-05-10 21:12:00 +00:00
|
|
|
<template v-if="!secret">
|
2019-07-14 16:00:47 +00:00
|
|
|
<p v-html="$t('text-pre-reveal-hint')" />
|
|
|
|
<b-button
|
|
|
|
variant="success"
|
|
|
|
@click="requestSecret"
|
|
|
|
>
|
|
|
|
{{ $t('btn-reveal-secret') }}
|
|
|
|
</b-button>
|
2019-05-10 21:12:00 +00:00
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<b-form-group>
|
|
|
|
<b-form-textarea
|
|
|
|
max-rows="25"
|
|
|
|
readonly
|
|
|
|
rows="5"
|
|
|
|
:value="secret"
|
2019-07-14 16:00:47 +00:00
|
|
|
/>
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-form-group>
|
2019-07-14 16:00:47 +00:00
|
|
|
<p v-html="$t('text-hint-burned')" />
|
2019-05-10 21:12:00 +00:00
|
|
|
</template>
|
|
|
|
</b-card>
|
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
|
|
|
|
<b-row class="mt-5">
|
|
|
|
<b-col class="footer">
|
2019-07-14 16:00:47 +00:00
|
|
|
{{ $t('text-powered-by') }} <a href="https://github.com/Luzifer/ots"><i class="fab fa-github" /> Luzifer/OTS</a> {{ $root.version }}
|
2019-05-10 21:12:00 +00:00
|
|
|
</b-col>
|
|
|
|
</b-row>
|
|
|
|
</b-container>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios'
|
|
|
|
import AES from 'gibberish-aes/src/gibberish-aes'
|
|
|
|
|
|
|
|
export default {
|
2019-07-14 16:00:47 +00:00
|
|
|
name: 'App',
|
2019-05-10 21:12:00 +00:00
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
error: '',
|
2019-07-14 19:21:18 +00:00
|
|
|
explanationShown: false,
|
2019-05-10 21:12:00 +00:00
|
|
|
mode: 'create',
|
|
|
|
secret: '',
|
2019-05-10 22:31:26 +00:00
|
|
|
securePassword: '',
|
2019-05-10 21:12:00 +00:00
|
|
|
secretId: '',
|
|
|
|
showError: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-07-14 16:00:47 +00:00
|
|
|
computed: {
|
|
|
|
secretUrl() {
|
|
|
|
return `${window.location.href}#${this.secretId}|${this.securePassword}`
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Trigger initialization functions
|
|
|
|
mounted() {
|
|
|
|
window.onhashchange = this.hashLoad
|
|
|
|
this.hashLoad()
|
|
|
|
},
|
|
|
|
|
2019-05-10 21:12:00 +00:00
|
|
|
methods: {
|
|
|
|
// createSecret executes the secret creation after encrypting the secret
|
|
|
|
createSecret() {
|
2019-05-10 22:31:26 +00:00
|
|
|
this.securePassword = Math.random().toString(36)
|
|
|
|
.substring(2)
|
2019-05-10 21:12:00 +00:00
|
|
|
const secret = AES.enc(this.secret, this.securePassword)
|
|
|
|
|
|
|
|
axios.post('api/create', { secret })
|
2019-05-10 22:31:26 +00:00
|
|
|
.then(resp => {
|
2019-05-10 21:12:00 +00:00
|
|
|
this.secretId = resp.data.secret_id
|
|
|
|
this.secret = ''
|
2019-07-14 16:20:16 +00:00
|
|
|
|
|
|
|
// Give the interface a moment to transistion and focus
|
|
|
|
window.setTimeout(() => this.$refs.secretUrl.focus(), 100)
|
2019-05-10 21:12:00 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
switch (err.response.status) {
|
2019-05-10 22:31:26 +00:00
|
|
|
case 404:
|
|
|
|
// Mock for interface testing
|
|
|
|
this.secretId = 'foobar'
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
this.error = this.$t('alert-something-went-wrong')
|
|
|
|
this.showError = true
|
2019-05-10 21:12:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return false
|
|
|
|
},
|
|
|
|
|
|
|
|
// hashLoad reacts on a changed window hash an starts the diplaying of the secret
|
|
|
|
hashLoad() {
|
2019-05-12 22:12:11 +00:00
|
|
|
const hash = decodeURIComponent(window.location.hash)
|
2019-05-10 22:31:26 +00:00
|
|
|
if (hash.length === 0) {
|
|
|
|
return
|
|
|
|
}
|
2019-05-10 21:12:00 +00:00
|
|
|
|
|
|
|
const parts = hash.substring(1).split('|')
|
2019-05-10 22:31:26 +00:00
|
|
|
if (parts.length === 2) {
|
2019-05-10 21:12:00 +00:00
|
|
|
this.securePassword = parts[1]
|
|
|
|
}
|
|
|
|
this.secretId = parts[0]
|
|
|
|
this.mode = 'view'
|
|
|
|
},
|
|
|
|
|
|
|
|
// newSecret removes the window hash and therefore returns to "new secret" mode
|
|
|
|
newSecret() {
|
|
|
|
location.href = location.href.split('#')[0]
|
|
|
|
},
|
|
|
|
|
|
|
|
// requestSecret requests the encrypted secret from the backend
|
|
|
|
requestSecret() {
|
|
|
|
axios.get(`api/get/${this.secretId}`)
|
|
|
|
.then(resp => {
|
|
|
|
let secret = resp.data.secret
|
|
|
|
if (this.securePassword) {
|
|
|
|
secret = AES.dec(secret, this.securePassword)
|
|
|
|
}
|
|
|
|
this.secret = secret
|
|
|
|
})
|
|
|
|
.catch(err => {
|
2019-05-10 22:31:26 +00:00
|
|
|
switch (err.response.status) {
|
|
|
|
case 404:
|
|
|
|
this.error = this.$t('alert-secret-not-found')
|
|
|
|
this.showError = true
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
this.error = this.$t('alert-something-went-wrong')
|
|
|
|
this.showError = true
|
2019-05-10 21:12:00 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
textarea {
|
|
|
|
font-family: monospace;
|
|
|
|
}
|
|
|
|
.footer {
|
|
|
|
color: #2f2f2f;
|
|
|
|
font-size: 0.9em;
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
</style>
|