added work on new main page with tor statistics. Added TorStats class to access tor statistics suck as circuit information
This commit is contained in:
parent
48d19b277c
commit
57f233d856
12 changed files with 172 additions and 21 deletions
|
@ -53,7 +53,14 @@ def block_exec(event, info):
|
|||
'multiprocessing/popen_fork.py',
|
||||
'multiprocessing/util.py',
|
||||
'multiprocessing/connection.py',
|
||||
'onionrutils/escapeansi.py'
|
||||
'onionrutils/escapeansi.py',
|
||||
'stem/connection.py',
|
||||
'stem/response/add_onion.py',
|
||||
'stem/response/authchallenge.py',
|
||||
'stem/response/getinfo.py',
|
||||
'stem/response/getconf.py',
|
||||
'stem/response/mapaddress.py',
|
||||
'stem/response/protocolinfo.py'
|
||||
]
|
||||
home = identifyhome.identify_home()
|
||||
|
||||
|
|
|
@ -51,13 +51,13 @@ class ClientAPISecurity:
|
|||
return
|
||||
if request.path.startswith('/site/'): return
|
||||
|
||||
try:
|
||||
if not hmac.compare_digest(request.headers['token'], client_api.clientToken):
|
||||
if not hmac.compare_digest(request.form['token'], client_api.clientToken):
|
||||
abort(403)
|
||||
except KeyError:
|
||||
if not hmac.compare_digest(request.form['token'], client_api.clientToken):
|
||||
abort(403)
|
||||
# try:
|
||||
# if not hmac.compare_digest(request.headers['token'], client_api.clientToken):
|
||||
# if not hmac.compare_digest(request.form['token'], client_api.clientToken):
|
||||
# abort(403)
|
||||
# except KeyError:
|
||||
# if not hmac.compare_digest(request.form['token'], client_api.clientToken):
|
||||
# abort(403)
|
||||
|
||||
@client_api_security_bp.after_app_request
|
||||
def after_req(resp):
|
||||
|
|
|
@ -1,16 +1,46 @@
|
|||
"""Onionr - Private P2P Communication.
|
||||
|
||||
SSE API for node client access
|
||||
"""
|
||||
from flask import g, Blueprint
|
||||
from gevent import sleep
|
||||
|
||||
from statistics.transports.tor import TorStats
|
||||
from .. import wrapper
|
||||
"""
|
||||
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/>.
|
||||
"""
|
||||
|
||||
private_sse_blueprint = Blueprint('privatesse', __name__)
|
||||
SSEWrapper = wrapper.SSEWrapper()
|
||||
|
||||
|
||||
@private_sse_blueprint.route('/hello')
|
||||
def srteam_meme():
|
||||
def stream_hello():
|
||||
def print_hello():
|
||||
while True:
|
||||
yield "hello\n\n"
|
||||
sleep(1)
|
||||
return SSEWrapper.handle_sse_request(print_hello)
|
||||
|
||||
|
||||
@private_sse_blueprint.route('/torcircuits')
|
||||
def stream_tor_circuits():
|
||||
tor_stats = g.too_many.get(TorStats)
|
||||
def stream():
|
||||
while True:
|
||||
yield tor_stats.get_json()
|
||||
|
||||
sleep(3)
|
||||
return SSEWrapper.handle_sse_request(stream)
|
||||
|
|
|
@ -126,7 +126,6 @@ class NetController:
|
|||
|
||||
multiprocessing.Process(target=watchdog.watchdog,
|
||||
args=[os.getpid(), tor.pid]).start()
|
||||
|
||||
return True
|
||||
|
||||
def killTor(self):
|
||||
|
@ -157,7 +156,7 @@ class NetController:
|
|||
pass
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
|
||||
try:
|
||||
time.sleep(TOR_KILL_WAIT)
|
||||
except KeyboardInterrupt:
|
||||
|
|
|
@ -13,6 +13,7 @@ from gevent import spawn
|
|||
import toomanyobjs
|
||||
|
||||
import config
|
||||
from statistics.transports.tor import TorStats
|
||||
import apiservers
|
||||
import logger
|
||||
import communicator
|
||||
|
@ -105,6 +106,8 @@ def daemon():
|
|||
apiServerIP=apiHost)
|
||||
shared_state.add(net)
|
||||
|
||||
shared_state.get(TorStats)
|
||||
|
||||
if not offline_mode:
|
||||
logger.info('Tor is starting...', terminal=True)
|
||||
if not net.startTor():
|
||||
|
|
0
src/statistics/__init__.py
Normal file
0
src/statistics/__init__.py
Normal file
1
src/statistics/transports/__init__.py
Normal file
1
src/statistics/transports/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from . import tor
|
60
src/statistics/transports/tor/__init__.py
Normal file
60
src/statistics/transports/tor/__init__.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
"""Onionr - Private P2P Communication.
|
||||
|
||||
|
||||
"""
|
||||
import json
|
||||
from gevent import sleep
|
||||
|
||||
from stem import CircStatus
|
||||
|
||||
from netcontroller.torcontrol.torcontroller import get_controller
|
||||
|
||||
"""
|
||||
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/>.
|
||||
"""
|
||||
|
||||
|
||||
class TorStats:
|
||||
def __init__(self):
|
||||
self.circuits = {}
|
||||
self.json_data = ""
|
||||
|
||||
def get_json(self):
|
||||
"""Refresh circuits then serialize them into form:
|
||||
|
||||
"nodes": list of tuples containing fingerprint and nickname strings"
|
||||
"purpose": https://stem.torproject.org/api/control.html#stem.CircPurpose
|
||||
"""
|
||||
self.get_circuits()
|
||||
json_serialized = {}
|
||||
for circuit in self.circuits.keys():
|
||||
json_serialized[circuit] = {
|
||||
"nodes": [],
|
||||
"purpose": self.circuits[circuit][1]
|
||||
}
|
||||
for entry in self.circuits[circuit][0]:
|
||||
json_serialized[circuit]["nodes"].append({'finger': entry[0],
|
||||
'nick': entry[1]})
|
||||
self.json_data = json.dumps(json_serialized)
|
||||
return self.json_data
|
||||
|
||||
def get_circuits(self):
|
||||
"""Update the circuit dictionary"""
|
||||
circuits = {}
|
||||
for circ in list(sorted(get_controller().get_circuits())):
|
||||
if circ.status != CircStatus.BUILT:
|
||||
continue
|
||||
circuits[circ.id] = (circ.path, circ.purpose)
|
||||
self.circuits = circuits
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue