2024-06-11 18:15:29 +00:00
|
|
|
<template>
|
2024-06-13 05:11:56 +00:00
|
|
|
<div>
|
2024-06-14 18:42:26 +00:00
|
|
|
<div>
|
2024-06-15 15:49:04 +00:00
|
|
|
<div class="filter-buttons">
|
|
|
|
<el-button-group>
|
|
|
|
<el-button
|
|
|
|
type="success"
|
|
|
|
v-for="band in filterBands"
|
|
|
|
:key="band"
|
|
|
|
@click="filterTable(band)"
|
|
|
|
>
|
|
|
|
{{ band }}
|
2024-06-13 17:54:48 +00:00
|
|
|
</el-button>
|
2024-06-15 15:49:04 +00:00
|
|
|
<el-button type="success" @click="clearFilter" v-if="showClear"
|
|
|
|
>Clear</el-button
|
|
|
|
>
|
|
|
|
</el-button-group>
|
2024-06-16 06:55:00 +00:00
|
|
|
<div>
|
2024-06-16 17:53:01 +00:00
|
|
|
<el-form-item label="Show OTPs">
|
|
|
|
<el-switch v-model="showSecrets" active-value="yes" inactive-value="no" />
|
|
|
|
</el-form-item>
|
2024-06-16 06:55:00 +00:00
|
|
|
</div>
|
|
|
|
<div class="sort-options">
|
|
|
|
<span>
|
|
|
|
<el-form-item label="Sort">
|
|
|
|
<el-select
|
|
|
|
v-model="currentSort"
|
|
|
|
placeholder="Select"
|
|
|
|
style="width: 80px"
|
|
|
|
@change="sortItems"
|
|
|
|
>
|
|
|
|
<el-option
|
|
|
|
v-for="item in sortOptions"
|
|
|
|
:key="item.key"
|
|
|
|
:label="item.name"
|
|
|
|
:value="item.key"
|
|
|
|
/>
|
|
|
|
</el-select>
|
|
|
|
</el-form-item>
|
|
|
|
</span>
|
|
|
|
</div>
|
2024-06-15 15:49:04 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div id="cards" v-if="loadCards">
|
|
|
|
<span v-for="secret in filteredSecretsList" :key="secret.id">
|
|
|
|
<SecretCard
|
|
|
|
:issuer="secret.issuer"
|
|
|
|
:username="secret.username"
|
|
|
|
:secret="secret.secret"
|
|
|
|
:id="secret.id"
|
2024-06-16 09:32:07 +00:00
|
|
|
:showOtp="showSecrets"
|
2024-06-16 17:53:01 +00:00
|
|
|
:key="showSecrets"
|
2024-06-15 15:49:04 +00:00
|
|
|
@edit="editSecret"
|
|
|
|
/>
|
|
|
|
</span>
|
|
|
|
</div>
|
2024-06-13 05:11:56 +00:00
|
|
|
</div>
|
2024-06-11 18:15:29 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2024-06-13 17:02:47 +00:00
|
|
|
import { TOTP } from "totp-generator";
|
|
|
|
|
2024-06-15 15:49:04 +00:00
|
|
|
import SecretCard from "./SecretCard.vue";
|
|
|
|
|
2024-06-11 18:15:29 +00:00
|
|
|
export default {
|
2024-06-15 15:49:04 +00:00
|
|
|
components: { SecretCard },
|
2024-06-11 18:15:29 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
message: "Hello List Secret",
|
2024-06-13 05:11:56 +00:00
|
|
|
apiBaseUrl: "http://localhost:8000",
|
|
|
|
secretsList: [],
|
2024-06-14 18:42:26 +00:00
|
|
|
filteredSecretsList: [],
|
|
|
|
filterBands: ["A-C", "D-I", "J-O", "P-S", "T-Z"],
|
|
|
|
filterBandsVals: {
|
|
|
|
"A-C": ["A", "B", "C"],
|
|
|
|
"D-I": ["D", "E", "F", "G", "H", "I"],
|
|
|
|
"J-O": ["J", "K", "L", "M", "N", "O"],
|
|
|
|
"P-S": ["P", "Q", "R", "S"],
|
|
|
|
"T-Z": ["T", "U", "V", "W", "X", "Y", "Z"],
|
|
|
|
},
|
|
|
|
currentFilter: [],
|
2024-06-15 15:49:04 +00:00
|
|
|
loadCards: false,
|
|
|
|
showClear: false,
|
2024-06-16 09:32:07 +00:00
|
|
|
showSecrets: "yes",
|
2024-06-16 17:53:01 +00:00
|
|
|
currentSort: "asc",
|
2024-06-16 06:55:00 +00:00
|
|
|
sortOptions: [
|
|
|
|
{
|
|
|
|
name: "A-Z",
|
|
|
|
key: "asc",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "Z-A",
|
|
|
|
key: "desc",
|
|
|
|
},
|
|
|
|
],
|
2024-06-11 18:15:29 +00:00
|
|
|
};
|
|
|
|
},
|
2024-06-13 05:11:56 +00:00
|
|
|
|
|
|
|
methods: {
|
|
|
|
async listSecrets() {
|
|
|
|
const url = `${this.apiBaseUrl}/secret`;
|
2024-06-14 18:42:26 +00:00
|
|
|
const token = sessionStorage.getItem("token");
|
2024-06-13 05:11:56 +00:00
|
|
|
const requestOptions = {
|
|
|
|
method: "GET",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
console.log(requestOptions);
|
|
|
|
const response = await fetch(url, requestOptions)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
2024-06-15 15:49:04 +00:00
|
|
|
// console.log(data);
|
2024-06-13 05:11:56 +00:00
|
|
|
return data;
|
|
|
|
})
|
|
|
|
.catch((err) => console.log(err));
|
|
|
|
|
|
|
|
response.forEach((element) => {
|
2024-06-13 17:54:48 +00:00
|
|
|
// console.log(element);
|
2024-06-13 05:11:56 +00:00
|
|
|
const row = this.parseSecret(element.data);
|
2024-06-13 17:54:48 +00:00
|
|
|
row["id"] = element["id"];
|
2024-06-13 05:11:56 +00:00
|
|
|
this.secretsList.push(row);
|
|
|
|
});
|
2024-06-15 15:49:04 +00:00
|
|
|
this.filteredSecretsList = this.secretsList;
|
2024-06-16 17:53:01 +00:00
|
|
|
this.sortItems();
|
2024-06-15 15:49:04 +00:00
|
|
|
this.loadCards = true;
|
2024-06-13 05:11:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
parseSecret(gibberish) {
|
|
|
|
const jsonString = atob(gibberish);
|
|
|
|
const secret = JSON.parse(jsonString);
|
|
|
|
return secret;
|
|
|
|
},
|
2024-06-13 17:02:47 +00:00
|
|
|
|
|
|
|
generateTotp(secret) {
|
|
|
|
const { otp, expires } = TOTP.generate(secret);
|
|
|
|
console.log(expires);
|
|
|
|
return otp;
|
|
|
|
},
|
2024-06-13 17:54:48 +00:00
|
|
|
|
2024-06-15 15:49:04 +00:00
|
|
|
editSecret(id) {
|
2024-06-15 18:12:12 +00:00
|
|
|
const editingSecret = this.secretsList.filter((element) => {
|
|
|
|
return element.id === id;
|
|
|
|
});
|
|
|
|
// console.log(editingSecret);
|
|
|
|
this.$emit("edit", editingSecret[0]);
|
2024-06-13 17:54:48 +00:00
|
|
|
},
|
2024-06-14 18:42:26 +00:00
|
|
|
|
|
|
|
filterTable(band) {
|
|
|
|
const letters = this.filterBandsVals[band];
|
|
|
|
this.currentFilter = letters;
|
2024-06-15 15:49:04 +00:00
|
|
|
this.showClear = true;
|
2024-06-14 18:42:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
checkFirstLetter(row) {
|
|
|
|
const firstLetter = row.issuer[0].toUpperCase();
|
2024-06-15 15:49:04 +00:00
|
|
|
const index = this.currentFilter.indexOf(firstLetter);
|
|
|
|
if (index >= 0) {
|
2024-06-14 18:42:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
2024-06-15 15:49:04 +00:00
|
|
|
|
|
|
|
clearFilter() {
|
|
|
|
this.filteredSecretsList = this.secretsList;
|
|
|
|
this.showClear = false;
|
|
|
|
},
|
2024-06-16 06:55:00 +00:00
|
|
|
|
|
|
|
sortItems() {
|
|
|
|
if (this.currentSort === "asc") {
|
|
|
|
this.filteredSecretsList.sort((a, b) => a.issuer.localeCompare(b.issuer));
|
|
|
|
} else if (this.currentSort === "desc") {
|
|
|
|
this.filteredSecretsList.sort((a, b) => b.issuer.localeCompare(a.issuer));
|
|
|
|
}
|
|
|
|
},
|
2024-06-14 18:42:26 +00:00
|
|
|
},
|
|
|
|
|
2024-06-15 15:49:04 +00:00
|
|
|
computed: {},
|
|
|
|
|
2024-06-14 18:42:26 +00:00
|
|
|
watch: {
|
2024-06-15 15:49:04 +00:00
|
|
|
currentFilter: function () {
|
2024-06-14 18:42:26 +00:00
|
|
|
const filteredList = this.secretsList.filter(this.checkFirstLetter);
|
|
|
|
this.filteredSecretsList = filteredList;
|
2024-06-16 17:53:01 +00:00
|
|
|
this.sortItems();
|
2024-06-14 18:42:26 +00:00
|
|
|
},
|
2024-06-16 09:32:07 +00:00
|
|
|
|
|
|
|
currentSort: function () {
|
|
|
|
localStorage.setItem("currentSort", this.currentSort);
|
|
|
|
},
|
|
|
|
|
|
|
|
showSecrets: function () {
|
|
|
|
localStorage.setItem("showSecrets", this.showSecrets);
|
|
|
|
},
|
|
|
|
|
|
|
|
secretsList: function () {
|
|
|
|
this.currentSort = localStorage.getItem("currentSort");
|
|
|
|
this.filteredSecretsList = this.secretsList;
|
|
|
|
this.sortItems();
|
|
|
|
},
|
2024-06-13 05:11:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.listSecrets();
|
2024-06-16 09:32:07 +00:00
|
|
|
this.showSecrets = localStorage.getItem("showSecrets");
|
|
|
|
this.currentSort = localStorage.getItem("currentSort");
|
2024-06-13 05:11:56 +00:00
|
|
|
},
|
2024-06-11 18:15:29 +00:00
|
|
|
};
|
|
|
|
</script>
|
2024-06-15 15:49:04 +00:00
|
|
|
|
|
|
|
<style>
|
|
|
|
#cards {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex-wrap: wrap;
|
2024-06-16 17:53:01 +00:00
|
|
|
justify-content: space-evenly;
|
|
|
|
max-width: 96vw;
|
2024-06-15 15:49:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.filter-buttons {
|
2024-06-16 17:53:01 +00:00
|
|
|
width: 96vw;
|
2024-06-15 15:49:04 +00:00
|
|
|
display: flex;
|
2024-06-16 17:53:01 +00:00
|
|
|
margin: 40px 0 20px 0;
|
|
|
|
justify-content: space-around;
|
2024-06-16 06:55:00 +00:00
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
.sort-options {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
min-width: 80px;
|
|
|
|
}
|
2024-06-15 15:49:04 +00:00
|
|
|
</style>
|