mirror of
https://github.com/donaldzou/WGDashboard.git
synced 2024-11-22 15:20:09 +01:00
Update dashboard.py
This commit is contained in:
parent
a136b86d81
commit
b5b30c8119
@ -124,22 +124,22 @@ def read_conf_file_interface(config_name):
|
||||
def read_conf_file(config_name):
|
||||
# Read Configuration File Start
|
||||
conf_location = wg_conf_path + "/" + config_name + ".conf"
|
||||
with open(conf_location, 'r', encoding='utf-8') as file_object:
|
||||
file = file_object.read().split("\n")
|
||||
f = open(conf_location, 'r')
|
||||
file = f.read().split("\n")
|
||||
conf_peer_data = {
|
||||
"Interface": {},
|
||||
"Peers": []
|
||||
}
|
||||
peers_start = 0
|
||||
for i in file:
|
||||
if not regex_match("#(.*)", i):
|
||||
if i == "[Peer]":
|
||||
for i in range(len(file)):
|
||||
if not regex_match("#(.*)", file[i]):
|
||||
if file[i] == "[Peer]":
|
||||
peers_start = i
|
||||
break
|
||||
|
||||
if len(i) > 0:
|
||||
if i != "[Interface]":
|
||||
tmp = re.split(r'\s*=\s*', i, 1)
|
||||
else:
|
||||
if len(file[i]) > 0:
|
||||
if file[i] != "[Interface]":
|
||||
tmp = re.split(r'\s*=\s*', file[i], 1)
|
||||
if len(tmp) == 2:
|
||||
conf_peer_data['Interface'][tmp[0]] = tmp[1]
|
||||
conf_peers = file[peers_start:]
|
||||
@ -151,10 +151,11 @@ def read_conf_file(config_name):
|
||||
conf_peer_data["Peers"].append({})
|
||||
elif peer > -1:
|
||||
if len(i) > 0:
|
||||
tmp = re.split(r'\s*=\s*', i, 1)
|
||||
tmp = re.split('\s*=\s*', i, 1)
|
||||
if len(tmp) == 2:
|
||||
conf_peer_data["Peers"][peer][tmp[0]] = tmp[1]
|
||||
|
||||
f.close()
|
||||
# Read Configuration File End
|
||||
return conf_peer_data
|
||||
|
||||
@ -199,6 +200,7 @@ def get_transfer(config_name, db, peers):
|
||||
count = 0
|
||||
for _ in range(int(len(data_usage) / 3)):
|
||||
cur_i = db.search(peers.id == data_usage[count])
|
||||
if len(cur_i) > 0:
|
||||
total_sent = cur_i[0]['total_sent']
|
||||
total_receive = cur_i[0]['total_receive']
|
||||
traffic = cur_i[0]['traffic']
|
||||
@ -353,12 +355,15 @@ def get_peers(config_name, search, sort_t):
|
||||
|
||||
# Get configuration public key
|
||||
def get_conf_pub_key(config_name):
|
||||
try:
|
||||
conf = configparser.ConfigParser(strict=False)
|
||||
conf.read(wg_conf_path + "/" + config_name + ".conf")
|
||||
pri = conf.get("Interface", "PrivateKey")
|
||||
pub = subprocess.run(f"echo '{pri}' | wg pubkey", check=True, shell=True, capture_output=True).stdout
|
||||
conf.clear()
|
||||
return pub.decode().strip("\n")
|
||||
except configparser.NoSectionError as e:
|
||||
return ""
|
||||
|
||||
|
||||
# Get configuration listen port
|
||||
@ -1322,8 +1327,7 @@ Dashboard Tools Related
|
||||
def get_ping_ip():
|
||||
config_name = request.form['config']
|
||||
sem.acquire(timeout=1)
|
||||
db = TinyDB(os.path.join(db_path, config + ".json"))
|
||||
|
||||
db = TinyDB(os.path.join(db_path, config_name + ".json"))
|
||||
html = ""
|
||||
for i in db.all():
|
||||
html += '<optgroup label="' + i['name'] + ' - ' + i['id'] + '">'
|
||||
|
Loading…
Reference in New Issue
Block a user