Outfleet::fix empty config

This commit is contained in:
2024-04-17 20:13:10 +03:00
parent f6bcb42ec4
commit 5cc32b18af
2 changed files with 13 additions and 4 deletions

11
lib.py
View File

@ -33,10 +33,19 @@ def get_config():
try: try:
with open(args.config, "r") as file: with open(args.config, "r") as file:
config = yaml.safe_load(file) config = yaml.safe_load(file)
if config == None:
config = {
"servers": {},
"clients": {}
}
except: except:
try: try:
with open(args.config, "w"): with open(args.config, "w"):
pass config = {
"servers": {},
"clients": {}
}
yaml.safe_dump(config, file)
except Exception as exp: except Exception as exp:
log.error(f"Couldn't create config. {exp}") log.error(f"Couldn't create config. {exp}")
return None return None

View File

@ -7,10 +7,10 @@
<h1 class="server-content-title">Servers</h1> <h1 class="server-content-title">Servers</h1>
</div> </div>
{% for server in 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"] %} {% for key in server.data["keys"] %}
{% if key.used_bytes %} {% 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 %} {% endif %}
{% endfor %} {% endfor %}
<div class="server-item server-item-{% if loop.index0 == selected_server|int %}unread{% else %}selected{% endif %} pure-g"> <div class="server-item server-item-{% if loop.index0 == selected_server|int %}unread{% else %}selected{% endif %} pure-g">
@ -19,7 +19,7 @@
<h4 class="server-info">{{ '/'.join(server.info()["url"].split('/')[0:-1]) }}</h4> <h4 class="server-info">{{ '/'.join(server.info()["url"].split('/')[0:-1]) }}</h4>
<h4 class="server-info">Port {{ server.info()["port_for_new_access_keys"] }}</h4> <h4 class="server-info">Port {{ server.info()["port_for_new_access_keys"] }}</h4>
<h4 class="server-info">Hostname {{ server.info()["hostname_for_access_keys"] }}</h4> <h4 class="server-info">Hostname {{ server.info()["hostname_for_access_keys"] }}</h4>
<h4 class="server-info">Traffic: {{ list_ns.total_bytes | filesizeformat }}</h4> <h4 class="server-info">Traffic: {{ total_traffic.total_bytes | filesizeformat }}</h4>
<h4 class="server-info">v.{{ server.info()["version"] }}</h4> <h4 class="server-info">v.{{ server.info()["version"] }}</h4>
<p class="server-comment"> <p class="server-comment">
{{ server.info()["comment"] }} {{ server.info()["comment"] }}