Skip to content

feat: add optional whitelist identifiying users to be allowed access … #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion config_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand All @@ -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
}


Expand Down
10 changes: 10 additions & 0 deletions example_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
7 changes: 5 additions & 2 deletions message_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,18 @@ 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']
message_string = message_bytes.decode('utf-8')
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"
Expand Down
3 changes: 2 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])

Expand Down