diff --git a/onionr/__init__.py b/onionr/__init__.py index 54a41c21..c730f428 100755 --- a/onionr/__init__.py +++ b/onionr/__init__.py @@ -61,6 +61,7 @@ def onionr_main(): if __name__ == "__main__": onionr_main() + # Cleanup standard out/err because Python refuses to do it itsself try: sys.stderr.close() except (IOError, BrokenPipeError) as e: diff --git a/onionr/httpapi/onionrsitesapi/__init__.py b/onionr/httpapi/onionrsitesapi/__init__.py index 48e7c116..08370e14 100644 --- a/onionr/httpapi/onionrsitesapi/__init__.py +++ b/onionr/httpapi/onionrsitesapi/__init__.py @@ -1,9 +1,9 @@ -''' +""" Onionr - Private P2P Communication view and interact with onionr sites -''' -''' +""" +""" 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,7 +16,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . -''' +""" import base64 import binascii diff --git a/onionr/httpapi/onionrsitesapi/findsite.py b/onionr/httpapi/onionrsitesapi/findsite.py index 3a6303df..77e5e484 100644 --- a/onionr/httpapi/onionrsitesapi/findsite.py +++ b/onionr/httpapi/onionrsitesapi/findsite.py @@ -1,10 +1,39 @@ +""" + Onionr - Private P2P Communication + + view and interact with onionr sites +""" +""" + 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 . +""" +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)->str: +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 + found_site = None + sites = blockmetadb.get_blocks_by_type('zsite') - #for - \ No newline at end of file + for site in sites: + site = Block(site) + if site.isSigner(user_id) and site.verifySig(): + found_site = site.hash + return found_site diff --git a/onionr/httpapi/onionrsitesapi/zsite.py b/onionr/httpapi/onionrsitesapi/zsite.py new file mode 100644 index 00000000..aedf66bc --- /dev/null +++ b/onionr/httpapi/onionrsitesapi/zsite.py @@ -0,0 +1,4 @@ +import zipfile +def get_zip_site_file(path): + with zipfile.ZipFile(zip_file, 'r') as zf: + for member in zf.infolist(): \ No newline at end of file diff --git a/onionr/onionrusers/contactmanager.py b/onionr/onionrusers/contactmanager.py index 00baebea..ea86b435 100755 --- a/onionr/onionrusers/contactmanager.py +++ b/onionr/onionrusers/contactmanager.py @@ -22,13 +22,13 @@ import unpaddedbase32 from onionrusers import onionrusers from onionrutils import bytesconverter, epoch from utils import identifyhome - +from onionrutils import mnemonickeys import mnemonic class ContactManager(onionrusers.OnionrUser): def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5): try: - if " " in publicKey: - publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey) + if mnemonickeys.DELIMITER in publicKey: + publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey.split(mnemonickeys.DELIMITER)) publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey)) except ValueError: pass diff --git a/onionr/onionrusers/onionrusers.py b/onionr/onionrusers/onionrusers.py index 51798c78..8de3b419 100755 --- a/onionr/onionrusers/onionrusers.py +++ b/onionr/onionrusers/onionrusers.py @@ -67,7 +67,7 @@ class OnionrUser: if saveUser: try: keydb.addkeys.add_peer(publicKey) - except AssertionError: + except (AssertionError, ValueError) as e: pass self.trust = keydb.userinfo.get_user_info(self.publicKey, 'trust') diff --git a/onionr/onionrutils/mnemonickeys.py b/onionr/onionrutils/mnemonickeys.py index 54032b8a..84bdcdc6 100644 --- a/onionr/onionrutils/mnemonickeys.py +++ b/onionr/onionrutils/mnemonickeys.py @@ -25,6 +25,8 @@ import unpaddedbase32 import onionrcrypto from etc import onionrvalues +DELIMITER = '-' + m = mnemonic.Mnemonic('english') def get_human_readable_ID(pub=''): @@ -35,8 +37,8 @@ def get_human_readable_ID(pub=''): if not len(pub) == onionrvalues.MAIN_PUBLIC_KEY_SIZE: pub = base64.b32decode(pub) - return m.to_mnemonic(pub).replace(' ', '-') + return m.to_mnemonic(pub).replace(' ', DELIMITER) def get_base32(words): '''converts mnemonic to base32''' - return unpaddedbase32.b32encode(m.to_entropy(words.replace('-', ' '))) + return unpaddedbase32.b32encode(m.to_entropy(words.replace(DELIMITER, ' ')))