mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-22 07:10:09 +01:00
Auto Refresh
This commit is contained in:
parent
785d7a932e
commit
9146e60c3c
13
dashboard.py
13
dashboard.py
@ -2,7 +2,7 @@ import os
|
|||||||
from flask import Flask, request, render_template
|
from flask import Flask, request, render_template
|
||||||
from tinydb import TinyDB, Query
|
from tinydb import TinyDB, Query
|
||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime
|
from datetime import datetime, date, time, timedelta
|
||||||
|
|
||||||
conf_location = "/etc/wireguard"
|
conf_location = "/etc/wireguard"
|
||||||
|
|
||||||
@ -48,9 +48,14 @@ def get_conf_peers_data(config_name):
|
|||||||
data_usage = data_usage.decode("UTF-8").split()
|
data_usage = data_usage.decode("UTF-8").split()
|
||||||
count = 0
|
count = 0
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
|
b = timedelta(minutes=2)
|
||||||
for i in range(int(len(data_usage)/2)):
|
for i in range(int(len(data_usage)/2)):
|
||||||
minus = now - datetime.fromtimestamp(int(data_usage[count+1]))
|
minus = now - datetime.fromtimestamp(int(data_usage[count+1]))
|
||||||
|
|
||||||
|
if minus < b:
|
||||||
|
peer_data[data_usage[count]]['status'] = "running"
|
||||||
|
else:
|
||||||
|
peer_data[data_usage[count]]['status'] = "stopped"
|
||||||
peer_data[data_usage[count]]['latest_handshake'] = minus
|
peer_data[data_usage[count]]['latest_handshake'] = minus
|
||||||
count += 2
|
count += 2
|
||||||
|
|
||||||
@ -79,7 +84,6 @@ def get_conf_listen_port(config_name):
|
|||||||
return pub_key.decode("UTF-8")
|
return pub_key.decode("UTF-8")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_conf_total_data(config_name):
|
def get_conf_total_data(config_name):
|
||||||
try: data_usage = subprocess.check_output("wg show "+config_name+" transfer", shell=True)
|
try: data_usage = subprocess.check_output("wg show "+config_name+" transfer", shell=True)
|
||||||
except Exception: return "stopped"
|
except Exception: return "stopped"
|
||||||
@ -132,6 +136,5 @@ def conf(config_name):
|
|||||||
"peer_data":get_conf_peers_data(config_name)
|
"peer_data":get_conf_peers_data(config_name)
|
||||||
}
|
}
|
||||||
return render_template('configuration.html', conf=get_conf_list(), conf_data=conf_data)
|
return render_template('configuration.html', conf=get_conf_list(), conf_data=conf_data)
|
||||||
|
|
||||||
|
|
||||||
app.run(host='0.0.0.0',debug=False, port=10086)
|
app.run(host='0.0.0.0',debug=False, port=10086)
|
||||||
|
@ -70,9 +70,19 @@
|
|||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
{% for i in conf_data['peer_data']%}
|
{% for i in conf_data['peer_data']%}
|
||||||
<div class="card mt-3">
|
<div class="card mb-3">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
<div class="col-sm">
|
||||||
|
<small class="text-muted"><strong>STATUS</strong></small>
|
||||||
|
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['status']}}<span class="dot dot-{{conf_data['peer_data'][i]['status']}}"></span></h6>
|
||||||
|
</div>
|
||||||
|
<div class="col-sm">
|
||||||
|
<small class="text-muted"><strong>PEER</strong></small>
|
||||||
|
<h6 style="text-transform: uppercase;"><samp>{{i}}</samp></h6>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-100"></div>
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<small class="text-muted"><strong>ALLOWED IP</strong></small>
|
<small class="text-muted"><strong>ALLOWED IP</strong></small>
|
||||||
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['allowed_ip']}}</h6>
|
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['allowed_ip']}}</h6>
|
||||||
@ -81,11 +91,6 @@
|
|||||||
<small class="text-muted"><strong>LATEST HANDSHAKE</strong></small>
|
<small class="text-muted"><strong>LATEST HANDSHAKE</strong></small>
|
||||||
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['latest_handshake']}}</h6>
|
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['latest_handshake']}}</h6>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-100"></div>
|
|
||||||
<div class="col-sm">
|
|
||||||
<small class="text-muted"><strong>PEER</strong></small>
|
|
||||||
<h6 style="text-transform: uppercase;"><samp>{{i}}</samp></h6>
|
|
||||||
</div>
|
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<small class="text-muted"><strong>END POINT</strong></small>
|
<small class="text-muted"><strong>END POINT</strong></small>
|
||||||
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['endpoint']}}</h6>
|
<h6 style="text-transform: uppercase;">{{conf_data['peer_data'][i]['endpoint']}}</h6>
|
||||||
@ -119,12 +124,10 @@
|
|||||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"
|
||||||
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
|
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// $.get("/get_conf", function(data, status){
|
setInterval(function(){
|
||||||
// for (var i = 0; i < data['data'].length; i++){
|
location.reload();
|
||||||
// $(".nav").append('<li class="nav-item"><a class="nav-link" href="/conf/'+data['data'][i]['conf']+'">'+data['data'][i]['conf']+'</a></li>');
|
},10000)
|
||||||
// $("main").append('<div class="card mt-3"><div class="card-body"><a href="/conf/'+data['data'][i]['conf']+'"><h5 class="card-title">'+data['data'][i]['conf']+'</h5></a><h6 class="card-subtitle mb-2 text-muted">Status: '+data['data'][i]['status']+'<span class="dot dot-'+data['data'][i]['status']+'"></span></h6></div></div>')
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user