easyctf-2017/server/app.py

47 lines
1.4 KiB
Python
Raw Normal View History

2015-12-23 06:26:27 +00:00
from argparse import ArgumentParser
2015-12-21 07:04:00 +00:00
from flask import Flask
2015-12-23 06:26:27 +00:00
2015-12-27 01:21:15 +00:00
import api
2015-12-21 21:08:50 +00:00
import config
2015-12-23 06:26:27 +00:00
import json
import os
2015-12-23 01:37:38 +00:00
2016-01-07 00:23:43 +00:00
from api.decorators import api_wrapper
2015-12-21 07:04:00 +00:00
app = Flask(__name__)
2015-12-24 02:06:49 +00:00
2015-12-31 02:56:00 +00:00
app.config["SQLALCHEMY_DATABASE_URI"] = config.SQLALCHEMY_DATABASE_URI
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = config.SQLALCHEMY_TRACK_MODIFICATIONS
2016-01-02 20:45:05 +00:00
app.config["UPLOAD_FOLDER"] = config.UPLOAD_FOLDER
2015-12-31 02:56:00 +00:00
if not os.path.exists(app.config["UPLOAD_FOLDER"]):
os.makedirs(app.config["UPLOAD_FOLDER"])
2015-12-24 02:06:49 +00:00
with app.app_context():
2016-01-02 20:45:05 +00:00
from api.models import db, Files, Teams, Problems, Solves, Users
2015-12-24 05:29:04 +00:00
db.init_app(app)
db.create_all()
2015-12-24 02:06:49 +00:00
2015-12-25 01:37:49 +00:00
app.secret_key = config.SECRET_KEY
2015-12-21 07:04:00 +00:00
2015-12-25 00:57:58 +00:00
app.register_blueprint(api.admin.blueprint, url_prefix="/api/admin")
2015-12-31 02:56:00 +00:00
app.register_blueprint(api.problem.blueprint, url_prefix="/api/problem")
2016-01-12 03:54:26 +00:00
app.register_blueprint(api.team.blueprint, url_prefix="/api/team")
app.register_blueprint(api.user.blueprint, url_prefix="/api/user")
2015-12-27 01:21:15 +00:00
api.logger.initialize_logs()
2015-12-25 00:57:58 +00:00
2015-12-23 06:26:27 +00:00
@app.route("/api")
2016-01-07 00:23:43 +00:00
@api_wrapper
2015-12-23 23:23:18 +00:00
def api_main():
2016-01-07 00:23:43 +00:00
return { "success": 1, "message": "The API is online." }
2015-12-21 16:08:47 +00:00
if __name__ == "__main__":
2015-12-24 05:29:04 +00:00
with app.app_context():
parser = ArgumentParser(description="EasyCTF Server Configuration")
parser.add_argument("-d", "--debug", action="store_true", help="Run the server in debug mode.", default=False)
args = parser.parse_args()
keyword_args, _ = dict(args._get_kwargs()), args._get_args()
2015-12-23 06:26:27 +00:00
2015-12-24 05:29:04 +00:00
app.debug = keyword_args["debug"]
2015-12-24 04:14:54 +00:00
app.run(host="0.0.0.0", port=8000)