diff --git a/.dockerignore b/.dockerignore index d76a75c1..4a0c253e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ onionr/data/**/* onionr/data +RUN-WINDOWS.bat +MY-RUN.sh diff --git a/Dockerfile b/Dockerfile index 7331dd6f..7b7feb20 100644 --- a/Dockerfile +++ b/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 diff --git a/onionr/api.py b/onionr/api.py index 1f68a49d..90a3b83e 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -506,7 +506,6 @@ class API: def authFail(err): self.requestFailed = True resp = Response("403") - return resp @app.errorhandler(401) diff --git a/onionr/core.py b/onionr/core.py index b3857393..76f55652 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -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) diff --git a/onionr/onionr.py b/onionr/onionr.py index c4c4529d..c6357089 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -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') diff --git a/onionr/onionrblacklist.py b/onionr/onionrblacklist.py index 7261cf4f..52d0957b 100644 --- a/onionr/onionrblacklist.py +++ b/onionr/onionrblacklist.py @@ -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,))