feat: add optional whitelist identifiying users to be allowed access to the bbs

This commit is contained in:
gzi01 2025-03-18 21:16:12 +01:00
parent 295fb35c92
commit 3620d33f7f
No known key found for this signature in database
4 changed files with 22 additions and 4 deletions

View File

@ -117,6 +117,9 @@ def initialize_config(config_file: str = None) -> dict[str, Any]:
allowed_nodes = config.get('allow_list', 'allowed_nodes', fallback='').split(',')
if allowed_nodes == ['']:
allowed_nodes = []
whitelist = config.get('whitelist', 'allowed_users', fallback='').split(',')
if whitelist == ['']:
whitelist = []
print(f"Nodes with Urgent board permissions: {allowed_nodes}")
@ -127,7 +130,8 @@ def initialize_config(config_file: str = None) -> dict[str, Any]:
'port': port,
'bbs_nodes': bbs_nodes,
'allowed_nodes': allowed_nodes,
'mqtt_topic': 'meshtastic.receive'
'mqtt_topic': 'meshtastic.receive',
'whitelist': whitelist
}

View File

@ -100,3 +100,13 @@ utilities_menu_items = S, F, W, X
# js8groups = @GRP1,@GRP2,@GRP3
# store_messages = True
# js8urgent = @URGNT
############################
#### Allowed User IDs ####
############################
# Provide a list of user IDs that are allowed to use the bbs.
# If allowed users is commented out anyone can use the bbs
# Example:
#[whitelist]
#allowed_users = 123456789,123456780
#

View File

@ -176,7 +176,8 @@ def process_message(sender_id, message, interface, is_sync_message=False):
handle_help_command(sender_id, interface)
def on_receive(packet, interface):
def on_receive(packet, interface, whitelist=None):
whitelist = whitelist or []
try:
if 'decoded' in packet and packet['decoded']['portnum'] == 'TEXT_MESSAGE_APP':
message_bytes = packet['decoded']['payload']
@ -184,7 +185,9 @@ def on_receive(packet, interface):
sender_id = packet['from']
to_id = packet.get('to')
sender_node_id = packet['fromId']
if whitelist and str(sender_id) not in whitelist:
logging.info(f'loaded whitelist {whitelist} does not contain {sender_id}')
return
sender_short_name = get_node_short_name(sender_node_id, interface)
receiver_short_name = get_node_short_name(get_node_id_from_num(to_id, interface),
interface) if to_id else "Group Chat"

View File

@ -66,9 +66,10 @@ def main():
logging.info(f"TC²-BBS is running on {system_config['interface_type']} interface...")
initialize_database()
whitelist = system_config['whitelist']
def receive_packet(packet, interface):
on_receive(packet, interface)
on_receive(packet, interface, whitelist)
pub.subscribe(receive_packet, system_config['mqtt_topic'])