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:
Kevin Froman 2020-01-21 02:34:15 -06:00
parent 48d19b277c
commit 57f233d856
12 changed files with 172 additions and 21 deletions

View File

@ -53,7 +53,14 @@ def block_exec(event, info):
'multiprocessing/popen_fork.py', 'multiprocessing/popen_fork.py',
'multiprocessing/util.py', 'multiprocessing/util.py',
'multiprocessing/connection.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() home = identifyhome.identify_home()

View File

@ -51,13 +51,13 @@ class ClientAPISecurity:
return return
if request.path.startswith('/site/'): return if request.path.startswith('/site/'): return
try: # try:
if not hmac.compare_digest(request.headers['token'], client_api.clientToken): # if not hmac.compare_digest(request.headers['token'], client_api.clientToken):
if not hmac.compare_digest(request.form['token'], client_api.clientToken): # if not hmac.compare_digest(request.form['token'], client_api.clientToken):
abort(403) # abort(403)
except KeyError: # except KeyError:
if not hmac.compare_digest(request.form['token'], client_api.clientToken): # if not hmac.compare_digest(request.form['token'], client_api.clientToken):
abort(403) # abort(403)
@client_api_security_bp.after_app_request @client_api_security_bp.after_app_request
def after_req(resp): def after_req(resp):

View File

@ -1,16 +1,46 @@
"""Onionr - Private P2P Communication.
SSE API for node client access
"""
from flask import g, Blueprint from flask import g, Blueprint
from gevent import sleep from gevent import sleep
from statistics.transports.tor import TorStats
from .. import wrapper 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__) private_sse_blueprint = Blueprint('privatesse', __name__)
SSEWrapper = wrapper.SSEWrapper() SSEWrapper = wrapper.SSEWrapper()
@private_sse_blueprint.route('/hello') @private_sse_blueprint.route('/hello')
def srteam_meme(): def stream_hello():
def print_hello(): def print_hello():
while True: while True:
yield "hello\n\n" yield "hello\n\n"
sleep(1) sleep(1)
return SSEWrapper.handle_sse_request(print_hello) 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)

View File

@ -126,7 +126,6 @@ class NetController:
multiprocessing.Process(target=watchdog.watchdog, multiprocessing.Process(target=watchdog.watchdog,
args=[os.getpid(), tor.pid]).start() args=[os.getpid(), tor.pid]).start()
return True return True
def killTor(self): def killTor(self):

View File

@ -13,6 +13,7 @@ from gevent import spawn
import toomanyobjs import toomanyobjs
import config import config
from statistics.transports.tor import TorStats
import apiservers import apiservers
import logger import logger
import communicator import communicator
@ -105,6 +106,8 @@ def daemon():
apiServerIP=apiHost) apiServerIP=apiHost)
shared_state.add(net) shared_state.add(net)
shared_state.get(TorStats)
if not offline_mode: if not offline_mode:
logger.info('Tor is starting...', terminal=True) logger.info('Tor is starting...', terminal=True)
if not net.startTor(): if not net.startTor():

View File

View File

@ -0,0 +1 @@
from . import tor

View 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

View File

@ -12,8 +12,8 @@
"insert_deniable_blocks": true, "insert_deniable_blocks": true,
"max_block_age": 2678400, "max_block_age": 2678400,
"public_key": "", "public_key": "",
"random_bind_ip": true, "random_bind_ip": false,
"use_bootstrap_list": true, "use_bootstrap_list": false,
"store_plaintext_blocks": true, "store_plaintext_blocks": true,
"show_notifications": true "show_notifications": true
}, },

View File

@ -79,7 +79,9 @@
<div class="field"> <div class="field">
<div class="field has-addons"> <div class="field has-addons">
<p class="control"> <p class="control">
<a class="button is-static">Identity</a> <a class="button is-static">
<i class="fas fa-fingerprint"></i>
</a>
</p> </p>
<p class="control is-expanded"> <p class="control is-expanded">
<input id="myPub" class="input myPub" type="text" readonly> <input id="myPub" class="input myPub" type="text" readonly>
@ -120,6 +122,11 @@
<!--Onionr Card--> <!--Onionr Card-->
<div class="card"> <div class="card">
<header class="card-header"> <header class="card-header">
<span class="card-header-icon">
<span class="icon">
<i class="fas fa-link"></i>
</span>
</span>
<p class="card-header-title"> <p class="card-header-title">
Onionr Sites Onionr Sites
</p> </p>
@ -130,10 +137,10 @@
<label class="label">Open Site</label> <label class="label">Open Site</label>
<div class="field has-addons"> <div class="field has-addons">
<p class="control is-expanded"> <p class="control is-expanded">
<input class="input" type="text" id='siteViewer' placeholder="Site Hash"> <input class="input" type="text" id='siteViewer' placeholder="Site ID">
</p> </p>
<p class="control"> <p class="control">
<a id='openSite' class="button is-info">Open Onionr Site</a> <a id='openSite' class="button is-info">Open</a>
</p> </p>
</div> </div>
</div> </div>
@ -142,6 +149,11 @@
</div> </div>
<div class="card motdCard"> <div class="card motdCard">
<header class="card-header"> <header class="card-header">
<span class="card-header-icon">
<span class="icon">
<i class="fas fa-newspaper"></i>
</span>
</span>
<p class="card-header-title" title="message of the day"> <p class="card-header-title" title="message of the day">
Onionr MOTD Onionr MOTD
</p> </p>
@ -152,13 +164,34 @@
</div> </div>
</div> </div>
</div> </div>
<br>
<div class="card transportCard">
<header class="card-header">
<span class="card-header-icon">
<span class="icon">
<img src="/shared/images/privacy.png" alt="">
</span>
</span>
<p class="card-header-title">
Networking Statistics
</p>
</header>
<div class="card-content">
<div class="content transportInfo">
</div>
</div>
</div>
</div> </div>
<div class="column"> <div class="column">
<!--Statistics Card-->
<div class="card"> <div class="card">
<header class="card-header"> <header class="card-header">
<span class="card-header-icon">
<span class="icon">
<i class="fas fa-tachometer-alt"></i>
</span>
</span>
<p class="card-header-title"> <p class="card-header-title">
Statistics Dashboard
</p> </p>
</header> </header>
<div class="card-content"> <div class="card-content">
@ -175,12 +208,29 @@
Uptime: <span id="uptime"></span> Uptime: <span id="uptime"></span>
</div> </div>
</div> </div>
<h6>Session Connections</h6>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
<a class="button is-info" id="torToggle">Tor Info</a> <div class="field has-addons">
<p class="control">
<button class="button is-info">
<span class="icon is-small">
<i class="fas fa-cubes"></i>
</span>
<span>Blocks</span>
</button>
</p>
<p class="control">
<button class="button is-info">
<span class="icon is-small">
<i class="fas fa-book-open"></i>
</span>
<span>Help Book</span>
</button>
</p>
</div>
</div> </div>
</div> </div>
<h6>Session Connections</h6>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">
Last Received: <span id="lastIncoming">None since start</span> Last Received: <span id="lastIncoming">None since start</span>
@ -210,7 +260,7 @@
</div> </div>
</div> </div>
<a class="button is-white" id="configToggle">Edit Configuration</a> <a class="button is-white" id="configToggle">Configuration</a>
<div id="configContent"> <div id="configContent">
<div class="content"> <div class="content">

View File

@ -0,0 +1 @@
privacy.png is Jony from the Noun Project https://thenounproject.com/jony4036 under https://creativecommons.org/licenses/by/3.0/us/legalcode

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB