mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2025-04-19 08:55:12 +00:00
Merge pull request #96 from pgalonza/change-path
Added the ability to change the path for files to be saved
This commit is contained in:
commit
f9e4fafe9f
@ -30,7 +30,11 @@ from icmplib import ping, multiping, traceroute, resolve, Host, Hop
|
|||||||
# Dashboard Version
|
# Dashboard Version
|
||||||
dashboard_version = 'v3.0'
|
dashboard_version = 'v3.0'
|
||||||
# Dashboard Config Name
|
# Dashboard Config Name
|
||||||
dashboard_conf = 'wg-dashboard.ini'
|
configuration_path = os.getenv('CONFIGURATION_PATH', '.')
|
||||||
|
db_path = os.path.join(configuration_path, 'db')
|
||||||
|
if not os.path.isdir(db_path):
|
||||||
|
os.mkdir(db_path)
|
||||||
|
dashboard_conf = os.path.join(configuration_path, 'wg-dashboard.ini')
|
||||||
# Upgrade Required
|
# Upgrade Required
|
||||||
update = ""
|
update = ""
|
||||||
# Flask App Configuration
|
# Flask App Configuration
|
||||||
@ -224,7 +228,7 @@ def get_allowed_ip(config_name, db, peers, conf_peer_data):
|
|||||||
# Look for new peers from WireGuard
|
# Look for new peers from WireGuard
|
||||||
def get_all_peers_data(config_name):
|
def get_all_peers_data(config_name):
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
db = TinyDB(os.path.join(db_path, config_name + '.json'))
|
||||||
peers = Query()
|
peers = Query()
|
||||||
conf_peer_data = read_conf_file(config_name)
|
conf_peer_data = read_conf_file(config_name)
|
||||||
config = get_dashboard_conf()
|
config = get_dashboard_conf()
|
||||||
@ -293,8 +297,7 @@ Frontend Related Functions
|
|||||||
def get_peers(config_name, search, sort_t):
|
def get_peers(config_name, search, sort_t):
|
||||||
get_all_peers_data(config_name)
|
get_all_peers_data(config_name)
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peer = Query()
|
peer = Query()
|
||||||
if len(search) == 0:
|
if len(search) == 0:
|
||||||
result = db.all()
|
result = db.all()
|
||||||
@ -337,8 +340,7 @@ def get_conf_listen_port(config_name):
|
|||||||
# Get configuration total data
|
# Get configuration total data
|
||||||
def get_conf_total_data(config_name):
|
def get_conf_total_data(config_name):
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
upload_total = 0
|
upload_total = 0
|
||||||
download_total = 0
|
download_total = 0
|
||||||
for i in db.all():
|
for i in db.all():
|
||||||
@ -416,8 +418,7 @@ def checkKeyMatch(private_key, public_key, config_name):
|
|||||||
return result
|
return result
|
||||||
else:
|
else:
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peers = Query()
|
peers = Query()
|
||||||
match = db.search(peers.id == result['data'])
|
match = db.search(peers.id == result['data'])
|
||||||
if len(match) != 1 or result['data'] != public_key:
|
if len(match) != 1 or result['data'] != public_key:
|
||||||
@ -431,10 +432,8 @@ def checkKeyMatch(private_key, public_key, config_name):
|
|||||||
|
|
||||||
# Check if there is repeated allowed IP
|
# Check if there is repeated allowed IP
|
||||||
def check_repeat_allowed_IP(public_key, ip, config_name):
|
def check_repeat_allowed_IP(public_key, ip, config_name):
|
||||||
|
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peers = Query()
|
peers = Query()
|
||||||
peer = db.search(peers.id == public_key)
|
peer = db.search(peers.id == public_key)
|
||||||
if len(peer) != 1:
|
if len(peer) != 1:
|
||||||
@ -813,8 +812,7 @@ def switch(config_name):
|
|||||||
@app.route('/add_peer/<config_name>', methods=['POST'])
|
@app.route('/add_peer/<config_name>', methods=['POST'])
|
||||||
def add_peer(config_name):
|
def add_peer(config_name):
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peers = Query()
|
peers = Query()
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
public_key = data['public_key']
|
public_key = data['public_key']
|
||||||
@ -883,8 +881,7 @@ def remove_peer(config_name):
|
|||||||
if get_conf_status(config_name) == "stopped":
|
if get_conf_status(config_name) == "stopped":
|
||||||
return "Your need to turn on " + config_name + " first."
|
return "Your need to turn on " + config_name + " first."
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peers = Query()
|
peers = Query()
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
delete_key = data['peer_id']
|
delete_key = data['peer_id']
|
||||||
@ -919,8 +916,7 @@ def save_peer_setting(config_name):
|
|||||||
allowed_ip = data['allowed_ip']
|
allowed_ip = data['allowed_ip']
|
||||||
endpoint_allowed_ip = data['endpoint_allowed_ip']
|
endpoint_allowed_ip = data['endpoint_allowed_ip']
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peers = Query()
|
peers = Query()
|
||||||
if len(db.search(peers.id == id)) == 1:
|
if len(db.search(peers.id == id)) == 1:
|
||||||
check_ip = check_repeat_allowed_IP(id, allowed_ip, config_name)
|
check_ip = check_repeat_allowed_IP(id, allowed_ip, config_name)
|
||||||
@ -992,8 +988,7 @@ def get_peer_name(config_name):
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
id = data['id']
|
id = data['id']
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
|
||||||
peers = Query()
|
peers = Query()
|
||||||
result = db.search(peers.id == id)
|
result = db.search(peers.id == id)
|
||||||
db.close()
|
db.close()
|
||||||
@ -1028,7 +1023,7 @@ def check_key_match(config_name):
|
|||||||
def generate_qrcode(config_name):
|
def generate_qrcode(config_name):
|
||||||
id = request.args.get('id')
|
id = request.args.get('id')
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
peers = Query()
|
peers = Query()
|
||||||
get_peer = db.search(peers.id == id)
|
get_peer = db.search(peers.id == id)
|
||||||
config = get_dashboard_conf()
|
config = get_dashboard_conf()
|
||||||
@ -1068,7 +1063,7 @@ def download(config_name):
|
|||||||
print(request.headers.get('User-Agent'))
|
print(request.headers.get('User-Agent'))
|
||||||
id = request.args.get('id')
|
id = request.args.get('id')
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
db = TinyDB('db/' + config_name + '.json')
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
peers = Query()
|
peers = Query()
|
||||||
get_peer = db.search(peers.id == id)
|
get_peer = db.search(peers.id == id)
|
||||||
config = get_dashboard_conf()
|
config = get_dashboard_conf()
|
||||||
@ -1131,7 +1126,8 @@ Dashboard Tools Related
|
|||||||
def get_ping_ip():
|
def get_ping_ip():
|
||||||
config = request.form['config']
|
config = request.form['config']
|
||||||
sem.acquire(timeout=1)
|
sem.acquire(timeout=1)
|
||||||
db = TinyDB('db/' + config + '.json')
|
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||||
|
|
||||||
html = ""
|
html = ""
|
||||||
for i in db.all():
|
for i in db.all():
|
||||||
html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">'
|
html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">'
|
||||||
@ -1191,8 +1187,8 @@ Dashboard Initialization
|
|||||||
"""
|
"""
|
||||||
def init_dashboard():
|
def init_dashboard():
|
||||||
# Set Default INI File
|
# Set Default INI File
|
||||||
if not os.path.isfile("wg-dashboard.ini"):
|
if not os.path.isfile(dashboard_conf):
|
||||||
conf_file = open("wg-dashboard.ini", "w+")
|
conf_file = open(dashboard_conf, "w+")
|
||||||
config = configparser.ConfigParser(strict=False)
|
config = configparser.ConfigParser(strict=False)
|
||||||
config.read(dashboard_conf)
|
config.read(dashboard_conf)
|
||||||
# Defualt dashboard account setting
|
# Defualt dashboard account setting
|
||||||
@ -1259,7 +1255,7 @@ if __name__ == "__main__":
|
|||||||
init_dashboard()
|
init_dashboard()
|
||||||
update = check_update()
|
update = check_update()
|
||||||
config = configparser.ConfigParser(strict=False)
|
config = configparser.ConfigParser(strict=False)
|
||||||
config.read('wg-dashboard.ini')
|
config.read(dashboard_conf)
|
||||||
app_ip = config.get("Server", "app_ip")
|
app_ip = config.get("Server", "app_ip")
|
||||||
app_port = config.get("Server", "app_port")
|
app_port = config.get("Server", "app_port")
|
||||||
wg_conf_path = config.get("Server", "wg_conf_path")
|
wg_conf_path = config.get("Server", "wg_conf_path")
|
||||||
@ -1269,7 +1265,7 @@ else:
|
|||||||
init_dashboard()
|
init_dashboard()
|
||||||
update = check_update()
|
update = check_update()
|
||||||
config = configparser.ConfigParser(strict=False)
|
config = configparser.ConfigParser(strict=False)
|
||||||
config.read('wg-dashboard.ini')
|
config.read(dashboard_conf)
|
||||||
app_ip = config.get("Server", "app_ip")
|
app_ip = config.get("Server", "app_ip")
|
||||||
app_port = config.get("Server", "app_port")
|
app_port = config.get("Server", "app_port")
|
||||||
wg_conf_path = config.get("Server", "wg_conf_path")
|
wg_conf_path = config.get("Server", "wg_conf_path")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user