-
+
Server List
-
-
+
+
+ Clickto add your server
diff --git a/src/static/app/src/router/index.js b/src/static/app/src/router/index.js
index 1072cb0..b31b5c1 100644
--- a/src/static/app/src/router/index.js
+++ b/src/static/app/src/router/index.js
@@ -138,19 +138,28 @@ router.beforeEach(async (to, from, next) => {
}
if (to.meta.requiresAuth){
- if (cookie.getCookie("authToken") && await checkAuth()){
+ if (!dashboardConfigurationStore.getActiveCrossServer()){
+ if (cookie.getCookie("authToken") && await checkAuth()){
+ await dashboardConfigurationStore.getConfiguration()
+ if (!wireguardConfigurationsStore.Configurations && to.name !== "Configuration List"){
+ await wireguardConfigurationsStore.getConfigurations();
+ }
+ dashboardConfigurationStore.Redirect = undefined;
+ next()
+ }else{
+ dashboardConfigurationStore.Redirect = to;
+ next("/signin")
+ dashboardConfigurationStore.newMessage("WGDashboard", "Session Ended", "warning")
+ }
+ }else{
await dashboardConfigurationStore.getConfiguration()
if (!wireguardConfigurationsStore.Configurations && to.name !== "Configuration List"){
await wireguardConfigurationsStore.getConfigurations();
}
- dashboardConfigurationStore.Redirect = undefined;
next()
- }else{
- dashboardConfigurationStore.Redirect = to;
- next("/signin")
- dashboardConfigurationStore.newMessage("WGDashboard", "Session Ended", "warning")
}
}else {
+
next();
}
});
diff --git a/src/static/app/src/stores/DashboardConfigurationStore.js b/src/static/app/src/stores/DashboardConfigurationStore.js
index ab62507..effe5a5 100644
--- a/src/static/app/src/stores/DashboardConfigurationStore.js
+++ b/src/static/app/src/stores/DashboardConfigurationStore.js
@@ -13,13 +13,12 @@ export const DashboardConfigurationStore = defineStore('DashboardConfigurationSt
},
CrossServerConfiguration:{
Enable: false,
- ServerList: []
+ ServerList: {}
}
}),
actions: {
initCrossServerConfiguration(){
const currentConfiguration = localStorage.getItem('CrossServerConfiguration');
-
if (currentConfiguration === null){
localStorage.setItem('CrossServerConfiguration', JSON.stringify(this.CrossServerConfiguration))
}else{
@@ -30,9 +29,23 @@ export const DashboardConfigurationStore = defineStore('DashboardConfigurationSt
localStorage.setItem('CrossServerConfiguration', JSON.stringify(this.CrossServerConfiguration))
},
addCrossServerConfiguration(){
- this.CrossServerConfiguration.ServerList.push(
- {host: "", apiKey: ""}
- )
+ this.CrossServerConfiguration.ServerList[v4().toString()] = {host: "", apiKey: "", active: false}
+ },
+ deleteCrossServerConfiguration(key){
+ delete this.CrossServerConfiguration.ServerList[key];
+ },
+ getActiveCrossServer(){
+ const key = localStorage.getItem('ActiveCrossServerConfiguration');
+ if (key !== null){
+ return this.CrossServerConfiguration.ServerList[key]
+ }
+ return undefined
+ },
+ setActiveCrossServer(key){
+ localStorage.setItem('ActiveCrossServerConfiguration', key)
+ },
+ removeActiveCrossServer(){
+ localStorage.removeItem('ActiveCrossServerConfiguration')
},
async getConfiguration(){
@@ -49,6 +62,7 @@ export const DashboardConfigurationStore = defineStore('DashboardConfigurationSt
},
async signOut(){
await fetchGet("/api/signout", {}, (res) => {
+ this.removeActiveCrossServer();
this.$router.go('/signin')
});
},
diff --git a/src/static/app/src/utilities/fetch.js b/src/static/app/src/utilities/fetch.js
index c7cd2dc..b8b5bd8 100644
--- a/src/static/app/src/utilities/fetch.js
+++ b/src/static/app/src/utilities/fetch.js
@@ -1,11 +1,31 @@
import router from "@/router/index.js";
import {DashboardConfigurationStore} from "@/stores/DashboardConfigurationStore.js";
+
+const getHeaders = () => {
+ let headers = {
+ "content-type": "application/json"
+ }
+ const store = DashboardConfigurationStore();
+ const apiKey = store.getActiveCrossServer();
+ if (apiKey){
+ headers['wg-dashboard-apikey'] = apiKey.apiKey
+ }
+ return headers
+}
+
+const getUrl = (url) => {
+ const store = DashboardConfigurationStore();
+ const apiKey = store.getActiveCrossServer();
+ if (apiKey){
+ return `${apiKey.host}${url}`
+ }
+ return url
+}
+
export const fetchGet = async (url, params=undefined, callback=undefined) => {
const urlSearchParams = new URLSearchParams(params);
- await fetch(`${url}?${urlSearchParams.toString()}`, {
- headers: {
- "content-type": "application/json"
- }
+ await fetch(`${getUrl(url)}?${urlSearchParams.toString()}`, {
+ headers: getHeaders()
})
.then((x) => {
const store = DashboardConfigurationStore();
@@ -26,10 +46,8 @@ export const fetchGet = async (url, params=undefined, callback=undefined) => {
}
export const fetchPost = async (url, body, callback) => {
- await fetch(`${url}`, {
- headers: {
- "content-type": "application/json"
- },
+ await fetch(`${getUrl(url)}`, {
+ headers: getHeaders(),
method: "POST",
body: JSON.stringify(body)
}).then((x) => {