diff --git a/docker-compose.yml b/docker-compose.yml index cae4893..ca6fe37 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,8 @@ version: "3.5" services: - web: + wgdashboard: + image: donaldzou/wgdashboard build: context: ./ dockerfile: ./Dockerfile diff --git a/src/api.py b/src/api.py index 0acc8d1..46e2362 100644 --- a/src/api.py +++ b/src/api.py @@ -1,5 +1,5 @@ import ipaddress, subprocess, datetime, os, util - +from datetime import datetime, timedelta from flask import jsonify from util import * @@ -45,19 +45,22 @@ def togglePeerAccess(data, g): class managePeer: def getPeerDataUsage(self, data, cur): + now = datetime.now() + now_string = now.strftime("%d/%m/%Y %H:%M:%S") interval = { - "30min": (60 * 30) / 30, - "1h": (60 * 60) / 30, - "6h": (60 * 60 * 6) / 30, - "24h": (60 * 60 * 24) / 30, + "30min": now - timedelta(hours=0, minutes=30), + "1h": now - timedelta(hours=1, minutes=0), + "6h": now - timedelta(hours=6, minutes=0), + "24h": now - timedelta(hours=24, minutes=0), "all": "" } if data['interval'] not in interval.keys(): return {"status": False, "reason": "Invalid interval."} intv = "" if data['interval'] != "all": - intv = f" LIMIT {int(interval[data['interval']])}" - timeData = cur.execute(f"SELECT total_receive, total_sent, time FROM wg0_transfer WHERE id='{data['peerID']}' ORDER BY time DESC{intv};") + t = interval[data['interval']].strftime("%d/%m/%Y %H:%M:%S") + intv = f" AND time >= '{t}'" + timeData = cur.execute(f"SELECT total_receive, total_sent, time FROM wg0_transfer WHERE id='{data['peerID']}' {intv} ORDER BY time DESC;") chartData = [] for i in timeData: chartData.append({ diff --git a/src/static/js/configuration.js b/src/static/js/configuration.js index 7854fe9..a377068 100644 --- a/src/static/js/configuration.js +++ b/src/static/js/configuration.js @@ -446,7 +446,7 @@ let peers = []; `; let peer_control = `