Merge branch 'SebastianObi:main' into main

This commit is contained in:
Swissbandit 2023-06-07 02:40:49 +02:00 committed by GitHub
commit 576e824860
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 2775 additions and 177 deletions

View file

@ -99,6 +99,7 @@ The full documentation is not yet available. Due to lack of time I can also not
Restart=always
RestartSec=3
User=root
Group=root
ExecStart=/root/lxmf_echo.py
[Install]
WantedBy=multi-user.target

View file

@ -283,13 +283,13 @@ class lxmf_connection:
if len(destination) != ((RNS.Reticulum.TRUNCATED_HASHLENGTH//8)*2):
log("LXMF - Destination length is invalid", LOG_ERROR)
return
return None
try:
destination = bytes.fromhex(destination)
except Exception as e:
log("LXMF - Destination is invalid", LOG_ERROR)
return
return None
if destination_name == None:
destination_name = self.destination_name
@ -298,7 +298,7 @@ class lxmf_connection:
destination_identity = RNS.Identity.recall(destination)
destination = RNS.Destination(destination_identity, RNS.Destination.OUT, RNS.Destination.SINGLE, destination_name, destination_type)
self.send_message(destination, self.destination, content, title, fields, timestamp, app_data)
return self.send_message(destination, self.destination, content, title, fields, timestamp, app_data)
def send_message(self, destination, source, content="", title="", fields=None, timestamp=None, app_data=""):
@ -329,10 +329,11 @@ class lxmf_connection:
try:
self.message_router.handle_outbound(message)
time.sleep(self.send_delay)
return message.hash
except Exception as e:
log("LXMF - Could not send message " + str(message), LOG_ERROR)
log("LXMF - The contained exception was: " + str(e), LOG_ERROR)
return
return None
def message_notification(self, message):
@ -627,8 +628,18 @@ class lxmf_announce_callback:
@staticmethod
def received_announce(destination_hash, announced_identity, app_data):
if app_data != None:
log("LXMF - Received an announce from " + RNS.prettyhexrep(destination_hash) + ": " + app_data.decode("utf-8"), LOG_INFO)
if app_data == None:
return
if len(app_data) == 0:
return
try:
app_data = app_data.decode("utf-8").strip()
except:
return
log("LXMF - Received an announce from " + RNS.prettyhexrep(destination_hash) + ": " + app_data, LOG_INFO)
@ -641,7 +652,35 @@ def lxmf_message_received_callback(message):
if CONFIG.has_option("allowed", "any") or CONFIG.has_option("allowed", "all") or CONFIG.has_option("allowed", "anybody") or CONFIG.has_option("allowed", RNS.hexrep(message.source_hash, False)) or CONFIG.has_option("allowed", RNS.prettyhexrep(message.source_hash)):
title = message.title.decode('utf-8').strip()
denys = config_get(CONFIG, "message", "deny_title")
if denys != "":
denys = denys.split(",")
if "*" in denys:
return
for deny in denys:
if deny in title:
return
content = message.content.decode('utf-8').strip()
denys = config_get(CONFIG, "message", "deny_content")
if denys != "":
denys = denys.split(",")
if "*" in denys:
return
for deny in denys:
if deny in title:
return
if message.fields:
denys = config_get(CONFIG, "message", "deny_fields")
if denys != "":
denys = denys.split(",")
if "*" in denys:
return
for deny in denys:
if deny in message.fields:
return
length = config_getint(CONFIG, "message", "receive_length_min", 0)
if length> 0:
@ -689,14 +728,19 @@ def lxmf_message_received_callback(message):
content = content_prefix + content + content_suffix
if CONFIG["message"].getboolean("title"):
title = message.title.decode('utf-8')
title = title.strip()
else:
if not CONFIG["message"].getboolean("title"):
title = ""
if CONFIG["message"].getboolean("fields"):
fields = message.fields
if fields:
search = config_get(CONFIG, "message", "fields_remove").split(",")
delete = []
for field in fields:
if field in search:
delete.append(field)
for field in delete:
del fields[field]
else:
fields = None
@ -897,6 +941,19 @@ def val_to_bool(val, fallback_true=True, fallback_false=False):
return fallback_false
def val_to_val(val):
if val.isdigit():
return int(val)
elif val.isnumeric():
return float(val)
elif val.lower() == "true":
return True
elif val.lower() == "false":
return False
else:
return val
##############################################################################################################
# Log
@ -1241,6 +1298,13 @@ signature_validated = Yes
#### Message settings ####
[message]
# Deny message if the title/content/fields contains the following content.
# Comma-separated list with text or field keys.
# *=any
deny_title =
deny_content =
deny_fields =
# Text is added.
receive_prefix =
receive_suffix =
@ -1278,6 +1342,9 @@ send_length_max = 0 #0=any length
title = Yes
fields = Yes
# Comma-separated list with fields which will be removed.
fields_remove =