diff --git a/server/api/problem.py b/server/api/problem.py index 56c035f..6ee206a 100644 --- a/server/api/problem.py +++ b/server/api/problem.py @@ -2,7 +2,7 @@ import hashlib import logger import os -from flask import Blueprint, session, request +from flask import Blueprint, jsonify, session, request from flask import current_app as app from werkzeug import secure_filename @@ -120,3 +120,16 @@ def problem_submit(): else: return { "success": 0, "message": "Problem does not exist!" } + +@blueprint.route("/data", methods=["POST"]) +#@api_wrapper # Disable atm due to json serialization issues: will fix +@login_required +def problem_data(): + problems = Problems.query.add_columns("pid", "name", "category", "description", "hint", "value", "solves").order_by(Problems.value).filter_by(disabled=False).all() + jason = [] + + for problem in problems: + problem_files = [ str(_file.location) for _file in Files.query.filter_by(pid=int(problem.pid)).all() ] + jason.append({"pid": problem[1], "name": problem[2] ,"category": problem[3], "description": problem[4], "hint": problem[5], "value": problem[6], "solves": problem[7], "files": problem_files}) + + return jsonify(data=jason) diff --git a/server/config.py b/server/config.py index 8d3112c..a28a51f 100644 --- a/server/config.py +++ b/server/config.py @@ -15,7 +15,7 @@ SECRET_KEY = key SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf" SQLALCHEMY_TRACK_MODIFICATIONS = False -UPLOAD_FOLDER = os.path.normpath("uploads") +UPLOAD_FOLDER = os.path.normpath("files") CTF_BEGIN = 0 # To be used later CTF_END = 0 # To be used later diff --git a/web/admin/submission.html b/web/admin/submission.html deleted file mode 100644 index 7affe51..0000000 --- a/web/admin/submission.html +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - EasyCTF 2016 - - - - - - - -
-
-
- -
-
-

Problems

-
-
-
- -
-
- -

-
- - - - -
-
- -
-
-
-
- - - - - - - - - - - diff --git a/web/index.html b/web/index.html index ec80906..32fd6ef 100644 --- a/web/index.html +++ b/web/index.html @@ -82,6 +82,19 @@   Logout + diff --git a/web/js/easyctf.js b/web/js/easyctf.js index 6e4f22d..fc3f611 100644 --- a/web/js/easyctf.js +++ b/web/js/easyctf.js @@ -43,6 +43,10 @@ app.config(function($routeProvider, $locationProvider) { .when("/scoreboard", { templateUrl: "pages/scoreboard.html", controller: "mainController" + }) + .when("/admin/problems", { + templateUrl: "pages/admin/problems.html", + controller: "mainController" }); $locationProvider.html5Mode(true); }); @@ -70,6 +74,9 @@ function load_navbar() { $("#login_link").show(); $("#register_link").show(); } + if (data.admin) { + $("#admin_dropdown").show(); + } }); } diff --git a/web/js/problems.js b/web/js/problems.js new file mode 100644 index 0000000..1e75b27 --- /dev/null +++ b/web/js/problems.js @@ -0,0 +1,44 @@ +function render_problems() { + $.post("/api/problem/data", { + }, function(data) { + data = data["data"]; + for (var i = 0; i < data.length; i++) { + files = data[i]["files"]; + problem = +`
+
+

` + data[i]["name"] + ` | ` + data[i]["category"] + `

+
+
+

` + data[i]["description"] + `

+
+ + + + + +
+
+
` + + for (var j = 0; j < files.length; j++) { + file_name = files[j].split("/").pop(); + problem += +` +

` + file_name + `

+
` + } + + problem += `
+
` + data[i]["hint"] + `
+
` + $("#problems").append(problem); + } + }); +} + +function show_hint(pid) { + $("#hint_" + pid).slideToggle(120, "swing"); +} + +$(document).ready( render_problems() ); diff --git a/web/pages/problems.html b/web/pages/problems.html index 731b149..614ed91 100644 --- a/web/pages/problems.html +++ b/web/pages/problems.html @@ -6,54 +6,6 @@ -->

Problems

-
-
-

Silly Caesar | Cryptography20 points

-
-
-

Do we even need this problem, just take the flag. - EasyCTF{no} -

-
- - - - - -
-
- -
-
-
-

Difficult Binary | Cryptography40 points

-
-
-

This is a very very hard problem. Here it is: - EasyCTF{yes} -

-
- - - - - -
-
- -
+
+