mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-06 16:00:28 +01:00
Fixed some bugs..
This commit is contained in:
parent
f507ac2569
commit
f274f6fd18
@ -621,7 +621,7 @@ class WireguardConfiguration:
|
|||||||
sqldb.commit()
|
sqldb.commit()
|
||||||
self.Peers.append(Peer(newPeer, self))
|
self.Peers.append(Peer(newPeer, self))
|
||||||
else:
|
else:
|
||||||
cursor.execute("UPDATE %s SET allowed_ip = ? WHERE id = ?" % self.Name,
|
sqldb.cursor().execute("UPDATE %s SET allowed_ip = ? WHERE id = ?" % self.Name,
|
||||||
(i.get("AllowedIPs", "N/A"), i['PublicKey'],))
|
(i.get("AllowedIPs", "N/A"), i['PublicKey'],))
|
||||||
sqldb.commit()
|
sqldb.commit()
|
||||||
self.Peers.append(Peer(checkIfExist, self))
|
self.Peers.append(Peer(checkIfExist, self))
|
||||||
@ -788,8 +788,8 @@ class WireguardConfiguration:
|
|||||||
if cur_i is not None:
|
if cur_i is not None:
|
||||||
total_sent = cur_i['total_sent']
|
total_sent = cur_i['total_sent']
|
||||||
total_receive = cur_i['total_receive']
|
total_receive = cur_i['total_receive']
|
||||||
cur_total_sent = round(int(data_usage[i][2]) / (1024 ** 3), 4)
|
cur_total_sent = float(data_usage[i][2]) / (1024 ** 3)
|
||||||
cur_total_receive = round(int(data_usage[i][1]) / (1024 ** 3), 4)
|
cur_total_receive = float(data_usage[i][1]) / (1024 ** 3)
|
||||||
cumulative_receive = cur_i['cumu_receive'] + total_receive
|
cumulative_receive = cur_i['cumu_receive'] + total_receive
|
||||||
cumulative_sent = cur_i['cumu_sent'] + total_sent
|
cumulative_sent = cur_i['cumu_sent'] + total_sent
|
||||||
if total_sent <= cur_total_sent and total_receive <= cur_total_receive:
|
if total_sent <= cur_total_sent and total_receive <= cur_total_receive:
|
||||||
@ -798,32 +798,20 @@ class WireguardConfiguration:
|
|||||||
else:
|
else:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"UPDATE %s SET cumu_receive = ?, cumu_sent = ?, cumu_data = ? WHERE id = ?" %
|
"UPDATE %s SET cumu_receive = ?, cumu_sent = ?, cumu_data = ? WHERE id = ?" %
|
||||||
self.Name, (round(cumulative_receive, 4), round(cumulative_sent, 4),
|
self.Name, (cumulative_receive, cumulative_sent,
|
||||||
round(cumulative_sent + cumulative_receive, 4),
|
rcumulative_sent + cumulative_receive,
|
||||||
data_usage[i][0],))
|
data_usage[i][0],))
|
||||||
total_sent = 0
|
total_sent = 0
|
||||||
total_receive = 0
|
total_receive = 0
|
||||||
|
|
||||||
_, p = self.searchPeer(data_usage[i][0])
|
_, p = self.searchPeer(data_usage[i][0])
|
||||||
if p.total_receive != round(total_receive, 4) or p.total_sent != round(total_sent, 4):
|
if p.total_receive != total_receive or p.total_sent != total_sent:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"UPDATE %s SET total_receive = ?, total_sent = ?, total_data = ? WHERE id = ?"
|
"UPDATE %s SET total_receive = ?, total_sent = ?, total_data = ? WHERE id = ?"
|
||||||
% self.Name, (round(total_receive, 4), round(total_sent, 4),
|
% self.Name, (total_receive, total_sent,
|
||||||
round(total_receive + total_sent, 4), data_usage[i][0],))
|
total_receive + total_sent, data_usage[i][0],))
|
||||||
now = datetime.now()
|
|
||||||
now_string = now.strftime("%d/%m/%Y %H:%M:%S")
|
|
||||||
# cursor.execute(f'''
|
|
||||||
# INSERT INTO %s_transfer
|
|
||||||
# (id, total_receive, total_sent, total_data,
|
|
||||||
# cumu_receive, cumu_sent, cumu_data, time)
|
|
||||||
# VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
||||||
# ''' % self.Name, (data_usage[i][0], round(total_receive, 4), round(total_sent, 4),
|
|
||||||
# round(total_receive + total_sent, 4), round(cumulative_receive, 4),
|
|
||||||
# round(cumulative_sent, 4),
|
|
||||||
# round(cumulative_sent + cumulative_receive, 4), now_string,))
|
|
||||||
# sqldb.commit()
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Error" + str(e))
|
print("Error: " + str(e))
|
||||||
|
|
||||||
def getPeersEndpoint(self):
|
def getPeersEndpoint(self):
|
||||||
if not self.getStatus():
|
if not self.getStatus():
|
||||||
@ -881,6 +869,12 @@ class WireguardConfiguration:
|
|||||||
"PostUp": self.PostUp,
|
"PostUp": self.PostUp,
|
||||||
"PostDown": self.PostDown,
|
"PostDown": self.PostDown,
|
||||||
"SaveConfig": self.SaveConfig
|
"SaveConfig": self.SaveConfig
|
||||||
|
# "DataUsage": {
|
||||||
|
# "Total": sum(list(map(lambda x: x.cumu_data + x.total_data, self.Peers))),
|
||||||
|
# "Sent": sum(list(map(lambda x: x.cumu_sent + x.total_sent, self.Peers))),
|
||||||
|
# "Receive": sum(list(map(lambda x: x.cumu_receive + x.total_receive, self.Peers)))
|
||||||
|
# },
|
||||||
|
# "ConnectedPeers": len(list(map(lambda x: x.status == "running", self.Peers)))
|
||||||
}
|
}
|
||||||
|
|
||||||
class Peer:
|
class Peer:
|
||||||
|
@ -232,7 +232,8 @@ export default {
|
|||||||
{
|
{
|
||||||
label: 'Data Received',
|
label: 'Data Received',
|
||||||
data: [...this.historyReceiveData.datasets[0].data,
|
data: [...this.historyReceiveData.datasets[0].data,
|
||||||
((receive - this.historyDataReceivedDifference[this.historyDataReceivedDifference.length - 1])*1000).toFixed(4)],
|
((receive - this.historyDataReceivedDifference[this.historyDataReceivedDifference.length - 1])*1000)
|
||||||
|
.toFixed(4)],
|
||||||
fill: false,
|
fill: false,
|
||||||
borderColor: '#0d6efd',
|
borderColor: '#0d6efd',
|
||||||
tension: 0
|
tension: 0
|
||||||
@ -253,12 +254,20 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
configurationSummary(){
|
configurationSummary(){
|
||||||
return {
|
const k = {
|
||||||
connectedPeers: this.configurationPeers.filter(x => x.status === "running").length,
|
connectedPeers: this.configurationPeers.filter(x => x.status === "running").length,
|
||||||
totalUsage: this.configurationPeers.length > 0 ? this.configurationPeers.map(x => x.total_data + x.cumu_data).reduce((a, b) => a + b) : 0,
|
totalUsage: this.configurationPeers.length > 0 ?
|
||||||
totalReceive: this.configurationPeers.length > 0 ? this.configurationPeers.map(x => x.total_receive + x.cumu_receive).reduce((a, b) => a + b) : 0,
|
this.configurationPeers.filter(x => !x.restricted)
|
||||||
totalSent: this.configurationPeers.length > 0 ? this.configurationPeers.map(x => x.total_sent + x.cumu_sent).reduce((a, b) => a + b) : 0
|
.map(x => x.total_data + x.cumu_data).reduce((a, b) => a + b).toFixed(4) : 0,
|
||||||
|
totalReceive: this.configurationPeers.length > 0 ?
|
||||||
|
this.configurationPeers.filter(x => !x.restricted)
|
||||||
|
.map(x => x.total_receive + x.cumu_receive).reduce((a, b) => a + b).toFixed(4) : 0,
|
||||||
|
totalSent: this.configurationPeers.length > 0 ?
|
||||||
|
this.configurationPeers.filter(x => !x.restricted)
|
||||||
|
.map(x => x.total_sent + x.cumu_sent).reduce((a, b) => a + b).toFixed(4) : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return k
|
||||||
},
|
},
|
||||||
receiveData(){
|
receiveData(){
|
||||||
return this.historyReceiveData
|
return this.historyReceiveData
|
||||||
@ -468,7 +477,7 @@ export default {
|
|||||||
<div class="card-body d-flex">
|
<div class="card-body d-flex">
|
||||||
<div>
|
<div>
|
||||||
<p class="mb-0 text-muted"><small>Total Usage</small></p>
|
<p class="mb-0 text-muted"><small>Total Usage</small></p>
|
||||||
<strong class="h4">{{configurationSummary.totalUsage.toFixed(4)}} GB</strong>
|
<strong class="h4">{{configurationSummary.totalUsage}} GB</strong>
|
||||||
</div>
|
</div>
|
||||||
<i class="bi bi-arrow-down-up ms-auto h2 text-muted"></i>
|
<i class="bi bi-arrow-down-up ms-auto h2 text-muted"></i>
|
||||||
</div>
|
</div>
|
||||||
@ -479,7 +488,7 @@ export default {
|
|||||||
<div class="card-body d-flex">
|
<div class="card-body d-flex">
|
||||||
<div>
|
<div>
|
||||||
<p class="mb-0 text-muted"><small>Total Received</small></p>
|
<p class="mb-0 text-muted"><small>Total Received</small></p>
|
||||||
<strong class="h4 text-primary">{{configurationSummary.totalReceive.toFixed(4)}} GB</strong>
|
<strong class="h4 text-primary">{{configurationSummary.totalReceive}} GB</strong>
|
||||||
</div>
|
</div>
|
||||||
<i class="bi bi-arrow-down ms-auto h2 text-muted"></i>
|
<i class="bi bi-arrow-down ms-auto h2 text-muted"></i>
|
||||||
</div>
|
</div>
|
||||||
@ -490,7 +499,7 @@ export default {
|
|||||||
<div class="card-body d-flex">
|
<div class="card-body d-flex">
|
||||||
<div>
|
<div>
|
||||||
<p class="mb-0 text-muted"><small>Total Sent</small></p>
|
<p class="mb-0 text-muted"><small>Total Sent</small></p>
|
||||||
<strong class="h4 text-success">{{configurationSummary.totalSent.toFixed(4)}} GB</strong>
|
<strong class="h4 text-success">{{configurationSummary.totalSent}} GB</strong>
|
||||||
</div>
|
</div>
|
||||||
<i class="bi bi-arrow-up ms-auto h2 text-muted"></i>
|
<i class="bi bi-arrow-up ms-auto h2 text-muted"></i>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user