Exemplo n.º 1
0
 def __init__(self, name, port, trafficType="TCP"):
   """
   name = string describing this port (ie, the purpose)
   port = int port number to try forwarding
   """
   #: string describing the purpose of this port
   self.name = name
   #: what type of traffic to forward (TCP or UDP)
   self.trafficType = trafficType
   #: port number to try forwarding
   self.port = port
   #: whether the UPNP program has been started yet
   self.startedUPNP = False
   #: whether UPNP succeeded
   self.usedUPNP = False
   if System.IS_WINDOWS:
     self.upnpcPath = os.path.join(Globals.WINDOWS_BIN, "upnp", "upnpc-static.exe")
     self.workingDir = os.path.join(Globals.WINDOWS_BIN, "upnp")
   else:
     self.upnpcPath = u"upnpc-static"
     self.workingDir = os.getcwd().decode('utf-8')
   #: the path to the upnp binary
   self.upnpcPath = System.encode_for_filesystem(self.upnpcPath)
   #: the path to the working directory for our binary
   self.workingDir = System.encode_for_filesystem(self.workingDir)
Exemplo n.º 2
0
 def __init__(self, name, port, trafficType="TCP"):
     """
 name = string describing this port (ie, the purpose)
 port = int port number to try forwarding
 """
     #: string describing the purpose of this port
     self.name = name
     #: what type of traffic to forward (TCP or UDP)
     self.trafficType = trafficType
     #: port number to try forwarding
     self.port = port
     #: whether the UPNP program has been started yet
     self.startedUPNP = False
     #: whether UPNP succeeded
     self.usedUPNP = False
     if System.IS_WINDOWS:
         self.upnpcPath = os.path.join(Globals.WINDOWS_BIN, "upnp",
                                       "upnpc-static.exe")
         self.workingDir = os.path.join(Globals.WINDOWS_BIN, "upnp")
     else:
         self.upnpcPath = u"upnpc-static"
         self.workingDir = os.getcwd().decode('utf-8')
     #: the path to the upnp binary
     self.upnpcPath = System.encode_for_filesystem(self.upnpcPath)
     #: the path to the working directory for our binary
     self.workingDir = System.encode_for_filesystem(self.workingDir)
Exemplo n.º 3
0
def apply_update():
  encodedInstallDir = System.encode_for_filesystem(ProgramState.INSTALL_DIR)
  encodedUpdateFile = System.encode_for_filesystem(Globals.UPDATE_FILE_NAME)
  cmd = "%s /S --LOCATION=\"%s\" --PID=%s" % (encodedUpdateFile, encodedInstallDir, os.getpid())
  log_msg("Updater command:  %s" % (cmd))
  if ProgramState.INSTALLED:
    p = subprocess.Popen(cmd, cwd=os.getcwd())
  else:
    log_msg("Go run the updater if you really feel like it.", 2)
Exemplo n.º 4
0
def get_launch_command():
    #if we're not running from py2exe, our executable is python, and it needs the main script name:
    encodedExe = System.encode_for_filesystem(ProgramState.EXECUTABLE)
    if not ProgramState.INSTALLED:
        encodedScript = System.encode_for_filesystem(ProgramState.MAIN_SCRIPT)
        command = "\"" + encodedExe + '" "' + encodedScript + "\""
    else:
        command = "\"" + encodedExe + "\""
    return command
Exemplo n.º 5
0
def get_launch_command():
  #if we're not running from py2exe, our executable is python, and it needs the main script name:
  encodedExe = System.encode_for_filesystem(ProgramState.EXECUTABLE)
  if not ProgramState.INSTALLED:
    encodedScript = System.encode_for_filesystem(ProgramState.MAIN_SCRIPT)
    command = "\"" + encodedExe + '" "' + encodedScript + "\""
  else:
    command = "\"" + encodedExe + "\""
  return command
Exemplo n.º 6
0
def apply_update():
    encodedInstallDir = System.encode_for_filesystem(ProgramState.INSTALL_DIR)
    encodedUpdateFile = System.encode_for_filesystem(Globals.UPDATE_FILE_NAME)
    cmd = "%s /S --LOCATION=\"%s\" --PID=%s" % (encodedUpdateFile,
                                                encodedInstallDir, os.getpid())
    log_msg("Updater command:  %s" % (cmd))
    if ProgramState.INSTALLED:
        p = subprocess.Popen(cmd, cwd=os.getcwd())
    else:
        log_msg("Go run the updater if you really feel like it.", 2)
Exemplo n.º 7
0
def make_platform_status():
  statusList = []
  #add program state:
  for varName in ("IS_LIVE", "INSTALLED", "PY2EXE", "JUST_UPDATED", "DEBUG", "IS_ADMIN"):
    statusList.append([varName, getattr(ProgramState, varName, None)])
    
  #check the state of each important directory:
  for varName in ("STARTING_DIR", "INSTALL_DIR", "USER_DIR"):
    dirName = getattr(ProgramState, varName, None)
    if dirName:
      #convert to a string if necessary:
      readAccess, writeAccess = System.check_folder_permissions(dirName)
      dirName = System.encode_for_filesystem(dirName)
    else:
      readAccess, writeAccess = (False, False)
    readStr = " "
    writeStr = " "
    if readAccess:
      readStr = "r"
    if writeAccess:
      writeStr = "w"
    permissionStr = readStr + writeStr
    dirStr = permissionStr + " " + str(dirName)
    statusList.append([varName, dirStr])
      
  #what type of GUI are they using?
  guiType = "console"
  if ProgramState.USE_GTK:
    guiType = "gtk"
  elif ProgramState.USE_CURSES:
    guiType = "gtk"
  statusList.append(["GUI", guiType])
  
  statusString = "\n".join([":  \t".join([str(r) for r in line]) for line in statusList])
  return statusString
Exemplo n.º 8
0
 def set_start_on_boot(self, newVal):
   """Change the registry key (if necessary) for auto launching BitBlinder at startup on windows, does nothing on *nix.
   Ends up calling a function made with NSIS that will get the necessary permissions to do the modification
   @param newVal:  whether to start on boot or not
   @type  newVal:  bool"""
   if not System.IS_WINDOWS:
     return
   #No need to change if the value is already correct?
   if self.check_start_on_boot() == newVal:
     if self.startOnBootDeferred:
       log_msg("Failed to modify 'start at bootup' value, already editing the registry!", 0)
     return
   if self.startOnBootDeferred:
     return
   def uac_done(result):
     self.startOnBootDeferred = None
     if result != True:
       log_ex(result, "Bad result while running BitBlinderSettingsUpdate.exe")
   #launch the program:
   if newVal:
     args = " --add-startup=" + ClientUtil.get_launch_command()
   else:
     args = " --remove-startup"
     
   encodedExe = System.encode_for_filesystem(os.path.join(Globals.WINDOWS_BIN, "BitBlinderSettingsUpdate.exe"))
   self.startOnBootDeferred = SerialProcessLauncher.get().run_app(encodedExe + "  /S" + args)
   self.startOnBootDeferred.addCallback(uac_done)
   self.startOnBootDeferred.addErrback(uac_done)
Exemplo n.º 9
0
def send_startup_arguments(startingDir):
    #send arguments to any process that is already running:
    encodedStartingDir = System.encode_for_filesystem(startingDir)
    argsToSend = [encodedStartingDir] + sys.argv[1:]
    if StartupClient.send_args(argsToSend):
        #if we managed to send the args to the other instance, we're done:
        sys.exit(0)
Exemplo n.º 10
0
 def set_half_open_conns(self, app, halfOpenConnections):
     """uses tcpz to change the number of half open connections to 218"""
     try:
         #this is a windows specific fix:
         if not System.IS_WINDOWS:
             return
         #also, this is only necessary if we are acting as a Tor server:
         if not app.torApp.settings.beRelay:
             return
         winInfo = sys.getwindowsversion()
         #not sure if this exists, but just in case :)
         if winInfo[0] > 6:
             return
         #if this is win7, we're all set:
         if winInfo[0] == 6 and winInfo[1] >= 1:
             return
         #if this is vista, check the service pack level:
         if winInfo[0] == 6 and winInfo[1] == 0:
             #default and SP1 need fixing:
             if winInfo[4] not in ('', 'Service Pack 1'):
                 return
         if halfOpenConnections:
             #if we already did this, also return:
             if self.appliedHalfOpenCorrection:
                 return
             self.appliedHalfOpenCorrection = True
             #we should only ever run one tcp-z, no going back etiher
             ids = System.get_process_ids()
             for id in ids:
                 if id[0] == 'tcpz.exe':
                     return
             #create the vbs script file to do what we need:
             encodedScriptFile = System.encode_for_filesystem(
                 os.path.join(Globals.USER_DATA_DIR, "tcpz.vbs"))
             encodedExe = System.encode_for_filesystem(
                 os.path.join(Globals.WINDOWS_BIN, 'tcpz.exe'))
             cmd = """Set oShell = WScript.CreateObject("WSCript.shell")\r\ncall oShell.run("cmd /c ""%s"" -limit:220 -autoexit", 0, false)\r\n""" % (
                 encodedExe)
             f = open(encodedScriptFile, "wb")
             f.write(cmd)
             f.close()
             #and execute the script:
             SerialProcessLauncher.get().run_app(
                 'cscript.exe "%s" //B //Nologo' % (encodedScriptFile))
             return
     except Exception, e:
         log_ex(e, "Failed to launch tcpz.exe")
Exemplo n.º 11
0
 def set_half_open_conns(self, app, halfOpenConnections):
   """uses tcpz to change the number of half open connections to 218"""
   try:
     #this is a windows specific fix:
     if not System.IS_WINDOWS:
       return
     #also, this is only necessary if we are acting as a Tor server:
     if not app.torApp.settings.beRelay:
       return
     winInfo = sys.getwindowsversion()
     #not sure if this exists, but just in case :)
     if winInfo [0] > 6:
       return
     #if this is win7, we're all set:
     if winInfo[0] == 6 and winInfo[1] >= 1:
       return
     #if this is vista, check the service pack level:
     if winInfo[0] == 6 and winInfo[1] == 0:
       #default and SP1 need fixing:
       if winInfo[4] not in ('', 'Service Pack 1'):
         return
     if halfOpenConnections:
       #if we already did this, also return:
       if self.appliedHalfOpenCorrection:
         return
       self.appliedHalfOpenCorrection = True
       #we should only ever run one tcp-z, no going back etiher
       ids = System.get_process_ids()
       for id in ids:
         if id[0] == 'tcpz.exe':
           return
       #create the vbs script file to do what we need:
       encodedScriptFile = System.encode_for_filesystem(os.path.join(Globals.USER_DATA_DIR, "tcpz.vbs"))
       encodedExe = System.encode_for_filesystem(os.path.join(Globals.WINDOWS_BIN,'tcpz.exe'))
       cmd = """Set oShell = WScript.CreateObject("WSCript.shell")\r\ncall oShell.run("cmd /c ""%s"" -limit:220 -autoexit", 0, false)\r\n""" % (encodedExe)
       f = open(encodedScriptFile, "wb")
       f.write(cmd)
       f.close()
       #and execute the script:
       SerialProcessLauncher.get().run_app('cscript.exe "%s" //B //Nologo' % (encodedScriptFile))
       return
   except Exception, e:
     log_ex(e, "Failed to launch tcpz.exe")
Exemplo n.º 12
0
 def write(unicodeFileName, coins):
     fileName = System.encode_for_filesystem(unicodeFileName)
     #do not overwrite existing until we're sure the whole file has been output
     newFileName = fileName + ".new"
     f = open(newFileName, "wb")
     msg = ""
     for coin in coins:
         msg += coin.write_binary()
     #TODO:  these should probably be stored encrypted?  use username and password to generate an AES key for the file
     #TODO:  should there actually be a different key?  What about if there are multiple users?
     f.write(msg)
     f.close()
     #move the file to the real location:
     shutil.move(newFileName, fileName)
Exemplo n.º 13
0
def import_gtk():
    #set the GTK path stuff specially on windows:
    if System.IS_WINDOWS:
        if ProgramState.INSTALLED:
            Globals.WINDOWS_BIN = ProgramState.INSTALL_DIR
            encodedInstallDir = System.encode_for_filesystem(
                ProgramState.INSTALL_DIR)
            os.environ['GTK2_RC_FILES'] = encodedInstallDir
            os.environ['GTK_PATH'] = encodedInstallDir
            os.environ['GTK_BASEPATH'] = encodedInstallDir
            os.environ['PATH'] = encodedInstallDir
        else:
            os.environ['PATH'] += ";" + Globals.WINDOWS_BIN
        Globals.WINDOWS_BIN = os.path.realpath(Globals.WINDOWS_BIN)
        #import gtk
        import pygtk
        pygtk.require('2.0')
        #NOTE:  this crazy bit is to avoid a warning from GTK, which prints an error.
        #we want to submit error logs if any errors happen, but dont want this particular warning to count
        #because it always happens and is pointless
        #    temp = sys.argv
        #    sys.argv = []
        #funny stuff with system args
        warnings.simplefilter("ignore")
        import gtk
        #    sys.argv = temp
        #reinstate warnings
        warnings.resetwarnings()
        import gobject
        #find and parse the right rc file
        rc_file = os.getcwdu()
        if not ProgramState.INSTALLED:
            rc_file = os.path.join(rc_file, 'windows', 'build', 'dist')
        rc_file = os.path.join(rc_file, 'share', 'themes', 'Default',
                               'gtk-2.0', 'gtkrc')
        gtk.rc_parse(rc_file)
    else:
        #import GTK if possible:
        try:
            #funny stuff with system args
            warnings.simplefilter("ignore")
            import pygtk
            pygtk.require('2.0')
            import gtk, gobject
            #reinstate warnings
            warnings.resetwarnings()
        except ImportError:
            log_msg("Failed to import gtk.", 1)
            ProgramState.USE_GTK = False
Exemplo n.º 14
0
 def read(unicodeFileName, addFunc):
     fileName = System.encode_for_filesystem(unicodeFileName)
     if not Files.file_exists(fileName):
         log_msg(
             "Could not load coins, file=%s does not exist." %
             (fileName), 1)
         return
     #TODO:  properly deal with various filesystem errors--permissions, etc  :-/
     #read in the original file:
     f = open(fileName, "rb")
     data = f.read()
     while len(data) > 0:
         acoin = ACoin.ACoin(self)
         data = acoin.read_binary(data)
         if acoin.is_fresh(self.currentACoinInterval):
             addFunc(acoin)
         else:
             log_msg("Dropped an expired acoin from %s interval because we are at %s." % \
                     (acoin.interval,self.currentACoinInterval), 1)
         f.close()
Exemplo n.º 15
0
def get_install_directory():
    #check if we're running as an installation or not:
    if System.IS_WINDOWS:
        encodedExeName = System.encode_for_filesystem(
            os.path.basename(ProgramState.EXECUTABLE)).lower()
        if encodedExeName in ("python", "python.exe", "pythonw.exe"):
            isInstalled = False
            installDir = _input_to_unicode(
                os.path.realpath(os.path.dirname(sys.argv[0])))
        else:
            isInstalled = True
            installDir = os.path.dirname(ProgramState.EXECUTABLE)
    else:
        installDir = _input_to_unicode(
            os.path.realpath(os.path.dirname(sys.argv[0])))
        if installDir == "/usr/share/python-support/python-bitblinder/bitblinder":
            isInstalled = True
        else:
            isInstalled = False
    return (installDir, isInstalled)
Exemplo n.º 16
0
def make_platform_status():
    statusList = []
    #add program state:
    for varName in ("IS_LIVE", "INSTALLED", "PY2EXE", "JUST_UPDATED", "DEBUG",
                    "IS_ADMIN"):
        statusList.append([varName, getattr(ProgramState, varName, None)])

    #check the state of each important directory:
    for varName in ("STARTING_DIR", "INSTALL_DIR", "USER_DIR"):
        dirName = getattr(ProgramState, varName, None)
        if dirName:
            #convert to a string if necessary:
            readAccess, writeAccess = System.check_folder_permissions(dirName)
            dirName = System.encode_for_filesystem(dirName)
        else:
            readAccess, writeAccess = (False, False)
        readStr = " "
        writeStr = " "
        if readAccess:
            readStr = "r"
        if writeAccess:
            writeStr = "w"
        permissionStr = readStr + writeStr
        dirStr = permissionStr + " " + str(dirName)
        statusList.append([varName, dirStr])

    #what type of GUI are they using?
    guiType = "console"
    if ProgramState.USE_GTK:
        guiType = "gtk"
    elif ProgramState.USE_CURSES:
        guiType = "gtk"
    statusList.append(["GUI", guiType])

    statusString = "\n".join(
        [":  \t".join([str(r) for r in line]) for line in statusList])
    return statusString
Exemplo n.º 17
0
    def set_start_on_boot(self, newVal):
        """Change the registry key (if necessary) for auto launching BitBlinder at startup on windows, does nothing on *nix.
    Ends up calling a function made with NSIS that will get the necessary permissions to do the modification
    @param newVal:  whether to start on boot or not
    @type  newVal:  bool"""
        if not System.IS_WINDOWS:
            return
        #No need to change if the value is already correct?
        if self.check_start_on_boot() == newVal:
            if self.startOnBootDeferred:
                log_msg(
                    "Failed to modify 'start at bootup' value, already editing the registry!",
                    0)
            return
        if self.startOnBootDeferred:
            return

        def uac_done(result):
            self.startOnBootDeferred = None
            if result != True:
                log_ex(
                    result,
                    "Bad result while running BitBlinderSettingsUpdate.exe")

        #launch the program:
        if newVal:
            args = " --add-startup=" + ClientUtil.get_launch_command()
        else:
            args = " --remove-startup"

        encodedExe = System.encode_for_filesystem(
            os.path.join(Globals.WINDOWS_BIN, "BitBlinderSettingsUpdate.exe"))
        self.startOnBootDeferred = SerialProcessLauncher.get().run_app(
            encodedExe + "  /S" + args)
        self.startOnBootDeferred.addCallback(uac_done)
        self.startOnBootDeferred.addErrback(uac_done)
Exemplo n.º 18
0
def destroy_marker_file():
  fileName = os.path.join(Globals.LOG_FOLDER, 'closedcleanly.txt')
  encodedFileName = System.encode_for_filesystem(fileName)
  os.remove(encodedFileName)