tor: Fixes for APT transport setup

- When Deb822 formatted source files are present, error out and don't
  show as enabled.

- When /etc/apt/sources.list.d/*.sources files are present, error out
  and don't show as enabled.

- Handle files /etc/apt/sources.list.d/*.list.

- Workaround Augeas lens not understanding '[options]' in sources.list.
This commit is contained in:
Sunil Mohan Adapa committed 2015-09-04 15:38:16 +05:30
1 parent 09f64f6a4b
commit bff8dd5a5c
2 files changed
+100 -17

No files matched your search

+22 -8
View File
@@ -22,16 +22,15 @@ Configuration helper for the Tor service
"""
import argparse
import augeas
import codecs
import os
import re
import socket
from plinth import action_utils
from plinth.modules.tor.tor import get_augeas, get_real_apt_uri_path, \
iter_apt_uris, APT_TOR_PREFIX
APT_SOURCES_URI_PATH = '/files/etc/apt/sources.list/*/uri'
APT_TOR_PREFIX = 'tor+'
TOR_CONFIG = '/etc/tor/torrc'
TOR_STATE_FILE = '/var/lib/tor/state'
TOR_AUTH_COOKIE = '/var/run/tor/control.authcookie'
@@ -204,21 +203,36 @@ def subcommand_get_ports(_):
def subcommand_enable_apt_transport_tor(_):
"""Enable package download over Tor."""
aug = augeas.Augeas()
for uri_path in aug.match(APT_SOURCES_URI_PATH):
try:
aug = get_augeas()
except Exception:
# If there was an error, don't proceed
print('Error: Unable to understand sources format.')
exit(1)
for uri_path in iter_apt_uris(aug):
uri_path = get_real_apt_uri_path(aug, uri_path)
uri = aug.get(uri_path)
if not uri.startswith(APT_TOR_PREFIX):
if uri.startswith('http://') or uri.startswith('https://'):
aug.set(uri_path, APT_TOR_PREFIX + uri)
aug.save()
def subcommand_disable_apt_transport_tor(_):
"""Disable package download over Tor."""
aug = augeas.Augeas()
for uri_path in aug.match(APT_SOURCES_URI_PATH):
try:
aug = get_augeas()
except Exception:
# Disable what we can, so APT is not unusable.
pass
for uri_path in iter_apt_uris(aug):
uri_path = get_real_apt_uri_path(aug, uri_path)
uri = aug.get(uri_path)
if uri.startswith(APT_TOR_PREFIX):
aug.set(uri_path, uri[len(APT_TOR_PREFIX):])
aug.save()