Merge branch 'master' into lan

This commit is contained in:
Kevin 2020-06-13 18:04:20 -05:00
commit 3c7b090a4e
4 changed files with 47 additions and 36 deletions

View File

@ -13,8 +13,6 @@
<img src='https://img.shields.io/github/license/beardog108/onionr'> <img src='https://gitlab.com/beardog/Onionr/badges/master/build.svg'> <img src='https://img.shields.io/badge/docker%20%F0%9F%90%8B-supported-success'> <img src='https://img.shields.io/badge/python%20version%20%F0%9F%90%8D-3.7+-blue'> <img src='https://img.shields.io/github/commit-activity/m/beardog108/onionr'> <img src='https://img.shields.io/github/license/beardog108/onionr'> <img src='https://gitlab.com/beardog/Onionr/badges/master/build.svg'> <img src='https://img.shields.io/badge/docker%20%F0%9F%90%8B-supported-success'> <img src='https://img.shields.io/badge/python%20version%20%F0%9F%90%8D-3.7+-blue'> <img src='https://img.shields.io/github/commit-activity/m/beardog108/onionr'>
<img src='https://onionr.net/block-count.svg' alt='current stored block count'>
<a href='https://www.reddit.com/r/onionr'><img src = 'https://img.shields.io/reddit/subreddit-subscribers/onionr?style=social'></a> <a href='https://twitter.com/onionrnet'><img src='https://img.shields.io/twitter/follow/onionrnet?style=social'></a> <a href='https://www.reddit.com/r/onionr'><img src = 'https://img.shields.io/reddit/subreddit-subscribers/onionr?style=social'></a> <a href='https://twitter.com/onionrnet'><img src='https://img.shields.io/twitter/follow/onionrnet?style=social'></a>
| | | | | | | |

View File

@ -1,8 +1,21 @@
""" """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
view and interact with onionr sites view and interact with onionr sites
""" """
import base64
import binascii
import mimetypes
import unpaddedbase32
from flask import Blueprint, Response, request, abort
from onionrblocks import onionrblockapi
import onionrexceptions
from onionrutils import stringvalidators
from utils import safezip
from onionrutils import mnemonickeys
from . import sitefiles
""" """
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -17,19 +30,7 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
""" """
import base64
import binascii
import mimetypes
import unpaddedbase32
from flask import Blueprint, Response, request, abort
from onionrblocks import onionrblockapi
import onionrexceptions
from onionrutils import stringvalidators
from onionrutils import mnemonickeys
from . import sitefiles
site_api = Blueprint('siteapi', __name__) site_api = Blueprint('siteapi', __name__)

View File

@ -1,21 +1,6 @@
""" """Onionr - Private P2P Communication.
Onionr - Private P2P Communication
Read onionr site files Read onionr site files
"""
"""
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
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 typing import Union, Tuple from typing import Union, Tuple
import tarfile import tarfile
@ -32,30 +17,52 @@ from onionrblocks import insert
from onionrtypes import UserID, DeterministicKeyPassphrase, BlockHash from onionrtypes import UserID, DeterministicKeyPassphrase, BlockHash
from onionrcrypto import generate_deterministic from onionrcrypto import generate_deterministic
"""
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
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
def find_site_gzip(user_id: str)->tarfile.TarFile: def find_site_gzip(user_id: str)->tarfile.TarFile:
"""Return verified site tar object""" """Return verified site tar object"""
sites = blockmetadb.get_blocks_by_type('osite') sites = blockmetadb.get_blocks_by_type('osite')
user_site = None user_site = None
unpadded_user = user_id
user_id = unpaddedbase32.repad(user_id) user_id = unpaddedbase32.repad(user_id)
for site in sites: for site in sites:
block = onionrblockapi.Block(site) block = onionrblockapi.Block(site)
if block.isSigner(user_id): if block.isSigner(user_id) or block.isSigner(unpadded_user):
user_site = block user_site = block
if not user_site is None: if not user_site is None:
return tarfile.open(fileobj=io.BytesIO(user_site.bcontent), mode='r') return tarfile.open(fileobj=io.BytesIO(user_site.bcontent), mode='r')
return None return None
def get_file(user_id, file)->Union[bytes, None]: def get_file(user_id, file)->Union[bytes, None]:
"""Get a site file content""" """Get a site file content"""
ret_data = "" ret_data = ""
site = find_site_gzip(user_id) site = find_site_gzip(user_id)
if file.endswith('/'):
file += 'index.html'
if site is None: return None if site is None: return None
for t_file in site.getmembers(): for t_file in site.getmembers():
if t_file.name.replace('./', '') == file: if t_file.name.replace('./', '') == file:
return site.extractfile(t_file) return site.extractfile(t_file)
return None return None
def create_site(admin_pass: DeterministicKeyPassphrase, directory:str='.')->Tuple[UserID, BlockHash]: def create_site(admin_pass: DeterministicKeyPassphrase, directory:str='.')->Tuple[UserID, BlockHash]:
public_key, private_key = generate_deterministic(admin_pass) public_key, private_key = generate_deterministic(admin_pass)

View File

@ -3,6 +3,7 @@
Command to create Onionr mutli-page sites Command to create Onionr mutli-page sites
""" """
import sys import sys
import os
import getpass import getpass
from httpapi import onionrsitesapi from httpapi import onionrsitesapi
@ -27,8 +28,11 @@ from etc import onionrvalues
def create_multipage_site(): def create_multipage_site():
"""Command to create mutlipage sites with specified dir and password.""" """Command to create mutlipage sites with specified dir and password."""
error_encountered = False error_encountered = False
orig_dir = os.getcwd()
try: try:
directory = sys.argv[2] directory = sys.argv[2]
os.chdir(directory)
directory = '.'
except IndexError: except IndexError:
directory = '.' directory = '.'
try: try:
@ -51,7 +55,7 @@ If you want to update your site later you must remember the passphrase.''',
error_encountered = True error_encountered = True
logger.error( logger.error(
f'Passphrase must be at least {onionrvalues.PASSWORD_LENGTH}' + f'Passphrase must be at least {onionrvalues.PASSWORD_LENGTH}' +
'characters.', terminal=True) ' characters.', terminal=True)
if error_encountered: if error_encountered:
sys.exit(1) sys.exit(1)
@ -61,6 +65,7 @@ If you want to update your site later you must remember the passphrase.''',
results = (results[0].replace('=', ''), results[1]) results = (results[0].replace('=', ''), results[1])
logger.info(f'Site address {results[0]}', terminal=True) logger.info(f'Site address {results[0]}', terminal=True)
logger.info(f'Block for this version {results[1]}', terminal=True) logger.info(f'Block for this version {results[1]}', terminal=True)
os.chdir(orig_dir)
create_multipage_site.onionr_help = "[directory path " # type: ignore create_multipage_site.onionr_help = "[directory path " # type: ignore