LXMF class improved, title and fields transport of distribution group and echo, added lxmf_provisioning server/script

This commit is contained in:
SebastianObi 2022-12-07 17:05:23 +01:00
parent 537a59cdd3
commit 81084f17f8
11 changed files with 1378 additions and 65 deletions

View file

@ -106,7 +106,7 @@ class lxmf_connection:
message_notification_failed_callback = None
def __init__(self, storage_path=None, identity_file="identity", identity=None, destination_name="lxmf", destination_type="delivery", display_name="", send_delay=0, desired_method="direct", propagation_node=None, try_propagation_on_fail=False, announce_startup=False, announce_startup_delay=0, announce_periodic=False, announce_periodic_interval=360, sync_startup=False, sync_startup_delay=0, sync_limit=8, sync_periodic=False, sync_periodic_interval=360):
def __init__(self, storage_path=None, identity_file="identity", identity=None, destination_name="lxmf", destination_type="delivery", display_name="", announce_data=None, send_delay=0, desired_method="direct", propagation_node=None, try_propagation_on_fail=False, announce_startup=False, announce_startup_delay=0, announce_periodic=False, announce_periodic_interval=360, sync_startup=False, sync_startup_delay=0, sync_limit=8, sync_periodic=False, sync_periodic_interval=360):
self.storage_path = storage_path
self.identity_file = identity_file
@ -118,6 +118,7 @@ class lxmf_connection:
self.aspect_filter = self.destination_name + "." + self.destination_type
self.display_name = display_name
self.announce_data = announce_data
self.send_delay = int(send_delay)
@ -173,9 +174,11 @@ class lxmf_connection:
self.message_router = LXMF.LXMRouter(identity=self.identity, storagepath=self.storage_path)
self.destination = self.message_router.register_delivery_identity(self.identity, display_name=self.display_name)
self.message_router.register_delivery_callback(self.process_lxmf_message_propagated)
if self.destination_name == "lxmf" and self.destination_type == "delivery":
self.destination = self.message_router.register_delivery_identity(self.identity, display_name=self.display_name)
self.message_router.register_delivery_callback(self.process_lxmf_message_propagated)
else:
self.destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, self.destination_name, self.destination_type)
if self.display_name == "":
self.display_name = RNS.prettyhexrep(self.destination_hash())
@ -375,8 +378,19 @@ class lxmf_connection:
def announce_now(self, app_data=None):
if app_data:
self.destination.announce(app_data.encode("utf-8"))
log("LXMF - Announced: " + RNS.prettyhexrep(self.destination_hash()) + ":" + app_data, LOG_DEBUG)
if isinstance(app_data, str):
self.destination.announce(app_data.encode("utf-8"))
log("LXMF - Announced: " + RNS.prettyhexrep(self.destination_hash()) +":" + announce_data, LOG_DEBUG)
else:
self.destination.announce(app_data)
log("LMF - Announced: " + RNS.prettyhexrep(self.destination_hash()), LOG_DEBUG)
elif self.announce_data:
if isinstance(self.announce_data, str):
self.destination.announce(self.announce_data.encode("utf-8"))
log("LXMF - Announced: " + RNS.prettyhexrep(self.destination_hash()) +":" + self.announce_data, LOG_DEBUG)
else:
self.destination.announce(self.announce_data)
log("LXMF - Announced: " + RNS.prettyhexrep(self.destination_hash()), LOG_DEBUG)
else:
self.destination.announce()
log("LXMF - Announced: " + RNS.prettyhexrep(self.destination_hash()) + ": " + self.display_name, LOG_DEBUG)
@ -655,11 +669,19 @@ class rns_connection:
def announce_now(self, app_data=None):
if app_data:
self.destination.announce(app_data.encode("utf-8"))
log("RNS - Announced: " + RNS.prettyhexrep(self.destination_hash()) + ":" + app_data, LOG_DEBUG)
if isinstance(app_data, str):
self.destination.announce(app_data.encode("utf-8"))
log("RNS - Announced: " + RNS.prettyhexrep(self.destination_hash()) +":" + announce_data, LOG_DEBUG)
else:
self.destination.announce(app_data)
log("RNS - Announced: " + RNS.prettyhexrep(self.destination_hash()), LOG_DEBUG)
else:
self.destination.announce(self.announce_data.encode("utf-8"))
log("RNS - Announced: " + RNS.prettyhexrep(self.destination_hash()) +":" + self.announce_data, LOG_DEBUG)
if isinstance(self.announce_data, str):
self.destination.announce(self.announce_data.encode("utf-8"))
log("RNS - Announced: " + RNS.prettyhexrep(self.destination_hash()) +":" + self.announce_data, LOG_DEBUG)
else:
self.destination.announce(self.announce_data)
log("RNS - Announced: " + RNS.prettyhexrep(self.destination_hash()), LOG_DEBUG)
##############################################################################################################
@ -731,11 +753,16 @@ def lxmf_message_received_callback(message):
content = message.content.decode('utf-8')
content = content.strip()
if content == "":
if CONFIG["message"].getboolean("fields") and message.fields:
pass
elif content == "":
return
title = message.title.decode('utf-8')
title = title.strip()
if CONFIG["message"].getboolean("title"):
title = message.title.decode('utf-8')
title = title.strip()
else:
title = ""
fields = message.fields
@ -805,6 +832,15 @@ def lxmf_message_received_callback(message):
else:
timestamp = time.time()
if CONFIG["message"].getboolean("fields"):
if message.fields:
fields = message.fields
else:
fields = {}
else:
fields = {}
fields["type"] = CONFIG["lxmf"]["destination_type_conv"]
if CONFIG["statistic"].getboolean("enabled") and CONFIG["statistic"].getboolean("cluster"):
statistic("add", "cluster_in_" + message.desired_method_str)
@ -813,7 +849,7 @@ def lxmf_message_received_callback(message):
if "receive_cluster" in config_get(CONFIG, "rights", section).split(","):
for (key, val) in DATA.items(section):
if key != source_hash:
LXMF_CONNECTION.send(key, content, title, {"type": CONFIG["lxmf"]["destination_type_conv"]}, timestamp, "cluster_send")
LXMF_CONNECTION.send(key, content, title, fields, timestamp, "cluster_send")
elif fields["m_t"] == "pin":
delimiter = CONFIG["interface"]["delimiter_output"]
@ -840,7 +876,7 @@ def lxmf_message_received_callback(message):
if "receive_cluster_pin_add" in config_get(CONFIG, "rights", section).split(","):
for (key, val) in DATA.items(section):
if key != source_hash:
LXMF_CONNECTION.send(key, content_group, "", {"type": CONFIG["lxmf"]["destination_type_conv"]}, None, "cluster_send")
LXMF_CONNECTION.send(key, content_group, "", fields, None, "cluster_send")
if CONFIG["main"].getboolean("auto_save_data"):
DATA.remove_option("main", "unsaved")
@ -849,7 +885,7 @@ def lxmf_message_received_callback(message):
else:
DATA["main"]["unsaved"] = "True"
return
return
if source_right == "" and DATA["main"].getboolean("auto_add_user"):
if CONFIG["lxmf"].getboolean("signature_validated_new") and not message.signature_validated:
@ -1053,7 +1089,13 @@ def lxmf_message_received_callback(message):
if search != "":
content = re.sub(search, config_get(CONFIG, "message", "cluster_send_regex_replace"), content)
fields = defaultdict(dict)
if CONFIG["message"].getboolean("fields"):
if message.fields:
fields = message.fields
else:
fields = {}
else:
fields = {}
fields["c_n"] = CONFIG["cluster"]["name"]
fields["c_t"] = CONFIG["cluster"]["type"]
@ -1087,11 +1129,20 @@ def lxmf_message_received_callback(message):
if destination in config_get(CONFIG, "cluster", "display_name", "", lng_key).split("/"):
cluster_loop = True
if CONFIG["message"].getboolean("fields"):
if message.fields:
fields = message.fields
else:
fields = {}
else:
fields = {}
fields["type"] = CONFIG["lxmf"]["destination_type_conv"]
for section in sections:
if "receive_cluster_send" in config_get(CONFIG, "rights", section).split(",") or (cluster_loop and "receive_cluster_loop" in config_get(CONFIG, "rights", section).split(",")):
for (key, val) in DATA.items(section):
if key != source_hash:
LXMF_CONNECTION.send(key, content, title, {"type": CONFIG["lxmf"]["destination_type_conv"]}, timestamp, "local_send")
LXMF_CONNECTION.send(key, content, title, fields, timestamp, "local_send")
return
@ -1136,6 +1187,15 @@ def lxmf_message_received_callback(message):
content = content_prefix + content + content_suffix
if CONFIG["message"].getboolean("fields"):
if message.fields:
fields = message.fields
else:
fields = {}
else:
fields = {}
fields["type"] = CONFIG["lxmf"]["destination_type_conv"]
if config_get(CONFIG, "message", "timestamp", "", lng_key) == "client":
timestamp = message.timestamp
else:
@ -1153,7 +1213,7 @@ def lxmf_message_received_callback(message):
if "receive_local" in config_get(CONFIG, "rights", section).split(","):
for (key, val) in DATA.items(section):
if key != source_hash:
LXMF_CONNECTION.send(key, content, title, {"type": CONFIG["lxmf"]["destination_type_conv"]}, timestamp, "local_send")
LXMF_CONNECTION.send(key, content, title, fields, timestamp, "local_send")
return
else:
log("LXMF - Source " + RNS.prettyhexrep(message.source_hash) + " 'send' not allowed", LOG_DEBUG)
@ -3861,6 +3921,10 @@ pin_id = %%y%%m%%d-%%H%%M%%S
# Define which message timestamp should be used.
timestamp = client #client/server
# Use title/fields.
title = Yes
fields = Yes