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-21 21:08:50 +00:00
|
|
|
import config
|
2015-12-23 06:26:27 +00:00
|
|
|
import json
|
2015-12-23 23:23:18 +00:00
|
|
|
import api
|
2015-12-23 01:37:38 +00:00
|
|
|
|
2015-12-23 23:23:18 +00:00
|
|
|
from api.api import api as api_blueprint
|
2015-12-24 00:54:47 +00:00
|
|
|
from api.user import blueprint as user_blueprint
|
2015-12-23 01:37:38 +00:00
|
|
|
|
2015-12-21 07:04:00 +00:00
|
|
|
app = Flask(__name__)
|
2015-12-21 21:08:50 +00:00
|
|
|
app.secret_key = config.SECRET
|
2015-12-23 23:23:18 +00:00
|
|
|
app.register_blueprint(api_blueprint)
|
2015-12-24 01:12:23 +00:00
|
|
|
app.register_blueprint(user_blueprint, url_prefix="/api/user")
|
2015-12-21 07:04:00 +00:00
|
|
|
|
2015-12-23 06:26:27 +00:00
|
|
|
@app.route("/api")
|
2015-12-23 23:23:18 +00:00
|
|
|
def api_main():
|
2015-12-23 06:26:27 +00:00
|
|
|
return json.dumps({ "success": 1, "message": "The API is online." })
|
2015-12-21 18:10:36 +00:00
|
|
|
|
2015-12-21 16:08:47 +00:00
|
|
|
if __name__ == "__main__":
|
2015-12-23 06:26:27 +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()
|
|
|
|
|
|
|
|
app.debug = keyword_args["debug"]
|
|
|
|
|
|
|
|
app.config["SQLALCHEMY_DATABASE_URI"] = "mysql://root:i_hate_passwords@localhost/easyctf"
|
|
|
|
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
|
|
|
|
|
|
|
|
from api.models import db
|
|
|
|
db.init_app(app)
|
|
|
|
db.create_all()
|
|
|
|
|
2015-12-23 22:53:00 +00:00
|
|
|
app.run(host="0.0.0.0", port=8000)
|