Solved issues bytes in the protocal for checkIPAddress

This commit is contained in:
jai.s 2019-12-17 13:06:43 +05:30
parent 9b1088b2e2
commit e21e2a7854
No known key found for this signature in database
GPG Key ID: 360CFA25EFC67D12
4 changed files with 31 additions and 15 deletions

View File

@ -572,10 +572,23 @@ class sqlThread(threading.Thread):
rowcount = 0 rowcount = 0
# print 'item', item # print 'item', item
# print 'parameters', parameters # print 'parameters', parameters
# print('++++454++++++++++++++++++++++++')
# print ('parameters')
# print (parameters)
# print ('+++++++++++++++++++++++++++++')
try:
if 'sent' == parameters[1] and 'B' in parameters[0]:
item = '''SELECT toaddress, fromaddress, subject, message, status, ackdata, lastactiontime FROM sent WHERE fromaddress = ? ORDER BY lastactiontime DESC '''
parameters = (parameters[0],)
except (IndexError,TypeError) as e:
pass
try: try:
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
rowcount = self.cur.rowcount rowcount = self.cur.rowcount
except Exception as err: except Exception as err:
print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
print('inside the expectation')
print('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@')
if str(err) == 'database or disk is full': if str(err) == 'database or disk is full':
logger.fatal( logger.fatal(
'(while cur.execute) Alert: Your disk or data storage volume is full.' '(while cur.execute) Alert: Your disk or data storage volume is full.'

View File

@ -29,7 +29,6 @@ sqlLock = threading.Lock()
def sqlQuery(sqlStatement, *args): def sqlQuery(sqlStatement, *args):
""" """
Query sqlite and return results Query sqlite and return results
:param str sqlStatement: SQL statement string :param str sqlStatement: SQL statement string
:param list args: SQL query parameters :param list args: SQL query parameters
:rtype: list :rtype: list

View File

@ -142,16 +142,14 @@ def network_group(host):
def checkIPAddress(host, private=False): def checkIPAddress(host, private=False):
"""
Returns hostStandardFormat if it is a valid IP address, """Returns hostStandardFormat if it is a valid IP address, otherwise returns False"""
otherwise returns False if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF'.encode('raw_unicode_escape'):
"""
if host[0:12] == '\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xFF\xFF':
hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:]) hostStandardFormat = socket.inet_ntop(socket.AF_INET, host[12:])
return checkIPv4Address(host[12:], hostStandardFormat, private) return checkIPv4Address(host[12:], hostStandardFormat, private)
elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43': elif host[0:6] == '\xfd\x87\xd8\x7e\xeb\x43'.encode('raw_unicode_escape'):
# Onion, based on BMD/bitcoind # Onion, based on BMD/bitcoind
hostStandardFormat = base64.b32encode(host[6:]).lower() + ".onion" hostStandardFormat = base64.b32encode(host[6:]) + ".onion".encode()
if private: if private:
return False return False
return hostStandardFormat return hostStandardFormat
@ -168,22 +166,21 @@ def checkIPAddress(host, private=False):
def checkIPv4Address(host, hostStandardFormat, private=False): def checkIPv4Address(host, hostStandardFormat, private=False):
"""
Returns hostStandardFormat if it is an IPv4 address, """Returns hostStandardFormat if it is an IPv4 address, otherwise returns False"""
otherwise returns False
""" if host[0] == '\x7F'.encode('raw_unicode_escape'): # 127/8
if host[0] == '\x7F': # 127/8
if not private: if not private:
logger.debug( logger.debug(
'Ignoring IP address in loopback range: %s', 'Ignoring IP address in loopback range: %s',
hostStandardFormat) hostStandardFormat)
return hostStandardFormat if private else False return hostStandardFormat if private else False
if host[0] == '\x0A': # 10/8 if host[0] == '\x0A'.encode('raw_unicode_escape'): # 10/8
if not private: if not private:
logger.debug( logger.debug(
'Ignoring IP address in private range: %s', hostStandardFormat) 'Ignoring IP address in private range: %s', hostStandardFormat)
return hostStandardFormat if private else False return hostStandardFormat if private else False
if host[0:2] == '\xC0\xA8': # 192.168/16 if host[0:2] == '\xC0\xA8'.encode('raw_unicode_escape'): # 192.168/16
if not private: if not private:
logger.debug( logger.debug(
'Ignoring IP address in private range: %s', hostStandardFormat) 'Ignoring IP address in private range: %s', hostStandardFormat)

View File

@ -28,6 +28,7 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
self.lock = RLock() self.lock = RLock()
def __contains__(self, hash_): def __contains__(self, hash_):
print('----------contains------------------')
with self.lock: with self.lock:
if hash_ in self._objects: if hash_ in self._objects:
return True return True
@ -38,6 +39,7 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
return True return True
def __getitem__(self, hash_): def __getitem__(self, hash_):
print('----------__getitem__------------------')
with self.lock: with self.lock:
if hash_ in self._inventory: if hash_ in self._inventory:
return self._inventory[hash_] return self._inventory[hash_]
@ -49,25 +51,30 @@ class SqliteInventory(InventoryStorage): # pylint: disable=too-many-ancestors
return InventoryItem(*rows[0]) return InventoryItem(*rows[0])
def __setitem__(self, hash_, value): def __setitem__(self, hash_, value):
print('----------__setitem__------------------')
with self.lock: with self.lock:
value = InventoryItem(*value) value = InventoryItem(*value)
self._inventory[hash_] = value self._inventory[hash_] = value
self._objects[hash_] = value.stream self._objects[hash_] = value.stream
def __delitem__(self, hash_): def __delitem__(self, hash_):
print('----------__delitem__------------------')
raise NotImplementedError raise NotImplementedError
def __iter__(self): def __iter__(self):
print('----------__iter__------------------')
with self.lock: with self.lock:
hashes = self._inventory.keys()[:] hashes = self._inventory.keys()[:]
hashes += (x for x, in sqlQuery('SELECT hash FROM inventory')) hashes += (x for x, in sqlQuery('SELECT hash FROM inventory'))
return hashes.__iter__() return hashes.__iter__()
def __len__(self): def __len__(self):
print('----------__len__------------------')
with self.lock: with self.lock:
return len(self._inventory) + sqlQuery('SELECT count(*) FROM inventory')[0][0] return len(self._inventory) + sqlQuery('SELECT count(*) FROM inventory')[0][0]
def by_type_and_tag(self, objectType, tag): def by_type_and_tag(self, objectType, tag):
print('----------by_type_and_tag------------------')
with self.lock: with self.lock:
values = [value for value in self._inventory.values() if value.type == objectType and value.tag == tag] values = [value for value in self._inventory.values() if value.type == objectType and value.tag == tag]
values += (InventoryItem(*value) for value in sqlQuery( values += (InventoryItem(*value) for value in sqlQuery(