diff --git a/src/dashboard.py b/src/dashboard.py index 9ef86e66..48f47641 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -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] diff --git a/src/modules/AmneziaWGPeer.py b/src/modules/AmneziaWGPeer.py index 30370ef2..11989989 100644 --- a/src/modules/AmneziaWGPeer.py +++ b/src/modules/AmneziaWGPeer.py @@ -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() \ No newline at end of file diff --git a/src/modules/DashboardWebHooks.py b/src/modules/DashboardWebHooks.py index 670c9948..a598444b 100644 --- a/src/modules/DashboardWebHooks.py +++ b/src/modules/DashboardWebHooks.py @@ -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): diff --git a/src/modules/Peer.py b/src/modules/Peer.py index 7f234caf..4724fdf7 100644 --- a/src/modules/Peer.py +++ b/src/modules/Peer.py @@ -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: diff --git a/src/modules/WireguardConfiguration.py b/src/modules/WireguardConfiguration.py index 27e93211..a58829ed 100644 --- a/src/modules/WireguardConfiguration.py +++ b/src/modules/WireguardConfiguration.py @@ -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 = [] diff --git a/src/static/app/src/components/configurationComponents/peerList.vue b/src/static/app/src/components/configurationComponents/peerList.vue index 3b943c94..85ea6651 100644 --- a/src/static/app/src/components/configurationComponents/peerList.vue +++ b/src/static/app/src/components/configurationComponents/peerList.vue @@ -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] -// })