mirror of
https://github.com/craigerl/aprsd.git
synced 2024-12-18 07:36:34 -05:00
Added enabled flag for every plugin object
This allows the admin interface to see which plugins are registered and enabled. Enabled is a flag that is set in the setup() method of the plugin. This gives the plugin developer a chance to disable the plugin if something isn't right at setup time. This allows aprsd to ignore plugins that are registered but not emabled.
This commit is contained in:
parent
7e6dffb34b
commit
3faf41b203
@ -55,6 +55,8 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
||||
|
||||
# Holds the list of APRSDThreads that the plugin creates
|
||||
threads = []
|
||||
# Set this in setup()
|
||||
enabled = False
|
||||
|
||||
def __init__(self, config):
|
||||
self.config = config
|
||||
@ -67,7 +69,7 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
||||
self.start_threads()
|
||||
|
||||
def start_threads(self):
|
||||
if self.threads:
|
||||
if self.enabled and self.threads:
|
||||
if not isinstance(self.threads, list):
|
||||
self.threads = [self.threads]
|
||||
|
||||
@ -99,8 +101,10 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
||||
"""Version"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def setup(self):
|
||||
"""Do any plugin setup here."""
|
||||
self.enabled = True
|
||||
|
||||
def create_threads(self):
|
||||
"""Gives the plugin writer the ability start a background thread."""
|
||||
@ -139,7 +143,6 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
||||
by a particular HAM callsign, write a plugin based off of
|
||||
this class.
|
||||
"""
|
||||
enabled = False
|
||||
|
||||
def setup(self):
|
||||
# if we have a watch list enabled, we need to add filtering
|
||||
@ -162,15 +165,18 @@ class APRSDWatchListPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
||||
LOG.warning("Watch list enabled, but no callsigns set.")
|
||||
|
||||
def filter(self, packet):
|
||||
wl = packets.WatchList()
|
||||
result = messaging.NULL_MESSAGE
|
||||
if wl.callsign_in_watchlist(packet["from"]):
|
||||
# packet is from a callsign in the watch list
|
||||
self.rx_inc()
|
||||
result = self.process()
|
||||
if result:
|
||||
self.tx_inc()
|
||||
wl.update_seen(packet)
|
||||
if self.enabled:
|
||||
wl = packets.WatchList()
|
||||
result = messaging.NULL_MESSAGE
|
||||
if wl.callsign_in_watchlist(packet["from"]):
|
||||
# packet is from a callsign in the watch list
|
||||
self.rx_inc()
|
||||
result = self.process()
|
||||
if result:
|
||||
self.tx_inc()
|
||||
wl.update_seen(packet)
|
||||
else:
|
||||
LOG.warning(f"{self.__class__} plugin is not enabled")
|
||||
|
||||
return result
|
||||
|
||||
@ -193,26 +199,33 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
||||
"""The regex to match from the caller"""
|
||||
raise NotImplementedError
|
||||
|
||||
def setup(self):
|
||||
"""Do any plugin setup here."""
|
||||
self.enabled = True
|
||||
|
||||
@hookimpl
|
||||
def filter(self, packet):
|
||||
result = None
|
||||
if self.enabled:
|
||||
result = None
|
||||
|
||||
message = packet.get("message_text", None)
|
||||
msg_format = packet.get("format", None)
|
||||
tocall = packet.get("addresse", None)
|
||||
message = packet.get("message_text", None)
|
||||
msg_format = packet.get("format", None)
|
||||
tocall = packet.get("addresse", None)
|
||||
|
||||
# Only process messages destined for us
|
||||
# and is an APRS message format and has a message.
|
||||
if (
|
||||
tocall == self.config["aprs"]["login"]
|
||||
and msg_format == "message"
|
||||
and message
|
||||
):
|
||||
if re.search(self.command_regex, message):
|
||||
self.rx_inc()
|
||||
result = self.process(packet)
|
||||
if result:
|
||||
self.tx_inc()
|
||||
# Only process messages destined for us
|
||||
# and is an APRS message format and has a message.
|
||||
if (
|
||||
tocall == self.config["aprs"]["login"]
|
||||
and msg_format == "message"
|
||||
and message
|
||||
):
|
||||
if re.search(self.command_regex, message):
|
||||
self.rx_inc()
|
||||
result = self.process(packet)
|
||||
if result:
|
||||
self.tx_inc()
|
||||
else:
|
||||
LOG.warning(f"{self.__class__} is not enabled.")
|
||||
|
||||
return result
|
||||
|
||||
|
@ -194,6 +194,7 @@ class APRSDStats:
|
||||
|
||||
for p in plugins:
|
||||
plugin_stats[full_name_with_qualname(p)] = {
|
||||
"enabled": p.enabled,
|
||||
"rx": p.rx_count,
|
||||
"tx": p.tx_count,
|
||||
}
|
||||
|
@ -60,7 +60,10 @@ function update_watchlist_from_packet(callsign, val) {
|
||||
|
||||
function update_plugins( data ) {
|
||||
var plugindiv = $("#pluginDiv");
|
||||
var html_str = '<table class="ui celled striped table"><thead><tr><th>Plugin Name</th><th>Processed Packets</th><th>Sent Packets</th></tr></thead><tbody>'
|
||||
var html_str = '<table class="ui celled striped table"><thead><tr>'
|
||||
html_str += '<th>Plugin Name</th><th>Plugin Enabled?</th>'
|
||||
html_str += '<th>Processed Packets</th><th>Sent Packets</th>'
|
||||
html_str += '</tr></thead><tbody>'
|
||||
plugindiv.html('')
|
||||
|
||||
var plugins = data["stats"]["plugins"];
|
||||
@ -69,7 +72,7 @@ function update_plugins( data ) {
|
||||
for (var i=0; i<keys.length; i++) { // now lets iterate in sort order
|
||||
var key = keys[i];
|
||||
var val = plugins[key];
|
||||
html_str += '<tr><td class="collapsing">' + key + '</td><td>' + val["rx"] + '</td><td>' + val["tx"] + '</td></tr>';
|
||||
html_str += '<tr><td class="collapsing">' + key + '</td><td>' + val["enabled"] + '</td><td>' + val["rx"] + '</td><td>' + val["tx"] + '</td></tr>';
|
||||
}
|
||||
html_str += "</tbody></table>";
|
||||
plugindiv.append(html_str);
|
||||
|
@ -30,6 +30,9 @@ def fake_packet(
|
||||
class FakeBaseNoThreadsPlugin(plugin.APRSDPluginBase):
|
||||
version = "1.0"
|
||||
|
||||
def setup(self):
|
||||
self.enabled = True
|
||||
|
||||
def filter(self, packet):
|
||||
return None
|
||||
|
||||
@ -48,6 +51,9 @@ class FakeThread(threads.APRSDThread):
|
||||
class FakeBaseThreadsPlugin(plugin.APRSDPluginBase):
|
||||
version = "1.0"
|
||||
|
||||
def setup(self):
|
||||
self.enabled = True
|
||||
|
||||
def filter(self, packet):
|
||||
return None
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user