mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
Check if tor is installed before running some commands.
This commit is contained in:
parent
8f2c8480b4
commit
e5de76401d
27
actions/tor
27
actions/tor
@ -34,6 +34,10 @@ def parse_arguments():
|
|||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||||
|
|
||||||
|
# Get whether Tor is installed
|
||||||
|
subparsers.add_parser('get-installed',
|
||||||
|
help='Get whether Tor is installed')
|
||||||
|
|
||||||
# Get whether Tor is running
|
# Get whether Tor is running
|
||||||
subparsers.add_parser('is-running', help='Get whether Tor is running')
|
subparsers.add_parser('is-running', help='Get whether Tor is running')
|
||||||
|
|
||||||
@ -55,6 +59,11 @@ def parse_arguments():
|
|||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def subcommand_get_installed(_):
|
||||||
|
"""Get whether Tor is installed"""
|
||||||
|
print('installed' if get_installed() else 'not installed')
|
||||||
|
|
||||||
|
|
||||||
def subcommand_is_running(_):
|
def subcommand_is_running(_):
|
||||||
"""Get whether Tor is running"""
|
"""Get whether Tor is running"""
|
||||||
try:
|
try:
|
||||||
@ -92,7 +101,7 @@ def subcommand_get_hs(_):
|
|||||||
|
|
||||||
def subcommand_enable_hs(_):
|
def subcommand_enable_hs(_):
|
||||||
"""Enable Tor hidden service"""
|
"""Enable Tor hidden service"""
|
||||||
if get_hidden_service():
|
if not get_installed() or get_hidden_service():
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(TOR_CONFIG, 'r') as conffile:
|
with open(TOR_CONFIG, 'r') as conffile:
|
||||||
@ -112,7 +121,7 @@ def subcommand_enable_hs(_):
|
|||||||
|
|
||||||
def subcommand_disable_hs(_):
|
def subcommand_disable_hs(_):
|
||||||
"""Disable Tor hidden service"""
|
"""Disable Tor hidden service"""
|
||||||
if not get_hidden_service():
|
if not get_installed() or not get_hidden_service():
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(TOR_CONFIG, 'r') as conffile:
|
with open(TOR_CONFIG, 'r') as conffile:
|
||||||
@ -145,8 +154,19 @@ def subcommand_disable_hs(_):
|
|||||||
subprocess.call(['service', 'tor', 'restart'])
|
subprocess.call(['service', 'tor', 'restart'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_installed():
|
||||||
|
"""Get whether Tor is installed"""
|
||||||
|
with open('/dev/null', 'w') as file_handle:
|
||||||
|
status = subprocess.call(['which', 'tor'], stdout=file_handle)
|
||||||
|
|
||||||
|
return not status
|
||||||
|
|
||||||
|
|
||||||
def set_tor_service(enable):
|
def set_tor_service(enable):
|
||||||
"""Enable/disable Tor service; enable: boolean"""
|
"""Enable/disable Tor service; enable: boolean"""
|
||||||
|
if not get_installed():
|
||||||
|
return
|
||||||
|
|
||||||
newline = 'RUN_DAEMON="yes"\n' if enable else 'RUN_DAEMON="no"\n'
|
newline = 'RUN_DAEMON="yes"\n' if enable else 'RUN_DAEMON="no"\n'
|
||||||
|
|
||||||
with open(SERVICE_CONFIG, 'r') as file:
|
with open(SERVICE_CONFIG, 'r') as file:
|
||||||
@ -162,6 +182,9 @@ def set_tor_service(enable):
|
|||||||
|
|
||||||
def get_hidden_service():
|
def get_hidden_service():
|
||||||
"""Return a string with configured Tor hidden service information"""
|
"""Return a string with configured Tor hidden service information"""
|
||||||
|
if not get_installed():
|
||||||
|
return ''
|
||||||
|
|
||||||
hs_dir = None
|
hs_dir = None
|
||||||
hs_ports = []
|
hs_ports = []
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user