-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
62 lines (44 loc) · 1.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import requests
from flask import Flask, request, Response
app = Flask(__name__)
apikey = os.environ['APILAYER_KEY']
@app.route('/')
def index():
return 'Hello from Flask!'
@app.route('/whois/<string:domain>')
def whois(domain):
url = f'https://api.apilayer.com/whois/query?domain={domain}'
headers = {'apikey': apikey}
try:
response = requests.get(url, headers=headers)
except requests.exceptions.RequestException as e:
return Response(f"error: {str(e)}", status=500)
status_code = response.status_code
result = response.text
return Response(result, status=status_code, mimetype="application/json")
@app.route('/dns/<string:record>/<string:domain>')
def dns(record, domain):
url = f'https://api.apilayer.com/dns_lookup/api/{record}/{domain}'
headers = {'apikey': apikey}
try:
response = requests.get(url, headers=headers)
except requests.exceptions.RequestException as e:
return Response(f"error: {str(e)}", status=500)
status_code = response.status_code
result = response.text
return Response(result, status=status_code, mimetype="application/json")
@app.route("/.well-known/ai-plugin.json")
def plugin_manifest():
host = request.headers['Host']
with open("ai-plugin.json") as f:
text = f.read()
text = text.replace("PLUGIN_HOSTNAME", f"https://{host}")
return Response(text, mimetype="text/json")
@app.route("/openapi.yaml")
def openapi_spec():
host = request.headers['Host']
with open("openapi.yaml") as f:
text = f.read()
text = text.replace("PLUGIN_HOSTNAME", f"https://{host}")
return Response(text, mimetype="text/yaml")