diff --git a/README.md b/README.md index a7bd771..5332e97 100644 --- a/README.md +++ b/README.md @@ -22,4 +22,5 @@ docker run -d \ | max_price | Maximum price to pay for a domain (in HNS) | 5 | | max_gifts_per_interval | Maximum number of gifts to send per interval | 24 | | interval | Interval to send gifts (in seconds) | 86400 (24 hours) | -| discord_webhook | Discord webhook to send notifications to | None | \ No newline at end of file +| discord_webhook | Discord webhook to send notifications to | None | +| api_key | API key for api gifts | None | \ No newline at end of file diff --git a/main.py b/main.py index d5c056a..ea9cd4a 100644 --- a/main.py +++ b/main.py @@ -75,6 +75,40 @@ def submit(): else: return render_template('error.html',error=status,address=address) +@app.route('/api', methods=['POST']) +def api(): + # Get from params + params = request.args + name = params['name'] + email = params['email'] + key = params['key'] + + if key != os.getenv('api_key'): + return jsonify({'error': 'Invalid API key', 'success': False}) + + if 'X-REAL-IP' in request.headers: + ip = request.headers['X-REAL-IP'] + + if 'X-Real-Ip' in request.headers: + ip = request.headers['X-Real-Ip'] + + # Validate email + try: + emailinfo = validate_email(email, check_deliverability=False) + email = emailinfo.normalized + except EmailNotValidError as e: + return jsonify({'error': 'Invalid email address', 'success': False}) + + + status = gift.gift(name, email, "api", ip) + print(status,flush=True) + + if status == True: + return jsonify({'success': True}) + else: + return jsonify({'error': status, 'success': False}) + + # Special routes @app.route('/.well-known/wallets/') def send_wallet(token):