Fix 2 DOS vulns, improve Onionr efficiency

This commit is contained in:
Arinerron 2018-06-06 18:54:35 -07:00
parent 9e9595b4ec
commit 1a6fa19323
2 changed files with 10 additions and 3 deletions

View File

@ -469,7 +469,7 @@ class Onionr:
with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
contents = ''
with open('static-data/default_plugin.py', 'rb') as file:
contents = file.read()
contents = file.read().decode()
# TODO: Fix $user. os.getlogin() is B U G G Y
main.write(contents.replace('$user', 'some random developer').replace('$date', datetime.datetime.now().strftime('%Y-%m-%d')).replace('$name', plugin_name))

View File

@ -111,7 +111,7 @@ class Block:
self.bheader = json.loads(self.getRaw()[:self.getRaw().index('\n')])
self.bcontent = self.getRaw()[self.getRaw().index('\n') + 1:]
self.bmetadata = json.loads(self.getHeader('meta'))
self.parent = (None if not 'parent' in self.getMetadata() else Block(self.getMetadata('parent')))
self.parent = (None if not 'parent' in self.getMetadata() else self.getMetadata('parent'))
self.btype = self.getMetadata('type')
self.powHash = self.getMetadata('powHash')
self.powToken = self.getMetadata('powToken')
@ -263,6 +263,14 @@ class Block:
- (Block): the Block's parent
'''
if self.parent == str:
if self.parent == self.getHash():
self.parent = self
elif Block.exists(self.parent):
self.parent = Block(self.getMetadata('parent'))
else:
self.parent = None
return self.parent
def getDate(self):
@ -459,7 +467,6 @@ class Block:
if relevant:
relevant_blocks.append(block)
if bool(reverse):
relevant_blocks.reverse()