Browse Source

renamed onionr dir and bugfixes/linting progress

merge-requests/27/head
Kevin Froman 7 months ago
parent
commit
720efe4fca
100 changed files with 90 additions and 92 deletions
  1. +1
    -0
      .env
  2. +19
    -23
      .gitignore
  3. +1
    -1
      make-release.sh
  4. +1
    -1
      onionr.sh
  5. +0
    -13
      onionr/etc/cleanup/__init__.py
  6. +0
    -30
      onionr/onionrutils/updater/__init__.py
  7. +1
    -1
      run-windows-dev.bat
  8. +1
    -1
      run-windows.bat
  9. +13
    -12
      src/__init__.py
  10. +0
    -0
      src/apiservers/README.md
  11. +0
    -0
      src/apiservers/__init__.py
  12. +0
    -0
      src/apiservers/private/README.md
  13. +0
    -0
      src/apiservers/private/__init__.py
  14. +0
    -0
      src/apiservers/private/register_private_blueprints.py
  15. +0
    -0
      src/apiservers/public/__init__.py
  16. +0
    -0
      src/communicator/README.md
  17. +0
    -0
      src/communicator/__init__.py
  18. +0
    -0
      src/communicator/bootstrappeers.py
  19. +0
    -0
      src/communicator/onlinepeers/README.md
  20. +0
    -0
      src/communicator/onlinepeers/__init__.py
  21. +0
    -0
      src/communicator/onlinepeers/clearofflinepeer.py
  22. +0
    -0
      src/communicator/onlinepeers/onlinepeers.py
  23. +0
    -0
      src/communicator/onlinepeers/pickonlinepeers.py
  24. +0
    -0
      src/communicator/onlinepeers/removeonlinepeer.py
  25. +0
    -0
      src/communicator/peeraction.py
  26. +0
    -0
      src/communicator/uploadqueue/__init__.py
  27. +0
    -0
      src/communicatorutils/README.md
  28. +0
    -0
      src/communicatorutils/__init__.py
  29. +0
    -0
      src/communicatorutils/announcenode.py
  30. +0
    -0
      src/communicatorutils/connectnewpeers.py
  31. +0
    -0
      src/communicatorutils/cooldownpeer.py
  32. +0
    -0
      src/communicatorutils/daemonqueuehandler.py
  33. +0
    -0
      src/communicatorutils/deniableinserts.py
  34. +0
    -0
      src/communicatorutils/downloadblocks/__init__.py
  35. +0
    -0
      src/communicatorutils/downloadblocks/shoulddownload.py
  36. +0
    -0
      src/communicatorutils/housekeeping.py
  37. +0
    -0
      src/communicatorutils/lookupadders.py
  38. +0
    -0
      src/communicatorutils/lookupblocks.py
  39. +0
    -0
      src/communicatorutils/netcheck.py
  40. +0
    -0
      src/communicatorutils/onionrcommunicatortimers.py
  41. +0
    -0
      src/communicatorutils/proxypicker.py
  42. +0
    -0
      src/communicatorutils/restarttor.py
  43. +0
    -0
      src/communicatorutils/servicecreator.py
  44. +0
    -0
      src/communicatorutils/uploadblocks/__init__.py
  45. +0
    -0
      src/communicatorutils/uploadblocks/session.py
  46. +0
    -0
      src/communicatorutils/uploadblocks/sessionmanager.py
  47. +0
    -0
      src/config.py
  48. +0
    -0
      src/coredb/__init__.py
  49. +0
    -0
      src/coredb/blockmetadb/__init__.py
  50. +0
    -0
      src/coredb/blockmetadb/add.py
  51. +0
    -0
      src/coredb/blockmetadb/expiredblocks.py
  52. +0
    -0
      src/coredb/blockmetadb/updateblockinfo.py
  53. +0
    -0
      src/coredb/daemonqueue/__init__.py
  54. +0
    -0
      src/coredb/dbfiles.py
  55. +0
    -0
      src/coredb/keydb/__init__.py
  56. +0
    -0
      src/coredb/keydb/addkeys.py
  57. +0
    -0
      src/coredb/keydb/listkeys.py
  58. +0
    -0
      src/coredb/keydb/removekeys.py
  59. +0
    -0
      src/coredb/keydb/transportinfo.py
  60. +0
    -0
      src/coredb/keydb/userinfo.py
  61. +0
    -0
      src/etc/README.md
  62. +0
    -0
      src/etc/__init__.py
  63. +32
    -0
      src/etc/cleanup/__init__.py
  64. +1
    -0
      src/etc/dependencycheck.py
  65. +0
    -0
      src/etc/humanreadabletime.py
  66. +0
    -0
      src/etc/onionrvalues.py
  67. +0
    -0
      src/etc/powchoice.py
  68. +0
    -0
      src/etc/waitforsetvar.py
  69. +0
    -0
      src/filepaths/__init__.py
  70. +0
    -0
      src/httpapi/README.md
  71. +0
    -0
      src/httpapi/__init__.py
  72. +0
    -0
      src/httpapi/apiutils/__init__.py
  73. +0
    -0
      src/httpapi/apiutils/getblockdata.py
  74. +0
    -0
      src/httpapi/apiutils/setbindip.py
  75. +0
    -0
      src/httpapi/apiutils/shutdown.py
  76. +0
    -0
      src/httpapi/configapi/__init__.py
  77. +0
    -0
      src/httpapi/directconnections/__init__.py
  78. +0
    -0
      src/httpapi/fdsafehandler.py
  79. +0
    -0
      src/httpapi/friendsapi/__init__.py
  80. +0
    -0
      src/httpapi/insertblock.py
  81. +0
    -0
      src/httpapi/miscclientapi/__init__.py
  82. +0
    -0
      src/httpapi/miscclientapi/endpoints.py
  83. +0
    -0
      src/httpapi/miscclientapi/getblocks.py
  84. +0
    -0
      src/httpapi/miscclientapi/motd/__init__.py
  85. +0
    -0
      src/httpapi/miscclientapi/staticfiles.py
  86. +0
    -0
      src/httpapi/miscpublicapi/__init__.py
  87. +0
    -0
      src/httpapi/miscpublicapi/announce.py
  88. +0
    -0
      src/httpapi/miscpublicapi/endpoints.py
  89. +0
    -0
      src/httpapi/miscpublicapi/getblocks.py
  90. +0
    -0
      src/httpapi/miscpublicapi/upload.py
  91. +0
    -0
      src/httpapi/onionrsitesapi/__init__.py
  92. +20
    -10
      src/httpapi/onionrsitesapi/findsite.py
  93. +0
    -0
      src/httpapi/onionrsitesapi/sitefiles.py
  94. +0
    -0
      src/httpapi/profilesapi/__init__.py
  95. +0
    -0
      src/httpapi/profilesapi/profiles.py
  96. +0
    -0
      src/httpapi/security/__init__.py
  97. +0
    -0
      src/httpapi/security/client.py
  98. +0
    -0
      src/httpapi/security/pluginwhitelist.py
  99. +0
    -0
      src/httpapi/security/public.py
  100. +0
    -0
      src/httpapi/themeapi/__init__.py

+ 1
- 0
.env View File

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

+ 19
- 23
.gitignore View File

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

# package files
onionr-*.pkg.tar.gz
pkg/
src/
spawnnodes.py

+ 1
- 1
make-release.sh View File

@@ -2,7 +2,7 @@
rm -rf dist
mkdir dist
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/
PIP_USER=false
export PIP_USER


+ 1
- 1
onionr.sh View File

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

+ 0
- 13
onionr/etc/cleanup/__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)

+ 0
- 30
onionr/onionrutils/updater/__init__.py View File

@@ -1,30 +0,0 @@
"""
Onionr - Private P2P Communication

Lib to keep Onionr up to date
"""
"""
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 onionrtypes import RestartRequiredStatus
from onionrblocks import onionrblockapi

from etc import onionrvalues
import onionrexceptions
import notifier

def update_event(bl)->RestartRequiredStatus:
"""Show update notification if available, return bool of if update happend"""
if not bl.isSigner(onionrvalues.UPDATE_SIGN_KEY): raise onionrexceptions.InvalidUpdate
notifier.notify(message="A new Onionr update is available. Stay updated to remain secure.")

+ 1
- 1
run-windows-dev.bat 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%
echo Using profile: %ONIONR_HOME%
setlocal
chdir onionr
chdir src
python __init__.py %*

+ 1
- 1
run-windows.bat View File

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

onionr/__init__.py → src/__init__.py View File

@@ -22,30 +22,29 @@
'''

# Set the user's locale for encoding reasons
import locale
import locale # noqa
locale.setlocale(locale.LC_ALL, '')

ran_as_script = False
if __name__ == "__main__": ran_as_script = True

# Import standard libraries
import sys
import sys # noqa

# 3rd party lib imports
# Ensure that PySocks is installed
try:
from urllib3.contrib.socks import SOCKSProxyManager
except ModuleNotFoundError:
# check here or else we get error when onionr runs with tor
raise ModuleNotFoundError("You need the PySocks module (for use with socks5 proxy to use Tor)")
from etc import dependencycheck # noqa
except ModuleNotFoundError as e:
print('Onionr needs ' + str(e) + ' installed')

# Onionr imports
from etc import onionrvalues # For different Onionr related constants such as versions
import onionrsetup as setup

min_ver = onionrvalues.MIN_PY_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:
sys.stderr.write('Error, Onionr requires Python 3.%s+\n' % (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.' + str(min_ver) + '\n')
sys.exit(1)

# 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_default_plugins()


def onionr_main():
"""Onionr entrypoint, start command processor"""
parser.register()


if ran_as_script:
onionr_main()

# Cleanup standard out/err because Python refuses to do it itsself
try:
sys.stderr.close()
except (IOError, BrokenPipeError) as e:
except (IOError, BrokenPipeError):
pass
try:
sys.stdout.close()
except (IOError, BrokenPipeError) as e:
except (IOError, BrokenPipeError):
pass

onionr/apiservers/README.md → src/apiservers/README.md View File


onionr/apiservers/__init__.py → src/apiservers/__init__.py View File


onionr/apiservers/private/README.md → src/apiservers/private/README.md View File


onionr/apiservers/private/__init__.py → src/apiservers/private/__init__.py View File


onionr/apiservers/private/register_private_blueprints.py → src/apiservers/private/register_private_blueprints.py View File


onionr/apiservers/public/__init__.py → src/apiservers/public/__init__.py View File


onionr/communicator/README.md → src/communicator/README.md View File


onionr/communicator/__init__.py → src/communicator/__init__.py View File


onionr/communicator/bootstrappeers.py → src/communicator/bootstrappeers.py View File


onionr/communicator/onlinepeers/README.md → src/communicator/onlinepeers/README.md View File


onionr/communicator/onlinepeers/__init__.py → src/communicator/onlinepeers/__init__.py View File


onionr/communicator/onlinepeers/clearofflinepeer.py → src/communicator/onlinepeers/clearofflinepeer.py View File


onionr/communicator/onlinepeers/onlinepeers.py → src/communicator/onlinepeers/onlinepeers.py View File


onionr/communicator/onlinepeers/pickonlinepeers.py → src/communicator/onlinepeers/pickonlinepeers.py View File


onionr/communicator/onlinepeers/removeonlinepeer.py → src/communicator/onlinepeers/removeonlinepeer.py View File


onionr/communicator/peeraction.py → src/communicator/peeraction.py View File


onionr/communicator/uploadqueue/__init__.py → src/communicator/uploadqueue/__init__.py View File


onionr/communicatorutils/README.md → src/communicatorutils/README.md View File


onionr/communicatorutils/__init__.py → src/communicatorutils/__init__.py View File


onionr/communicatorutils/announcenode.py → src/communicatorutils/announcenode.py View File


onionr/communicatorutils/connectnewpeers.py → src/communicatorutils/connectnewpeers.py View File


onionr/communicatorutils/cooldownpeer.py → src/communicatorutils/cooldownpeer.py View File


onionr/communicatorutils/daemonqueuehandler.py → src/communicatorutils/daemonqueuehandler.py View File


onionr/communicatorutils/deniableinserts.py → src/communicatorutils/deniableinserts.py View File


onionr/communicatorutils/downloadblocks/__init__.py → src/communicatorutils/downloadblocks/__init__.py View File


onionr/communicatorutils/downloadblocks/shoulddownload.py → src/communicatorutils/downloadblocks/shoulddownload.py View File


onionr/communicatorutils/housekeeping.py → src/communicatorutils/housekeeping.py View File


onionr/communicatorutils/lookupadders.py → src/communicatorutils/lookupadders.py View File


onionr/communicatorutils/lookupblocks.py → src/communicatorutils/lookupblocks.py View File


onionr/communicatorutils/netcheck.py → src/communicatorutils/netcheck.py View File


onionr/communicatorutils/onionrcommunicatortimers.py → src/communicatorutils/onionrcommunicatortimers.py View File


onionr/communicatorutils/proxypicker.py → src/communicatorutils/proxypicker.py View File


onionr/communicatorutils/restarttor.py → src/communicatorutils/restarttor.py View File


onionr/communicatorutils/servicecreator.py → src/communicatorutils/servicecreator.py View File


onionr/communicatorutils/uploadblocks/__init__.py → src/communicatorutils/uploadblocks/__init__.py View File


onionr/communicatorutils/uploadblocks/session.py → src/communicatorutils/uploadblocks/session.py View File


onionr/communicatorutils/uploadblocks/sessionmanager.py → src/communicatorutils/uploadblocks/sessionmanager.py View File


onionr/config.py → src/config.py View File


onionr/coredb/__init__.py → src/coredb/__init__.py View File


onionr/coredb/blockmetadb/__init__.py → src/coredb/blockmetadb/__init__.py View File


onionr/coredb/blockmetadb/add.py → src/coredb/blockmetadb/add.py View File


onionr/coredb/blockmetadb/expiredblocks.py → src/coredb/blockmetadb/expiredblocks.py View File


onionr/coredb/blockmetadb/updateblockinfo.py → src/coredb/blockmetadb/updateblockinfo.py View File


onionr/coredb/daemonqueue/__init__.py → src/coredb/daemonqueue/__init__.py View File


onionr/coredb/dbfiles.py → src/coredb/dbfiles.py View File


onionr/coredb/keydb/__init__.py → src/coredb/keydb/__init__.py View File


onionr/coredb/keydb/addkeys.py → src/coredb/keydb/addkeys.py View File


onionr/coredb/keydb/listkeys.py → src/coredb/keydb/listkeys.py View File


onionr/coredb/keydb/removekeys.py → src/coredb/keydb/removekeys.py View File


onionr/coredb/keydb/transportinfo.py → src/coredb/keydb/transportinfo.py View File


onionr/coredb/keydb/userinfo.py → src/coredb/keydb/userinfo.py View File


onionr/etc/README.md → src/etc/README.md View File


onionr/etc/__init__.py → src/etc/__init__.py View File


+ 32
- 0
src/etc/cleanup/__init__.py View File

@@ -0,0 +1,32 @@
"""
Onionr - Private P2P Communication

cleanup 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/>.
"""
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)

+ 1
- 0
src/etc/dependencycheck.py View File

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

onionr/etc/humanreadabletime.py → src/etc/humanreadabletime.py View File


onionr/etc/onionrvalues.py → src/etc/onionrvalues.py View File


onionr/etc/powchoice.py → src/etc/powchoice.py View File


onionr/etc/waitforsetvar.py → src/etc/waitforsetvar.py View File


onionr/filepaths/__init__.py → src/filepaths/__init__.py View File


onionr/httpapi/README.md → src/httpapi/README.md View File


onionr/httpapi/__init__.py → src/httpapi/__init__.py View File


onionr/httpapi/apiutils/__init__.py → src/httpapi/apiutils/__init__.py View File


onionr/httpapi/apiutils/getblockdata.py → src/httpapi/apiutils/getblockdata.py View File


onionr/httpapi/apiutils/setbindip.py → src/httpapi/apiutils/setbindip.py View File


onionr/httpapi/apiutils/shutdown.py → src/httpapi/apiutils/shutdown.py View File


onionr/httpapi/configapi/__init__.py → src/httpapi/configapi/__init__.py View File


onionr/httpapi/directconnections/__init__.py → src/httpapi/directconnections/__init__.py View File


onionr/httpapi/fdsafehandler.py → src/httpapi/fdsafehandler.py View File


onionr/httpapi/friendsapi/__init__.py → src/httpapi/friendsapi/__init__.py View File


onionr/httpapi/insertblock.py → src/httpapi/insertblock.py View File


onionr/httpapi/miscclientapi/__init__.py → src/httpapi/miscclientapi/__init__.py View File


onionr/httpapi/miscclientapi/endpoints.py → src/httpapi/miscclientapi/endpoints.py View File


onionr/httpapi/miscclientapi/getblocks.py → src/httpapi/miscclientapi/getblocks.py View File


onionr/httpapi/miscclientapi/motd/__init__.py → src/httpapi/miscclientapi/motd/__init__.py View File


onionr/httpapi/miscclientapi/staticfiles.py → src/httpapi/miscclientapi/staticfiles.py View File


onionr/httpapi/miscpublicapi/__init__.py → src/httpapi/miscpublicapi/__init__.py View File


onionr/httpapi/miscpublicapi/announce.py → src/httpapi/miscpublicapi/announce.py View File


onionr/httpapi/miscpublicapi/endpoints.py → src/httpapi/miscpublicapi/endpoints.py View File


onionr/httpapi/miscpublicapi/getblocks.py → src/httpapi/miscpublicapi/getblocks.py View File


onionr/httpapi/miscpublicapi/upload.py → src/httpapi/miscpublicapi/upload.py View File


onionr/httpapi/onionrsitesapi/__init__.py → src/httpapi/onionrsitesapi/__init__.py View File


onionr/httpapi/onionrsitesapi/findsite.py → src/httpapi/onionrsitesapi/findsite.py View File

@@ -3,6 +3,16 @@

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
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
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]:
"""Returns block hash string for latest block for a site by a given user id"""
if '-' in user_id: user_id = mnemonickeys.get_base32(user_id)
if not stringvalidators.validate_pub_key(user_id): raise onionrexceptions.InvalidPubkey
def find_site(user_id: str) -> Union[BlockHash, None]:
"""Returns block hash str for latest block for a site by a given user id"""
# If mnemonic delim in key, convert to base32 version
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
sites = blockmetadb.get_blocks_by_type('zsite')

# Find site by searching all site blocks. eww O(N) ☹️, TODO: event based
for site in sites:
site = Block(site)
if site.isSigner(user_id) and site.verifySig():

onionr/httpapi/onionrsitesapi/sitefiles.py → src/httpapi/onionrsitesapi/sitefiles.py View File


onionr/httpapi/profilesapi/__init__.py → src/httpapi/profilesapi/__init__.py View File


onionr/httpapi/profilesapi/profiles.py → src/httpapi/profilesapi/profiles.py View File


onionr/httpapi/security/__init__.py → src/httpapi/security/__init__.py View File


onionr/httpapi/security/client.py → src/httpapi/security/client.py View File


onionr/httpapi/security/pluginwhitelist.py → src/httpapi/security/pluginwhitelist.py View File


onionr/httpapi/security/public.py → src/httpapi/security/public.py View File


onionr/httpapi/themeapi/__init__.py → src/httpapi/themeapi/__init__.py View File


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

Loading…
Cancel
Save