Exemplo n.º 1
0
 def _check_for_firefoxes(self):
   self.checkFFEvent = None
   existingFFPIDs = System.get_process_ids_by_exe_path(re.compile("^.*apps\\\\firefoxportable.*\\\\firefox(portable)*.exe$", re.IGNORECASE))
   #if it is NOT running
   if len(existingFFPIDs) <= 0:
     log_msg("Waited long enough.  This is probably shutdown time.", 4)
     self.stop()
     return
   #if firefox is running now, lets just update our process list:
   for pid in existingFFPIDs:
     self.add_process(Process.Process(pid))
Exemplo n.º 2
0
 def _launch_thread(self):
   processes = []
   if len(self.liveCircuits) <= 0:
     #build some initial Circuits
     self.launch_initial_circuits()
   if System.IS_WINDOWS:
     #we determine which processes should live and die based on their exe path.
     FF_PROC_REGEX = re.compile("^.*\\\\apps\\\\firefoxportable.*\\\\(firefoxportable.exe|firefox.exe)$", re.IGNORECASE)
     #kill any leftover processes from last time:
     existingFFPIDs = System.get_process_ids_by_exe_path(FF_PROC_REGEX)
     for pid in existingFFPIDs:
       kill_process(pid)
     #launch polipo:
     path = "%s\\%s\\" % (self.appBasePath, self.name)
     p = LaunchProcess.LaunchProcess([path+"polipo.exe", "-c", path+"polipo.conf"], creationflags=win32process.CREATE_NO_WINDOW)
     self.polipoProc = Process.Process(p.pid)
     #launch firefox:
     p = LaunchProcess.LaunchProcess([path+"FirefoxPortable.exe", self.startPage])
     #have to wait for both processes to launch properly:
     children = System.get_process_ids_by_exe_path(FF_PROC_REGEX)
     startTime = time.time()
     #dont wait any more than 15 seconds for everything to be started
     while len(children) < 2 and time.time() < startTime + 15:
       time.sleep(0.2)
       children = System.get_process_ids_by_exe_path(FF_PROC_REGEX)
     #if some of the processes are STILL missing:
     if len(children) < 2:
       #kill what we have:
       for child in children:
         kill_process(child)
       #and inform the user:
       raise DependencyError("Failed to launch Firefox.  Try again?")
     #create entries for FirefoxPortable.exe, Firefox.exe and polipo.exe:
     for pid in children:
       processes.append(Process.Process(pid))
     processes.append(self.polipoProc)
   elif System.IS_LINUX:
     raise DependencyError("Anonymous browsing is not yet supported for Linux.  Support is coming soon!")
   else:
     raise Exception("This platform is not supported:  %s" % (sys.platform))
   return processes
Exemplo n.º 3
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.º 4
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