From 3dd23fa2ad1d248c815df4b60915a79bd01a2203 Mon Sep 17 00:00:00 2001 From: Hemna Date: Tue, 12 Jan 2021 09:31:04 -0500 Subject: [PATCH] Added a fix for failed logins to APRS-IS This patch adds a check for a failed login to ARPS due to LoginError. This accounts for bad accounts or username/password failures. aprsd server will exit immediately upon failed login now. --- aprsd/client.py | 6 ++++++ aprsd/main.py | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/aprsd/client.py b/aprsd/client.py index 57d2683..81152ec 100644 --- a/aprsd/client.py +++ b/aprsd/client.py @@ -17,6 +17,8 @@ class Client: aprs_client = None config = None + connected = False + def __new__(cls, *args, **kwargs): """This magic turns this into a singleton.""" if cls._instance is None: @@ -55,6 +57,10 @@ class Client: aprs_client.connect() connected = True backoff = 1 + except LoginError as e: + LOG.error("Failed to login to APRS-IS Server '{}'".format(e)) + connected = False + raise e except Exception as e: LOG.error("Unable to connect to APRS-IS server. '{}' ".format(e)) time.sleep(backoff) diff --git a/aprsd/main.py b/aprsd/main.py index 51ab8b2..1b3fb89 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -34,6 +34,7 @@ import time import aprsd from aprsd import client, email, messaging, plugin, threads, utils import aprslib +from aprslib.exceptions import LoginError import click import click_completion import yaml @@ -387,7 +388,11 @@ def server(loglevel, quiet, disable_validation, config_file, flush): # Create the initial PM singleton and Register plugins plugin_manager = plugin.PluginManager(config) plugin_manager.setup_plugins() - client.Client(config) + try: + cl = client.Client(config) + cl.setup_connection() + except LoginError: + sys.exit(-1) # Now load the msgTrack from disk if any if flush: