From 5cc32b18afd6973a454a2d5c430d1517778a021d Mon Sep 17 00:00:00 2001 From: Max Milavkin Date: Wed, 17 Apr 2024 20:13:10 +0300 Subject: [PATCH] Outfleet::fix empty config --- lib.py | 11 ++++++++++- templates/index.html | 6 +++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib.py b/lib.py index c8194e8..71b2ecd 100755 --- a/lib.py +++ b/lib.py @@ -33,10 +33,19 @@ def get_config(): try: with open(args.config, "r") as file: config = yaml.safe_load(file) + if config == None: + config = { + "servers": {}, + "clients": {} + } except: try: with open(args.config, "w"): - pass + config = { + "servers": {}, + "clients": {} + } + yaml.safe_dump(config, file) except Exception as exp: log.error(f"Couldn't create config. {exp}") return None diff --git a/templates/index.html b/templates/index.html index 3628a0e..0124b20 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,10 +7,10 @@

Servers

{% for server in SERVERS %} - {% set list_ns = namespace(total_bytes=0) %} + {% set total_traffic = namespace(total_bytes=0) %} {% for key in server.data["keys"] %} {% if key.used_bytes %} - {% set list_ns.total_bytes = list_ns.total_bytes + key.used_bytes %} + {% set total_traffic.total_bytes = total_traffic.total_bytes + key.used_bytes %} {% endif %} {% endfor %}
@@ -19,7 +19,7 @@

{{ '/'.join(server.info()["url"].split('/')[0:-1]) }}

Port {{ server.info()["port_for_new_access_keys"] }}

Hostname {{ server.info()["hostname_for_access_keys"] }}

-

Traffic: {{ list_ns.total_bytes | filesizeformat }}

+

Traffic: {{ total_traffic.total_bytes | filesizeformat }}

v.{{ server.info()["version"] }}

{{ server.info()["comment"] }}