diff --git a/bridge_gps_data.py b/bridge_gps_data.py index 7d22a16..d906527 100755 --- a/bridge_gps_data.py +++ b/bridge_gps_data.py @@ -183,7 +183,30 @@ def dashboard_bb_write(call, dmr_id, time, bulletin): user_bb_file.close() logger.info('User bulletin entry saved.') #logger.info(dash_bb) - + +def mailbox_write(call, dmr_id, time, message, recipient): + #try: + mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read()) + mail_file.insert(0, {'call': call, 'dmr_id': dmr_id, 'time': time, 'message':message, 'recipient': recipient}) + with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file: + mailbox_file.write(str(mail_file[:100])) + mailbox_file.close() + logger.info('User mail saved.') + +def mailbox_delete(dmr_id): + mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read()) + call = str(get_alias((dmr_id), subscriber_ids)) + new_data = [] + for message in mail_file: + if message['recipient'] != call: + new_data.append(message) + with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file: + mailbox_file.write(str(new_data[:100])) + mailbox_file.close() + logger.info('Mailbox updated. Delete occurred.') + + + def sos_write(dmr_id, time, message): user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) try: @@ -285,6 +308,12 @@ def process_sms(_rf_src, sms): elif '@REM SOS' == sms: os.remove('/tmp/gps_data_user_sos.txt') logger.info('Removing SOS') + elif '@' and 'M-' in sms: + message = re.sub('@.* |M-','',sms) + recipient = re.sub('@| M-.*','',sms) + mailbox_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), message, str(recipient).upper()) + elif '@REM MAIL' == sms: + mailbox_delete(_rf_src) elif '@MH' in sms: grid_square = re.sub('@MH ', '', sms) if len(grid_square) < 6: @@ -1763,7 +1792,13 @@ if __name__ == '__main__': with open("/tmp/gps_data_user_bb.txt", 'w') as user_bb_file: user_bb_file.write("[]") user_bb_file.close() - + if Path('/tmp/gps_data_user_mailbox.txt').is_file(): + pass + else: + Path('/tmp/gps_data_user_mailbox.txt').touch() + with open("/tmp/gps_data_user_mailbox.txt", 'w') as user_loc_file: + user_loc_file.write("[]") + user_loc_file.close() # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message diff --git a/gps_data.py b/gps_data.py index c2f7f0f..2cbdd9d 100644 --- a/gps_data.py +++ b/gps_data.py @@ -177,6 +177,28 @@ def dashboard_bb_write(call, dmr_id, time, bulletin): logger.info('User bulletin entry saved.') #logger.info(dash_bb) +def mailbox_write(call, dmr_id, time, message, recipient): + #try: + mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read()) + mail_file.insert(0, {'call': call, 'dmr_id': dmr_id, 'time': time, 'message':message, 'recipient': recipient}) + with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file: + mailbox_file.write(str(mail_file[:100])) + mailbox_file.close() + logger.info('User mail saved.') + +def mailbox_delete(dmr_id): + mail_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read()) + call = str(get_alias((dmr_id), subscriber_ids)) + new_data = [] + for message in mail_file: + if message['recipient'] != call: + new_data.append(message) + with open("/tmp/gps_data_user_mailbox.txt", 'w') as mailbox_file: + mailbox_file.write(str(new_data[:100])) + mailbox_file.close() + logger.info('Mailbox updated. Delete occurred.') + + def sos_write(dmr_id, time, message): user_settings = ast.literal_eval(os.popen('cat ./user_settings.txt').read()) try: @@ -277,6 +299,12 @@ def process_sms(_rf_src, sms): elif '@REM SOS' == sms: os.remove('/tmp/gps_data_user_sos.txt') logger.info('Removing SOS or Notice') + elif '@' and 'M-' in sms: + message = re.sub('@.* |M-','',sms) + recipient = re.sub('@| M-.*','',sms) + mailbox_write(get_alias(int_id(_rf_src), subscriber_ids), int_id(_rf_src), time.strftime('%H:%M:%S - %m/%d/%y'), message, str(recipient).upper()) + elif '@REM MAIL' == sms: + mailbox_delete(_rf_src) elif '@MH' in sms: grid_square = re.sub('@MH ', '', sms) if len(grid_square) < 6: @@ -666,6 +694,13 @@ if __name__ == '__main__': with open("/tmp/gps_data_user_bb.txt", 'w') as user_bb_file: user_bb_file.write("[]") user_bb_file.close() + if Path('/tmp/gps_data_user_mailbox.txt').is_file(): + pass + else: + Path('/tmp/gps_data_user_mailbox.txt').touch() + with open("/tmp/gps_data_user_mailbox.txt", 'w') as user_loc_file: + user_loc_file.write("[]") + user_loc_file.close() # CLI argument parser - handles picking up the config file from the command line, and sending a "help" message parser = argparse.ArgumentParser() parser.add_argument('-c', '--config', action='store', dest='CONFIG_FILE', help='/full/path/to/config.file (usually gps_data.cfg)') diff --git a/scripts/dashboard/dashboard.py b/scripts/dashboard/dashboard.py index 19eb5fc..6feef12 100644 --- a/scripts/dashboard/dashboard.py +++ b/scripts/dashboard/dashboard.py @@ -399,6 +399,68 @@ def user_settings(): return render_template('user_settings.html', title = dashboard_title, logo = logo, user_result = Markup(user_result)) +@app.route('/mailbox') +def mailbox(): + recipient = request.args.get('recipient') + if not recipient: + mail_content = """ +

The Mailbox is a place where users can leave messages via DMR SMS. A user can leave a message for someone else by sending a specially formatted SMS to """ + data_call_id + """. + The message recipient can then use the mailbox to check for messages. Enter your call sign below to check for messages. See the help page for more information.

+
+ + + + + + + + + + + + +
+

+
+
+

 

+ +""" + + else: + mailbox_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read()) + mail_content = '

Messages for: ' + recipient.upper() + ''' +

\n

\n +

Mailbox RSS Feed for ''' + recipient.upper() + '''

+ ''' + for messages in mailbox_file: + if messages['recipient'] == recipient.upper(): + mail_content = mail_content + """ +

 

+ + + + + + + + + + + + + + + + + + + +
Callsign:""" + messages['call'] + """
DMR ID:""" + str(messages['dmr_id']) + """
Time:""" + messages['time'] + """
Message:""" + messages['message'] + """
+ + """ + return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(mail_content)) + @app.route('/bulletin_rss.xml') def bb_rss(): try: @@ -421,5 +483,28 @@ def bb_rss(): return Response(rss_header + post_data + "\n\n", mimetype='text/xml') except: return str('

No data

') + +@app.route('/mailbox_rss') +def mail_rss(): + mailbox_file = ast.literal_eval(os.popen('cat /tmp/gps_data_user_mailbox.txt').read()) + post_data = '' + recipient = request.args.get('recipient').upper() + rss_header = """ + + + """ + dashboard_title + """ - Mailbox Feed for """ + recipient + """ + """ + rss_link + """ + This is a Mailbox feed from """ + dashboard_title + """ for """ + recipient + """.""" + for entry in mailbox_file: + if entry['recipient'] == recipient: + post_data = post_data + """ + + """ + entry['call'] + ' - ' + str(entry['dmr_id']) + """ + """ + rss_link + """ + """ + entry['message'] + """ - """ + entry['time'] + """ + + """ + return Response(rss_header + post_data + "\n\n", mimetype='text/xml') + if __name__ == '__main__': app.run(debug = True, port=dash_port, host=dash_host) diff --git a/scripts/dashboard/templates/header.html b/scripts/dashboard/templates/header.html index fbfbbcf..971fe24 100644 --- a/scripts/dashboard/templates/header.html +++ b/scripts/dashboard/templates/header.html @@ -6,6 +6,7 @@ +