Exemplo n.º 1
0
        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)
Exemplo n.º 2
0
 def exit(self):
   shutdownDeferred = defer.Deferred()
   try:
     #for every process that did not yet exit, kill it
     for processObj in self.processes:
       #TODO:  change to this once kill_recursive runs on linux:
       #kill_recursive(p.pid)
       System.kill_process(processObj.pid)
   except Exception, error:
     log_ex(error, "Failed to kill Application process:")
Exemplo n.º 3
0
 def exit(self):
     shutdownDeferred = defer.Deferred()
     try:
         #for every process that did not yet exit, kill it
         for processObj in self.processes:
             #TODO:  change to this once kill_recursive runs on linux:
             #kill_recursive(p.pid)
             System.kill_process(processObj.pid)
     except Exception, error:
         log_ex(error, "Failed to kill Application process:")
Exemplo n.º 4
0
def cleanup_previous_processes(installDir):
    if System.IS_WINDOWS:
        #ensure that no processes from a previous run are left over:
        try:
            oldProcs = System.get_process_ids_by_exe_path(
                re.compile(
                    "^%s.*(tor|firefox|firefoxportable|polipo|bitblinder|bitblindersettingsupdate)\\.exe$"
                    % (installDir.replace("\\", "\\\\")), re.IGNORECASE))
            for pid in oldProcs:
                #dont commit suicide...
                if pid == os.getpid():
                    continue
                log_msg(
                    "Trying to shut down leftover process (%s) while booting BitBlinder..."
                    % (pid), 1)
                System.kill_process(pid)
        except Exception, error:
            log_ex(error, "Failed while trying to shut down old processes")
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
def cleanup_previous_update(options):
    #This option is defined to indicate that we just ran the updater script.  We set
    #the appropriate global, and just try to delete the update exe
    ignoreUpdater = False
    if os.path.exists(Globals.UPDATE_FILE_NAME):
        #kill any leftover updater processes
        try:
            startTime = time.time()
            while True:
                updaterProcs = System.get_process_ids_by_exe_path(
                    re.compile(
                        "^%s$" %
                        (Globals.UPDATE_FILE_NAME.replace("\\", "\\\\")),
                        re.IGNORECASE))
                if len(updaterProcs) <= 0:
                    break
                for pid in updaterProcs:
                    log_msg("Waiting for updater (%s) to shut down..." % (pid),
                            1)
                    System.kill_process(pid)
                if time.time() > startTime + 10.0:
                    raise Exception(
                        "Waited 15 seconds and updater still had not shut down"
                    )
                else:
                    time.sleep(1.0)
        except Exception, error:
            log_ex(error, "Failed while waiting for updater to finish")
            message = "The BitBlinderUpdate.exe is still running.  You must wait for it to finish or forcefully close it before you can run BitBlinder again.  Maybe try running BitBlinder as Administrator just once?"
            die(message, "Error", EXIT_CODES.BITBLINDER_ALREADY_RUNNING)
        #if this is the first run after an update:
        if options.FINISHED_UPDATE:
            #ok, NOW try moving the updater file
            startTime = time.time()
            while True:
                try:
                    if os.path.exists(Globals.UPDATE_FILE_NAME):
                        shutil.move(Globals.UPDATE_FILE_NAME,
                                    Globals.UPDATE_FILE_NAME + ".prev")
                    break
                except Exception, error:
                    time.sleep(0.5)
                    if time.time() > startTime + 5.0:
                        log_ex(
                            error,
                            "Failed to remove update .exe from the previous update"
                        )
                        ignoreUpdater = True
                        #ok, lets try making a file, just so I can see why this is failing for people:
                        if issubclass(type(error), WindowsError):
                            try:
                                testFile = open(
                                    Globals.UPDATE_FILE_NAME + ".test", "wb")
                                testFile.write("hello?")
                                testFile.close()
                            except Exception, error:
                                log_ex(error, "And we could NOT write a file")
                            else:
                                log_msg(
                                    "But we successfully wrote to a file (%s)  Weird."
                                    % (Globals.UPDATE_FILE_NAME + ".test"))
                        break
Exemplo n.º 7
0
      if not os.path.exists(to_directory):
        os.makedirs(to_directory)
      shutil.copyfile(from_, to_)

if __name__ == '__main__':
  #check if the script is already running:
  authFileName = "AUTH.PID"
  processes = []
  if os.path.exists(authFileName):
    pidFile = open(authFileName, "rb")
    data = pidFile.read()
    pidFile.close()
    data = data.split("\n")
    data.pop()
    for pid in data:
      System.kill_process(int(pid))
  pidFile = open(authFileName, "wb")
  #first generate the DirServer entries:
  dirServers = TorUtils.make_auth_lines(Conf.AUTH_SERVERS)
  #now make each of the torrc files and delete any leftover data:
  authConfs = []
  for i in range(1, len(Conf.AUTH_SERVERS)+1):
    data = dirServers + AUTH_TORRC_DATA
    conf = Conf.AUTH_SERVERS[i-1]
    found = False
    for arg in args:
      if arg == conf["address"]:
        found = True
        break
    if not found:
      continue
Exemplo n.º 8
0
def kill_all():
    for p in processes:
        System.kill_process(p.pid)
Exemplo n.º 9
0

def syscall(cmd):
    return os.system(cmd)


ADDRESS = "98.236.61.1"
NUM_CLIENTS = 3
BB_CMD = "python Main.py --allow-multiple --no-gui --dev-network"
TEST_PASSWORD = "******"
TEST_USERNAME = "******"

#make sure there are no leftover Tor or BitBlinder processes:
torIds = System.get_process_ids_by_name(Globals.TOR_RE)
for pid in torIds:
    System.kill_process(pid)
bbIds = System.get_process_ids_by_name(re.compile("^%s.*$" % (BB_CMD)))
for pid in bbIds:
    System.kill_process(pid)

processes = []


def kill_all():
    for p in processes:
        System.kill_process(p.pid)


def handler(signum, frame):
    kill_all()
Exemplo n.º 10
0
def kill_all():
  for p in processes:
    System.kill_process(p.pid)
Exemplo n.º 11
0
else:
  from common.conf import Dev as Conf
  
def syscall(cmd):
  return os.system(cmd)

ADDRESS = "98.236.61.1"
NUM_CLIENTS = 3
BB_CMD = "python Main.py --allow-multiple --no-gui --dev-network"
TEST_PASSWORD = "******"
TEST_USERNAME = "******"

#make sure there are no leftover Tor or BitBlinder processes:
torIds = System.get_process_ids_by_name(Globals.TOR_RE)
for pid in torIds:
  System.kill_process(pid)
bbIds = System.get_process_ids_by_name(re.compile("^%s.*$" % (BB_CMD)))
for pid in bbIds:
  System.kill_process(pid)

processes = []
def kill_all():
  for p in processes:
    System.kill_process(p.pid)
def handler(signum, frame):
  kill_all()
signal.signal(signal.SIGTERM, handler)

#for each checkout:
for i in range(1, NUM_CLIENTS+1):
  baseDir = os.path.join("clients", str(i))
Exemplo n.º 12
0
def send_args(args):
    #if we dont care about other processes, just return immediately:
    if Globals.ALLOW_MULTIPLE_INSTANCES:
        return False
    #Check if any other InnomiNet process is already running:
    #if there is no "closedcleanly.txt", then it definitely is not running
    if os.path.exists(os.path.join(Globals.LOG_FOLDER, 'closedcleanly.txt')):
        #If we succeed, the pass the arguments and exit.
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.connect(
                (Globals.NOMNET_STARTUP_HOST, Globals.NOMNET_STARTUP_PORT))
            data = "STARTUP " + "\n".join(args)
            structFormat = "!I"
            prefixLength = struct.calcsize(structFormat)
            s.sendall(struct.pack(structFormat, len(data)) + data)
            timeout = 5
            try:
                recvd = ""
                msg = ""
                startTime = time.time()
                try:
                    while True:
                        r, w, exceptions = select.select([s], [], [s], 1)
                        #If there are exceptions, connection was probably closed...
                        if exceptions:
                            raise SocketClosed
                        #if there is actually something to read (didnt just timeout):
                        if r:
                            #4096 seemed like a good number...
                            chunk = s.recv(4096, 0)
                            if chunk == '':
                                raise SocketClosed, "socket connection broken"
                            recvd = recvd + chunk
                            while len(recvd) >= prefixLength:
                                length, = struct.unpack(
                                    structFormat, recvd[:prefixLength])
                                if len(recvd) < length + prefixLength:
                                    break
                                msg = recvd[prefixLength:length + prefixLength]
                                msg = msg.split(" ")[0]
                                recvd = recvd[length + prefixLength:]
                            if msg:
                                break
                        #check if we've waited too long:
                        elapsed = time.time() - startTime
                        if elapsed > timeout:
                            raise SocketTimeout(
                                "Exceeded user requested timeout")
                #handle socket errors
                except socket.error:
                    exception, value, traceback = sys.exc_info()
                    if value[0] == ERR_CONNECTION_RESET_BY_PEER:
                        raise SocketClosed(
                            "recv:  ERR_CONNECTION_RESET_BY_PEER")
                    raise
                if msg == "SUCCESS":
                    log_msg("Finished passing arguments to running instance.",
                            2)
                else:
                    log_msg("Previous process died!", 1)
            except Exception, e:
                if e.__class__.__name__ == "SocketTimeout":
                    log_msg("Failed to read response message!", 0)
                    raise e
                else:
                    log_ex(
                        e,
                        "Unhandled exception while waiting for response from running instance"
                    )
            return True
        #If we FAIL to connect, then the program must not already be running, so start up and listen for later connections:
        #NOTE:  sys.exit throws an exception, but it derives from BaseException, which is why we only catch Exceptions here...
        except Exception, e:
            if e.__class__.__name__ == "SocketTimeout":
                #see if Tor is running:
                IDs = System.get_process_ids_by_name(Globals.TOR_RE)
                for ID in IDs:
                    log_msg("Trying to kill tor process %s" % (ID), 2)
                    System.kill_process(ID)
            #just make sure that socket is closed:
            try:
                s.shutdown()
            except:
                pass
            try:
                s.close()
            except:
                pass
Exemplo n.º 13
0
def send_args(args):
  #if we dont care about other processes, just return immediately:
  if Globals.ALLOW_MULTIPLE_INSTANCES:
    return False
  #Check if any other InnomiNet process is already running:
  #if there is no "closedcleanly.txt", then it definitely is not running
  if os.path.exists(os.path.join(Globals.LOG_FOLDER, 'closedcleanly.txt')):
    #If we succeed, the pass the arguments and exit.
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
      s.connect((Globals.NOMNET_STARTUP_HOST, Globals.NOMNET_STARTUP_PORT))
      data = "STARTUP " + "\n".join(args)
      structFormat = "!I"
      prefixLength = struct.calcsize(structFormat)
      s.sendall(struct.pack(structFormat, len(data)) + data)
      timeout = 5
      try:
        recvd = ""
        msg = ""
        startTime = time.time()
        try:      
          while True:
            r, w, exceptions = select.select([s], [], [s], 1)
            #If there are exceptions, connection was probably closed...
            if exceptions:
              raise SocketClosed
            #if there is actually something to read (didnt just timeout):
            if r:
              #4096 seemed like a good number...
              chunk = s.recv(4096, 0)
              if chunk == '':
                raise SocketClosed, "socket connection broken"
              recvd = recvd + chunk
              while len(recvd) >= prefixLength:
                length ,= struct.unpack(structFormat, recvd[:prefixLength])
                if len(recvd) < length + prefixLength:
                  break
                msg = recvd[prefixLength:length + prefixLength]
                msg = msg.split(" ")[0]
                recvd = recvd[length + prefixLength:]
              if msg:
                break
            #check if we've waited too long:
            elapsed = time.time() - startTime
            if elapsed > timeout:
              raise SocketTimeout("Exceeded user requested timeout")
        #handle socket errors
        except socket.error:
          exception, value, traceback = sys.exc_info()
          if value[0] == ERR_CONNECTION_RESET_BY_PEER:
            raise SocketClosed("recv:  ERR_CONNECTION_RESET_BY_PEER")
          raise
        if msg == "SUCCESS":
          log_msg("Finished passing arguments to running instance.", 2)
        else:
          log_msg("Previous process died!", 1)
      except Exception, e:
        if e.__class__.__name__ == "SocketTimeout":
          log_msg("Failed to read response message!", 0)
          raise e
        else:
          log_ex(e, "Unhandled exception while waiting for response from running instance")
      return True
    #If we FAIL to connect, then the program must not already be running, so start up and listen for later connections:
    #NOTE:  sys.exit throws an exception, but it derives from BaseException, which is why we only catch Exceptions here...
    except Exception, e:
      if e.__class__.__name__ == "SocketTimeout":
        #see if Tor is running:
        IDs = System.get_process_ids_by_name(Globals.TOR_RE)
        for ID in IDs:
          log_msg("Trying to kill tor process %s" % (ID), 2)
          System.kill_process(ID)
      #just make sure that socket is closed:
      try:
        s.shutdown()
      except:
        pass
      try:
        s.close()
      except:
        pass