Added "State" status for webhook session

This commit is contained in:
Donald Zou
2025-09-14 15:38:19 +08:00
parent 628464d2e1
commit 2eb3a17775
8 changed files with 68 additions and 32 deletions

View File

@@ -585,6 +585,7 @@ def API_updatePeerSettings(configName):
else: else:
status, msg = peer.updatePeer(name, private_key, preshared_key, dns_addresses, status, msg = peer.updatePeer(name, private_key, preshared_key, dns_addresses,
allowed_ip, endpoint_allowed_ip, mtu, keepalive, "off") allowed_ip, endpoint_allowed_ip, mtu, keepalive, "off")
wireguardConfig.getPeers()
DashboardWebHooks.RunWebHook('peer_updated', { DashboardWebHooks.RunWebHook('peer_updated', {
"configuration": wireguardConfig.Name, "configuration": wireguardConfig.Name,
"peers": [id] "peers": [id]

View File

@@ -149,12 +149,6 @@ class AmneziaWGPeer(Peer):
shell=True, stderr=subprocess.STDOUT) shell=True, stderr=subprocess.STDOUT)
if f"wg showconf {self.configuration.Name}" not in saveConfig.decode().strip('\n'): if f"wg showconf {self.configuration.Name}" not in saveConfig.decode().strip('\n'):
return False, "Update peer failed when saving the configuration" 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: with self.configuration.engine.begin() as conn:
conn.execute( conn.execute(
@@ -171,7 +165,7 @@ class AmneziaWGPeer(Peer):
self.configuration.peersTable.c.id == self.id self.configuration.peersTable.c.id == self.id
) )
) )
self.configuration.getPeers()
return True, None return True, None
except subprocess.CalledProcessError as exc: except subprocess.CalledProcessError as exc:
return False, exc.output.decode("UTF-8").strip() return False, exc.output.decode("UTF-8").strip()

View File

@@ -3,7 +3,7 @@ import threading
import time import time
import urllib.parse import urllib.parse
import uuid import uuid
from datetime import datetime from datetime import datetime, timedelta
import requests import requests
from pydantic import BaseModel, field_serializer from pydantic import BaseModel, field_serializer
@@ -77,6 +77,17 @@ class DashboardWebHooks:
self.metadata.create_all(self.engine) self.metadata.create_all(self.engine)
self.WebHooks: list[WebHook] = [] 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() self.__getWebHooks()
def __getWebHooks(self): def __getWebHooks(self):

View File

@@ -68,13 +68,13 @@ class Peer:
if len(dns_addresses) > 0 and not ValidateDNSAddress(dns_addresses): if len(dns_addresses) > 0 and not ValidateDNSAddress(dns_addresses):
return False, f"DNS format is incorrect" return False, f"DNS format is incorrect"
if type(mtu) is str: if type(mtu) is str or mtu is None:
mtu = 0 mtu = 0
if mtu < 0 or mtu > 1460: if mtu < 0 or mtu > 1460:
return False, "MTU format is not correct" return False, "MTU format is not correct"
if type(keepalive) is str: if type(keepalive) is str or keepalive is None:
keepalive = 0 keepalive = 0
if keepalive < 0: if keepalive < 0:

View File

@@ -398,6 +398,7 @@ class WireguardConfiguration:
def getPeers(self): def getPeers(self):
tmpList = [] tmpList = []
current_app.logger.info(f"Refreshing {self.Name} peer list")
if self.configurationFileChanged(): if self.configurationFileChanged():
with open(self.configPath, 'r') as configFile: with open(self.configPath, 'r') as configFile:
p = [] p = []

View File

@@ -13,6 +13,7 @@ import PeerListModals from "@/components/configurationComponents/peerListCompone
import PeerIntersectionObserver from "@/components/configurationComponents/peerIntersectionObserver.vue"; import PeerIntersectionObserver from "@/components/configurationComponents/peerIntersectionObserver.vue";
import ConfigurationDescription from "@/components/configurationComponents/configurationDescription.vue"; import ConfigurationDescription from "@/components/configurationComponents/configurationDescription.vue";
import PeerDetailsModal from "@/components/configurationComponents/peerDetailsModal.vue"; import PeerDetailsModal from "@/components/configurationComponents/peerDetailsModal.vue";
import {parseCidr} from "cidr-tools";
// Async Components // Async Components
const PeerSearchBar = defineAsyncComponent(() => import("@/components/configurationComponents/peerSearchBar.vue")) 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() 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 searchPeers = computed(() => {
const result = wireguardConfigurationStore.searchString ? const result = wireguardConfigurationStore.searchString ?
configurationPeers.value.filter(x => { configurationPeers.value.filter(x => {
@@ -196,17 +205,36 @@ const searchPeers = computed(() => {
}).slice(0, showPeersCount.value); }).slice(0, showPeersCount.value);
} }
return result.sort((a, b) => { let re = []
if ( a[dashboardStore.Configuration.Server.dashboard_sort]
< b[dashboardStore.Configuration.Server.dashboard_sort] ){ if (dashboardStore.Configuration.Server.dashboard_sort === 'allowed_ip'){
return -1; re = result.sort((a, b) => {
} if ( firstAllowedIPCount(a[dashboardStore.Configuration.Server.dashboard_sort])
if ( a[dashboardStore.Configuration.Server.dashboard_sort] < firstAllowedIPCount(b[dashboardStore.Configuration.Server.dashboard_sort]) ){
> b[dashboardStore.Configuration.Server.dashboard_sort]){ return -1;
return 1; }
} if ( firstAllowedIPCount(a[dashboardStore.Configuration.Server.dashboard_sort])
return 0; > firstAllowedIPCount(b[dashboardStore.Configuration.Server.dashboard_sort])){
}).slice(0, showPeersCount.value) 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) => { watch(() => route.query.id, (newValue) => {
@@ -218,11 +246,6 @@ watch(() => route.query.id, (newValue) => {
}, { }, {
immediate: true immediate: true
}) })
// onMounted(() => {
// configurationModalSelectedPeer.value = searchPeers.value[0]
// })
</script> </script>
<template> <template>

View File

@@ -9,10 +9,13 @@ const collapse = ref(true)
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<p class="d-flex mb-0" role="button" @click="collapse = !collapse"> <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"> <span v-if="session.Status === 0">
<i class="bi bi-check-circle-fill me-2"></i> <i class="bi bi-check-circle-fill me-2"></i>
</span> </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"> <span v-else-if="session.Status === 1">
<i class="bi bi-x-circle-fill me-2"></i> <i class="bi bi-x-circle-fill me-2"></i>
</span> </span>

View File

@@ -14,16 +14,19 @@ const formattedBody = computed(() => {
<small class="text-muted"> <small class="text-muted">
<LocaleText t="Status"></LocaleText> <LocaleText t="Status"></LocaleText>
</small> </small>
<h3 :class="{'text-success': session.Status === 0, 'text-danger': session.Status === 1}"> <h3 :class="{'text-success': session.Status === 0, 'text-danger': session.Status === 1, 'text-warning': session.Status === 2}">
<span v-if="session.Status === 0"> <span v-if="session.Status === 0">
<i class="bi bi-check-circle-fill me-2"></i><LocaleText t="Success"></LocaleText> <i class="bi bi-check-circle-fill me-2"></i><LocaleText t="Success"></LocaleText>
</span> </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"> <span v-else-if="session.Status === 1">
<i class="bi bi-x-circle-fill me-2"></i><LocaleText t="Failed"></LocaleText> <i class="bi bi-x-circle-fill me-2"></i><LocaleText t="Failed"></LocaleText>
</span> </span>
<span v-else-if="session.Status === -1"> <span v-else-if="session.Status === -1">
<i class="spinner-border me-2"></i><LocaleText t="Requesting..."></LocaleText> <i class="spinner-border me-2"></i><LocaleText t="Requesting..."></LocaleText>
</span> </span>
</h3> </h3>
<div class="d-flex gap-4 align-items-center"> <div class="d-flex gap-4 align-items-center">
<div> <div>