From 063330cfee16554a872a7dd9cf51c043b46aad31 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 30 Mar 2019 23:50:54 -0500 Subject: [PATCH] basic cs messages supported --- .../default-plugins/clandestine/controlapi.py | 51 +++++++++++++++++-- .../default-plugins/clandestine/peerserver.py | 21 ++++++-- 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/onionr/static-data/default-plugins/clandestine/controlapi.py b/onionr/static-data/default-plugins/clandestine/controlapi.py index 5631a2a4..f203c0af 100644 --- a/onionr/static-data/default-plugins/clandestine/controlapi.py +++ b/onionr/static-data/default-plugins/clandestine/controlapi.py @@ -17,10 +17,55 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -from flask import Response, request, redirect, Blueprint, abort +import json +from flask import Response, request, redirect, Blueprint, g +import core -flask_blueprint = Blueprint('clandenstine', __name__) +core_inst = core.Core() +flask_blueprint = Blueprint('clandestine_control', __name__) -@flask_blueprint.route('/clandenstine/ping') +@flask_blueprint.route('/clandestine/ping') def ping(): return 'pong!' + +@flask_blueprint.route('/clandestine/send/', methods=['POST']) +def send_message(peer): + data = request.get_json(force=True) + core_inst.keyStore.refresh() + existing = core_inst.keyStore.get('s' + peer) + if existing is None: + existing = [] + existing.append(data) + core_inst.keyStore.put('s' + peer, existing) + core_inst.keyStore.flush() + return Response('success') + +@flask_blueprint.route('/clandestine/gets/') +def get_sent(peer): + sent = core_inst.keyStore.get('s' + peer) + if sent is None: + sent = [] + return Response(json.dumps(sent)) + +@flask_blueprint.route('/clandestine/addrec/', methods=['POST']) +def add_rec(peer): + data = request.get_json(force=True) + core_inst.keyStore.refresh() + existing = core_inst.keyStore.get('r' + peer) + if existing is None: + existing = [] + existing.append(data) + core_inst.keyStore.put('r' + peer, existing) + core_inst.keyStore.flush() + return Response('success') + +@flask_blueprint.route('/clandestine/getrec/') +def get_messages(peer): + core_inst.keyStore.refresh() + existing = core_inst.keyStore.get('r' + peer) + if existing is None: + existing = [] + else: + existing = list(existing) + core_inst.keyStore.delete('r' + peer) + return Response(json.dumps(existing)) \ No newline at end of file diff --git a/onionr/static-data/default-plugins/clandestine/peerserver.py b/onionr/static-data/default-plugins/clandestine/peerserver.py index e10fa016..b5fb3913 100644 --- a/onionr/static-data/default-plugins/clandestine/peerserver.py +++ b/onionr/static-data/default-plugins/clandestine/peerserver.py @@ -17,9 +17,10 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' +import sys, os, json import core from flask import Response, request, redirect, Blueprint, abort, g - +sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) direct_blueprint = Blueprint('clandestine', __name__) core_inst = core.Core() @@ -36,7 +37,19 @@ def request_setup(): @direct_blueprint.route('/clandestine/ping') def pingdirect(): - return 'pong!' + g.peer + return 'pong!' -@direct_blueprint.route('/clandestine/send') -def poll_chat \ No newline at end of file +@direct_blueprint.route('/clandestine/sendto', methods=['POST', 'GET']) +def sendto(): + try: + msg = request.get_json(force=True) + except: + msg = '' + if msg == None or msg == '': + msg = json.dumps({'m': 'hello world', 't': core_inst._utils.getEpoch()}) + core_inst._utils.localCommand('/clandestine/addrec/%s' % (g.peer,), post=True, postData=msg) + return Response('success') + +@direct_blueprint.route('/clandestine/poll') +def poll_chat(): + return Response(core_inst._utils.localCommand('/clandestine/gets/%s' % (g.peer,))) \ No newline at end of file