mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
tor: Avoid unneeded service restarts
- Fix an import error.
This commit is contained in:
parent
0844151244
commit
a22595af77
28
actions/tor
28
actions/tor
@ -29,8 +29,8 @@ import socket
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
from plinth.modules.tor.tor import get_augeas, get_real_apt_uri_path, \
|
from plinth.modules.tor import is_enabled, is_running, get_augeas, \
|
||||||
iter_apt_uris, APT_TOR_PREFIX
|
get_real_apt_uri_path, iter_apt_uris, APT_TOR_PREFIX
|
||||||
|
|
||||||
SERVICE_FILE = '/etc/firewalld/services/tor-{0}.xml'
|
SERVICE_FILE = '/etc/firewalld/services/tor-{0}.xml'
|
||||||
TOR_CONFIG = '/etc/tor/torrc'
|
TOR_CONFIG = '/etc/tor/torrc'
|
||||||
@ -109,15 +109,17 @@ def subcommand_get_hs(_):
|
|||||||
|
|
||||||
def subcommand_configure(arguments):
|
def subcommand_configure(arguments):
|
||||||
"""Configure Tor."""
|
"""Configure Tor."""
|
||||||
if arguments.service == 'enable':
|
if arguments.service == 'disable':
|
||||||
_enable()
|
|
||||||
elif arguments.service == 'disable':
|
|
||||||
_disable()
|
_disable()
|
||||||
|
|
||||||
|
restart = arguments.service == None
|
||||||
if arguments.hidden_service == 'enable':
|
if arguments.hidden_service == 'enable':
|
||||||
_enable_hs()
|
_enable_hs(restart=restart)
|
||||||
elif arguments.hidden_service == 'disable':
|
elif arguments.hidden_service == 'disable':
|
||||||
_disable_hs()
|
_disable_hs(restart=restart)
|
||||||
|
|
||||||
|
if arguments.service == 'enable':
|
||||||
|
_enable()
|
||||||
|
|
||||||
if arguments.apt_transport_tor == 'enable':
|
if arguments.apt_transport_tor == 'enable':
|
||||||
_enable_apt_transport_tor()
|
_enable_apt_transport_tor()
|
||||||
@ -206,7 +208,7 @@ def _disable():
|
|||||||
action_utils.service_disable('tor')
|
action_utils.service_disable('tor')
|
||||||
|
|
||||||
|
|
||||||
def _enable_hs():
|
def _enable_hs(restart=True):
|
||||||
"""Enable Tor hidden service"""
|
"""Enable Tor hidden service"""
|
||||||
if get_hidden_service():
|
if get_hidden_service():
|
||||||
return
|
return
|
||||||
@ -223,10 +225,12 @@ def _enable_hs():
|
|||||||
with open(TOR_CONFIG, 'w') as conffile:
|
with open(TOR_CONFIG, 'w') as conffile:
|
||||||
conffile.writelines(lines)
|
conffile.writelines(lines)
|
||||||
|
|
||||||
action_utils.service_restart('tor')
|
if restart:
|
||||||
|
if is_enabled() and is_running():
|
||||||
|
action_utils.service_restart('tor')
|
||||||
|
|
||||||
|
|
||||||
def _disable_hs():
|
def _disable_hs(restart=True):
|
||||||
"""Disable Tor hidden service"""
|
"""Disable Tor hidden service"""
|
||||||
if not get_hidden_service():
|
if not get_hidden_service():
|
||||||
return
|
return
|
||||||
@ -258,7 +262,9 @@ def _disable_hs():
|
|||||||
with open(TOR_CONFIG, 'w') as conffile:
|
with open(TOR_CONFIG, 'w') as conffile:
|
||||||
conffile.writelines(filtered_lines)
|
conffile.writelines(filtered_lines)
|
||||||
|
|
||||||
action_utils.service_restart('tor')
|
if restart:
|
||||||
|
if is_enabled() and is_running():
|
||||||
|
action_utils.service_restart('tor')
|
||||||
|
|
||||||
|
|
||||||
def _enable_apt_transport_tor():
|
def _enable_apt_transport_tor():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user