Beispiel #1
0
  def test_expand_path(self, tor_controller_mock, config):
    tor_controller_mock().get_pid.return_value = 12345
    self.assertEqual('/absolute/path/to/torrc', expand_path('/absolute/path/to/torrc'))
    self.assertEqual('/your_cwd/torrc', expand_path('torrc'))

    config.set('tor.chroot', '/chroot')
    self.assertEqual('/chroot/absolute/path/to/torrc', expand_path('/absolute/path/to/torrc'))
    self.assertEqual('/chroot/your_cwd/torrc', expand_path('torrc'))

    config.set('tor.chroot', None)
Beispiel #2
0
def log_file_path(controller):
  """
  Provides the path where tor's log file resides, if one exists.

  :params stem.control.Controller controller: tor controller connection

  :returns: **str** with the absolute path of our log file, or **None** if one
    doesn't exist
  """

  for log_entry in controller.get_conf('Log', [], True):
    entry_comp = log_entry.split()  # looking for an entry like: notice file /var/log/tor/notices.log

    if entry_comp[1] == 'file':
      return nyx.expand_path(entry_comp[2])
Beispiel #3
0
def log_file_path(controller):
    """
  Provides the path where tor's log file resides, if one exists.

  :params stem.control.Controller controller: tor controller connection

  :returns: **str** with the absolute path of our log file, or **None** if one
    doesn't exist
  """

    for log_entry in controller.get_conf('Log', [], True):
        entry_comp = log_entry.split(
        )  # looking for an entry like: notice file /var/log/tor/notices.log

        if entry_comp[1] == 'file':
            return nyx.expand_path(entry_comp[2])
Beispiel #4
0
  def reset_listener(self, controller, event_type, _):
    """
    Reloads and displays the torrc on tor reload (sighup) events.
    """

    if event_type == State.RESET:
      try:
        self._torrc_location = expand_path(controller.get_info('config-file'))
        self._torrc_content = _read_torrc(self._torrc_location)
      except ControllerError as exc:
        self._torrc_load_error = msg('panel.torrc.unable_to_find_torrc', error = exc)
        self._torrc_location = None
        self._torrc_content = None
      except Exception as exc:
        exc_msg = exc.strerror if (hasattr(exc, 'strerror') and exc.strerror) else str(exc)
        self._torrc_load_error = msg('panel.torrc.unable_to_load_torrc', error = exc_msg)
        self._torrc_content = None
Beispiel #5
0
  def _reset_listener(self, controller, event_type, _):
    """
    Reloads and displays the torrc on tor reload (sighup) events.
    """

    if event_type == State.RESET:
      try:
        self._torrc_location = expand_path(controller.get_info('config-file'))
        self._torrc_content = _read_torrc(self._torrc_location)
      except ControllerError as exc:
        self._torrc_load_error = 'Unable to determine our torrc location: %s' % exc
        self._torrc_location = None
        self._torrc_content = None
      except Exception as exc:
        exc_msg = exc.strerror if (hasattr(exc, 'strerror') and exc.strerror) else str(exc)
        self._torrc_load_error = 'Unable to read our torrc: %s' % exc_msg
        self._torrc_content = None
Beispiel #6
0
    def reset_listener(self, controller, event_type, _):
        """
    Reloads and displays the torrc on tor reload (sighup) events.
    """

        if event_type == State.RESET:
            try:
                self._torrc_location = expand_path(
                    controller.get_info('config-file'))
                self._torrc_content = _read_torrc(self._torrc_location)
            except ControllerError as exc:
                self._torrc_load_error = msg(
                    'panel.torrc.unable_to_find_torrc', error=exc)
                self._torrc_location = None
                self._torrc_content = None
            except Exception as exc:
                exc_msg = exc.strerror if (hasattr(exc, 'strerror')
                                           and exc.strerror) else str(exc)
                self._torrc_load_error = msg(
                    'panel.torrc.unable_to_load_torrc', error=exc_msg)
                self._torrc_content = None
Beispiel #7
0
  def reset_listener(self, controller, event_type, _):
    """
    Reloads and displays the torrc on tor reload (sighup) events.
    """

    if event_type == State.RESET:
      try:
        self._torrc_location = expand_path(controller.get_info('config-file'))
        contents = []

        with open(self._torrc_location) as torrc_file:
          for line in torrc_file.readlines():
            line = line.replace('\t', '   ').replace('\xc2', "'").rstrip()
            contents.append(filter(lambda char: char in string.printable, line))

        self._torrc_content = contents
      except ControllerError as exc:
        self._torrc_load_error = msg('panel.torrc.unable_to_find_torrc', error = exc)
        self._torrc_location = None
        self._torrc_content = None
      except Exception as exc:
        self._torrc_load_error = msg('panel.torrc.unable_to_load_torrc', error = exc.strerror)
        self._torrc_content = None
Beispiel #8
0
 def test_expand_path_with_chroot(self):
     self.assertEqual('/chroot/absolute/path/to/torrc',
                      expand_path('/absolute/path/to/torrc'))
     self.assertEqual('/chroot/your_cwd/torrc', expand_path('torrc'))
Beispiel #9
0
 def test_expand_path(self):
     self.assertEqual('/absolute/path/to/torrc',
                      expand_path('/absolute/path/to/torrc'))
     self.assertEqual('/your_cwd/torrc', expand_path('torrc'))