renamed onionr dir and bugfixes/linting progress

This commit is contained in:
Kevin Froman 2019-11-20 04:52:50 -06:00
parent 2b996da17f
commit 720efe4fca
226 changed files with 179 additions and 142 deletions

1
.env Normal file
View File

@ -0,0 +1 @@
PYTHONPATH=./venv/bin/python3.7

42
.gitignore vendored
View File

@ -1,25 +1,22 @@
__pycache__/ __pycache__/
onionr/data/config.ini src/data/config.ini
onionr/data/*.db src/data/*.db
onionr/data-old/* src/data-old/*
onionr/data* src/data*
onionr/tor src/tor
onionr/tor.exe src/tor.exe
onionr/testdata src/testdata
onionr/*.pyc src/*.pyc
onionr/*.log src/*.log
onionr/data/hs/hostname src/data/hs/hostname
onionr/data/* src/data/*
onionr/data-backup/* src/data-backup/*
onionr/gnupg/*
run.sh run.sh
onionr/data-encrypted.dat src/.onionr-lock
onionr/.onionr-lock
core
.vscode/* .vscode/*
venv/* venv/*
onionr/fs* src/fs*
onionr/tmp/* src/tmp/*
testdata/* testdata/*
*.dll *.dll
*.exe *.exe
@ -29,13 +26,12 @@ dist/*
# log files # log files
output.log output.log
*.log *.log
onionr/output.log src/output.log
onionr/*.log src/*.log
onionr/data/output.log src/data/output.log
onionr/data/*.log src/data/*.log
# package files # package files
onionr-*.pkg.tar.gz onionr-*.pkg.tar.gz
pkg/ pkg/
src/
spawnnodes.py spawnnodes.py

View File

@ -2,7 +2,7 @@
rm -rf dist rm -rf dist
mkdir dist mkdir dist
mkdir dist/onionr/ mkdir dist/onionr/
cp -t dist/onionr/ -r docs static-data install onionr onionr.sh start-daemon.sh setprofile.sh cp -t dist/onionr/ -r docs static-data install src onionr.sh start-daemon.sh setprofile.sh
cp *.md dist/onionr/ cp *.md dist/onionr/
PIP_USER=false PIP_USER=false
export PIP_USER export PIP_USER

View File

@ -2,5 +2,5 @@
ORIG_ONIONR_RUN_DIR=`pwd` ORIG_ONIONR_RUN_DIR=`pwd`
export ORIG_ONIONR_RUN_DIR export ORIG_ONIONR_RUN_DIR
cd "$(dirname "$0")" cd "$(dirname "$0")"
cd onionr cd src
./__init__.py "$@" ./__init__.py "$@"

View File

@ -1,13 +0,0 @@
import os, filepaths
def _safe_remove(path):
try:
os.remove(path)
except FileNotFoundError:
pass
def delete_run_files():
_safe_remove(filepaths.public_API_host_file)
_safe_remove(filepaths.private_API_host_file)
_safe_remove(filepaths.daemon_mark_file)
_safe_remove(filepaths.lock_file)

View File

@ -3,5 +3,5 @@ echo This script is only intended for use in Onionr development, as it uses a ra
set ONIONR_HOME=data%random% set ONIONR_HOME=data%random%
echo Using profile: %ONIONR_HOME% echo Using profile: %ONIONR_HOME%
setlocal setlocal
chdir onionr chdir src
python __init__.py %* python __init__.py %*

View File

@ -1,4 +1,4 @@
@echo off @echo off
setlocal setlocal
chdir onionr chdir src
python __init__.py %* python __init__.py %*

View File

@ -22,30 +22,29 @@
''' '''
# Set the user's locale for encoding reasons # Set the user's locale for encoding reasons
import locale import locale # noqa
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
ran_as_script = False ran_as_script = False
if __name__ == "__main__": ran_as_script = True if __name__ == "__main__": ran_as_script = True
# Import standard libraries # Import standard libraries
import sys import sys # noqa
# 3rd party lib imports
# Ensure that PySocks is installed
try: try:
from urllib3.contrib.socks import SOCKSProxyManager from etc import dependencycheck # noqa
except ModuleNotFoundError: except ModuleNotFoundError as e:
# check here or else we get error when onionr runs with tor print('Onionr needs ' + str(e) + ' installed')
raise ModuleNotFoundError("You need the PySocks module (for use with socks5 proxy to use Tor)")
# Onionr imports # Onionr imports
from etc import onionrvalues # For different Onionr related constants such as versions from etc import onionrvalues # For different Onionr related constants such as versions
import onionrsetup as setup import onionrsetup as setup
min_ver = onionrvalues.MIN_PY_VERSION
# Ensure we have at least the minimum python version # Ensure we have at least the minimum python version
if sys.version_info[0] == 2 or sys.version_info[1] < onionrvalues.MIN_PY_VERSION: if sys.version_info[0] == 2 or sys.version_info[1] < min_ver:
sys.stderr.write('Error, Onionr requires Python 3.%s+\n' % (onionrvalues.MIN_PY_VERSION,)) sys.stderr.write('Error, Onionr requires Python 3.' + str(min_ver) + '\n')
sys.exit(1) sys.exit(1)
# Create Onionr data directories, must be done before most imports # Create Onionr data directories, must be done before most imports
@ -58,19 +57,21 @@ from onionrplugins import onionrevents as events
setup.setup_config() setup.setup_config()
setup.setup_default_plugins() setup.setup_default_plugins()
def onionr_main(): def onionr_main():
"""Onionr entrypoint, start command processor""" """Onionr entrypoint, start command processor"""
parser.register() parser.register()
if ran_as_script: if ran_as_script:
onionr_main() onionr_main()
# Cleanup standard out/err because Python refuses to do it itsself # Cleanup standard out/err because Python refuses to do it itsself
try: try:
sys.stderr.close() sys.stderr.close()
except (IOError, BrokenPipeError) as e: except (IOError, BrokenPipeError):
pass pass
try: try:
sys.stdout.close() sys.stdout.close()
except (IOError, BrokenPipeError) as e: except (IOError, BrokenPipeError):
pass pass

View File

@ -1,7 +1,7 @@
""" """
Onionr - Private P2P Communication Onionr - Private P2P Communication
Lib to keep Onionr up to date cleanup files
""" """
""" """
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -17,14 +17,16 @@
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/>.
""" """
from onionrtypes import RestartRequiredStatus import os, filepaths
from onionrblocks import onionrblockapi
from etc import onionrvalues def _safe_remove(path):
import onionrexceptions try:
import notifier os.remove(path)
except FileNotFoundError:
pass
def update_event(bl)->RestartRequiredStatus: def delete_run_files():
"""Show update notification if available, return bool of if update happend""" _safe_remove(filepaths.public_API_host_file)
if not bl.isSigner(onionrvalues.UPDATE_SIGN_KEY): raise onionrexceptions.InvalidUpdate _safe_remove(filepaths.private_API_host_file)
notifier.notify(message="A new Onionr update is available. Stay updated to remain secure.") _safe_remove(filepaths.daemon_mark_file)
_safe_remove(filepaths.lock_file)

View File

@ -0,0 +1 @@
from urllib3.contrib.socks import SOCKSProxyManager # noqa

View File

@ -3,6 +3,16 @@
view and interact with onionr sites view and interact with onionr sites
""" """
from typing import Union
import onionrexceptions
from onionrutils import mnemonickeys
from onionrutils import stringvalidators
from coredb import blockmetadb
from onionrblocks.onionrblockapi import Block
from onionrtypes import BlockHash
""" """
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,21 +27,21 @@
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/>.
""" """
from typing import Union
import onionrexceptions
from onionrutils import mnemonickeys
from onionrutils import stringvalidators
from coredb import blockmetadb
from onionrblocks.onionrblockapi import Block
def find_site(user_id: str)->Union[str, None]: def find_site(user_id: str) -> Union[BlockHash, None]:
"""Returns block hash string for latest block for a site by a given user id""" """Returns block hash str for latest block for a site by a given user id"""
if '-' in user_id: user_id = mnemonickeys.get_base32(user_id) # If mnemonic delim in key, convert to base32 version
if not stringvalidators.validate_pub_key(user_id): raise onionrexceptions.InvalidPubkey if mnemonickeys.DELIMITER in user_id:
user_id = mnemonickeys.get_base32(user_id)
if not stringvalidators.validate_pub_key(user_id):
raise onionrexceptions.InvalidPubkey
found_site = None found_site = None
sites = blockmetadb.get_blocks_by_type('zsite') sites = blockmetadb.get_blocks_by_type('zsite')
# Find site by searching all site blocks. eww O(N) ☹️, TODO: event based
for site in sites: for site in sites:
site = Block(site) site = Block(site)
if site.isSigner(user_id) and site.verifySig(): if site.isSigner(user_id) and site.verifySig():

Some files were not shown because too many files have changed in this diff Show More