mirror of
https://github.com/craigerl/aprsd.git
synced 2025-09-04 06:07:48 -04: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
|
# Holds the list of APRSDThreads that the plugin creates
|
||||||
threads = []
|
threads = []
|
||||||
|
# Set this in setup()
|
||||||
|
enabled = False
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
self.config = config
|
self.config = config
|
||||||
@ -67,7 +69,7 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
|||||||
self.start_threads()
|
self.start_threads()
|
||||||
|
|
||||||
def start_threads(self):
|
def start_threads(self):
|
||||||
if self.threads:
|
if self.enabled and self.threads:
|
||||||
if not isinstance(self.threads, list):
|
if not isinstance(self.threads, list):
|
||||||
self.threads = [self.threads]
|
self.threads = [self.threads]
|
||||||
|
|
||||||
@ -99,8 +101,10 @@ class APRSDPluginBase(metaclass=abc.ABCMeta):
|
|||||||
"""Version"""
|
"""Version"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abc.abstractmethod
|
||||||
def setup(self):
|
def setup(self):
|
||||||
"""Do any plugin setup here."""
|
"""Do any plugin setup here."""
|
||||||
|
self.enabled = True
|
||||||
|
|
||||||
def create_threads(self):
|
def create_threads(self):
|
||||||
"""Gives the plugin writer the ability start a background thread."""
|
"""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
|
by a particular HAM callsign, write a plugin based off of
|
||||||
this class.
|
this class.
|
||||||
"""
|
"""
|
||||||
enabled = False
|
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
# if we have a watch list enabled, we need to add filtering
|
# 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.")
|
LOG.warning("Watch list enabled, but no callsigns set.")
|
||||||
|
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
wl = packets.WatchList()
|
if self.enabled:
|
||||||
result = messaging.NULL_MESSAGE
|
wl = packets.WatchList()
|
||||||
if wl.callsign_in_watchlist(packet["from"]):
|
result = messaging.NULL_MESSAGE
|
||||||
# packet is from a callsign in the watch list
|
if wl.callsign_in_watchlist(packet["from"]):
|
||||||
self.rx_inc()
|
# packet is from a callsign in the watch list
|
||||||
result = self.process()
|
self.rx_inc()
|
||||||
if result:
|
result = self.process()
|
||||||
self.tx_inc()
|
if result:
|
||||||
wl.update_seen(packet)
|
self.tx_inc()
|
||||||
|
wl.update_seen(packet)
|
||||||
|
else:
|
||||||
|
LOG.warning(f"{self.__class__} plugin is not enabled")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -193,26 +199,33 @@ class APRSDRegexCommandPluginBase(APRSDPluginBase, metaclass=abc.ABCMeta):
|
|||||||
"""The regex to match from the caller"""
|
"""The regex to match from the caller"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
"""Do any plugin setup here."""
|
||||||
|
self.enabled = True
|
||||||
|
|
||||||
@hookimpl
|
@hookimpl
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
result = None
|
if self.enabled:
|
||||||
|
result = None
|
||||||
|
|
||||||
message = packet.get("message_text", None)
|
message = packet.get("message_text", None)
|
||||||
msg_format = packet.get("format", None)
|
msg_format = packet.get("format", None)
|
||||||
tocall = packet.get("addresse", None)
|
tocall = packet.get("addresse", None)
|
||||||
|
|
||||||
# Only process messages destined for us
|
# Only process messages destined for us
|
||||||
# and is an APRS message format and has a message.
|
# and is an APRS message format and has a message.
|
||||||
if (
|
if (
|
||||||
tocall == self.config["aprs"]["login"]
|
tocall == self.config["aprs"]["login"]
|
||||||
and msg_format == "message"
|
and msg_format == "message"
|
||||||
and message
|
and message
|
||||||
):
|
):
|
||||||
if re.search(self.command_regex, message):
|
if re.search(self.command_regex, message):
|
||||||
self.rx_inc()
|
self.rx_inc()
|
||||||
result = self.process(packet)
|
result = self.process(packet)
|
||||||
if result:
|
if result:
|
||||||
self.tx_inc()
|
self.tx_inc()
|
||||||
|
else:
|
||||||
|
LOG.warning(f"{self.__class__} is not enabled.")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -194,6 +194,7 @@ class APRSDStats:
|
|||||||
|
|
||||||
for p in plugins:
|
for p in plugins:
|
||||||
plugin_stats[full_name_with_qualname(p)] = {
|
plugin_stats[full_name_with_qualname(p)] = {
|
||||||
|
"enabled": p.enabled,
|
||||||
"rx": p.rx_count,
|
"rx": p.rx_count,
|
||||||
"tx": p.tx_count,
|
"tx": p.tx_count,
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,10 @@ function update_watchlist_from_packet(callsign, val) {
|
|||||||
|
|
||||||
function update_plugins( data ) {
|
function update_plugins( data ) {
|
||||||
var plugindiv = $("#pluginDiv");
|
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('')
|
plugindiv.html('')
|
||||||
|
|
||||||
var plugins = data["stats"]["plugins"];
|
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
|
for (var i=0; i<keys.length; i++) { // now lets iterate in sort order
|
||||||
var key = keys[i];
|
var key = keys[i];
|
||||||
var val = plugins[key];
|
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>";
|
html_str += "</tbody></table>";
|
||||||
plugindiv.append(html_str);
|
plugindiv.append(html_str);
|
||||||
|
@ -30,6 +30,9 @@ def fake_packet(
|
|||||||
class FakeBaseNoThreadsPlugin(plugin.APRSDPluginBase):
|
class FakeBaseNoThreadsPlugin(plugin.APRSDPluginBase):
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.enabled = True
|
||||||
|
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@ -48,6 +51,9 @@ class FakeThread(threads.APRSDThread):
|
|||||||
class FakeBaseThreadsPlugin(plugin.APRSDPluginBase):
|
class FakeBaseThreadsPlugin(plugin.APRSDPluginBase):
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.enabled = True
|
||||||
|
|
||||||
def filter(self, packet):
|
def filter(self, packet):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user