fix existing tor daemon not having closed ephemeral onions and work on mail test
This commit is contained in:
parent
dfc42953f7
commit
04133035ba
8 changed files with 74 additions and 3 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue