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
28
dashboard.py
28
dashboard.py
@ -1,6 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask, request, render_template
|
from flask import Flask, request, render_template, redirect, url_for
|
||||||
from tinydb import TinyDB, Query
|
|
||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime, date, time, timedelta
|
from datetime import datetime, date, time, timedelta
|
||||||
|
|
||||||
@ -115,6 +114,9 @@ def get_conf_list():
|
|||||||
if ".conf" in i:
|
if ".conf" in i:
|
||||||
i = i.replace('.conf','')
|
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)
|
conf.append(temp)
|
||||||
return conf
|
return conf
|
||||||
|
|
||||||
@ -125,15 +127,33 @@ def index():
|
|||||||
|
|
||||||
@app.route('/configuration/<config_name>', methods=['GET'])
|
@app.route('/configuration/<config_name>', methods=['GET'])
|
||||||
def conf(config_name):
|
def conf(config_name):
|
||||||
|
|
||||||
conf_data = {
|
conf_data = {
|
||||||
"name": config_name,
|
"name": config_name,
|
||||||
"status": get_conf_status(config_name),
|
"status": get_conf_status(config_name),
|
||||||
"total_data_usage": get_conf_total_data(config_name),
|
"total_data_usage": get_conf_total_data(config_name),
|
||||||
"public_key": get_conf_pub_key(config_name),
|
"public_key": get_conf_pub_key(config_name),
|
||||||
"listen_port": get_conf_listen_port(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": ""
|
||||||
}
|
}
|
||||||
|
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)
|
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)
|
app.run(host='0.0.0.0',debug=False, port=10086)
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
<title>Wireguard Dashboard</title>
|
<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" 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 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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -38,9 +40,17 @@
|
|||||||
</div>
|
</div>
|
||||||
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-md-4 mt-4">
|
<main role="main" class="col-md-9 ml-sm-auto col-lg-10 px-md-4 mt-4">
|
||||||
<div class="info mt-4">
|
<div class="info mt-4">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm">
|
||||||
<small class="text-muted"><strong>CONFIGURATION</strong></small>
|
<small class="text-muted"><strong>CONFIGURATION</strong></small>
|
||||||
<h1 class="mb-3">{{conf_data['name']}}</h1>
|
<h1 class="mb-3">{{conf_data['name']}}</h1>
|
||||||
<div class="row">
|
</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">
|
<div class="col-sm">
|
||||||
<small class="text-muted"><strong>STATUS</strong></small>
|
<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>
|
<h6 style="text-transform: uppercase;">{{conf_data['status']}}<span class="dot dot-{{conf_data['status']}}"></span></h6>
|
||||||
@ -69,6 +79,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% for i in conf_data['peer_data']%}
|
{% for i in conf_data['peer_data']%}
|
||||||
<div class="card mb-3">
|
<div class="card mb-3">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@ -112,7 +123,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{%endfor%}
|
{%endfor%}
|
||||||
|
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
@ -124,10 +134,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 src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
setInterval(function(){
|
// setInterval(function(){
|
||||||
location.reload();
|
// location.reload();
|
||||||
},10000)
|
// },10000)
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
@ -6,6 +6,7 @@
|
|||||||
<title>Wireguard Dashboard</title>
|
<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" 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 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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -40,10 +41,16 @@
|
|||||||
{% for i in conf%}
|
{% for i in conf%}
|
||||||
<div class="card mt-3">
|
<div class="card mt-3">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm">
|
||||||
<a href="/configuration/{{i['conf']}}">
|
<a href="/configuration/{{i['conf']}}">
|
||||||
<h5 class="card-title">{{i['conf']}}</h5>
|
<h5 class="card-title">{{i['conf']}}</h5>
|
||||||
</a>
|
</a>
|
||||||
<div class="row">
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="w-100"></div>
|
||||||
<div class="col-sm">
|
<div class="col-sm">
|
||||||
<small class="text-muted"><strong>STATUS</strong></small>
|
<small class="text-muted"><strong>STATUS</strong></small>
|
||||||
<h6 style="text-transform: uppercase;">{{i['status']}}<span class="dot dot-{{i['status']}}"></span></h6>
|
<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>
|
<small class="text-muted"><strong>PUBLIC KEY</strong></small>
|
||||||
<h6 style="text-transform: uppercase;"><samp>{{i['public_key']}}</samp></h6>
|
<h6 style="text-transform: uppercase;"><samp>{{i['public_key']}}</samp></h6>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -67,12 +77,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 src="https://cdn.jsdelivr.net/gh/gitbrent/bootstrap4-toggle@3.6.1/js/bootstrap4-toggle.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
// $.get("/get_conf", function(data, status){
|
$('.switch').change(function() {
|
||||||
// for (var i = 0; i < data['data'].length; i++){
|
location.replace("/switch/"+$(this).attr('id'))
|
||||||
// $(".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>')
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue
Block a user