mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-22 15:20:09 +01:00
On/Off Switch
This commit is contained in:
parent
893784e7b9
commit
032ea1d967
34
dashboard.py
34
dashboard.py
@ -1,6 +1,5 @@
|
||||
import os
|
||||
from flask import Flask, request, render_template
|
||||
from tinydb import TinyDB, Query
|
||||
from flask import Flask, request, render_template, redirect, url_for
|
||||
import subprocess
|
||||
from datetime import datetime, date, time, timedelta
|
||||
|
||||
@ -114,7 +113,10 @@ def get_conf_list():
|
||||
for i in os.listdir(conf_location):
|
||||
if ".conf" in i:
|
||||
i = i.replace('.conf','')
|
||||
temp = {"conf":i, "status":get_conf_status(i), "public_key": get_conf_pub_key(i)}
|
||||
temp = {"conf":i, "status":get_conf_status(i), "public_key": get_conf_pub_key(i)}
|
||||
if temp['status'] == "running":
|
||||
temp['checked'] = 'checked'
|
||||
else: temp['checked'] = ""
|
||||
conf.append(temp)
|
||||
return conf
|
||||
|
||||
@ -125,15 +127,33 @@ def index():
|
||||
|
||||
@app.route('/configuration/<config_name>', methods=['GET'])
|
||||
def conf(config_name):
|
||||
|
||||
conf_data = {
|
||||
"name": config_name,
|
||||
"status": get_conf_status(config_name),
|
||||
"total_data_usage": get_conf_total_data(config_name),
|
||||
"public_key": get_conf_pub_key(config_name),
|
||||
"listen_port": get_conf_listen_port(config_name),
|
||||
"peer_data":get_conf_peers_data(config_name)
|
||||
"peer_data":get_conf_peers_data(config_name),
|
||||
"checked": ""
|
||||
}
|
||||
return render_template('configuration.html', conf=get_conf_list(), conf_data=conf_data)
|
||||
|
||||
if conf_data['status'] == "stopped":
|
||||
return redirect('/')
|
||||
else:
|
||||
conf_data['checked'] = "checked"
|
||||
return render_template('configuration.html', conf=get_conf_list(), conf_data=conf_data)
|
||||
|
||||
|
||||
@app.route('/switch/<config_name>', methods=['GET'])
|
||||
def switch(config_name):
|
||||
status = get_conf_status(config_name)
|
||||
if status == "running":
|
||||
try: status = subprocess.check_output("wg-quick down "+config_name, shell=True)
|
||||
except Exception: return redirect('/')
|
||||
elif status == "stopped":
|
||||
try: status = subprocess.check_output("wg-quick up "+config_name, shell=True)
|
||||
except Exception: return redirect('/')
|
||||
return redirect('/')
|
||||
|
||||
|
||||
|
||||
app.run(host='0.0.0.0',debug=False, port=10086)
|
||||
|
@ -6,6 +6,8 @@
|
||||
<title>Wireguard Dashboard</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='dashboard.css') }}">
|
||||
<link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet">
|
||||
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -38,9 +40,17 @@
|
||||
</div>
|
||||
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-md-4 mt-4">
|
||||
<div class="info mt-4">
|
||||
<small class="text-muted"><strong>CONFIGURATION</strong></small>
|
||||
<h1 class="mb-3">{{conf_data['name']}}</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<small class="text-muted"><strong>CONFIGURATION</strong></small>
|
||||
<h1 class="mb-3">{{conf_data['name']}}</h1>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<small class="text-muted"><strong>ACTION</strong></small><br>
|
||||
<input class="mt-2"id="chkToggle1" type="checkbox" data-toggle="toggle" data-onstyle="outline-success" {{conf_data['checked']}}>
|
||||
</div>
|
||||
<div class="w-100"></div>
|
||||
<div class="col-sm">
|
||||
<small class="text-muted"><strong>STATUS</strong></small>
|
||||
<h6 style="text-transform: uppercase;">{{conf_data['status']}}<span class="dot dot-{{conf_data['status']}}"></span></h6>
|
||||
@ -69,6 +79,7 @@
|
||||
</div>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
{% for i in conf_data['peer_data']%}
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
@ -112,7 +123,6 @@
|
||||
</div>
|
||||
</div>
|
||||
{%endfor%}
|
||||
|
||||
</main>
|
||||
</div>
|
||||
</body>
|
||||
@ -124,10 +134,10 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"
|
||||
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
|
||||
<script>
|
||||
setInterval(function(){
|
||||
location.reload();
|
||||
},10000)
|
||||
// setInterval(function(){
|
||||
// location.reload();
|
||||
// },10000)
|
||||
</script>
|
||||
</html>
|
@ -6,6 +6,7 @@
|
||||
<title>Wireguard Dashboard</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
|
||||
<link rel= "stylesheet" type= "text/css" href= "{{ url_for('static',filename='dashboard.css') }}">
|
||||
<link href="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/css/bootstrap4-toggle.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@ -40,10 +41,16 @@
|
||||
{% for i in conf%}
|
||||
<div class="card mt-3">
|
||||
<div class="card-body">
|
||||
<a href="/configuration/{{i['conf']}}">
|
||||
<h5 class="card-title">{{i['conf']}}</h5>
|
||||
</a>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm">
|
||||
<a href="/configuration/{{i['conf']}}">
|
||||
<h5 class="card-title">{{i['conf']}}</h5>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="w-100"></div>
|
||||
<div class="col-sm">
|
||||
<small class="text-muted"><strong>STATUS</strong></small>
|
||||
<h6 style="text-transform: uppercase;">{{i['status']}}<span class="dot dot-{{i['status']}}"></span></h6>
|
||||
@ -52,6 +59,9 @@
|
||||
<small class="text-muted"><strong>PUBLIC KEY</strong></small>
|
||||
<h6 style="text-transform: uppercase;"><samp>{{i['public_key']}}</samp></h6>
|
||||
</div>
|
||||
<div class="col-sm">
|
||||
<input class="mt-2 switch" id="{{i['conf']}}" type="checkbox" data-toggle="toggle" {{i['checked']}} data-height="15">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -67,12 +77,10 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.3/dist/js/bootstrap.min.js"
|
||||
integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s"
|
||||
crossorigin="anonymous"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
|
||||
<script>
|
||||
// $.get("/get_conf", function(data, status){
|
||||
// for (var i = 0; i < data['data'].length; i++){
|
||||
// $(".nav").append('<li class="nav-item"><a class="nav-link" href="/conf/'+data['data'][i]['conf']+'">'+data['data'][i]['conf']+'</a></li>');
|
||||
// $("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>')
|
||||
// }
|
||||
// });
|
||||
$('.switch').change(function() {
|
||||
location.replace("/switch/"+$(this).attr('id'))
|
||||
})
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user