Пример #1
0
  def _tor_status_listener(self, controller, event_type, _):
    with self._process_lock:
      if not self._halt and event_type in (stem.control.State.INIT, stem.control.State.RESET):
        tor_pid = controller.get_pid(None)
        tor_cmd = system.name_by_pid(tor_pid) if tor_pid else None

        self._process_pid = tor_pid
        self._process_name = tor_cmd if tor_cmd else 'tor'
Пример #2
0
  def _tor_status_listener(self, controller, event_type, _):
    with self._process_lock:
      if not self._halt and event_type in (stem.control.State.INIT, stem.control.State.RESET):
        tor_pid = controller.get_pid(None)
        tor_cmd = system.name_by_pid(tor_pid) if tor_pid else None

        self._process_pid = tor_pid
        self._process_name = tor_cmd if tor_cmd else 'tor'
      elif event_type == stem.control.State.CLOSED:
        self._process_pid = None
        self._process_name = None
Пример #3
0
  def test_name_by_pid_ps(self, call_mock):
    """
    Tests the name_by_pid function with ps responses.
    """

    responses = {
      'success': ['COMMAND', 'vim'],
      'malformed_command_1': ['COMMAND'],
      'malformed_command_2': ['foobar'],
      'malformed_command_3': ['NOT_COMMAND', 'vim'],
      'no_results': [],
      'command_fails': None,
    }

    call_mock.side_effect = mock_call(system.GET_NAME_BY_PID_PS, responses)

    for test_input in responses:
      expected_response = 'vim' if test_input == 'success' else None
      self.assertEqual(expected_response, system.name_by_pid(test_input))
Пример #4
0
    def test_name_by_pid_ps(self, call_mock):
        """
    Tests the name_by_pid function with ps responses.
    """

        responses = {
            'success': ['COMMAND', 'vim'],
            'malformed_command_1': ['COMMAND'],
            'malformed_command_2': ['foobar'],
            'malformed_command_3': ['NOT_COMMAND', 'vim'],
            'no_results': [],
            'command_fails': None,
        }

        call_mock.side_effect = mock_call(system.GET_NAME_BY_PID_PS, responses)

        for test_input in responses:
            expected_response = 'vim' if test_input == 'success' else None
            self.assertEqual(expected_response, system.name_by_pid(test_input))
Пример #5
0
def init_controller(stdscr, start_time):
  """
  Spawns the controller, and related panels for it.

  Arguments:
    stdscr - curses window
  """

  global NYX_CONTROLLER

  # initializes the panels

  sticky_panels = [
    nyx.header_panel.HeaderPanel(stdscr, start_time),
    LabelPanel(stdscr),
  ]

  page_panels, first_page_panels = [], []

  # first page: graph and log
  if CONFIG['features.panels.show.graph']:
    first_page_panels.append(nyx.graph_panel.GraphPanel(stdscr))

  if CONFIG['features.panels.show.log']:
    expanded_events = nyx.arguments.expand_events(CONFIG['startup.events'])
    first_page_panels.append(nyx.log_panel.LogPanel(stdscr, expanded_events))

  if first_page_panels:
    page_panels.append(first_page_panels)

  # second page: connections
  if CONFIG['features.panels.show.connection']:
    page_panels.append([nyx.connection_panel.ConnectionPanel(stdscr)])

    # The DisableDebuggerAttachment will prevent our connection panel from really
    # functioning. It'll have circuits, but little else. If this is the case then
    # notify the user and tell them what they can do to fix it.

    controller = tor_controller()

    if controller.get_conf('DisableDebuggerAttachment', None) == '1':
      log.notice("Tor is preventing system utilities like netstat and lsof from working. This means that nyx can't provide you with connection information. You can change this by adding 'DisableDebuggerAttachment 0' to your torrc and restarting tor. For more information see...\nhttps://trac.torproject.org/3313")
      nyx.util.tracker.get_connection_tracker().set_paused(True)
    else:
      # Configures connection resoultions. This is paused/unpaused according to
      # if Tor's connected or not.

      controller.add_status_listener(conn_reset_listener)

      tor_pid = controller.get_pid(None)

      if tor_pid:
        # use the tor pid to help narrow connection results
        tor_cmd = system.name_by_pid(tor_pid)

        if tor_cmd is None:
          tor_cmd = 'tor'

        resolver = nyx.util.tracker.get_connection_tracker()
        log.info('Operating System: %s, Connection Resolvers: %s' % (os.uname()[0], ', '.join(resolver._resolvers)))
      else:
        # constructs singleton resolver and, if tor isn't connected, initizes
        # it to be paused

        nyx.util.tracker.get_connection_tracker().set_paused(not controller.is_alive())

  # third page: config

  if CONFIG['features.panels.show.config']:
    page_panels.append([nyx.config_panel.ConfigPanel(stdscr, nyx.config_panel.State.TOR)])

  # fourth page: torrc

  if CONFIG['features.panels.show.torrc']:
    page_panels.append([nyx.torrc_panel.TorrcPanel(stdscr, nyx.torrc_panel.Config.TORRC)])

  # initializes the controller

  NYX_CONTROLLER = Controller(stdscr, sticky_panels, page_panels)