Esempio n. 1
0
    def handleKey(self, key):
        isKeystrokeConsumed = True

        if key in (ord('n'),
                   ord('N')) and torTools.getConn().isNewnymAvailable():
            self.sendNewnym()
        elif key in (ord('r'), ord('R')) and not self._isTorConnected:
            torctlConn = None
            allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes(
            )

            if os.path.exists(self._config["startup.interface.socket"]
                              ) and allowSocketConnection:
                try:
                    torctlConn = torTools.connect_socket(
                        self._config["startup.interface.socket"])
                except IOError, exc:
                    if not allowPortConnection:
                        cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
            elif not allowPortConnection:
                cli.popups.showMsg(
                    "Unable to reconnect (socket '%s' doesn't exist)" %
                    self._config["startup.interface.socket"], 3)

            if not torctlConn and allowPortConnection:
                try:
                    ctlAddr, ctlPort = self._config[
                        "startup.interface.ipAddress"], self._config[
                            "startup.interface.port"]
                    tmpConn, authType, authValue = TorCtl.TorCtl.preauth_connect(
                        ctlAddr, ctlPort)

                    if authType == TorCtl.TorCtl.AUTH_TYPE.PASSWORD:
                        authValue = cli.popups.inputPrompt(
                            "Controller Password: "******"Reconnected to Tor's control port")
                        cli.popups.showMsg("Tor reconnected", 1)
                    except:
                        # displays notice for the first failed connection attempt
                        if exc.args:
                            cli.popups.showMsg(
                                "Unable to reconnect (%s)" % exc, 3)
Esempio n. 2
0
    def handleKey(self, key):
        isKeystrokeConsumed = True

        if key in (ord('n'),
                   ord('N')) and torTools.getConn().isNewnymAvailable():
            self.sendNewnym()
        elif key in (ord('r'), ord('R')) and not self._isTorConnected:
            controller = None
            allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes(
            )

            if os.path.exists(CONFIG["startup.interface.socket"]
                              ) and allowSocketConnection:
                try:
                    # TODO: um... what about passwords?
                    controller = Controller.from_socket_file(
                        CONFIG["startup.interface.socket"])
                    controller.authenticate()
                except (IOError, stem.SocketError), exc:
                    controller = None

                    if not allowPortConnection:
                        cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
            elif not allowPortConnection:
                cli.popups.showMsg(
                    "Unable to reconnect (socket '%s' doesn't exist)" %
                    CONFIG["startup.interface.socket"], 3)

            if not controller and allowPortConnection:
                # TODO: This has diverged from starter.py's connection, for instance it
                # doesn't account for relative cookie paths or multiple authentication
                # methods. We can't use the starter.py's connection function directly
                # due to password prompts, but we could certainly make this mess more
                # manageable.

                try:
                    ctlAddr, ctlPort = CONFIG[
                        "startup.interface.ipAddress"], CONFIG[
                            "startup.interface.port"]
                    controller = Controller.from_port(ctlAddr, ctlPort)

                    try:
                        controller.authenticate()
                    except stem.connection.MissingPassword:
                        controller.authenticate(
                            authValue)  # already got the password above
                except Exception, exc:
                    controller = None
Esempio n. 3
0
 def handleKey(self, key):
   isKeystrokeConsumed = True
   
   if key in (ord('n'), ord('N')) and torTools.getConn().isNewnymAvailable():
     self.sendNewnym()
   elif key in (ord('r'), ord('R')) and not self._isTorConnected:
     torctlConn = None
     allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes()
     
     if os.path.exists(self._config["startup.interface.socket"]) and allowSocketConnection:
       try: torctlConn = torTools.connect_socket(self._config["startup.interface.socket"])
       except IOError, exc:
         if not allowPortConnection:
           cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
     elif not allowPortConnection:
       cli.popups.showMsg("Unable to reconnect (socket '%s' doesn't exist)" % self._config["startup.interface.socket"], 3)
     
     if not torctlConn and allowPortConnection:
       # TODO: This has diverged from starter.py's connection, for instance it
       # doesn't account for relative cookie paths or multiple authentication
       # methods. We can't use the starter.py's connection function directly
       # due to password prompts, but we could certainly make this mess more
       # manageable.
       
       try:
         ctlAddr, ctlPort = self._config["startup.interface.ipAddress"], self._config["startup.interface.port"]
         tmpConn, authType, authValue = TorCtl.TorCtl.preauth_connect(ctlAddr, ctlPort)
         
         if authType == TorCtl.TorCtl.AUTH_TYPE.PASSWORD:
           authValue = cli.popups.inputPrompt("Controller Password: "******"authentication cookie '%s' is the wrong size (%i bytes instead of 32)" % (authValue, authCookieSize))
         
         tmpConn.authenticate(authValue)
         torctlConn = tmpConn
       except Exception, exc:
         # attempts to use the wizard port too
         try:
           cli.controller.getController().getTorManager().connectManagedInstance()
           log.log(log.NOTICE, "Reconnected to Tor's control port")
           cli.popups.showMsg("Tor reconnected", 1)
         except:
           # displays notice for the first failed connection attempt
           if exc.args: cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
Esempio n. 4
0
 def handleKey(self, key):
   isKeystrokeConsumed = True
   
   if key in (ord('n'), ord('N')) and torTools.getConn().isNewnymAvailable():
     self.sendNewnym()
   elif key in (ord('r'), ord('R')) and not self._isTorConnected:
     controller = None
     allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes()
     
     if os.path.exists(self._config["startup.interface.socket"]) and allowSocketConnection:
       try:
         # TODO: um... what about passwords?
         controller = Controller.from_socket_file(self._config["startup.interface.socket"])
         controller.authenticate()
       except (IOError, stem.SocketError), exc:
         controller = None
         
         if not allowPortConnection:
           cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
     elif not allowPortConnection:
       cli.popups.showMsg("Unable to reconnect (socket '%s' doesn't exist)" % self._config["startup.interface.socket"], 3)
     
     if not controller and allowPortConnection:
       # TODO: This has diverged from starter.py's connection, for instance it
       # doesn't account for relative cookie paths or multiple authentication
       # methods. We can't use the starter.py's connection function directly
       # due to password prompts, but we could certainly make this mess more
       # manageable.
       
       try:
         ctlAddr, ctlPort = self._config["startup.interface.ipAddress"], self._config["startup.interface.port"]
         controller = Controller.from_port(ctlAddr, ctlPort)
         
         try:
           controller.authenticate()
         except stem.connection.MissingPassword:
           controller.authenticate(authValue) # already got the password above
       except Exception, exc:
         controller = None
Esempio n. 5
0
 def handleKey(self, key):
   isKeystrokeConsumed = True
   
   if key in (ord('n'), ord('N')) and torTools.getConn().isNewnymAvailable():
     self.sendNewnym()
   elif key in (ord('r'), ord('R')) and not self._isTorConnected:
     torctlConn = None
     allowPortConnection, allowSocketConnection, _ = starter.allowConnectionTypes()
     
     if os.path.exists(self._config["startup.interface.socket"]) and allowSocketConnection:
       try: torctlConn = torTools.connect_socket(self._config["startup.interface.socket"])
       except IOError, exc:
         if not allowPortConnection:
           cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)
     elif not allowPortConnection:
       cli.popups.showMsg("Unable to reconnect (socket '%s' doesn't exist)" % self._config["startup.interface.socket"], 3)
     
     if not torctlConn and allowPortConnection:
       try:
         ctlAddr, ctlPort = self._config["startup.interface.ipAddress"], self._config["startup.interface.port"]
         tmpConn, authType, authValue = TorCtl.TorCtl.preauth_connect(ctlAddr, ctlPort)
         
         if authType == TorCtl.TorCtl.AUTH_TYPE.PASSWORD:
           authValue = cli.popups.inputPrompt("Controller Password: "******"Reconnected to Tor's control port")
           cli.popups.showMsg("Tor reconnected", 1)
         except:
           # displays notice for the first failed connection attempt
           if exc.args: cli.popups.showMsg("Unable to reconnect (%s)" % exc, 3)