from flask import Flask, render_template, request, session, jsonify, send_file
from hashlib import sha256
from os import path as path
leaderboard_path = 'leaderboard.txt'
safetytime = 'csawctf{i_look_different_in_prod}'
cookie = request.cookies.get('session')
token = cookie.encode('utf-8')
tokenHash = sha256(token).hexdigest()
if tokenHash == '25971dadcb50db2303d6a68de14ae4f2d7eb8449ef9b3818bd3fafd052735f3b':
with open(leaderboard_path, 'r') as file:
except FileNotFoundError:
lbdata = 'Leaderboard file not found'
lbdata = f'Error: {str(e)}'
return '<br>'.join(lbdata.split('\n'))
open('logs.txt', mode='w').close()
return render_template("index.html")
return render_template("report.html")
@app.route('/clear_logs', methods=['POST'])
def clear_logs() -> Flask.response_class:
open('logs.txt', 'w').close()
return jsonify(status='success')
return jsonify(status='error', reason=str(e))
@app.route('/submit_logs', methods=['POST'])
def submit_logs() -> Flask.response_class:
with open('logs.txt', 'a') as logFile:
logFile.write(f"{log['player']} pressed {log['key']}\n")
return jsonify(status='success')
return jsonify(status='error', reason=str(e))
@app.route('/get_logs', methods=['GET'])
def get_logs() -> Flask.response_class:
if path.exists('logs.txt'):
return send_file('logs.txt', as_attachment=False)
return jsonify(status='error', reason='Log file not found'), 404
return jsonify(status='error', reason=str(e))
@app.route('/get_moves', methods=['POST'])
def eval_moves() -> Flask.response_class:
reported_player = data['playerName']
if path.exists('logs.txt'):
with open('logs.txt', 'r') as file:
player, key = line.split(' pressed ')
if player.strip() == reported_player:
return jsonify(status='success', result=moves)
return jsonify(status='error', reason=str(e))
@app.route('/get_eval', methods=['POST'])
def get_eval() -> Flask.response_class:
return jsonify(status='success', result=deep_eval(expr))
return jsonify(status='error', reason=str(e))
def deep_eval(expr:str) -> str:
if __name__ == '__main__':