work on sites api for finding user sites

This commit is contained in:
Kevin Froman 2019-09-28 00:37:24 -05:00
parent 60f0ef0fef
commit 4df69b7842
4 changed files with 32 additions and 1 deletions

View File

@ -19,6 +19,8 @@ upload_list = home + 'upload-list.json'
config_file = home + 'config.json' config_file = home + 'config.json'
daemon_mark_file = app_root + '/daemon-true.txt' daemon_mark_file = app_root + '/daemon-true.txt'
site_cache = home + 'onionr-sites.txt'
tor_hs_address_file = home + 'hs/hostname' tor_hs_address_file = home + 'hs/hostname'
run_check_file = home + '.runcheck' run_check_file = home + '.runcheck'

View File

@ -19,10 +19,16 @@
''' '''
import base64 import base64
import binascii import binascii
import unpaddedbase32
from flask import Blueprint, Response, request, abort from flask import Blueprint, Response, request, abort
from onionrblocks import onionrblockapi from onionrblocks import onionrblockapi
import onionrexceptions import onionrexceptions
from onionrutils import stringvalidators from onionrutils import stringvalidators
from utils import safezip
from onionrutils import mnemonickeys
site_api = Blueprint('siteapi', __name__) site_api = Blueprint('siteapi', __name__)
@ -30,6 +36,12 @@ site_api = Blueprint('siteapi', __name__)
def site(name): def site(name):
bHash = name bHash = name
resp = 'Not Found' resp = 'Not Found'
if '-' in name:
name = mnemonickeys.get_base32(name)
if stringvalidators.validate_pub_key(name):
name = unpaddedbase32.repad(name)
if stringvalidators.validate_hash(bHash): if stringvalidators.validate_hash(bHash):
try: try:
resp = onionrblockapi.Block(bHash).bcontent resp = onionrblockapi.Block(bHash).bcontent

View File

@ -0,0 +1,10 @@
import onionrexceptions
from onionrutils import mnemonickeys
from onionrutils import stringvalidators
def find_site(user_id: str)->str:
if '-' in user_id: user_id = mnemonickeys.get_base32(user_id)
if not stringvalidators.validate_pub_key(user_id): raise onionrexceptions.InvalidPubkey
#for

7
onionr/utils/safezip.py Normal file
View File

@ -0,0 +1,7 @@
# safe unzip https://stackoverflow.com/a/36583849
def safe_unzip(zip_file, extractpath='.'):
with zipfile.ZipFile(zip_file, 'r') as zf:
for member in zf.infolist():
abspath = os.path.abspath(os.path.join(extractpath, member.filename))
if abspath.startswith(os.path.abspath(extractpath)):
zf.extract(member, extractpath)