()
| 19 | |
| 20 | @app.route("/webhook", methods=["POST"]) |
| 21 | def webhook(): |
| 22 | whitelisted_ips = ['52.89.214.238', '34.212.75.30', '54.218.53.128', '52.32.178.7'] |
| 23 | client_ip = request.headers.get('X-Forwarded-For', request.remote_addr) |
| 24 | if client_ip not in whitelisted_ips: |
| 25 | return jsonify({'message': 'Unauthorized'}), 401 |
| 26 | try: |
| 27 | if request.method == "POST": |
| 28 | data = request.get_json() |
| 29 | if data["key"] == config.sec_key: |
| 30 | print(get_timestamp(), "Alert Received & Sent!") |
| 31 | send_alert(data) |
| 32 | return jsonify({'message': 'Webhook received successfully'}), 200 |
| 33 | |
| 34 | else: |
| 35 | print("[X]", get_timestamp(), "Alert Received & Refused! (Wrong Key)") |
| 36 | return jsonify({'message': 'Unauthorized'}), 401 |
| 37 | |
| 38 | except Exception as e: |
| 39 | print("[X]", get_timestamp(), "Error:\n>", e) |
| 40 | return jsonify({'message': 'Error'}), 400 |
| 41 | |
| 42 | |
| 43 | if __name__ == "__main__": |
nothing calls this directly
no test coverage detected