tested and working API to external app
This commit is contained in:
parent
e15169b09c
commit
7b2b33b2d9
@ -1,11 +1,20 @@
|
||||
{
|
||||
'XYZ':{
|
||||
'mode':'msg_xfer',
|
||||
'network_name':'My HBlink Server',
|
||||
'url':'http://example.net/api',
|
||||
'user':'test_name',
|
||||
'password':'passw0rd'
|
||||
},
|
||||
'APP':{
|
||||
'mode':'app',
|
||||
'app_name':'Test app',
|
||||
'url':'http://localhost:8080/post',
|
||||
},
|
||||
'ABC':{
|
||||
'mode':'msg_xfer',
|
||||
'network_name':'Regional HBlink Network 1',
|
||||
'url':'http://localhost:8092/api',
|
||||
'user':'test_name',
|
||||
'password':'passw0rd'
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
'ABC':{
|
||||
'XYZ':{
|
||||
'mode':'msg_xfer',
|
||||
'user':'test_name',
|
||||
'password':'passw0rd'
|
||||
|
@ -34,8 +34,10 @@ msg_xfer = {
|
||||
}
|
||||
|
||||
json_object = json.dumps(msg_xfer, indent = 4)
|
||||
print('App')
|
||||
print('-----------------------------------------')
|
||||
print('msg_xfer')
|
||||
print(json_object)
|
||||
print('-----------------------------------------')
|
||||
|
||||
app_request = {
|
||||
'mode':'app',
|
||||
@ -44,7 +46,6 @@ app_request = {
|
||||
'auth_token':'1234567899',
|
||||
'data':{
|
||||
'source_id':1234,
|
||||
'destination_id':3153591,
|
||||
'slot':2,
|
||||
'msg_type':'unit',
|
||||
'msg_format':'motorola',
|
||||
@ -53,21 +54,24 @@ app_request = {
|
||||
}
|
||||
|
||||
json_object = json.dumps(app_request, indent = 4)
|
||||
print('-----------------------------------------')
|
||||
print('app, request, sent to the APP server')
|
||||
print(json_object)
|
||||
print('-----------------------------------------')
|
||||
|
||||
app_response = {
|
||||
'mode':'app',
|
||||
'system_name':'APP',
|
||||
'auth_token':'1234567899',
|
||||
'auth_token':'736a9ced7e7688c951490a7f8e1ebdd4',
|
||||
'data':{
|
||||
1:{'source_id':1234,
|
||||
1:{'source_app':'app_name',
|
||||
'destination_id':3153591,
|
||||
'slot':2,
|
||||
'msg_type':'unit',
|
||||
'msg_format':'motorola',
|
||||
'message':'text of the message'
|
||||
},
|
||||
2:{'source_id':1234,
|
||||
2:{'source_id':'app_name',
|
||||
'destination_id':3153591,
|
||||
'slot':2,
|
||||
'msg_type':'unit',
|
||||
@ -78,9 +82,11 @@ app_response = {
|
||||
}
|
||||
|
||||
json_object = json.dumps(app_response, indent = 4)
|
||||
print('-----------------------------------------')
|
||||
print('app, response, sent to your dashboard')
|
||||
print(json_object)
|
||||
|
||||
msg_xfer = {
|
||||
print('-----------------------------------------')
|
||||
raw_msg_xfer = {
|
||||
'mode':'raw',
|
||||
'system_name':'ABC',
|
||||
'response_url':'http://localhost:8093/api/',
|
||||
|
@ -2,8 +2,9 @@
|
||||
#
|
||||
###############################################################################
|
||||
# Copyright (C) 2016-2019 Cortney T. Buffington, N0MJS <n0mjs@me.com>
|
||||
# GPS/Data - Copyright (C) 2020 Eric Craw, KF7EEL <kf7eel@qsl.net>
|
||||
# GPS/Data - Copyright (C) 2021 Eric Craw, KF7EEL <kf7eel@qsl.net>
|
||||
# Annotated modifications Copyright (C) 2021 Xavier FRS2013
|
||||
# Static position by IU7IGU
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -242,7 +243,7 @@ def sos_write(dmr_id, time, message):
|
||||
sos_file.close()
|
||||
logger.info('Saved SOS.')
|
||||
def send_app_request(url, message, source_id):
|
||||
url = url + '/app'
|
||||
#url = url + '/app'
|
||||
#Load current AUTH token list
|
||||
auth_file = ast.literal_eval(os.popen('cat ' + auth_token_file).read())
|
||||
the_token = str(hashlib.md5(str(time()).encode('utf-8')).hexdigest())
|
||||
@ -255,7 +256,7 @@ def send_app_request(url, message, source_id):
|
||||
app_request = {
|
||||
'mode':'app',
|
||||
'system_name':CONFIG['GPS_DATA']['MY_API_NAME'],
|
||||
'response_url':CONFIG['GPS_DATA']['DASHBOARD_URL'],
|
||||
'response_url':CONFIG['GPS_DATA']['DASHBOARD_URL'] + '/api',
|
||||
'auth_token':the_token,
|
||||
'data':{
|
||||
'source_id':source_id,
|
||||
|
@ -726,7 +726,7 @@ def mail_rss():
|
||||
def api(api_mode=None):
|
||||
if request.method == 'GET':
|
||||
api_content = '<h3 style="text-align: center;"><strong>API Enabled: ' + str(use_api) + '</strong></h3>'
|
||||
return render_template('generic.html', title = dashboard_title, content = Markup(api_content))
|
||||
return render_template('generic.html', title = dashboard_title, logo = logo, content = Markup(api_content))
|
||||
if use_api == 'True' or use_api == "true":
|
||||
access_systems = ast.literal_eval(os.popen('cat ' + access_systems_file).read())
|
||||
authorized_users = ast.literal_eval(os.popen('cat ' + authorized_users_file).read())
|
||||
@ -776,6 +776,7 @@ def api(api_mode=None):
|
||||
return make_response(message, 400)
|
||||
if api_data['mode'] == 'app':
|
||||
auth_file = ast.literal_eval(os.popen('cat ' + auth_token_file).read())
|
||||
print(auth_file)
|
||||
for token in auth_file:
|
||||
print()
|
||||
print(token)
|
||||
@ -792,7 +793,7 @@ def api(api_mode=None):
|
||||
send_slot = 0
|
||||
if sms_data['slot'] == 2:
|
||||
send_slot = 1
|
||||
send_sms(False, sms_data['destination_id'], sms_data['source_id'], 0000, 'unit', send_slot, sms_data['message'])
|
||||
send_sms(False, sms_data['destination_id'], 0000, 0000, 'unit', send_slot, sms_data['message'])
|
||||
new_auth_file = auth_file
|
||||
with open(auth_token_file, 'w') as auth_token:
|
||||
auth_token.write(str(auth_file))
|
||||
@ -803,9 +804,9 @@ def api(api_mode=None):
|
||||
mode=api_data['mode'],
|
||||
status='Token accepted, SMS generated',
|
||||
)
|
||||
if token != api_data['auth_token']:
|
||||
message = jsonify(message='Auth token not found')
|
||||
return make_response(message, 401)
|
||||
## if token != api_data['auth_token']:
|
||||
## message = jsonify(message='Auth token not found')
|
||||
## return make_response(message, 401)
|
||||
|
||||
else:
|
||||
message = jsonify(message='Mode not found')
|
||||
|
Loading…
x
Reference in New Issue
Block a user