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..2f662f1b 100755 --- a/onionr/onionrusers/contactmanager.py +++ b/onionr/onionrusers/contactmanager.py @@ -27,7 +27,7 @@ import mnemonic class ContactManager(onionrusers.OnionrUser): def __init__(self, publicKey, saveUser=False, recordExpireSeconds=5): try: - if " " in publicKey: + if "-" in publicKey: publicKey = mnemonic.Mnemonic('english').to_entropy(publicKey) publicKey = unpaddedbase32.b32encode(bytesconverter.str_to_bytes(publicKey)) except ValueError: