mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +00:00
Added "State" status for webhook session
This commit is contained in:
@@ -585,6 +585,7 @@ def API_updatePeerSettings(configName):
|
||||
else:
|
||||
status, msg = peer.updatePeer(name, private_key, preshared_key, dns_addresses,
|
||||
allowed_ip, endpoint_allowed_ip, mtu, keepalive, "off")
|
||||
wireguardConfig.getPeers()
|
||||
DashboardWebHooks.RunWebHook('peer_updated', {
|
||||
"configuration": wireguardConfig.Name,
|
||||
"peers": [id]
|
||||
|
@@ -149,12 +149,6 @@ class AmneziaWGPeer(Peer):
|
||||
shell=True, stderr=subprocess.STDOUT)
|
||||
if f"wg showconf {self.configuration.Name}" not in saveConfig.decode().strip('\n'):
|
||||
return False, "Update peer failed when saving the configuration"
|
||||
# sqlUpdate(
|
||||
# '''UPDATE '%s' SET name = ?, private_key = ?, DNS = ?, endpoint_allowed_ip = ?, mtu = ?,
|
||||
# keepalive = ?, preshared_key = ?, advanced_security = ? WHERE id = ?''' % self.configuration.Name,
|
||||
# (name, private_key, dns_addresses, endpoint_allowed_ip, mtu,
|
||||
# keepalive, preshared_key, advanced_security, self.id,)
|
||||
# )
|
||||
|
||||
with self.configuration.engine.begin() as conn:
|
||||
conn.execute(
|
||||
@@ -171,7 +165,7 @@ class AmneziaWGPeer(Peer):
|
||||
self.configuration.peersTable.c.id == self.id
|
||||
)
|
||||
)
|
||||
|
||||
self.configuration.getPeers()
|
||||
return True, None
|
||||
except subprocess.CalledProcessError as exc:
|
||||
return False, exc.output.decode("UTF-8").strip()
|
@@ -3,7 +3,7 @@ import threading
|
||||
import time
|
||||
import urllib.parse
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
import requests
|
||||
from pydantic import BaseModel, field_serializer
|
||||
@@ -77,6 +77,17 @@ class DashboardWebHooks:
|
||||
|
||||
self.metadata.create_all(self.engine)
|
||||
self.WebHooks: list[WebHook] = []
|
||||
|
||||
with self.engine.begin() as conn:
|
||||
conn.execute(
|
||||
self.webHookSessionsTable.update().values({
|
||||
"EndDate": datetime.now(),
|
||||
"Status": 2
|
||||
}).where(
|
||||
self.webHookSessionsTable.c.Status == -1
|
||||
)
|
||||
)
|
||||
|
||||
self.__getWebHooks()
|
||||
|
||||
def __getWebHooks(self):
|
||||
|
@@ -68,13 +68,13 @@ class Peer:
|
||||
if len(dns_addresses) > 0 and not ValidateDNSAddress(dns_addresses):
|
||||
return False, f"DNS format is incorrect"
|
||||
|
||||
if type(mtu) is str:
|
||||
if type(mtu) is str or mtu is None:
|
||||
mtu = 0
|
||||
|
||||
if mtu < 0 or mtu > 1460:
|
||||
return False, "MTU format is not correct"
|
||||
|
||||
if type(keepalive) is str:
|
||||
if type(keepalive) is str or keepalive is None:
|
||||
keepalive = 0
|
||||
|
||||
if keepalive < 0:
|
||||
|
@@ -398,6 +398,7 @@ class WireguardConfiguration:
|
||||
|
||||
def getPeers(self):
|
||||
tmpList = []
|
||||
current_app.logger.info(f"Refreshing {self.Name} peer list")
|
||||
if self.configurationFileChanged():
|
||||
with open(self.configPath, 'r') as configFile:
|
||||
p = []
|
||||
|
@@ -13,6 +13,7 @@ import PeerListModals from "@/components/configurationComponents/peerListCompone
|
||||
import PeerIntersectionObserver from "@/components/configurationComponents/peerIntersectionObserver.vue";
|
||||
import ConfigurationDescription from "@/components/configurationComponents/configurationDescription.vue";
|
||||
import PeerDetailsModal from "@/components/configurationComponents/peerDetailsModal.vue";
|
||||
import {parseCidr} from "cidr-tools";
|
||||
|
||||
// Async Components
|
||||
const PeerSearchBar = defineAsyncComponent(() => import("@/components/configurationComponents/peerSearchBar.vue"))
|
||||
@@ -168,6 +169,14 @@ const taggedPeers = computed(() => {
|
||||
return Object.values(configurationInfo.value.Info.PeerGroups).map(x => x.Peers).flat()
|
||||
})
|
||||
|
||||
const firstAllowedIPCount = (allowed_ip) => {
|
||||
try{
|
||||
return parseCidr(allowed_ip.replace(" ", "").split(",")[0]).start
|
||||
}catch (e){
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
const searchPeers = computed(() => {
|
||||
const result = wireguardConfigurationStore.searchString ?
|
||||
configurationPeers.value.filter(x => {
|
||||
@@ -196,17 +205,36 @@ const searchPeers = computed(() => {
|
||||
}).slice(0, showPeersCount.value);
|
||||
}
|
||||
|
||||
return result.sort((a, b) => {
|
||||
if ( a[dashboardStore.Configuration.Server.dashboard_sort]
|
||||
< b[dashboardStore.Configuration.Server.dashboard_sort] ){
|
||||
return -1;
|
||||
}
|
||||
if ( a[dashboardStore.Configuration.Server.dashboard_sort]
|
||||
> b[dashboardStore.Configuration.Server.dashboard_sort]){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}).slice(0, showPeersCount.value)
|
||||
let re = []
|
||||
|
||||
if (dashboardStore.Configuration.Server.dashboard_sort === 'allowed_ip'){
|
||||
re = result.sort((a, b) => {
|
||||
if ( firstAllowedIPCount(a[dashboardStore.Configuration.Server.dashboard_sort])
|
||||
< firstAllowedIPCount(b[dashboardStore.Configuration.Server.dashboard_sort]) ){
|
||||
return -1;
|
||||
}
|
||||
if ( firstAllowedIPCount(a[dashboardStore.Configuration.Server.dashboard_sort])
|
||||
> firstAllowedIPCount(b[dashboardStore.Configuration.Server.dashboard_sort])){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}).slice(0, showPeersCount.value)
|
||||
}else{
|
||||
re = result.sort((a, b) => {
|
||||
if ( a[dashboardStore.Configuration.Server.dashboard_sort]
|
||||
< b[dashboardStore.Configuration.Server.dashboard_sort] ){
|
||||
return -1;
|
||||
}
|
||||
if ( a[dashboardStore.Configuration.Server.dashboard_sort]
|
||||
> b[dashboardStore.Configuration.Server.dashboard_sort]){
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}).slice(0, showPeersCount.value)
|
||||
}
|
||||
|
||||
|
||||
return re
|
||||
})
|
||||
|
||||
watch(() => route.query.id, (newValue) => {
|
||||
@@ -218,11 +246,6 @@ watch(() => route.query.id, (newValue) => {
|
||||
}, {
|
||||
immediate: true
|
||||
})
|
||||
|
||||
|
||||
// onMounted(() => {
|
||||
// configurationModalSelectedPeer.value = searchPeers.value[0]
|
||||
// })
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@@ -9,10 +9,13 @@ const collapse = ref(true)
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<p class="d-flex mb-0" role="button" @click="collapse = !collapse">
|
||||
<span :class="{'text-success': session.Status === 0, 'text-danger': session.Status === 1}">
|
||||
<span :class="{'text-success': session.Status === 0, 'text-danger': session.Status === 1, 'text-warning': session.Status === 2}">
|
||||
<span v-if="session.Status === 0">
|
||||
<i class="bi bi-check-circle-fill me-2"></i>
|
||||
</span>
|
||||
<span v-else-if="session.Status === 2">
|
||||
<i class="bi bi-trash3-fill me-2"></i>
|
||||
</span>
|
||||
<span v-else-if="session.Status === 1">
|
||||
<i class="bi bi-x-circle-fill me-2"></i>
|
||||
</span>
|
||||
|
@@ -14,16 +14,19 @@ const formattedBody = computed(() => {
|
||||
<small class="text-muted">
|
||||
<LocaleText t="Status"></LocaleText>
|
||||
</small>
|
||||
<h3 :class="{'text-success': session.Status === 0, 'text-danger': session.Status === 1}">
|
||||
<span v-if="session.Status === 0">
|
||||
<i class="bi bi-check-circle-fill me-2"></i><LocaleText t="Success"></LocaleText>
|
||||
</span>
|
||||
<h3 :class="{'text-success': session.Status === 0, 'text-danger': session.Status === 1, 'text-warning': session.Status === 2}">
|
||||
<span v-if="session.Status === 0">
|
||||
<i class="bi bi-check-circle-fill me-2"></i><LocaleText t="Success"></LocaleText>
|
||||
</span>
|
||||
<span v-if="session.Status === 2">
|
||||
<i class="bi bi-trash3-fill me-2"></i><LocaleText t="Timeout"></LocaleText>
|
||||
</span>
|
||||
<span v-else-if="session.Status === 1">
|
||||
<i class="bi bi-x-circle-fill me-2"></i><LocaleText t="Failed"></LocaleText>
|
||||
</span>
|
||||
<span v-else-if="session.Status === -1">
|
||||
<i class="spinner-border me-2"></i><LocaleText t="Requesting..."></LocaleText>
|
||||
</span>
|
||||
</span>
|
||||
</h3>
|
||||
<div class="d-flex gap-4 align-items-center">
|
||||
<div>
|
||||
|
Reference in New Issue
Block a user