- Removed direct connections (will be a different project in the future)
- removed chat for now - removed onionrcommunicatortimers
This commit is contained in:
parent
59330149e1
commit
30a4285b92
25 changed files with 21 additions and 823 deletions
|
@ -1,75 +0,0 @@
|
|||
"""Onionr - Private P2P Communication.
|
||||
|
||||
HTTP endpoints for controlling IMs
|
||||
"""
|
||||
import ujson as json
|
||||
|
||||
from flask import Response, request, redirect, Blueprint, send_from_directory
|
||||
import deadsimplekv as simplekv
|
||||
|
||||
import filepaths
|
||||
"""
|
||||
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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
flask_blueprint = Blueprint('chat_control', __name__)
|
||||
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
|
||||
@flask_blueprint.route('/chatapi/ping')
|
||||
def ping():
|
||||
return 'pong!'
|
||||
|
||||
@flask_blueprint.route('/chatapi/send/<peer>', methods=['POST'])
|
||||
def send_message(peer):
|
||||
"""Send a message to the peer"""
|
||||
data = request.get_json(force=True)
|
||||
key_store.refresh()
|
||||
existing = key_store.get('s' + peer)
|
||||
if existing is None:
|
||||
existing = []
|
||||
existing.append(data)
|
||||
key_store.put('s' + peer, existing)
|
||||
key_store.flush()
|
||||
return Response('success')
|
||||
|
||||
@flask_blueprint.route('/chatapi/gets/<peer>')
|
||||
def get_sent(peer):
|
||||
"""Get messages sent to peer"""
|
||||
sent = key_store.get('s' + peer)
|
||||
if sent is None:
|
||||
sent = []
|
||||
return Response(json.dumps(sent))
|
||||
|
||||
@flask_blueprint.route('/chatapi/addrec/<peer>', methods=['POST'])
|
||||
def add_rec(peer):
|
||||
"""Add a received message from the peer"""
|
||||
data = request.get_json(force=True)
|
||||
key_store.refresh()
|
||||
existing = key_store.get('r' + peer)
|
||||
if existing is None:
|
||||
existing = []
|
||||
existing.append(data)
|
||||
key_store.put('r' + peer, existing)
|
||||
key_store.flush()
|
||||
return Response('success')
|
||||
|
||||
@flask_blueprint.route('/chatapi/getrec/<peer>')
|
||||
def get_messages(peer):
|
||||
"""Get received messages for the peer"""
|
||||
key_store.refresh()
|
||||
existing = key_store.get('r' + peer)
|
||||
if existing is None:
|
||||
existing = []
|
||||
else:
|
||||
existing = list(existing)
|
||||
key_store.delete('r' + peer)
|
||||
return Response(json.dumps(existing))
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name" : "chat",
|
||||
"version" : "1.0",
|
||||
"author" : "onionr"
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
|
||||
Instant message conversations with Onionr peers
|
||||
'''
|
||||
'''
|
||||
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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
|
||||
# Imports some useful libraries
|
||||
import locale, sys, os, threading, ujson as json
|
||||
locale.setlocale(locale.LC_ALL, '')
|
||||
import onionrservices, logger, config
|
||||
from onionrservices import bootstrapservice
|
||||
from onionrutils import stringvalidators, epoch, basicrequests
|
||||
|
||||
plugin_name = 'chat'
|
||||
PLUGIN_VERSION = '0.0.0'
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
import controlapi, peerserver
|
||||
flask_blueprint = controlapi.flask_blueprint
|
||||
direct_blueprint = peerserver.direct_blueprint
|
||||
security_whitelist = ['staticfiles.chat', 'staticfiles.chatIndex']
|
||||
|
||||
def exit_with_error(text=''):
|
||||
if text != '':
|
||||
logger.error(text)
|
||||
sys.exit(1)
|
|
@ -1,65 +0,0 @@
|
|||
"""Onionr - Private P2P Communication.
|
||||
|
||||
HTTP endpoints for communicating with peers
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
from json import JSONDecodeError
|
||||
|
||||
import deadsimplekv as simplekv
|
||||
import ujson as json
|
||||
from flask import Response, request, redirect, Blueprint, abort, g
|
||||
|
||||
from utils import identifyhome
|
||||
from onionrutils import localcommand
|
||||
import filepaths
|
||||
"""
|
||||
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
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
|
||||
direct_blueprint = Blueprint('chat', __name__)
|
||||
|
||||
key_store = simplekv.DeadSimpleKV(filepaths.cached_storage, refresh_seconds=5)
|
||||
storage_dir = identifyhome.identify_home()
|
||||
|
||||
@direct_blueprint.before_request
|
||||
def request_setup():
|
||||
key_store.refresh()
|
||||
host = request.host
|
||||
host = host.strip('.b32.i2p')
|
||||
host = host.strip('.onion')
|
||||
g.host = host
|
||||
g.peer = key_store.get('dc-' + g.host)
|
||||
|
||||
@direct_blueprint.route('/chat/ping')
|
||||
def pingdirect():
|
||||
return 'pong!'
|
||||
|
||||
@direct_blueprint.route('/chat/sendto', methods=['POST', 'GET'])
|
||||
def sendto():
|
||||
"""Endpoint peers send chat messages to"""
|
||||
try:
|
||||
msg = request.get_json(force=True)
|
||||
except JSONDecodeError:
|
||||
msg = ''
|
||||
else:
|
||||
msg = json.dumps(msg)
|
||||
localcommand.local_command('/chat/addrec/%s' % (g.peer,), post=True, post_data=msg)
|
||||
return Response('success')
|
||||
|
||||
@direct_blueprint.route('/chat/poll')
|
||||
def poll_chat():
|
||||
"""Endpoints peers get new messages from"""
|
||||
return Response(localcommand.local_command('/chat/gets/%s' % (g.peer,)))
|
||||
|
|
@ -46,7 +46,6 @@
|
|||
},
|
||||
"plugins": {
|
||||
"disabled": [
|
||||
"chat"
|
||||
],
|
||||
"enabled": []
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue