2019-09-29 20:39:03 +00:00
|
|
|
"""
|
2019-07-01 20:38:55 +00:00
|
|
|
Onionr - Private P2P Communication
|
|
|
|
|
|
|
|
view and interact with onionr sites
|
2019-09-29 20:39:03 +00:00
|
|
|
"""
|
|
|
|
"""
|
2019-07-01 20:38:55 +00:00
|
|
|
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/>.
|
2019-09-29 20:39:03 +00:00
|
|
|
"""
|
2019-07-01 20:38:55 +00:00
|
|
|
import base64
|
2019-09-09 00:21:36 +00:00
|
|
|
import binascii
|
2019-09-28 05:37:24 +00:00
|
|
|
|
|
|
|
import unpaddedbase32
|
|
|
|
|
2019-07-01 20:38:55 +00:00
|
|
|
from flask import Blueprint, Response, request, abort
|
2019-09-28 05:37:24 +00:00
|
|
|
|
2019-09-21 23:49:24 +00:00
|
|
|
from onionrblocks import onionrblockapi
|
|
|
|
import onionrexceptions
|
2019-07-01 20:38:55 +00:00
|
|
|
from onionrutils import stringvalidators
|
2019-09-28 05:37:24 +00:00
|
|
|
from utils import safezip
|
|
|
|
from onionrutils import mnemonickeys
|
2019-07-01 20:38:55 +00:00
|
|
|
|
|
|
|
site_api = Blueprint('siteapi', __name__)
|
|
|
|
|
|
|
|
@site_api.route('/site/<name>', endpoint='site')
|
|
|
|
def site(name):
|
|
|
|
bHash = name
|
|
|
|
resp = 'Not Found'
|
2019-09-28 05:37:24 +00:00
|
|
|
if '-' in name:
|
|
|
|
name = mnemonickeys.get_base32(name)
|
|
|
|
if stringvalidators.validate_pub_key(name):
|
|
|
|
name = unpaddedbase32.repad(name)
|
|
|
|
|
|
|
|
|
2019-07-01 20:38:55 +00:00
|
|
|
if stringvalidators.validate_hash(bHash):
|
|
|
|
try:
|
|
|
|
resp = onionrblockapi.Block(bHash).bcontent
|
|
|
|
except onionrexceptions.NoDataAvailable:
|
|
|
|
abort(404)
|
|
|
|
except TypeError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
resp = base64.b64decode(resp)
|
2019-09-09 00:21:36 +00:00
|
|
|
except binascii.Error:
|
2019-07-01 20:38:55 +00:00
|
|
|
pass
|
|
|
|
if resp == 'Not Found' or not resp:
|
|
|
|
abort(404)
|
2019-09-28 05:37:24 +00:00
|
|
|
return Response(resp)
|