added work on new main page with tor statistics. Added TorStats class to access tor statistics suck as circuit information

master
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/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()

View File

@ -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):

View File

@ -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)

View File

@ -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:

View File

@ -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():

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,
"max_block_age": 2678400,
"public_key": "",
"random_bind_ip": true,
"use_bootstrap_list": true,
"random_bind_ip": false,
"use_bootstrap_list": false,
"store_plaintext_blocks": true,
"show_notifications": true
},

View File

@ -79,7 +79,9 @@
<div class="field">
<div class="field has-addons">
<p class="control">
<a class="button is-static">Identity</a>
<a class="button is-static">
<i class="fas fa-fingerprint"></i>
</a>
</p>
<p class="control is-expanded">
<input id="myPub" class="input myPub" type="text" readonly>
@ -120,6 +122,11 @@
<!--Onionr Card-->
<div class="card">
<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">
Onionr Sites
</p>
@ -130,10 +137,10 @@
<label class="label">Open Site</label>
<div class="field has-addons">
<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 class="control">
<a id='openSite' class="button is-info">Open Onionr Site</a>
<a id='openSite' class="button is-info">Open</a>
</p>
</div>
</div>
@ -142,6 +149,11 @@
</div>
<div class="card motdCard">
<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">
Onionr MOTD
</p>
@ -152,13 +164,34 @@
</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 class="column">
<!--Statistics Card-->
<div class="card">
<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">
Statistics
Dashboard
</p>
</header>
<div class="card-content">
@ -175,12 +208,29 @@
Uptime: <span id="uptime"></span>
</div>
</div>
<h6>Session Connections</h6>
<div class="columns">
<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>
<h6>Session Connections</h6>
<div class="columns">
<div class="column">
Last Received: <span id="lastIncoming">None since start</span>
@ -210,7 +260,7 @@
</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 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