mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
tor: Styling changes due to yapf
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
c530c03242
commit
595997ff7c
47
actions/tor
47
actions/tor
@ -15,7 +15,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Configuration helper for the Tor service
|
Configuration helper for the Tor service
|
||||||
"""
|
"""
|
||||||
@ -47,8 +46,7 @@ def parse_arguments():
|
|||||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||||
|
|
||||||
subparsers.add_parser('setup', help='Setup Tor configuration')
|
subparsers.add_parser('setup', help='Setup Tor configuration')
|
||||||
subparsers.add_parser('get-status',
|
subparsers.add_parser('get-status', help='Get Tor status in JSON format')
|
||||||
help='Get Tor status in JSON format')
|
|
||||||
|
|
||||||
configure = subparsers.add_parser('configure', help='Configure Tor')
|
configure = subparsers.add_parser('configure', help='Configure Tor')
|
||||||
configure.add_argument('--service', choices=['enable', 'disable'],
|
configure.add_argument('--service', choices=['enable', 'disable'],
|
||||||
@ -111,12 +109,9 @@ def subcommand_setup(_):
|
|||||||
|
|
||||||
aug.set(TOR_CONFIG + '/HiddenServiceDir',
|
aug.set(TOR_CONFIG + '/HiddenServiceDir',
|
||||||
'/var/lib/tor-instances/plinth/hidden_service')
|
'/var/lib/tor-instances/plinth/hidden_service')
|
||||||
aug.set(TOR_CONFIG + '/HiddenServicePort[1]',
|
aug.set(TOR_CONFIG + '/HiddenServicePort[1]', '22 127.0.0.1:22')
|
||||||
'22 127.0.0.1:22')
|
aug.set(TOR_CONFIG + '/HiddenServicePort[2]', '80 127.0.0.1:80')
|
||||||
aug.set(TOR_CONFIG + '/HiddenServicePort[2]',
|
aug.set(TOR_CONFIG + '/HiddenServicePort[3]', '443 127.0.0.1:443')
|
||||||
'80 127.0.0.1:80')
|
|
||||||
aug.set(TOR_CONFIG + '/HiddenServicePort[3]',
|
|
||||||
'443 127.0.0.1:443')
|
|
||||||
|
|
||||||
aug.save()
|
aug.save()
|
||||||
|
|
||||||
@ -190,12 +185,14 @@ def subcommand_restart(_):
|
|||||||
def get_status():
|
def get_status():
|
||||||
"""Return dict with Tor status."""
|
"""Return dict with Tor status."""
|
||||||
aug = augeas_load()
|
aug = augeas_load()
|
||||||
return {'use_upstream_bridges': _are_upstream_bridges_enabled(aug),
|
return {
|
||||||
'upstream_bridges': _get_upstream_bridges(aug),
|
'use_upstream_bridges': _are_upstream_bridges_enabled(aug),
|
||||||
'relay_enabled': _is_relay_enabled(aug),
|
'upstream_bridges': _get_upstream_bridges(aug),
|
||||||
'bridge_relay_enabled': _is_bridge_relay_enabled(aug),
|
'relay_enabled': _is_relay_enabled(aug),
|
||||||
'ports': _get_ports(),
|
'bridge_relay_enabled': _is_bridge_relay_enabled(aug),
|
||||||
'hidden_service': _get_hidden_service(aug)}
|
'ports': _get_ports(),
|
||||||
|
'hidden_service': _get_hidden_service(aug)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _are_upstream_bridges_enabled(aug):
|
def _are_upstream_bridges_enabled(aug):
|
||||||
@ -280,8 +277,7 @@ def _get_hidden_service(aug=None):
|
|||||||
|
|
||||||
for hs_port_path in hs_port_paths:
|
for hs_port_path in hs_port_paths:
|
||||||
port_info = aug.get(hs_port_path).split()
|
port_info = aug.get(hs_port_path).split()
|
||||||
hs_ports.append({'virtport': port_info[0],
|
hs_ports.append({'virtport': port_info[0], 'target': port_info[1]})
|
||||||
'target': port_info[1]})
|
|
||||||
|
|
||||||
if not hs_dir:
|
if not hs_dir:
|
||||||
hs_status = 'Not Configured'
|
hs_status = 'Not Configured'
|
||||||
@ -293,8 +289,12 @@ def _get_hidden_service(aug=None):
|
|||||||
except Exception:
|
except Exception:
|
||||||
hs_status = 'Not available (Run Tor at least once)'
|
hs_status = 'Not available (Run Tor at least once)'
|
||||||
|
|
||||||
return {'enabled': hs_enabled, 'status': hs_status,
|
return {
|
||||||
'hostname': hs_hostname, 'ports': hs_ports}
|
'enabled': hs_enabled,
|
||||||
|
'status': hs_status,
|
||||||
|
'hostname': hs_hostname,
|
||||||
|
'ports': hs_ports
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def _enable():
|
def _enable():
|
||||||
@ -386,12 +386,9 @@ def _enable_hs(aug=None):
|
|||||||
|
|
||||||
aug.set(TOR_CONFIG + '/HiddenServiceDir',
|
aug.set(TOR_CONFIG + '/HiddenServiceDir',
|
||||||
'/var/lib/tor-instances/plinth/hidden_service')
|
'/var/lib/tor-instances/plinth/hidden_service')
|
||||||
aug.set(TOR_CONFIG + '/HiddenServicePort[1]',
|
aug.set(TOR_CONFIG + '/HiddenServicePort[1]', '22 127.0.0.1:22')
|
||||||
'22 127.0.0.1:22')
|
aug.set(TOR_CONFIG + '/HiddenServicePort[2]', '80 127.0.0.1:80')
|
||||||
aug.set(TOR_CONFIG + '/HiddenServicePort[2]',
|
aug.set(TOR_CONFIG + '/HiddenServicePort[3]', '443 127.0.0.1:443')
|
||||||
'80 127.0.0.1:80')
|
|
||||||
aug.set(TOR_CONFIG + '/HiddenServicePort[3]',
|
|
||||||
'443 127.0.0.1:443')
|
|
||||||
aug.save()
|
aug.save()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -65,8 +65,7 @@ manual_page = 'Tor'
|
|||||||
def init():
|
def init():
|
||||||
"""Initialize the module."""
|
"""Initialize the module."""
|
||||||
menu = main_menu.get('apps')
|
menu = main_menu.get('apps')
|
||||||
menu.add_urlname(name, 'tor', 'tor:index',
|
menu.add_urlname(name, 'tor', 'tor:index', short_description)
|
||||||
short_description)
|
|
||||||
|
|
||||||
setup_helper = globals()['setup_helper']
|
setup_helper = globals()['setup_helper']
|
||||||
needs_setup = setup_helper.get_state() == 'needs-setup'
|
needs_setup = setup_helper.get_state() == 'needs-setup'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user