Fix gettransports
parent
039d791b90
commit
026901ce90
|
@ -9,7 +9,6 @@ def detect_disk_access(info):
|
|||
|
||||
whitelist = [identify_home(), 'onionr/src/', '/site-packages/', '/usr/lib64/']
|
||||
|
||||
|
||||
for item in whitelist:
|
||||
if item in info[0]:
|
||||
return
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Public endpoints to get block data and lists
|
||||
'''
|
||||
'''
|
||||
Public endpoints to get block data and lists
|
||||
"""
|
||||
from flask import Response, abort
|
||||
|
||||
import config
|
||||
from onionrutils import bytesconverter, stringvalidators
|
||||
from coredb import blockmetadb
|
||||
from utils import reconstructhash
|
||||
from onionrblocks import BlockList
|
||||
from .. import apiutils
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
|
@ -16,13 +23,9 @@
|
|||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
from flask import Response, abort
|
||||
import config
|
||||
from onionrutils import bytesconverter, stringvalidators
|
||||
from coredb import blockmetadb
|
||||
from utils import reconstructhash
|
||||
from .. import apiutils
|
||||
"""
|
||||
|
||||
|
||||
def get_public_block_list(publicAPI, request):
|
||||
# Provide a list of our blocks, with a date offset
|
||||
dateAdjust = request.args.get('date')
|
||||
|
@ -37,15 +40,16 @@ def get_public_block_list(publicAPI, request):
|
|||
share_list += '%s\n' % (reconstructhash.deconstruct_hash(b),)
|
||||
return Response(share_list)
|
||||
|
||||
|
||||
def get_block_data(publicAPI, data):
|
||||
'''data is the block hash in hex'''
|
||||
"""data is the block hash in hex"""
|
||||
resp = ''
|
||||
if stringvalidators.validate_hash(data):
|
||||
if not config.get('general.hide_created_blocks', True) or data not in publicAPI.hideBlocks:
|
||||
if data in blockmetadb.get_block_list():
|
||||
if data in publicAPI._too_many.get(BlockList).get():
|
||||
block = apiutils.GetBlockData().get_block_data(data, raw=True, decrypt=False)
|
||||
try:
|
||||
block = block.encode() # Encode in case data is binary
|
||||
block = block.encode('utf-8') # Encode in case data is binary
|
||||
except AttributeError:
|
||||
if len(block) == 0:
|
||||
abort(404)
|
||||
|
|
|
@ -32,9 +32,11 @@ class PublicAPISecurity:
|
|||
"""Validate request has the correct hostname"""
|
||||
# If high security level, deny requests to public
|
||||
# (HS should be disabled anyway for Tor, but might not be for I2P)
|
||||
g.is_onionr_client = False
|
||||
transports = gettransports.get()
|
||||
if public_api.config.get('general.security_level', default=1) > 0:
|
||||
abort(403)
|
||||
|
||||
if request.host not in transports:
|
||||
# Abort conn if wrong HTTP hostname, to prevent DNS rebinding
|
||||
abort(403)
|
||||
|
@ -57,10 +59,12 @@ class PublicAPISecurity:
|
|||
NON_NETWORK_HEADERS = ('Content-Security-Policy', 'X-Frame-Options',
|
||||
'X-Content-Type-Options', 'Feature-Policy',
|
||||
'Clear-Site-Data', 'Referrer-Policy')
|
||||
|
||||
try:
|
||||
if g.is_onionr_client:
|
||||
for header in NON_NETWORK_HEADERS: del resp.headers[header]
|
||||
except AttributeError:
|
||||
abort(403)
|
||||
|
||||
public_api.lastRequest = epoch.get_rounded_epoch(roundS=5)
|
||||
return resp
|
||||
|
|
|
@ -52,7 +52,7 @@ def learn_services(lan_client):
|
|||
if 'onionr' not in service_ips:
|
||||
continue
|
||||
service_ips = service_ips.replace('onionr-', '').split('-')
|
||||
print(service_ips)
|
||||
|
||||
port = 0
|
||||
for service in service_ips:
|
||||
try:
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Output raw data to file or terminal
|
||||
'''
|
||||
'''
|
||||
Output raw data to file or terminal
|
||||
"""
|
||||
import sys
|
||||
import os
|
||||
from . import settings, colors
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
|
@ -16,14 +18,14 @@
|
|||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import sys, os
|
||||
from . import settings, colors
|
||||
"""
|
||||
colors = colors.Colors
|
||||
|
||||
|
||||
def raw(data, fd = sys.stdout, terminal = False):
|
||||
'''
|
||||
"""
|
||||
Outputs raw data to console without formatting
|
||||
'''
|
||||
"""
|
||||
|
||||
if terminal and (settings.get_settings() & settings.OUTPUT_TO_CONSOLE):
|
||||
try:
|
||||
|
@ -33,8 +35,14 @@ def raw(data, fd = sys.stdout, terminal = False):
|
|||
if settings.get_settings() & settings.OUTPUT_TO_FILE:
|
||||
fdata = ''
|
||||
try:
|
||||
with open(settings._outputfile, 'r') as file:
|
||||
fdata = file.read()
|
||||
for _ in range(5):
|
||||
try:
|
||||
with open(settings._outputfile, 'r') as file:
|
||||
fdata = file.read()
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
else:
|
||||
break
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
fdata = fdata + '\n' + data
|
||||
|
@ -43,4 +51,4 @@ def raw(data, fd = sys.stdout, terminal = False):
|
|||
fdata.pop(0)
|
||||
fdata = '\n'.join(fdata)
|
||||
with open(settings._outputfile, 'w') as file:
|
||||
file.write(fdata)
|
||||
file.write(fdata)
|
||||
|
|
|
@ -1,9 +1,18 @@
|
|||
'''
|
||||
Onionr - Private P2P Communication
|
||||
"""Onionr - Private P2P Communication.
|
||||
|
||||
Proof of work module
|
||||
'''
|
||||
'''
|
||||
Proof of work module
|
||||
"""
|
||||
import multiprocessing, time, math, threading, binascii, sys, json
|
||||
import nacl.encoding, nacl.hash, nacl.utils
|
||||
|
||||
import config
|
||||
import logger
|
||||
from onionrblocks import onionrblockapi, storagecounter
|
||||
from onionrutils import bytesconverter
|
||||
from onionrcrypto import hashers
|
||||
|
||||
from .blocknoncestart import BLOCK_NONCE_START_INT
|
||||
"""
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
|
@ -16,31 +25,22 @@
|
|||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
'''
|
||||
import multiprocessing, time, math, threading, binascii, sys, json
|
||||
import nacl.encoding, nacl.hash, nacl.utils
|
||||
|
||||
import config, logger
|
||||
from onionrblocks import onionrblockapi, storagecounter
|
||||
from onionrutils import bytesconverter
|
||||
from onionrcrypto import hashers
|
||||
|
||||
from .blocknoncestart import BLOCK_NONCE_START_INT
|
||||
"""
|
||||
config.reload()
|
||||
|
||||
def getDifficultyModifier():
|
||||
'''returns the difficulty modifier for block storage based
|
||||
"""returns the difficulty modifier for block storage based
|
||||
on a variety of factors, currently only disk use.
|
||||
'''
|
||||
"""
|
||||
percentUse = storagecounter.StorageCounter().get_percent()
|
||||
difficultyIncrease = math.floor(4 * percentUse) # difficulty increase is a step function
|
||||
|
||||
return difficultyIncrease
|
||||
|
||||
def getDifficultyForNewBlock(data):
|
||||
'''
|
||||
"""
|
||||
Get difficulty for block. Accepts size in integer, Block instance, or str/bytes full block contents
|
||||
'''
|
||||
"""
|
||||
if isinstance(data, onionrblockapi.Block):
|
||||
dataSizeInBytes = len(bytesconverter.str_to_bytes(data.getRaw()))
|
||||
else:
|
||||
|
@ -54,15 +54,15 @@ def getDifficultyForNewBlock(data):
|
|||
return retData
|
||||
|
||||
def getHashDifficulty(h: str):
|
||||
'''
|
||||
"""
|
||||
Return the amount of leading zeroes in a hex hash string (hexHash)
|
||||
'''
|
||||
"""
|
||||
return len(h) - len(h.lstrip('0'))
|
||||
|
||||
def hashMeetsDifficulty(hexHash):
|
||||
'''
|
||||
"""
|
||||
Return bool for a hash string to see if it meets pow difficulty defined in config
|
||||
'''
|
||||
"""
|
||||
hashDifficulty = getHashDifficulty(hexHash)
|
||||
|
||||
try:
|
||||
|
@ -138,9 +138,9 @@ class POW:
|
|||
self.difficulty = newDiff
|
||||
|
||||
def getResult(self):
|
||||
'''
|
||||
"""
|
||||
Returns the result then sets to false, useful to automatically clear the result
|
||||
'''
|
||||
"""
|
||||
|
||||
try:
|
||||
retVal = self.result
|
||||
|
@ -151,9 +151,9 @@ class POW:
|
|||
return retVal
|
||||
|
||||
def waitForResult(self):
|
||||
'''
|
||||
"""
|
||||
Returns the result only when it has been found, False if not running and not found
|
||||
'''
|
||||
"""
|
||||
result = False
|
||||
try:
|
||||
while True:
|
||||
|
|
|
@ -21,11 +21,28 @@ import filepaths
|
|||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
files = [filepaths.tor_hs_address_file]
|
||||
files = []
|
||||
|
||||
|
||||
class _GetTor:
|
||||
def __init__(self):
|
||||
self.tor_hs = None
|
||||
|
||||
def get(self):
|
||||
if self.tor_hs is None:
|
||||
try:
|
||||
with open(filepaths.tor_hs_address_file, 'r') as transport_file:
|
||||
self.tor_hs = transport_file.read().strip()
|
||||
if not self.tor_hs:
|
||||
self.tor_hs = None
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return self.tor_hs
|
||||
|
||||
_tor_getter = _GetTor()
|
||||
|
||||
def get():
|
||||
transports = []
|
||||
transports = [_tor_getter.get()]
|
||||
for file in files:
|
||||
try:
|
||||
with open(file, 'r') as transport_file:
|
||||
|
|
Loading…
Reference in New Issue