def findBitcoind(self, extraSearchPaths=[]): self.foundExe = [] searchPaths = list(extraSearchPaths) # create a copy if OS_WINDOWS: # Making sure the search path argument comes with /daemon and /Bitcoin on Windows searchPaths.extend( [os.path.join(sp, 'Groestlcoin') for sp in searchPaths]) searchPaths.extend( [os.path.join(sp, 'daemon') for sp in searchPaths]) possBaseDir = [] from platform import machine if '64' in machine(): possBaseDir.append(os.getenv("ProgramW6432")) possBaseDir.append(os.getenv('PROGRAMFILES(X86)')) else: possBaseDir.append(os.getenv('PROGRAMFILES')) # check desktop for links home = os.path.expanduser('~') desktop = os.path.join(home, 'Desktop') if os.path.exists(desktop): dtopfiles = os.listdir(desktop) for path in [os.path.join(desktop, fn) for fn in dtopfiles]: if 'groestlcoin' in path.lower() and path.lower().endswith( '.lnk'): import win32com.client shell = win32com.client.Dispatch('WScript.Shell') targ = shell.CreateShortCut(path).Targetpath targDir = os.path.dirname(targ) LOGINFO('Found Groestlcoin-Qt link on desktop: %s', targDir) possBaseDir.append(targDir) # Also look in default place in ProgramFiles dirs # Now look at a few subdirs of the searchPaths.extend(possBaseDir) searchPaths.extend([ os.path.join(p, 'Groestlcoin', 'daemon') for p in possBaseDir ]) searchPaths.extend( [os.path.join(p, 'daemon') for p in possBaseDir]) searchPaths.extend( [os.path.join(p, 'Groestlcoin') for p in possBaseDir]) for p in searchPaths: testPath = os.path.join(p, 'groestlcoind.exe') if os.path.exists(testPath): self.foundExe.append(testPath) else: # In case this was a downloaded copy, make sure we traverse to bin/64 dir searchPaths.extend( [os.path.join(p, 'bin') for p in extraSearchPaths]) if SystemSpecs.IsX64: searchPaths.extend( [os.path.join(p, 'bin/64') for p in extraSearchPaths]) else: searchPaths.extend( [os.path.join(p, 'bin/32') for p in extraSearchPaths]) searchPaths.extend(['/usr/lib/groestlcoin/']) searchPaths.extend(os.getenv("PATH").split(':')) for p in searchPaths: testPath = os.path.join(p, 'groestlcoind') if os.path.exists(testPath): self.foundExe.append(testPath) try: locs = subprocess_check_output(['whereis', 'groestlcoind']).split() if len(locs) > 1: locs = filter( lambda x: os.path.basename(x) == 'groestlcoind', locs) LOGINFO('"whereis" returned: %s', str(locs)) self.foundExe.extend(locs) except: LOGEXCEPT('Error executing "whereis" command') # For logging purposes, check that the first answer matches one of the # extra search paths. There should be some kind of notification that # their supplied search path was invalid and we are using something else. if len(self.foundExe) > 0 and len(extraSearchPaths) > 0: foundIt = False for p in extraSearchPaths: if self.foundExe[0].startswith(p): foundIt = True if not foundIt: LOGERROR( 'Groestlcoind could not be found in the specified installation:' ) for p in extraSearchPaths: LOGERROR(' %s', p) LOGERROR('Groestlcoind is being started from:') LOGERROR(' %s', self.foundExe[0]) return self.foundExe
def readBitcoinConf(self, makeIfDNE=False): LOGINFO('Reading groestlcoin.conf file') bitconf = os.path.join(self.satoshiRoot, 'groestlcoin.conf') if not os.path.exists(bitconf): if not makeIfDNE: raise self.BitcoinDotConfError, 'Could not find groestlcoin.conf' else: LOGINFO('No groestlcoin.conf available. Creating it...') touchFile(bitconf) # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower() == 'xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR( '(it usually is, but Groestlcoin Armory cannot guarantee it ' ) LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on groestlcoin.conf') import ctypes username_u16 = ctypes.create_unicode_buffer(u'\0', 512) str_length = ctypes.c_int(512) ctypes.windll.Advapi32.GetUserNameW(ctypes.byref(username_u16), ctypes.byref(str_length)) CLI_OPTIONS.disableConfPermis = True #!!!GRS if not CLI_OPTIONS.disableConfPermis: import win32process LOGINFO('Setting permissions on groestlcoin.conf') cmd_icacls = [ u'icacls', bitconf, u'/inheritance:r', u'/grant:r', u'%s:F' % username_u16.value ] kargs = {} kargs['shell'] = True kargs['creationflags'] = win32process.CREATE_NO_WINDOW icacls_out = subprocess_check_output(cmd_icacls, **kargs) LOGINFO('icacls returned: %s', icacls_out) else: LOGWARN( 'Skipped setting permissions on groestlcoin.conf file') else: if not CLI_OPTIONS.disableConfPermis: LOGINFO('Setting permissions on groestlcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) else: LOGWARN('Skipped setting permissions on groestlcoin.conf file') with open(bitconf, 'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find( '#') > 1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x) > 1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # Look for rpcport, use default if not there self.bitconf['rpcport'] = int( self.bitconf.get('rpcport', BITCOIN_RPC_PORT)) # We must have a username and password. If not, append to file if not self.bitconf.has_key('rpcuser'): LOGDEBUG('No rpcuser: creating one') with open(bitconf, 'a') as f: f.write('\n') f.write('rpcuser=generated_by_armory\n') self.bitconf['rpcuser'] = '******' if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: creating one') with open(bitconf, 'a') as f: randBase58 = SecureBinaryData().GenerateRandom(32).toBinStr() randBase58 = binary_to_base58(randBase58) f.write('\n') f.write('rpcpassword=%s' % randBase58) self.bitconf['rpcpassword'] = randBase58 if not isASCII(self.bitconf['rpcuser']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcuser)!') if not isASCII(self.bitconf['rpcpassword']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcpassword)!') self.bitconf['host'] = '127.0.0.1'
def readBitcoinConf(self, makeIfDNE=False): LOGINFO('Reading bitcoin.conf file') bitconf = os.path.join(self.satoshiRoot, 'bitcoin.conf') if not os.path.exists(bitconf): if not makeIfDNE: raise self.BitcoinDotConfError, 'Could not find bitcoin.conf' else: LOGINFO('No bitcoin.conf available. Creating it...') touchFile(bitconf) # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower()=='xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR('(it usually is, but Armory cannot guarantee it ') LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on bitcoin.conf') import ctypes username_u16 = ctypes.create_unicode_buffer(u'\0', 512) str_length = ctypes.c_int(512) ctypes.windll.Advapi32.GetUserNameW(ctypes.byref(username_u16), ctypes.byref(str_length)) if not CLI_OPTIONS.disableConfPermis: import win32process LOGINFO('Setting permissions on bitcoin.conf') cmd_icacls = [u'icacls',bitconf,u'/inheritance:r',u'/grant:r', u'%s:F' % username_u16.value] kargs = {} kargs['shell'] = True kargs['creationflags'] = win32process.CREATE_NO_WINDOW icacls_out = subprocess_check_output(cmd_icacls, **kargs) LOGINFO('icacls returned: %s', icacls_out) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') else: if not CLI_OPTIONS.disableConfPermis: LOGINFO('Setting permissions on bitcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') with open(bitconf,'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find('#')>1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x)>1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # Look for rpcport, use default if not there self.bitconf['rpcport'] = int(self.bitconf.get('rpcport', BITCOIN_RPC_PORT)) # We must have a username and password. If not, append to file if not self.bitconf.has_key('rpcuser'): LOGDEBUG('No rpcuser: creating one') with open(bitconf,'a') as f: f.write('\n') f.write('rpcuser=generated_by_armory\n') self.bitconf['rpcuser'] = '******' if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: creating one') with open(bitconf,'a') as f: randBase58 = SecureBinaryData().GenerateRandom(32).toBinStr() randBase58 = binary_to_base58(randBase58) f.write('\n') f.write('rpcpassword=%s' % randBase58) self.bitconf['rpcpassword'] = randBase58 if not isASCII(self.bitconf['rpcuser']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcuser)!') if not isASCII(self.bitconf['rpcpassword']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcpassword)!') self.bitconf['host'] = '127.0.0.1'
def findBitcoind(self, extraSearchPaths=[]): self.foundExe = [] searchPaths = list(extraSearchPaths) # create a copy if OS_WINDOWS: # Making sure the search path argument comes with /daemon and /Bitcoin on Windows searchPaths.extend([os.path.join(sp, 'Bitcoin') for sp in searchPaths]) searchPaths.extend([os.path.join(sp, 'daemon') for sp in searchPaths]) possBaseDir = [] from platform import machine if '64' in machine(): possBaseDir.append(os.getenv("ProgramW6432")) possBaseDir.append(os.getenv('PROGRAMFILES(X86)')) else: possBaseDir.append(os.getenv('PROGRAMFILES')) # check desktop for links home = os.path.expanduser('~') desktop = os.path.join(home, 'Desktop') if os.path.exists(desktop): dtopfiles = os.listdir(desktop) for path in [os.path.join(desktop, fn) for fn in dtopfiles]: if 'bitcoin' in path.lower() and path.lower().endswith('.lnk'): import win32com.client shell = win32com.client.Dispatch('WScript.Shell') targ = shell.CreateShortCut(path).Targetpath targDir = os.path.dirname(targ) LOGINFO('Found Bitcoin-Core link on desktop: %s', targDir) possBaseDir.append( targDir ) # Also look in default place in ProgramFiles dirs # Now look at a few subdirs of the searchPaths.extend(possBaseDir) searchPaths.extend([os.path.join(p, 'Bitcoin', 'daemon') for p in possBaseDir]) searchPaths.extend([os.path.join(p, 'daemon') for p in possBaseDir]) searchPaths.extend([os.path.join(p, 'Bitcoin') for p in possBaseDir]) for p in searchPaths: testPath = os.path.join(p, 'bitcoind.exe') if os.path.exists(testPath): self.foundExe.append(testPath) else: # In case this was a downloaded copy, make sure we traverse to bin/64 dir if SystemSpecs.IsX64: searchPaths.extend([os.path.join(p, 'bin/64') for p in extraSearchPaths]) else: searchPaths.extend([os.path.join(p, 'bin/32') for p in extraSearchPaths]) searchPaths.extend(['/usr/lib/bitcoin/']) searchPaths.extend(os.getenv("PATH").split(':')) for p in searchPaths: testPath = os.path.join(p, 'bitcoind') if os.path.exists(testPath): self.foundExe.append(testPath) try: locs = subprocess_check_output(['whereis','bitcoind']).split() if len(locs)>1: locs = filter(lambda x: os.path.basename(x)=='bitcoind', locs) LOGINFO('"whereis" returned: %s', str(locs)) self.foundExe.extend(locs) except: LOGEXCEPT('Error executing "whereis" command') # For logging purposes, check that the first answer matches one of the # extra search paths. There should be some kind of notification that # their supplied search path was invalid and we are using something else. if len(self.foundExe)>0 and len(extraSearchPaths)>0: foundIt = False for p in extraSearchPaths: if self.foundExe[0].startswith(p): foundIt=True if not foundIt: LOGERROR('Bitcoind could not be found in the specified installation:') for p in extraSearchPaths: LOGERROR(' %s', p) LOGERROR('Bitcoind is being started from:') LOGERROR(' %s', self.foundExe[0]) return self.foundExe
def readBitcoinConf(self, makeIfDNE=False): LOGINFO('Reading bitcoin.conf file') bitconf = os.path.join( self.satoshiHome, 'bitcoin.conf' ) if not os.path.exists(bitconf): if not makeIfDNE: raise self.BitcoinDotConfError, 'Could not find bitcoin.conf' else: LOGINFO('No bitcoin.conf available. Creating it...') touchFile(bitconf) # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower()=='xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR('(it usually is, but Armory cannot guarantee it ') LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on bitcoin.conf') import win32api username = win32api.GetUserName() LOGINFO('Setting permissions on bitcoin.conf') cmd_icacls = ['icacls',bitconf,'/inheritance:r','/grant:r', '%s:F' % username] icacls_out = subprocess_check_output(cmd_icacls, shell=True) LOGINFO('icacls returned: %s', icacls_out) else: LOGINFO('Setting permissions on bitcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) with open(bitconf,'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find('#')>1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x)>1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # Look for rpcport, use default if not there self.bitconf['rpcport'] = int(self.bitconf.get('rpcport', BITCOIN_RPC_PORT)) # We must have a username and password. If not, append to file if not self.bitconf.has_key('rpcuser'): LOGDEBUG('No rpcuser: creating one') with open(bitconf,'a') as f: f.write('\n') f.write('rpcuser=generated_by_armory\n') self.bitconf['rpcuser'] = '******' if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: creating one') with open(bitconf,'a') as f: randBase58 = SecureBinaryData().GenerateRandom(32).toBinStr() randBase58 = binary_to_base58(randBase58) f.write('\n') f.write('rpcpassword=%s' % randBase58) self.bitconf['rpcpassword'] = randBase58 if not isASCII(self.bitconf['rpcuser']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcuser)!') if not isASCII(self.bitconf['rpcpassword']): LOGERROR('Non-ASCII character in bitcoin.conf (rpcpassword)!') self.bitconf['host'] = '127.0.0.1'
def readBitcoinConf(self): LOGINFO('Reading bitcoin.conf file') bitconf = os.path.join(self.satoshiRoot, 'bitcoin.conf') if os.path.exists(bitconf): # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower() == 'xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR( 'Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR('(it usually is, but Armory cannot guarantee it ') LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on bitcoin.conf') import ctypes username_u16 = ctypes.create_unicode_buffer(u'\0', 512) str_length = ctypes.c_int(512) ctypes.windll.Advapi32.GetUserNameW( ctypes.byref(username_u16), ctypes.byref(str_length)) if not CLI_OPTIONS.disableConfPermis: import win32process LOGINFO('Setting permissions on bitcoin.conf') cmd_icacls = [ u'icacls', bitconf, u'/inheritance:r', u'/grant:r', u'%s:F' % username_u16.value ] kargs = {} kargs['shell'] = True kargs['creationflags'] = win32process.CREATE_NO_WINDOW icacls_out = subprocess_check_output( cmd_icacls, **kargs) LOGINFO('icacls returned: %s', icacls_out) else: LOGWARN( 'Skipped setting permissions on bitcoin.conf file') else: if not CLI_OPTIONS.disableConfPermis: LOGINFO('Setting permissions on bitcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') with open(bitconf, 'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find( '#') > 1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [ l[:endchr(l)].strip().split('=') for l in f.readlines() ] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x) > 1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # If there is no password, use cookie auth if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: Using cookie Auth') self.readCookieFile() # defaults self.bitconf['host'] = '127.0.0.1' self.bitconf['rpcport'] = BITCOIN_RPC_PORT
def readBitcoinConf(self): LOGINFO('Reading bitcoin.conf file') bitconf = os.path.join(self.satoshiRoot, 'bitcoin.conf') if os.path.exists(bitconf): # Guarantee that bitcoin.conf file has very strict permissions if OS_WINDOWS: if OS_VARIANT[0].lower()=='xp': LOGERROR('Cannot set permissions correctly in XP!') LOGERROR('Please confirm permissions on the following file ') LOGERROR('are set to exclusive access only for your user ') LOGERROR('(it usually is, but Armory cannot guarantee it ') LOGERROR('on XP systems):') LOGERROR(' %s', bitconf) else: LOGINFO('Setting permissions on bitcoin.conf') import ctypes username_u16 = ctypes.create_unicode_buffer(u'\0', 512) str_length = ctypes.c_int(512) ctypes.windll.Advapi32.GetUserNameW(ctypes.byref(username_u16), ctypes.byref(str_length)) if not CLI_OPTIONS.disableConfPermis: import win32process LOGINFO('Setting permissions on bitcoin.conf') cmd_icacls = [u'icacls',bitconf,u'/inheritance:r',u'/grant:r', u'%s:F' % username_u16.value] kargs = {} kargs['shell'] = True kargs['creationflags'] = win32process.CREATE_NO_WINDOW icacls_out = subprocess_check_output(cmd_icacls, **kargs) LOGINFO('icacls returned: %s', icacls_out) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') else: if not CLI_OPTIONS.disableConfPermis: LOGINFO('Setting permissions on bitcoin.conf') os.chmod(bitconf, stat.S_IRUSR | stat.S_IWUSR) else: LOGWARN('Skipped setting permissions on bitcoin.conf file') with open(bitconf,'r') as f: # Find the last character of the each line: either a newline or '#' endchr = lambda line: line.find('#') if line.find('#')>1 else len(line) # Reduce each line to a list of key,value pairs separated with '=' allconf = [l[:endchr(l)].strip().split('=') for l in f.readlines()] # Need to convert to (x[0],x[1:]) in case the password has '=' in it allconfPairs = [[x[0], '='.join(x[1:])] for x in allconf if len(x)>1] # Convert the list of pairs to a dictionary self.bitconf = dict(allconfPairs) # If there is no password, use cookie auth if not self.bitconf.has_key('rpcpassword'): LOGDEBUG('No rpcpassword: Using cookie Auth') self.readCookieFile() # defaults self.bitconf['host'] = '127.0.0.1' self.bitconf['rpcport'] = BITCOIN_RPC_PORT