From eabf7df017d2ac972845c90c08ff4e260cd2e7e1 Mon Sep 17 00:00:00 2001 From: KF7EEL Date: Tue, 1 Mar 2022 19:47:17 -0800 Subject: [PATCH] add local executable commands --- data_gateway.py | 21 ++++++++++++--------- data_gateway_local_commands.py | 4 ++++ 2 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 data_gateway_local_commands.py diff --git a/data_gateway.py b/data_gateway.py index 9bde677..43e191c 100644 --- a/data_gateway.py +++ b/data_gateway.py @@ -98,6 +98,9 @@ import traceback from socket import gethostbyname +from data_gateway_local_commands import LOCAL_COMMANDS +import subprocess + ################################# @@ -794,15 +797,15 @@ def process_sms(_rf_src, sms, call_type, system_name): logger.error('User APRS messaging disabled.') ## if call_type == 'vcsbk': ## send_sms(False, 9, 9, 9, 'group', 'APRS Messaging must be enabled. Send command "@APRS ON" or use dashboard to enable.') - -## try: -## if sms in cmd_list: -## logger.info('Executing command/script.') -## os.popen(cmd_list[sms]).read() -## packet_assembly = '' -## except Exception as error_exception: -## logger.info('Exception. Command possibly not in list, or other error.') -## logger.info(error_exception) + elif '%' in parse_sms[0]: + try: +## if parse_sms[0][1:] in LOCAL_COMMANDS: + + logger.info('Executing command/script.') + subprocess.Popen(LOCAL_COMMANDS[parse_sms[0][1:]], shell=False) + except Exception as error_exception: + logger.info('Exception. Command possibly not in list, or other error.') + logger.info(error_exception) ## logger.info(str(traceback.extract_tb(error_exception.__traceback__))) ## packet_assembly = '' else: diff --git a/data_gateway_local_commands.py b/data_gateway_local_commands.py new file mode 100644 index 0000000..c0b82ae --- /dev/null +++ b/data_gateway_local_commands.py @@ -0,0 +1,4 @@ +# Python dictionary of commands that can be executed via SMS +# 'SMS':'COMMAND TO EXECUTE' +LOCAL_COMMANDS = {'ls':'ls', + 'pwd':'pwd'}