def response_cb(dialog, response, portNum=portNum, successFunc=successFunc, programName=programName): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return if response == 0: System.kill_process(pid) startTime = time.time() while time.time() < startTime + 2: pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return time.sleep(0.1) def try_again(dialog, response, portNum=portNum, successFunc=successFunc): self.prompt_about_port(portNum, successFunc) self.show_msgbox( "Failed to kill program! Try killing process yourself. pid=%s, name=%s" % (pid, programName), cb=try_again) elif response == 1: self.prompt_about_port(portNum, successFunc)
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break def response_cb(dialog, response, portNum=portNum, successFunc=successFunc, programName=programName): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return if response == 0: System.kill_process(pid) startTime = time.time() while time.time() < startTime + 2: pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return time.sleep(0.1) def try_again(dialog, response, portNum=portNum, successFunc=successFunc): self.prompt_about_port(portNum, successFunc) self.show_msgbox("Failed to kill program! Try killing process yourself. pid=%s, name=%s" % (pid, programName), cb=try_again) elif response == 1: self.prompt_about_port(portNum, successFunc) self.show_msgbox("Port %s is in use by another program (%s). BitBlinder needs this port to run. \n\nWould you like to kill that program or retry the port?" % (portNum, programName), "Port Conflict!", response_cb, buttons=("Kill", 0, "Retry", 1))
def response_cb(dialog, response, portNum=portNum, successFunc=successFunc, programName=programName): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return if response == 0: System.kill_process(pid) startTime = time.time() while time.time() < startTime + 2: pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return time.sleep(0.1) def try_again(dialog, response, portNum=portNum, successFunc=successFunc): self.prompt_about_port(portNum, successFunc) self.show_msgbox("Failed to kill program! Try killing process yourself. pid=%s, name=%s" % (pid, programName), cb=try_again) elif response == 1: self.prompt_about_port(portNum, successFunc)
def check_port(portNum, successFunc): if portNum: pid = System.get_pid_from_port(portNum) if pid > 0: controller = GUIController.get() if controller: controller.prompt_about_port(portNum, successFunc) else: log_msg("no gui controller yet to prompt_about_port", 2) return successFunc()
def check_port(portNum, successFunc): if portNum: pid = System.get_pid_from_port(portNum) if pid > 0: controller = GUIController.get() if controller: controller.prompt_about_port(portNum, successFunc) else: log_msg("no gui controller yet to prompt_about_port", 2) return successFunc()
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break def response_cb(dialog, response, portNum=portNum, successFunc=successFunc, programName=programName): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return if response == 0: System.kill_process(pid) startTime = time.time() while time.time() < startTime + 2: pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return time.sleep(0.1) def try_again(dialog, response, portNum=portNum, successFunc=successFunc): self.prompt_about_port(portNum, successFunc) self.show_msgbox( "Failed to kill program! Try killing process yourself. pid=%s, name=%s" % (pid, programName), cb=try_again) elif response == 1: self.prompt_about_port(portNum, successFunc) self.show_msgbox( "Port %s is in use by another program (%s). BitBlinder needs this port to run. \n\nWould you like to kill that program or retry the port?" % (portNum, programName), "Port Conflict!", response_cb, buttons=("Kill", 0, "Retry", 1))
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break #this has to go in the console as it isn't seen otherwise self.shutdown_func = "" msg = "Port %s is taken by program %s (pid=%s). Please kill the program or otherwise free the port and restart BitBlinder."% (portNum, programName, pid) log_msg(msg, 0) atexit.register(self.print_wrapper, msg) GlobalEvents.throw_event("quit_signal")
def prompt_about_port(self, portNum, successFunc): pid = System.get_pid_from_port(portNum) if pid <= 0: successFunc() return programs = System.get_process_ids() programName = "None" for p in programs: if p[1] == pid: programName = p[0] break #this has to go in the console as it isn't seen otherwise self.shutdown_func = "" msg = "Port %s is taken by program %s (pid=%s). Please kill the program or otherwise free the port and restart BitBlinder." % ( portNum, programName, pid) log_msg(msg, 0) atexit.register(self.print_wrapper, msg) GlobalEvents.throw_event("quit_signal")
def on_new_stream(self, event): #will automatically register itself with it's application stream = Stream.Stream(event) #figure out who should handle the stream next: if stream.isInternal and Stream.OBSERVE_INTERNAL: stream.app = self.torApp stream.app.on_new_stream(stream) else: try: #first check if this was launched internally, directly through Tor: #TODO: this is a little weird, multiple failure conditions: if self.waiting_for_stream(stream): self.handle_stream_creation(stream) return port = int(event.source_addr.split(":")[1]) #need to figure out the original application that started this: assert port, "port must be defined to map a Stream to an Application" pid = System.get_pid_from_port(port) assert pid != 0, "pid must be non-zero in order to map from a Stream to Application" originalApp = self.get_app_by_pid(pid) originalApp.on_new_stream(stream, None) except Exception, e: log_ex(e, "No app for stream=%d?" % (stream.id))
def on_new_stream(self, event): #will automatically register itself with it's application stream = Stream.Stream(event) #figure out who should handle the stream next: if stream.isInternal and Stream.OBSERVE_INTERNAL: stream.app = self.torApp stream.app.on_new_stream(stream) else: try: #first check if this was launched internally, directly through Tor: #TODO: this is a little weird, multiple failure conditions: if self.waiting_for_stream(stream): self.handle_stream_creation(stream) return port = int(event.source_addr.split(":")[1]) #need to figure out the original application that started this: assert port, "port must be defined to map a Stream to an Application" pid = System.get_pid_from_port(port) assert pid != 0, "pid must be non-zero in order to map from a Stream to Application" originalApp = self.get_app_by_pid(pid) originalApp.on_new_stream(stream, None) except Exception, e: log_ex(e, "No app for stream=%d?" % (stream.id))