* cache pip requirements in dockerfile

* import blacklist into core
+ began work on blacklist command
* work on blacklist module
* modified dockerignore
This commit is contained in:
Kevin Froman 2018-08-10 17:13:58 -05:00
parent 1e37684163
commit 12d39393b4
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
6 changed files with 50 additions and 15 deletions

View File

@ -1,2 +1,4 @@
onionr/data/**/* onionr/data/**/*
onionr/data onionr/data
RUN-WINDOWS.bat
MY-RUN.sh

View File

@ -6,16 +6,17 @@ ENV HOME /root
#Install needed packages #Install needed packages
RUN apt update && apt install -y python3 python3-dev python3-pip tor RUN apt update && apt install -y python3 python3-dev python3-pip tor
#Add Onionr source WORKDIR /srv/
COPY . /root ADD ./requirements.txt /srv/requirements.txt
VOLUME /root/data
WORKDIR /root
RUN pip3 install -r requirements.txt RUN pip3 install -r requirements.txt
WORKDIR /root/
#Add Onionr source
COPY . /root/
VOLUME /root/data/
#Set upstart command #Set upstart command
#CMD (! ${ENABLE_TOR} || tor&) && python zeronet.py --ui_ip 0.0.0.0 --fileserver_port 26552
CMD bash CMD bash
#Expose ports #Expose ports

View File

@ -506,7 +506,6 @@ class API:
def authFail(err): def authFail(err):
self.requestFailed = True self.requestFailed = True
resp = Response("403") resp = Response("403")
return resp return resp
@app.errorhandler(401) @app.errorhandler(401)

View File

@ -21,6 +21,7 @@ import sqlite3, os, sys, time, math, base64, tarfile, getpass, simplecrypt, hash
from onionrblockapi import Block from onionrblockapi import Block
import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrexceptions, onionrvalues import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrexceptions, onionrvalues
import onionrblacklist
if sys.version_info < (3, 6): if sys.version_info < (3, 6):
try: try:
@ -71,6 +72,7 @@ class Core:
self._utils = onionrutils.OnionrUtils(self) self._utils = onionrutils.OnionrUtils(self)
# Initialize the crypto object # Initialize the crypto object
self._crypto = onionrcrypto.OnionrCrypto(self) self._crypto = onionrcrypto.OnionrCrypto(self)
self._blacklist = onionrblacklist.OnionrBlackList(self)
except Exception as error: except Exception as error:
logger.error('Failed to initialize core Onionr library.', error=error) logger.error('Failed to initialize core Onionr library.', error=error)

View File

@ -186,6 +186,8 @@ class Onionr:
'addaddress': self.addAddress, 'addaddress': self.addAddress,
'list-peers': self.listPeers, 'list-peers': self.listPeers,
'blacklist-block': self.banBlock,
'add-file': self.addFile, 'add-file': self.addFile,
'addfile': self.addFile, 'addfile': self.addFile,
'listconn': self.listConn, 'listconn': self.listConn,
@ -258,6 +260,19 @@ class Onionr:
def getCommands(self): def getCommands(self):
return self.cmds return self.cmds
def banBlock(self):
try:
ban = sys.argv[2]
except IndexError:
while True:
ban = logger.readline('Enter a block hash:')
if self.onionrUtils.validateHash(ban):
if not self.onionrCore._blacklist.inBlacklist(ban):
self.onionrCore._blacklist.addToDB(ban)
return
def listConn(self): def listConn(self):
self.onionrCore.daemonQueueAdd('connectedPeers') self.onionrCore.daemonQueueAdd('connectedPeers')

View File

@ -29,21 +29,29 @@ class OnionrBlackList:
return return
def inBlacklist(self, data): def inBlacklist(self, data):
return hashed = self._core._utils.bytesToStr(self._core._crypto.sha3Hash(data))
retData = False
if not hashed.isalnum():
raise Exception("Hashed data is not alpha numeric")
for i in self._dbExecute("select * from blacklist where hash='%s'" % (hashed,)):
retData = True # this only executes if an entry is present by that hash
break
return retData
def _dbExecute(self, toExec): def _dbExecute(self, toExec):
conn = sqlite3.connect(self.blacklistDB) conn = sqlite3.connect(self.blacklistDB)
c = conn.cursor() c = conn.cursor()
c.execute(toExec) retData = c.execute(toExec)
conn.commit() conn.commit()
conn.close() return retData
def deleteBeforeDate(self, date): def deleteBeforeDate(self, date):
# TODO, delete blacklist entries before date # TODO, delete blacklist entries before date
return return
def generateDB(self): def generateDB(self):
self._dbExecute'''CREATE TABLE blacklist( self._dbExecute('''CREATE TABLE blacklist(
hash text primary key not null, hash text primary key not null,
type text type text
); );
@ -53,10 +61,18 @@ class OnionrBlackList:
def clearDB(self): def clearDB(self):
self._dbExecute('''delete from blacklist;);''') self._dbExecute('''delete from blacklist;);''')
def getList(self):
data = self._dbExecute('select * from blacklist')
myList = []
for i in data:
myList.append(i[0])
return myList
def addToDB(self, data): def addToDB(self, data):
hashed = self._core._crypto.sha3Hash(data) '''Add to the blacklist. Intended to be block hash, block data, peers, or transport addresses'''
# we hash the data so we can remove data entirely from our node's disk
hashed = self._core._utils.bytesToStr(self._core._crypto.sha3Hash(data))
if not hashed.isalnum(): if not hashed.isalnum():
raise Exception("Hashed data is not alpha numeric") raise Exception("Hashed data is not alpha numeric")
insert = (hashed,) insert = (hashed,)
self._dbExecute('insert into blacklist (hash) VALUES(' + data + ');') self._dbExecute("insert into blacklist (hash) VALUES('%s');" % (hashed,))