예제 #1
0
    def _load_settings(self):
        """Load global and core settings files.  Deals with old format for storing settings"""

        #load a global config that said whether to store the last user that logged in (and his password)
        self.globalSettings = GlobalSettings.load()
        #always save, so the user can more easily edit the file for starting up from the console
        self.globalSettings.save()

        #does a settings file already exist?
        settingsFile = os.path.join(Globals.USER_DATA_DIR,
                                    CoreSettings.CoreSettings.defaultFile)
        if not Files.file_exists(settingsFile):
            #if not, make the folder
            if not Files.file_exists(Globals.USER_DATA_DIR):
                os.makedirs(Globals.USER_DATA_DIR)
            #and check that this isnt an old installation (we used to store settings on a
            #per username basis, which turned out to be a stupid idea).  If that data exists,
            #copy it to the new location.
            if len(self.globalSettings.username) > 0:
                oldSettingsFilePath = os.path.join(
                    Globals.USER_DATA_DIR, self.globalSettings.username,
                    CoreSettings.CoreSettings.defaultFile)
                if os.path.exists(oldSettingsFilePath):
                    oldFolder = os.path.join(Globals.USER_DATA_DIR,
                                             self.globalSettings.username)
                    newFolder = Globals.USER_DATA_DIR
                    Files.recursive_copy_folder(oldFolder, newFolder)

        #load the core settings:
        CoreSettings.start()
        self.coreSettings = CoreSettings.get()
        self.coreSettings.load(settingsFile)
        self.coreSettings.fileName = settingsFile
예제 #2
0
 def _load_settings(self):
   """Load global and core settings files.  Deals with old format for storing settings"""
   
   #load a global config that said whether to store the last user that logged in (and his password)
   self.globalSettings = GlobalSettings.load()
   #always save, so the user can more easily edit the file for starting up from the console
   self.globalSettings.save()
   
   #does a settings file already exist?
   settingsFile = os.path.join(Globals.USER_DATA_DIR, CoreSettings.CoreSettings.defaultFile)
   if not Files.file_exists(settingsFile):
     #if not, make the folder
     if not Files.file_exists(Globals.USER_DATA_DIR):
       os.makedirs(Globals.USER_DATA_DIR)
     #and check that this isnt an old installation (we used to store settings on a 
     #per username basis, which turned out to be a stupid idea).  If that data exists,
     #copy it to the new location.
     if len(self.globalSettings.username) > 0:
       oldSettingsFilePath = os.path.join(Globals.USER_DATA_DIR, self.globalSettings.username, CoreSettings.CoreSettings.defaultFile)
       if os.path.exists(oldSettingsFilePath):
         oldFolder = os.path.join(Globals.USER_DATA_DIR, self.globalSettings.username)
         newFolder = Globals.USER_DATA_DIR
         Files.recursive_copy_folder(oldFolder, newFolder)
       
   #load the core settings:
   CoreSettings.start()
   self.coreSettings = CoreSettings.get()
   self.coreSettings.load(settingsFile)
   self.coreSettings.fileName = settingsFile
예제 #3
0
 def _load_private_key(self):
     """Load (and generate if necessary) the Tor public and private keys"""
     log_msg("Loading private key...", 3)
     try:
         torKey = os.path.join(Globals.USER_DATA_DIR, "tor_data", "keys",
                               "secret_id_key")
         if not Files.file_exists(torKey):
             #have to create it ourselves.  First make the folders if necessary:
             keyFolder = os.path.join(Globals.USER_DATA_DIR, "tor_data",
                                      "keys")
             if not Files.file_exists(keyFolder):
                 os.makedirs(keyFolder)
             #then generate the key
             Globals.PRIVATE_KEY = PrivateKey.PrivateKey(1024)
             #and save it in the appropriate format
             if not Globals.PRIVATE_KEY.key.save_key(torKey, cipher=None):
                 raise Exception("Failed to save key as PEM!")
         else:
             Globals.PRIVATE_KEY = PrivateKey.PrivateKey(torKey)
         Globals.PUBLIC_KEY = Globals.PRIVATE_KEY.publickey()
         Globals.FINGERPRINT = TorUtils.fingerprint(Globals.PRIVATE_KEY.n,
                                                    Globals.PRIVATE_KEY.e)
         log_msg("Globals.FINGERPRINT = %s" % (Globals.FINGERPRINT), 3)
     except Exception, error:
         log_ex(error, "Failed while loading private key data")
예제 #4
0
def create_error_archive(description):
  logs = ["main.out", "errors.out", "stderr.out", "tor.out", "tor_conn.out", "tor_conn.out.old", "log.out.old"]
  zipFile = zipfile.ZipFile(Globals.BUG_REPORT_NAME, "w")
  MAX_SIZE = 2 * 1024L * 1024L
  for log in logs:
    #write the file log with name log
    logName = os.path.join(Globals.LOG_FOLDER, log)
    if Files.file_exists(logName):
      fileSize = os.path.getsize(logName)
      if fileSize > MAX_SIZE:
        log_msg("There were %s bytes, too many to include  :(" % (fileSize), 0)
        f = open(logName, "rb")
        initialData = f.read(MAX_SIZE/2)
        f.seek(-1 * MAX_SIZE/2, 2)
        finalData = f.read(MAX_SIZE/2)
        data = initialData + "\n\n...\n\n" + finalData
        f.close()
        zipFile.writestr(log, data + "\nStopping becaue there were %s bytes, too many to include  :(" % (fileSize))
      else:
        zipFile.write(logName, log)
    else:
      log_msg("Could not find log file:  %s" % (logName), 0)
  description = "%s\n%s\n%s\n%s\nDescription:  %s" % (Logging.dump_system_info(), Logging.make_platform_status(), Logging.make_application_status(), Logging.make_program_status(), description)
  zipFile.writestr("description.out", description)
  zipFile.close()
예제 #5
0
 def set_value(self, val):
   val = unicode(val)
   if not Files.file_exists(val):
     try:
       os.makedirs(val)
     except Exception, error:
       log_msg("Could not make a dir: %s" % (error), 0)
예제 #6
0
 def set_value(self, val):
     val = unicode(val)
     if not Files.file_exists(val):
         try:
             os.makedirs(val)
         except Exception, error:
             log_msg("Could not make a dir: %s" % (error), 0)
예제 #7
0
파일: build.py 프로젝트: wallydz/BitBlinder
def pdebuildrrc_exists():
    """verifies that the pdebuilderrc file exists
  this is necessary for pbuilder to work correctly"""
    path = os.path.expanduser('~/.pbuilderrc')
    if Files.file_exists(path):
        print 'Found the pbuilder rc file'
        return True
    print 'Did not find the pbuilder rc file.'
    return False
예제 #8
0
파일: build.py 프로젝트: kans/BitBlinder
def pdebuildrrc_exists():
    """verifies that the pdebuilderrc file exists
  this is necessary for pbuilder to work correctly"""
    path = os.path.expanduser("~/.pbuilderrc")
    if Files.file_exists(path):
        print "Found the pbuilder rc file"
        return True
    print "Did not find the pbuilder rc file."
    return False
예제 #9
0
def check_previous_logs():
  try:
    #check to see if we closed cleanly before we start_logs!
    errorFile = os.path.join(Globals.LOG_FOLDER, 'errors.out')
    shutdownMarkerFileName = os.path.join(Globals.LOG_FOLDER, 'closedcleanly.txt')
    failedToCloseCleanlyLastTime = Files.file_exists(shutdownMarkerFileName)
    wasErrorLastTime = Files.file_exists(errorFile) and os.path.getsize(errorFile) != 0
    
    #submit error log
    if failedToCloseCleanlyLastTime or wasErrorLastTime:
      startTime = time.time()
      ClientUtil.create_error_archive("autogenerated")
      log_msg("Took %.2f seconds to zip error logs" % (time.time() - startTime), 2)
    #remove error log
    else:
      Files.delete_file(Globals.BUG_REPORT_NAME, True)
  except Exception, error:
    log_ex(error, "Failed to make error report!")
예제 #10
0
 def _load_private_key(self):
   """Load (and generate if necessary) the Tor public and private keys"""
   log_msg("Loading private key...", 3)
   try:
     torKey = os.path.join(Globals.USER_DATA_DIR, "tor_data", "keys", "secret_id_key")
     if not Files.file_exists(torKey):
       #have to create it ourselves.  First make the folders if necessary:
       keyFolder = os.path.join(Globals.USER_DATA_DIR, "tor_data", "keys")
       if not Files.file_exists(keyFolder):
         os.makedirs(keyFolder)
       #then generate the key
       Globals.PRIVATE_KEY = PrivateKey.PrivateKey(1024)
       #and save it in the appropriate format
       if not Globals.PRIVATE_KEY.key.save_key(torKey, cipher=None):
         raise Exception("Failed to save key as PEM!")
     else:
       Globals.PRIVATE_KEY = PrivateKey.PrivateKey(torKey)
     Globals.PUBLIC_KEY = Globals.PRIVATE_KEY.publickey()
     Globals.FINGERPRINT = TorUtils.fingerprint(Globals.PRIVATE_KEY.n, Globals.PRIVATE_KEY.e)
     log_msg("Globals.FINGERPRINT = %s" % (Globals.FINGERPRINT), 3)
   except Exception, error:
     log_ex(error, "Failed while loading private key data")
예제 #11
0
파일: Bank.py 프로젝트: wallydz/BitBlinder
 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()
예제 #12
0
def create_error_archive(description):
    logs = [
        "main.out", "errors.out", "stderr.out", "tor.out", "tor_conn.out",
        "tor_conn.out.old", "log.out.old"
    ]
    zipFile = zipfile.ZipFile(Globals.BUG_REPORT_NAME, "w")
    MAX_SIZE = 2 * 1024L * 1024L
    for log in logs:
        #write the file log with name log
        logName = os.path.join(Globals.LOG_FOLDER, log)
        if Files.file_exists(logName):
            fileSize = os.path.getsize(logName)
            if fileSize > MAX_SIZE:
                log_msg(
                    "There were %s bytes, too many to include  :(" %
                    (fileSize), 0)
                f = open(logName, "rb")
                initialData = f.read(MAX_SIZE / 2)
                f.seek(-1 * MAX_SIZE / 2, 2)
                finalData = f.read(MAX_SIZE / 2)
                data = initialData + "\n\n...\n\n" + finalData
                f.close()
                zipFile.writestr(
                    log, data +
                    "\nStopping becaue there were %s bytes, too many to include  :("
                    % (fileSize))
            else:
                zipFile.write(logName, log)
        else:
            log_msg("Could not find log file:  %s" % (logName), 0)
    description = "%s\n%s\n%s\n%s\nDescription:  %s" % (
        Logging.dump_system_info(), Logging.make_platform_status(),
        Logging.make_application_status(), Logging.make_program_status(),
        description)
    zipFile.writestr("description.out", description)
    zipFile.close()
예제 #13
0
 def get_value(self):
   newVal = unicode(self.entry.get_text())
   if not Files.file_exists(newVal):
     os.makedirs(newVal)
   return newVal
예제 #14
0
 def get_value(self):
     newVal = unicode(self.entry.get_text())
     if not Files.file_exists(newVal):
         os.makedirs(newVal)
     return newVal
예제 #15
0
def has_report_to_send():
  return Files.file_exists(Globals.BUG_REPORT_NAME)
예제 #16
0
                    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
    #apply any pending updates and quit:
    if ProgramState.INSTALLED and not ignoreUpdater and Files.file_exists(
            Globals.UPDATE_FILE_NAME):
        ClientUtil.apply_update()
예제 #17
0
import os
import sys
import os.path
import shutil
import subprocess
import copy
import optparse

from common.utils.Basic import log_msg, log_ex, _ # pylint: disable-msg=W0611
from common import Globals
from common.system import System
from common.utils import TorUtils
from common.system import Files

if Files.file_exists("THIS_IS_LIVE"):
  from common.conf import Live as Conf
  LOG_FOLDER = "/mnt/logs/authority/"
  if System.IS_WINDOWS:
    TOR_EXE = "tor_authority.exe"
  else:
    TOR_EXE = "tor"
else:
  from common.conf import Dev as Conf
  LOG_FOLDER = "/home/development/authority/"
  if System.IS_WINDOWS:
    TOR_EXE = "tor_authority.exe"
  else:
    TOR_EXE = "/home/innomitor/src/or/tor"  

AUTH_TORRC_DATA = copy.copy(Globals.TORRC_DATA) + [