Display problems from database to problems.html

This commit is contained in:
James Wang 2016-01-02 19:40:28 -05:00
parent 7f1453499d
commit 499de76caa
7 changed files with 81 additions and 161 deletions

View file

@ -2,7 +2,7 @@ import hashlib
import logger import logger
import os import os
from flask import Blueprint, session, request from flask import Blueprint, jsonify, session, request
from flask import current_app as app from flask import current_app as app
from werkzeug import secure_filename from werkzeug import secure_filename
@ -120,3 +120,16 @@ def problem_submit():
else: else:
return { "success": 0, "message": "Problem does not exist!" } 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)

View file

@ -15,7 +15,7 @@ SECRET_KEY = key
SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf" SQLALCHEMY_DATABASE_URI = "mysql://root:i_hate_passwords@localhost/easyctf"
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
UPLOAD_FOLDER = os.path.normpath("uploads") UPLOAD_FOLDER = os.path.normpath("files")
CTF_BEGIN = 0 # To be used later CTF_BEGIN = 0 # To be used later
CTF_END = 0 # To be used later CTF_END = 0 # To be used later

View file

@ -1,109 +0,0 @@
<html ng-app="easyctf" class="ng-scope">
<script src="js/submission.js"></script>
<head>
<style type="text/css">
@charset "UTF-8";
[ng\:cloak],
[ng-cloak],
[data-ng-cloak],
[x-ng-cloak],
.ng-cloak,
.x-ng-cloak,
.ng-hide:not(.ng-hide-animate) {
display: none !important;
}
ng\:form {
display: block;
}
.ng-animate-shim {
visibility: hidden;
}
.ng-anchor {
position: absolute;
}
</style>
<meta charset="utf-8">
<title>EasyCTF 2016</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link type="text/css" rel="stylesheet" href="../css/style.css">
<base href="/">
</head>
<body ng-controller="mainController" class="ng-scope" waid71fa0d88-5390-4b5b-a2f4-e45fa93d85e2="SA password protect entry checker">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid" style="background-color: #0080FF; margin: -0.1em;">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">EasyCTF</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-fixed">
<li><a href="../pages/about">About</a></li>
<li><a href="../pages/rules">Rules</a></li>
<li><a href="../pages/updates">Updates</a></li>
<li><a href="../pages/chat">Chat</a></li>
<li><a href="../pages/scoreboard">Scoreboard</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="../pages/programming">Programming</a></li>
<li><a href="../pages/shell">Shell</a></li>
<li><a href="../pages/problems">Problems</a></li>
<li><a href="../pages/login">Login</a></li>
<li><a href="../pages/register">Register</a></li>
</ul>
</div>
</div>
</nav>
<br>
<br>
<div id="mainContent" class="ui container">
<!-- ngView: -->
<div>
<center class="fade_in ng-scope">
<h1>Problems</h1>
<div class="panel panel-info">
<form id="submission-form">
<div class="panel-heading">
<input type="text" name="question-title" id="question-title" autocomplete="on" placeholder="Title | Category" class="form-control">
</div>
<div class="panel-body">
<textarea type="text" name="question-text" id="question-text" autocomplete="on" placeholder="Description" class="form-control"></textarea>
<br><br>
<div class="input-group" style="margin-left:10em;margin-right:10em;">
<input type="text" name="correct-flag" id="correct-flag" autocomplete="off" placeholder="EasyCTF{insert_correct_flag_here}" class="form-control">
<span class="input-group-btn">
<input type="submit" class="btn btn-success" value="Submit">
</span>
</div>
</div>
<div class="panel-footer">
<h4>These are important files!</h4>
<hr>
<div class="row">
<input type="file" name="imp-files" id="imp-files" multiple="true">
</div>
</div>
</form>
</div>
</div>
</div>
</center>
</div>
</div>
<script src="https://code.jquery.com/jquery-2.1.4.min.js" integrity="sha384-R4/ztc4ZlRqWjqIuvf6RX5yb/v90qNGx6fS48N0tRxiGkqveZETq72KgDVJCp2TC" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.8/angular.min.js" integrity="sha384-r1y8TJcloKTvouxnYsi4PJAx+nHNr90ibsEn3zznzDzWBN9X3o3kbHLSgcIPtzAp" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-route.min.js" integrity="sha384-9MZDoFf10trgrfsQOs9GJhf/mP/sh5weVp3FDSi8h/4TEaV6dloEDkpxGTaOmAs6" crossorigin="anonymous"></script>
<script src="../js/easyctf.js"></script>
</body>
</html>

View file

@ -82,6 +82,19 @@
<a href="/api/user/logout"> <a href="/api/user/logout">
<span class="fa fa-pencil"></span>&nbsp;&nbsp;Logout</a> <span class="fa fa-pencil"></span>&nbsp;&nbsp;Logout</a>
</li> </li>
<li id="admin_dropdown" style="display:none">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;Admin<span class="caret"></span></a>
<ul class="dropdown-menu" id="menubox">
<li>
<a href="/admin/problems">
<span class="fa fa-pencil"></span>&nbsp;&nbsp;Problems</a>
</li>
<li>
<a href="/admin/teams">
<span class="fa fa-code"></span>&nbsp;&nbsp;Teams</a>
</li>
</ul>
</li>
</ul> </ul>
</div> </div>
</div> </div>

View file

@ -43,6 +43,10 @@ app.config(function($routeProvider, $locationProvider) {
.when("/scoreboard", { .when("/scoreboard", {
templateUrl: "pages/scoreboard.html", templateUrl: "pages/scoreboard.html",
controller: "mainController" controller: "mainController"
})
.when("/admin/problems", {
templateUrl: "pages/admin/problems.html",
controller: "mainController"
}); });
$locationProvider.html5Mode(true); $locationProvider.html5Mode(true);
}); });
@ -70,6 +74,9 @@ function load_navbar() {
$("#login_link").show(); $("#login_link").show();
$("#register_link").show(); $("#register_link").show();
} }
if (data.admin) {
$("#admin_dropdown").show();
}
}); });
} }

44
web/js/problems.js Normal file
View file

@ -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 =
`<div class=\"panel panel-info\">
<div class=\"panel-heading\">
<h3 class=\"panel-title\">` + data[i]["name"] + ` | ` + data[i]["category"] + `</h3>
</div>
<div class=\"panel-body\">
<p>` + data[i]["description"] + `</p>
<div class=\"input-group\">
<input type=\"text\" class=\"form-control\" placeholder=\"Flag\">
<span class=\"input-group-btn\">
<button class=\"btn btn-success\" id=\"hint\" type=\"button\" onclick=\"show_hint(\'` + data[i]["pid"] + `\');\">Hint</button>
<button class=\"btn btn-success\" type=\"button\">Submit!</button>
</span>
</div>
</div>
<div class=\"panel-footer\">`
for (var j = 0; j < files.length; j++) {
file_name = files[j].split("/").pop();
problem +=
`<a href=\"` + files[j] + `\" class=\"filelink\" target=\"_blank\">
<h4 class=\"probfile\">` + file_name + `</h4>
</a>`
}
problem += `<br>
<div id=\"hint_` + data[i]["pid"] + `\" style=\"display:none\">` + data[i]["hint"] + `</div>
</div></div>`
$("#problems").append(problem);
}
});
}
function show_hint(pid) {
$("#hint_" + pid).slideToggle(120, "swing");
}
$(document).ready( render_problems() );

View file

@ -6,54 +6,6 @@
--> -->
<div class="fade_in"> <div class="fade_in">
<h1 class="heading1 text-center">Problems</h1> <h1 class="heading1 text-center">Problems</h1>
<div class="panel panel-info"> <div id="problems"></div>
<div class="panel-heading">
<h3 class="panel-title">Silly Caesar | Cryptography<span class="pointvalue">20 points</span></h3>
</div>
<div class="panel-body">
<p>Do we even need this problem, just take the flag.
<code>EasyCTF{no}</code>
</p>
<div class="input-group">
<input type="text" class="form-control" placeholder="EasyCTF{...}">
<span class="input-group-btn">
<button class="btn btn-success" id="hint" type="button">Hint</button>
<button class="btn btn-success" type="button">Check</button>
</span>
</div>
</div>
<div class="panel-footer">
<a href="/files/example.txt" class="filelink" target="_blank">
<h4 class="probfile">Example.txt</h4>
</a>
<a href="/files/example2.txt" class="filelink" target="_blank">
<h4 class="probfile">Example2.txt</h4>
</a>
</div>
</div>
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Difficult Binary | Cryptography<span class="pointvalue">40 points</span></h3>
</div>
<div class="panel-body">
<p>This is a very very hard problem. Here it is:
<code>EasyCTF{yes}</code>
</p>
<div class="input-group">
<input type="text" class="form-control" placeholder="EasyCTF{...}">
<span class="input-group-btn">
<button class="btn btn-success" id="hint" type="button">Hint</button>
<button class="btn btn-success" type="button">Check</button>
</span>
</div>
</div>
<div class="panel-footer">
<a href="/files/example.txt" class="filelink" target="_blank">
<h4 class="probfile">Binary.txt</h4>
</a>
<a href="/files/example2.txt" class="filelink" target="_blank">
<h4 class="probfile">Binary2.txt</h4>
</a>
</div>
</div>
</div> </div>
<script src="js/problems.js">