mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-10-03 07:46:18 +00:00
Added Reset Total Data as a valid peer job task #763
This commit is contained in:
@@ -185,10 +185,10 @@ class Peer:
|
|||||||
def getShareLink(self):
|
def getShareLink(self):
|
||||||
self.ShareLink = self.configuration.AllPeerShareLinks.getLink(self.configuration.Name, self.id)
|
self.ShareLink = self.configuration.AllPeerShareLinks.getLink(self.configuration.Name, self.id)
|
||||||
|
|
||||||
def resetDataUsage(self, type):
|
def resetDataUsage(self, mode: str):
|
||||||
try:
|
try:
|
||||||
with self.configuration.engine.begin() as conn:
|
with self.configuration.engine.begin() as conn:
|
||||||
if type == "total":
|
if mode == "total":
|
||||||
conn.execute(
|
conn.execute(
|
||||||
self.configuration.peersTable.update().values({
|
self.configuration.peersTable.update().values({
|
||||||
"total_data": 0,
|
"total_data": 0,
|
||||||
@@ -207,7 +207,7 @@ class Peer:
|
|||||||
self.cumu_data = 0
|
self.cumu_data = 0
|
||||||
self.cumu_sent = 0
|
self.cumu_sent = 0
|
||||||
self.cumu_receive = 0
|
self.cumu_receive = 0
|
||||||
elif type == "receive":
|
elif mode == "receive":
|
||||||
conn.execute(
|
conn.execute(
|
||||||
self.configuration.peersTable.update().values({
|
self.configuration.peersTable.update().values({
|
||||||
"total_receive": 0,
|
"total_receive": 0,
|
||||||
@@ -218,7 +218,7 @@ class Peer:
|
|||||||
)
|
)
|
||||||
self.cumu_receive = 0
|
self.cumu_receive = 0
|
||||||
self.total_receive = 0
|
self.total_receive = 0
|
||||||
elif type == "sent":
|
elif mode == "sent":
|
||||||
conn.execute(
|
conn.execute(
|
||||||
self.configuration.peersTable.update().values({
|
self.configuration.peersTable.update().values({
|
||||||
"total_sent": 0,
|
"total_sent": 0,
|
||||||
@@ -308,25 +308,6 @@ class Peer:
|
|||||||
).fetchall()
|
).fetchall()
|
||||||
time = list(map(lambda x : x[0], result))
|
time = list(map(lambda x : x[0], result))
|
||||||
return time
|
return time
|
||||||
# sessions = []
|
|
||||||
# if len(time) > 1:
|
|
||||||
# current_session = [time[0]]
|
|
||||||
#
|
|
||||||
# for ts in time[1:]:
|
|
||||||
# if ts - current_session[-1] <= datetime.timedelta(minutes=3):
|
|
||||||
# current_session.append(ts)
|
|
||||||
# else:
|
|
||||||
# sessions.append({
|
|
||||||
# "duration": self.__duration(current_session[-1], current_session[0]),
|
|
||||||
# "timestamps": current_session
|
|
||||||
# })
|
|
||||||
# current_session = [ts]
|
|
||||||
# sessions.append({
|
|
||||||
# "duration": self.__duration(current_session[-1], current_session[0]),
|
|
||||||
# "timestamps": current_session
|
|
||||||
# })
|
|
||||||
# print(sessions)
|
|
||||||
# return sessions
|
|
||||||
|
|
||||||
def __duration(self, t1: datetime.datetime, t2: datetime.datetime):
|
def __duration(self, t1: datetime.datetime, t2: datetime.datetime):
|
||||||
delta = t1 - t2
|
delta = t1 - t2
|
||||||
|
@@ -162,6 +162,10 @@ class PeerJobs:
|
|||||||
s, msg = c.restrictPeers([fp.id])
|
s, msg = c.restrictPeers([fp.id])
|
||||||
elif job.Action == "delete":
|
elif job.Action == "delete":
|
||||||
s, msg = c.deletePeers([fp.id])
|
s, msg = c.deletePeers([fp.id])
|
||||||
|
elif job.Action == "reset_total_data_usage":
|
||||||
|
s = fp.resetDataUsage("total")
|
||||||
|
c.restrictPeers([fp.id])
|
||||||
|
c.allowAccessPeers([fp.id])
|
||||||
|
|
||||||
if s is True:
|
if s is True:
|
||||||
self.JobLogger.log(job.JobID, s,
|
self.JobLogger.log(job.JobID, s,
|
||||||
|
@@ -27,10 +27,10 @@ export default {
|
|||||||
:class="{'disabled border-transparent': !edit}" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
:class="{'disabled border-transparent': !edit}" type="button" data-bs-toggle="dropdown" aria-expanded="false">
|
||||||
<samp>{{this.currentSelection.display}}</samp>
|
<samp>{{this.currentSelection.display}}</samp>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu rounded-3 shadow" style="font-size: 0.875rem; width: 200px">
|
<ul class="dropdown-menu rounded-3 shadow" style="font-size: 0.875rem;">
|
||||||
<li v-for="x in this.options" v-if="edit">
|
<li v-for="x in this.options" v-if="edit">
|
||||||
<a class="dropdown-item d-flex align-items-center" role="button" @click="$emit('update', x.value)">
|
<a class="dropdown-item d-flex align-items-center" role="button" @click="$emit('update', x.value)">
|
||||||
<samp>{{x.display}}</samp>
|
<samp class="pe-5">{{x.display}}</samp>
|
||||||
<i class="bi bi-check ms-auto" v-if="x.value === this.currentSelection.value"></i>
|
<i class="bi bi-check ms-auto" v-if="x.value === this.currentSelection.value"></i>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@@ -121,7 +121,10 @@ const setMapCenter = (endpoint) => {
|
|||||||
<div class="m-auto" v-if="!loaded">
|
<div class="m-auto" v-if="!loaded">
|
||||||
<span class="spinner-border spinner-border-sm me-2"></span><LocaleText t="Loading..."></LocaleText>
|
<span class="spinner-border spinner-border-sm me-2"></span><LocaleText t="Loading..."></LocaleText>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="w-100 d-flex flex-column gap-3">
|
<div class="m-auto" v-else-if="loaded && endpoints.endpoints.length === 0">
|
||||||
|
<LocaleText t="No Historical Endpoints"></LocaleText>
|
||||||
|
</div>
|
||||||
|
<div v-else-if="loaded && endpoints.endpoints.length > 0" class="w-100 d-flex flex-column gap-3">
|
||||||
<div class="bg-body d-flex w-100 rounded-3" style="height: 500px" id="map">
|
<div class="bg-body d-flex w-100 rounded-3" style="height: 500px" id="map">
|
||||||
<div class="m-auto" v-if="!mapAvailable">
|
<div class="m-auto" v-if="!mapAvailable">
|
||||||
<div v-if="mapAvailable === undefined">
|
<div v-if="mapAvailable === undefined">
|
||||||
|
@@ -77,6 +77,10 @@ export const WireguardConfigurationsStore = defineStore('WireguardConfigurations
|
|||||||
{
|
{
|
||||||
display: GetLocale("Delete Peer"),
|
display: GetLocale("Delete Peer"),
|
||||||
value: "delete"
|
value: "delete"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
display: GetLocale("Reset Total Data Usage"),
|
||||||
|
value: "reset_total_data_usage"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user