Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public api #45

Closed
wants to merge 15 commits into from
Closed
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app/views/public_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from flask import jsonify
from flask import request
from flask import abort
from app import app, db
from app.helpers import check_api_auth
from app.useful_functions import *
from app.models import Urls, UrlQueue
from urllib.parse import urlsplit
import datetime
import json

# Public API calls. These are available without authentication, so that the
# general public can access them.

@app.route('/api/onion_info', methods=['GET'])
def onion_info():
# Get the basic information about the specified onion.

# Are we authenticated?
# NOTE: As of right now, the returned information is the same regardless
# of authentication. However, in the future, we might want to return
# less data to clients without authentication.
authenticated = False
if check_api_auth():
# We'll provide more information in an authenticated request.
authenticated = True

try:
# Get the requested url.
onion_request = json.loads(request.args.get('q'))['node_name']
except:
# Invalid request.
abort(400)

# Get the base onion domain.
parts = onion_request.split('/')
for part in parts:
if part.endswith('.onion'):
onion_request = part
break

try:
# Get the Onion's data and send it off.
onion = Onions.query.filter(Onions.domain == onion).first()
return_value = {
domain = onion.domain,
online = onion.online,
last_online = onion.last_online,
scan_date = onion.scan_date,
base_url = onion.base_url,
title = onion.title
}
return json.dumps({'objects': return_value})
except:
# If there's an error, return nothing.
return jsonify({"objects": []})