diff --git a/Dockerfile.dev b/Dockerfile.dev index 45e6073..1d8b396 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -19,6 +19,6 @@ RUN apk del build-deps EXPOSE 5000 ENV PYTHONUNBUFFERED 1 -ENV TOKEN="123abc!'?" +ENV TOKEN="123abc" CMD flask --app ping_engine --debug run --host=0.0.0.0 \ No newline at end of file diff --git a/check_json.sh b/check_json.sh new file mode 100644 index 0000000..fca16b0 --- /dev/null +++ b/check_json.sh @@ -0,0 +1 @@ +curl -X POST -H "Content-Type: application/json" -d @data1.json http://127.0.0.1:5000/api/?token=123abc diff --git a/data.json b/data.json new file mode 100644 index 0000000..0984819 --- /dev/null +++ b/data.json @@ -0,0 +1,3 @@ +{ + "msg" : "This message is in a JSON File" +} diff --git a/data1.json b/data1.json new file mode 100644 index 0000000..8c83b4e --- /dev/null +++ b/data1.json @@ -0,0 +1,3 @@ +{ + "address" : "https://jira.kbb.eu/status" +} diff --git a/ping_engine.py b/ping_engine.py index 5f46dab..8a520dc 100644 --- a/ping_engine.py +++ b/ping_engine.py @@ -2,6 +2,7 @@ from flask import Flask,request,jsonify import os import requests import datetime +import json app = Flask(__name__) @@ -85,6 +86,29 @@ def https(name): time = now, status = status_string) +@app.route('/api/', methods=['POST']) +def api(): + apiToken = request.args.get('token') + now = str(datetime.datetime.now()) + if apiToken == token: + request_data = request.get_json() + address = request_data['address'] + if address[0 : 4] == 'http': + r = requests.get(address) + try: + json.loads(r.content) + status_string=r.content + except ValueError as e: + status_string="not json" + else: + status_string = ' wrong token' + ip_addr = request.remote_addr + out = '%s - Unauthorized from IP: %s' %(now, ip_addr) + print (out) + return status_string +# return jsonify ( + # time = now, + # status = status_string) if __name__ == '__main__': app.run(debug=True) \ No newline at end of file