fix existing tor daemon not having closed ephemeral onions and work on mail test
This commit is contained in:
parent
dfc42953f7
commit
04133035ba
@ -34,3 +34,5 @@ keys_file = home + 'keys.txt'
|
||||
onboarding_mark_file = home + 'onboarding-completed'
|
||||
|
||||
log_file = home + 'onionr.log'
|
||||
|
||||
ephemeral_services_file = home + 'ephemeral-services.list'
|
||||
|
@ -1,5 +1,7 @@
|
||||
from . import getopenport, torcontrol
|
||||
from . import torcontrol
|
||||
from . import cleanephemeral
|
||||
tor_binary = torcontrol.torbinary.tor_binary
|
||||
get_open_port = getopenport.get_open_port
|
||||
NetController = torcontrol.NetController
|
||||
NetController = torcontrol.NetController
|
||||
clean_ephemeral_services = cleanephemeral.clean_ephemeral_services
|
40
src/netcontroller/cleanephemeral.py
Normal file
40
src/netcontroller/cleanephemeral.py
Normal file
@ -0,0 +1,40 @@
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Remove ephemeral services
|
||||
"""
|
||||
from filenuke.nuke import clean
|
||||
|
||||
from onionrutils.stringvalidators import validate_transport
|
||||
from filepaths import ephemeral_services_file
|
||||
|
||||
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/>.
|
||||
"""
|
||||
|
||||
|
||||
def clean_ephemeral_services():
|
||||
"""Remove transport's ephemeral services from respective controllers"""
|
||||
try:
|
||||
with open(ephemeral_services_file, 'r') as services:
|
||||
services = services.readlines()
|
||||
with get_controller() as torcontroller:
|
||||
for hs in services:
|
||||
hs += '.onion'
|
||||
if validate_transport(hs):
|
||||
torcontroller.remove_ephemeral_hidden_service(hs)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
else:
|
||||
clean(ephemeral_services_file)
|
@ -3,6 +3,8 @@
|
||||
Create an ephemeral onion service
|
||||
"""
|
||||
from .torcontroller import get_controller
|
||||
|
||||
from filepaths import ephemeral_services_file
|
||||
"""
|
||||
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
|
||||
@ -19,7 +21,7 @@ from .torcontroller import get_controller
|
||||
"""
|
||||
|
||||
|
||||
def create_onion_service(port=80):
|
||||
def create_onion_service(port=80, record_to_service_removal_file=True):
|
||||
controller = get_controller()
|
||||
hs = controller.create_ephemeral_hidden_service(
|
||||
{80: port},
|
||||
@ -27,4 +29,7 @@ def create_onion_service(port=80):
|
||||
key_content = 'ED25519-V3',
|
||||
await_publication=True,
|
||||
detached=True)
|
||||
if record_to_service_removal_file:
|
||||
with open(ephemeral_services_file, 'a') as service_file:
|
||||
service_file.write(hs.service_id + '\n')
|
||||
return (hs.service_id, hs.private_key)
|
||||
|
@ -23,6 +23,7 @@ import communicator
|
||||
from onionrplugins import onionrevents as events
|
||||
from netcontroller import NetController
|
||||
from netcontroller import get_open_port
|
||||
from netcontroller import clean_ephemeral_services
|
||||
from onionrutils import localcommand
|
||||
from utils import identifyhome
|
||||
import filepaths
|
||||
@ -163,6 +164,8 @@ def daemon():
|
||||
events.event('daemon_start')
|
||||
communicator.startCommunicator(shared_state)
|
||||
|
||||
clean_ephemeral_services()
|
||||
|
||||
if not offline_mode and not use_existing_tor:
|
||||
net.killTor()
|
||||
else:
|
||||
|
@ -124,6 +124,7 @@ def show_details():
|
||||
active user ID in mnemonic form
|
||||
"""
|
||||
details = {
|
||||
'Data directory': identifyhome.identify_home(),
|
||||
'Node Address': gethostname.get_hostname(),
|
||||
'Public Key': onionrcrypto.pub_key.replace('=', ''),
|
||||
'Human-readable Public Key': mnemonickeys.get_human_readable_ID()
|
||||
|
@ -21,7 +21,6 @@ from . import identifyhome
|
||||
import filepaths
|
||||
def get_hostname():
|
||||
try:
|
||||
print(identifyhome.identify_home())
|
||||
with open(identifyhome.identify_home() + '/hs/hostname', 'r') as hostname:
|
||||
return hostname.read().strip()
|
||||
except FileNotFoundError:
|
||||
|
@ -47,4 +47,23 @@ class OnionrTests(unittest.TestCase):
|
||||
Popen(['./onionr.sh', 'stop']).wait()
|
||||
web_driver.quit()
|
||||
|
||||
def test_mail(self):
|
||||
Popen(['./onionr.sh', 'start'])
|
||||
while b'http' not in Popen(['./onionr.sh', 'url'], stdout=subprocess.PIPE).communicate()[0]:
|
||||
sleep(1)
|
||||
|
||||
url = 'http' + escapeansi.escape_ANSI(Popen(['./onionr.sh', 'url'], stdout=subprocess.PIPE).communicate()[0].decode().split('http')[1])
|
||||
web_driver = start_firefox(url=url, headless=BROWSER_HEADLESS)
|
||||
if not Text('Mail').exists():
|
||||
click('Get Started')
|
||||
sleep(2)
|
||||
click('Mail')
|
||||
sleep(5)
|
||||
if not Text('Mail').exists():
|
||||
Popen(['./onionr.sh', 'stop']).wait()
|
||||
web_driver.quit()
|
||||
raise ValueError
|
||||
Popen(['./onionr.sh', 'stop']).wait()
|
||||
web_driver.quit()
|
||||
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user