mirror of
https://github.com/donaldzou/WGDashboard
synced 2025-02-26 05:58:47 +00:00
added the ability to change the path for files to be saved
This commit is contained in:
parent
99c42ff2c1
commit
e84616f5f5
@ -6,6 +6,8 @@ Under Apache-2.0 License
|
||||
|
||||
# Python Built-in Library
|
||||
import os
|
||||
import sys
|
||||
|
||||
from flask import Flask, request, render_template, redirect, url_for, session, abort, jsonify
|
||||
import subprocess
|
||||
from datetime import datetime, date, time, timedelta
|
||||
@ -24,7 +26,10 @@ from icmplib import ping, multiping, traceroute, resolve, Host, Hop
|
||||
# Dashboard Version
|
||||
dashboard_version = 'v2.3.1'
|
||||
# Dashboard Config Name
|
||||
dashboard_conf = 'wg-dashboard.ini'
|
||||
configuration_path = os.getenv('CONFIGURATION_PATH', '.')
|
||||
db_path = os.path.join(configuration_path, 'db')
|
||||
dashboard_conf = os.path.join(configuration_path, 'wg-dashboard.ini')
|
||||
sys.exit()
|
||||
# Upgrade Required
|
||||
update = ""
|
||||
# Flask App Configuration
|
||||
@ -261,7 +266,7 @@ def get_allowed_ip(config_name, db, peers, conf_peer_data):
|
||||
|
||||
# Look for new peers from WireGuard
|
||||
def get_all_peers_data(config_name):
|
||||
db = TinyDB('db/' + config_name + '.json')
|
||||
db = TinyDB(os.path.join(db_path, config_name + '.json'))
|
||||
peers = Query()
|
||||
conf_peer_data = read_conf_file(config_name)
|
||||
config = get_dashboard_conf()
|
||||
@ -325,7 +330,7 @@ Frontend Related Functions
|
||||
# Search for peers
|
||||
def get_peers(config_name, search, sort_t):
|
||||
get_all_peers_data(config_name)
|
||||
db = TinyDB('db/' + config_name + '.json')
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peer = Query()
|
||||
if len(search) == 0:
|
||||
result = db.all()
|
||||
@ -363,7 +368,7 @@ def get_conf_listen_port(config_name):
|
||||
|
||||
# Get configuration total data
|
||||
def get_conf_total_data(config_name):
|
||||
db = TinyDB('db/' + config_name + '.json')
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
upload_total = 0
|
||||
download_total = 0
|
||||
for i in db.all():
|
||||
@ -439,7 +444,7 @@ def checkKeyMatch(private_key, public_key, config_name):
|
||||
if result['status'] == 'failed':
|
||||
return result
|
||||
else:
|
||||
db = TinyDB('db/' + config_name + '.json')
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
match = db.search(peers.id == result['data'])
|
||||
if len(match) != 1 or result['data'] != public_key:
|
||||
@ -449,7 +454,7 @@ def checkKeyMatch(private_key, public_key, config_name):
|
||||
|
||||
# Check if there is repeated allowed IP
|
||||
def check_repeat_allowed_IP(public_key, ip, config_name):
|
||||
db = TinyDB('db/' + config_name + '.json')
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
peer = db.search(peers.id == public_key)
|
||||
if len(peer) != 1:
|
||||
@ -816,7 +821,7 @@ def switch(config_name):
|
||||
# Add peer
|
||||
@app.route('/add_peer/<config_name>', methods=['POST'])
|
||||
def add_peer(config_name):
|
||||
db = TinyDB("db/" + config_name + ".json")
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
data = request.get_json()
|
||||
public_key = data['public_key']
|
||||
@ -866,7 +871,7 @@ def add_peer(config_name):
|
||||
def remove_peer(config_name):
|
||||
if get_conf_status(config_name) == "stopped":
|
||||
return "Your need to turn on " + config_name + " first."
|
||||
db = TinyDB("db/" + config_name + ".json")
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
data = request.get_json()
|
||||
delete_key = data['peer_id']
|
||||
@ -897,7 +902,7 @@ def save_peer_setting(config_name):
|
||||
DNS = data['DNS']
|
||||
allowed_ip = data['allowed_ip']
|
||||
endpoint_allowed_ip = data['endpoint_allowed_ip']
|
||||
db = TinyDB("db/" + config_name + ".json")
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
if len(db.search(peers.id == id)) == 1:
|
||||
check_ip = check_repeat_allowed_IP(id, allowed_ip, config_name)
|
||||
@ -947,7 +952,7 @@ def save_peer_setting(config_name):
|
||||
def get_peer_name(config_name):
|
||||
data = request.get_json()
|
||||
id = data['id']
|
||||
db = TinyDB("db/" + config_name + ".json")
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
result = db.search(peers.id == id)
|
||||
db.close()
|
||||
@ -981,7 +986,7 @@ def check_key_match(config_name):
|
||||
def download(config_name):
|
||||
print(request.headers.get('User-Agent'))
|
||||
id = request.args.get('id')
|
||||
db = TinyDB("db/" + config_name + ".json")
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
peers = Query()
|
||||
get_peer = db.search(peers.id == id)
|
||||
config = get_dashboard_conf()
|
||||
@ -1039,7 +1044,7 @@ Dashboard Tools Related
|
||||
@app.route('/get_ping_ip', methods=['POST'])
|
||||
def get_ping_ip():
|
||||
config = request.form['config']
|
||||
db = TinyDB('db/' + config + '.json')
|
||||
db = TinyDB(os.path.join(db_path, config + ".json"))
|
||||
html = ""
|
||||
for i in db.all():
|
||||
html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">'
|
||||
@ -1099,8 +1104,8 @@ Dashboard Initialization
|
||||
"""
|
||||
def init_dashboard():
|
||||
# Set Default INI File
|
||||
if not os.path.isfile("wg-dashboard.ini"):
|
||||
conf_file = open("wg-dashboard.ini", "w+")
|
||||
if not os.path.isfile(dashboard_conf):
|
||||
conf_file = open(dashboard_conf, "w+")
|
||||
config = configparser.ConfigParser(strict=False)
|
||||
config.read(dashboard_conf)
|
||||
# Defualt dashboard account setting
|
||||
@ -1166,7 +1171,7 @@ if __name__ == "__main__":
|
||||
init_dashboard()
|
||||
update = check_update()
|
||||
config = configparser.ConfigParser(strict=False)
|
||||
config.read('wg-dashboard.ini')
|
||||
config.read(dashboard_conf)
|
||||
app_ip = config.get("Server", "app_ip")
|
||||
app_port = config.get("Server", "app_port")
|
||||
wg_conf_path = config.get("Server", "wg_conf_path")
|
||||
|
Loading…
Reference in New Issue
Block a user