""" Website for Craftbroec RR stuff """ import os import hashlib import hmac import subprocess from flask import jsonify, abort, request, send_from_directory from app import app from app.util import job @app.route('/') def index(): """Show index page""" return send_from_directory('static', 'index.html') @app.route("/tutorial/.pdf") def tutorial_document(document): """Display tutorial document""" return send_from_directory('static', 'tutorial/%s.pdf' % document) @app.route("/tutorial/.png") def tutorial_image(image): """Display tutorial image""" return send_from_directory('static', 'tutorial/%s.png' % image) @app.route("/tutorial/") def tutorial_image_page(image): """Display tutorial image""" return send_from_directory('static', 'tutorial/%s_afbeelding.html' % image) @app.route('/typeset', methods=['GET', 'POST']) def typeset(): """Add job to schedeuler""" job.typeset_add() return jsonify(True) @app.route('/deploy', methods=['POST']) def deploy(): """Run deploy script""" secret = os.environ["WEBHOOK_KEY"].encode('utf-8') digest = hmac.new(secret, request.data, hashlib.sha256).hexdigest() signature = request.headers['X-Gogs-Signature'] if len(signature) < 2 or not hmac.compare_digest(signature, digest): abort(400, 'Invalid signature') job.upgrade_add() return jsonify(True) @app.errorhandler(404) def page_not_found(e): """Return 404 page""" return send_from_directory('static', '404.html'), 404