* 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:
parent
1e37684163
commit
12d39393b4
@ -1,2 +1,4 @@
|
||||
onionr/data/**/*
|
||||
onionr/data
|
||||
RUN-WINDOWS.bat
|
||||
MY-RUN.sh
|
||||
|
15
Dockerfile
15
Dockerfile
@ -6,16 +6,17 @@ ENV HOME /root
|
||||
#Install needed packages
|
||||
RUN apt update && apt install -y python3 python3-dev python3-pip tor
|
||||
|
||||
#Add Onionr source
|
||||
COPY . /root
|
||||
VOLUME /root/data
|
||||
|
||||
WORKDIR /root
|
||||
|
||||
WORKDIR /srv/
|
||||
ADD ./requirements.txt /srv/requirements.txt
|
||||
RUN pip3 install -r requirements.txt
|
||||
|
||||
|
||||
WORKDIR /root/
|
||||
#Add Onionr source
|
||||
COPY . /root/
|
||||
VOLUME /root/data/
|
||||
|
||||
#Set upstart command
|
||||
#CMD (! ${ENABLE_TOR} || tor&) && python zeronet.py --ui_ip 0.0.0.0 --fileserver_port 26552
|
||||
CMD bash
|
||||
|
||||
#Expose ports
|
||||
|
@ -506,7 +506,6 @@ class API:
|
||||
def authFail(err):
|
||||
self.requestFailed = True
|
||||
resp = Response("403")
|
||||
|
||||
return resp
|
||||
|
||||
@app.errorhandler(401)
|
||||
|
@ -21,6 +21,7 @@ import sqlite3, os, sys, time, math, base64, tarfile, getpass, simplecrypt, hash
|
||||
from onionrblockapi import Block
|
||||
|
||||
import onionrutils, onionrcrypto, onionrproofs, onionrevents as events, onionrexceptions, onionrvalues
|
||||
import onionrblacklist
|
||||
|
||||
if sys.version_info < (3, 6):
|
||||
try:
|
||||
@ -71,6 +72,7 @@ class Core:
|
||||
self._utils = onionrutils.OnionrUtils(self)
|
||||
# Initialize the crypto object
|
||||
self._crypto = onionrcrypto.OnionrCrypto(self)
|
||||
self._blacklist = onionrblacklist.OnionrBlackList(self)
|
||||
|
||||
except Exception as error:
|
||||
logger.error('Failed to initialize core Onionr library.', error=error)
|
||||
|
@ -186,6 +186,8 @@ class Onionr:
|
||||
'addaddress': self.addAddress,
|
||||
'list-peers': self.listPeers,
|
||||
|
||||
'blacklist-block': self.banBlock,
|
||||
|
||||
'add-file': self.addFile,
|
||||
'addfile': self.addFile,
|
||||
'listconn': self.listConn,
|
||||
@ -258,6 +260,19 @@ class Onionr:
|
||||
def getCommands(self):
|
||||
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):
|
||||
self.onionrCore.daemonQueueAdd('connectedPeers')
|
||||
|
||||
|
@ -29,21 +29,29 @@ class OnionrBlackList:
|
||||
return
|
||||
|
||||
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):
|
||||
conn = sqlite3.connect(self.blacklistDB)
|
||||
c = conn.cursor()
|
||||
c.execute(toExec)
|
||||
retData = c.execute(toExec)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return retData
|
||||
|
||||
def deleteBeforeDate(self, date):
|
||||
# TODO, delete blacklist entries before date
|
||||
return
|
||||
|
||||
def generateDB(self):
|
||||
self._dbExecute'''CREATE TABLE blacklist(
|
||||
self._dbExecute('''CREATE TABLE blacklist(
|
||||
hash text primary key not null,
|
||||
type text
|
||||
);
|
||||
@ -53,10 +61,18 @@ class OnionrBlackList:
|
||||
def clearDB(self):
|
||||
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):
|
||||
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():
|
||||
raise Exception("Hashed data is not alpha numeric")
|
||||
insert = (hashed,)
|
||||
self._dbExecute('insert into blacklist (hash) VALUES(' + data + ');')
|
||||
self._dbExecute("insert into blacklist (hash) VALUES('%s');" % (hashed,))
|
||||
|
Loading…
Reference in New Issue
Block a user