Added tor restart button to index and tor restart command. Enabled tor restart daemon event

master
Kevin Froman 2020-09-15 17:08:50 +00:00
parent b4d80da3ff
commit 1f067f614a
9 changed files with 63 additions and 6 deletions

View File

@ -67,14 +67,16 @@ def daemon_event_handlers(shared_state: 'TooMany'):
return "removed" return "removed"
def restart_tor(): def restart_tor():
restarttor.restart(comm_inst) restarttor.restart(shared_state)
kv.put('offlinePeers', []) kv.put('offlinePeers', [])
kv.put('onlinePeers', [])
def test_runtime(): def test_runtime():
Thread(target=comm_inst.shared_state.get_by_string( Thread(target=comm_inst.shared_state.get_by_string(
"OnionrRunTestManager").run_tests).start() "OnionrRunTestManager").run_tests).start()
events_api.register_listener(remove_from_insert_queue_wrapper) events_api.register_listener(remove_from_insert_queue_wrapper)
events_api.register_listener(restart_tor)
events_api.register_listener(print_test) events_api.register_listener(print_test)
events_api.register_listener(upload_event) events_api.register_listener(upload_event)
events_api.register_listener(test_runtime) events_api.register_listener(test_runtime)

View File

@ -53,7 +53,7 @@ def net_check(comm_inst):
'the Internet, and is Tor working? ' + 'the Internet, and is Tor working? ' +
'This is usually temporary, but bugs and censorship can cause this to persist, in which case you should report it to beardog [at] mailbox.org', # noqa 'This is usually temporary, but bugs and censorship can cause this to persist, in which case you should report it to beardog [at] mailbox.org', # noqa
terminal=True) terminal=True)
restarttor.restart(comm_inst) restarttor.restart(comm_inst.shared_state)
kv.put('offlinePeers', []) kv.put('offlinePeers', [])
kv.put('isOnline', False) kv.put('isOnline', False)
else: else:

View File

@ -21,8 +21,8 @@ import config
""" """
def restart(comm_inst): def restart(shared_state):
if not config.get('tor.use_existing_tor', False): if not config.get('tor.use_existing_tor', False):
net = comm_inst.shared_state.get(netcontroller.NetController) net = shared_state.get(netcontroller.NetController)
net.killTor() net.killTor()
net.startTor() net.startTor()

View File

@ -30,3 +30,6 @@ def rebuild():
is_json=True, is_json=True,
post_data={} post_data={}
).get(10) ).get(10)
rebuild.onionr_help = "If Onionr is running and is managing its own Tor daemon, restart that daemon."

View File

@ -19,6 +19,7 @@ from .. import motdcreator # cmd to generate new Onionr MOTDs
from .. import sitecreator # cmd to create multi-page sites from .. import sitecreator # cmd to create multi-page sites
from .. import togglebootstrap # cmd to toggle bootstrap file usage from .. import togglebootstrap # cmd to toggle bootstrap file usage
from ..listsites import print_site_list # cmd to list list ids from ..listsites import print_site_list # cmd to list list ids
from netcontroller.torcontrol.rebuildtor import rebuild as tor_restart
import onionrexceptions import onionrexceptions
from onionrutils import importnewblocks # func to import new blocks from onionrutils import importnewblocks # func to import new blocks
@ -53,6 +54,7 @@ def get_arguments() -> dict:
('start', 'daemon'): daemonlaunch.start, ('start', 'daemon'): daemonlaunch.start,
('stop', 'kill'): daemonlaunch.kill_daemon, ('stop', 'kill'): daemonlaunch.kill_daemon,
('restart',): restartonionr.restart, ('restart',): restartonionr.restart,
('restart-tor', 'restarttor'): tor_restart,
('add-address', 'addaddress', 'addadder'): keyadders.add_address, ('add-address', 'addaddress', 'addadder'): keyadders.add_address,
('openhome', 'gui', 'openweb', ('openhome', 'gui', 'openweb',
'open-home', 'open-web'): openwebinterface.open_home, 'open-home', 'open-web'): openwebinterface.open_home,

View File

@ -24,7 +24,6 @@ import logger
def toggle_bootstrap_config(): def toggle_bootstrap_config():
"""Toggles the bootstrap configuration.""" """Toggles the bootstrap configuration."""
print("test")
if config.get('general.use_bootstrap_list') is None: if config.get('general.use_bootstrap_list') is None:
logger.error('No general.bootstrap_list setting found') logger.error('No general.bootstrap_list setting found')
sys.exit(3) sys.exit(3)

View File

@ -1,10 +1,11 @@
"""Onionr - Private P2P Communication. """Onionr - Private P2P Communication.
tor stats info
""" """
import ujson as json import ujson as json
from stem import CircStatus from stem import CircStatus
import logger
from netcontroller.torcontrol.torcontroller import get_controller from netcontroller.torcontrol.torcontroller import get_controller
""" """
@ -37,6 +38,9 @@ class TorStats:
""" """
if self.controller is None: if self.controller is None:
self.controller = get_controller() self.controller = get_controller()
if not self.controller.is_alive():
logger.info(f'{__name__} reconnecting to tor control')
self.controller = get_controller()
self.get_circuits() self.get_circuits()
json_serialized = {} json_serialized = {}
for circuit in self.circuits.keys(): for circuit in self.circuits.keys():

View File

@ -12,6 +12,7 @@
<link rel="stylesheet" href="/shared/fontawesome-free-5.10.2/css/all.min.css"> <link rel="stylesheet" href="/shared/fontawesome-free-5.10.2/css/all.min.css">
<link rel="stylesheet" href="/shared/main/PNotifyBrightTheme.css"> <link rel="stylesheet" href="/shared/main/PNotifyBrightTheme.css">
<link rel="stylesheet" href="/shared/bulma-quickview.min.css"> <link rel="stylesheet" href="/shared/bulma-quickview.min.css">
<link rel="stylesheet" href="/shared/bulma-tooltip.min.css">
<link rel="stylesheet" href="/gettheme"> <link rel="stylesheet" href="/gettheme">
<link rel="stylesheet" href="/shared/sidebar/sidebar.css"> <link rel="stylesheet" href="/shared/sidebar/sidebar.css">
<script defer src="/shared/node_modules/pnotify/dist/iife/PNotify.js"></script> <script defer src="/shared/node_modules/pnotify/dist/iife/PNotify.js"></script>
@ -274,6 +275,12 @@
<pre id="connectedNodes">Unable to get nodes</pre> <pre id="connectedNodes">Unable to get nodes</pre>
</div> </div>
<br> <br>
<div class="field">
<p class="control">
<a class="button is-light restartTor" data-tooltip="Use if there have been no incoming or outgoing connections in a long time">Restart Tor</a>
</p>
</div>
<br>
<h4>Blocks</h4> <h4>Blocks</h4>
<div class="columns"> <div class="columns">
<div class="column"> <div class="column">

View File

@ -20,6 +20,46 @@
shutdownBtn = document.getElementById('shutdownNode') shutdownBtn = document.getElementById('shutdownNode')
restartBtn = document.getElementById('restartNode') restartBtn = document.getElementById('restartNode')
let restartTorBtnControl = function(){
if (typeof config == "undefined" || typeof config.tor == "undefined"){
setTimeout(function(){restartTorBtnControl()}, 10)
return
}
var restartTor = document.getElementsByClassName('restartTor')[0]
if (config.tor.use_existing_tor){
restartTor.classList.add('is-hidden')
return
}
restartTor.onclick = function(){
if (restartTor.disabled){
console.debug("Tor still restarting (or restart_tor event failed)")
return
}
restartTor.disabled = true
PNotify.success({
text: 'Initializing Tor restart...'
})
fetch('/daemon-event/restart_tor', {
method: 'POST',
body: {},
headers: {
"content-type": "application/json",
"token": webpass
}})
.then((resp) => resp.text())
.then(function(data) {
PNotify.success({
text: 'Tor restarting...'
})
restartTor.disabled = false
})
}
}
restartTorBtnControl()
shutdownBtn.onclick = function(){ shutdownBtn.onclick = function(){
if (! nowebpass){ if (! nowebpass){
if (confirm("Really shutdown Onionr?")){ if (confirm("Really shutdown Onionr?")){