Commit f39bdd51 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

rename crypto tasks to text tasks

parent 2e3fb55f
......@@ -57,7 +57,7 @@ teams:
password: "1a7fcdd5a9fd433523268883cfded9d0" #anteq1 md5
email: "antonigrzanka@gmail.com"
cryptoTasks:
textTasks:
- name: "Szyfro1"
text: "Odszyfruj1"
flags:
......
package core;
import helpers.CryptoTaskConfig;
import helpers.TextTaskConfig;
import helpers.WebTaskConfig;
import io.dropwizard.Configuration;
import objects.Team;
......@@ -15,7 +15,7 @@ public class ApplicationConfiguration extends Configuration
private String dbName;
private String flagHashMethod;
private List<Team> teams;
private List<CryptoTaskConfig> cryptoTasks;
private List<TextTaskConfig> textTasks;
private List<WebTaskConfig> webTasks;
private List<User> admins;
......@@ -29,14 +29,14 @@ public class ApplicationConfiguration extends Configuration
this.admins = admins;
}
public List<CryptoTaskConfig> getCryptoTasks()
public List<TextTaskConfig> getTextTasks()
{
return cryptoTasks;
return textTasks;
}
public void setCryptoTasks(List<CryptoTaskConfig> cryptoTasks)
public void setTextTasks(List<TextTaskConfig> textTasks)
{
this.cryptoTasks = cryptoTasks;
this.textTasks = textTasks;
}
public List<WebTaskConfig> getWebTasks()
......
......@@ -5,7 +5,7 @@ package core;
*/
public enum TaskType {
WEB("WEB"),
CRYPTO("CRYPTO"),
TEXT("TEXT"),
UNDEFINED("UNDEFINED");
private final String type;
......
......@@ -2,10 +2,8 @@ package helpers;
import java.util.List;
/**
* Created by gpietrus on 23.02.2016.
*/
public class CryptoTaskConfig {
public class TextTaskConfig
{
private String name;
private int level;
private String text;
......
......@@ -2,7 +2,7 @@ package repositories;
import core.ApplicationConfiguration;
import core.TaskType;
import helpers.CryptoTaskConfig;
import helpers.TextTaskConfig;
import helpers.WebTaskConfig;
import objects.Flag;
import objects.Solution;
......@@ -79,7 +79,7 @@ public class TasksRepository implements Repository
@Override
public void initialize()
{
List<CryptoTaskConfig> cryptoTasks = applicationConfiguration.getCryptoTasks();
List<TextTaskConfig> cryptoTasks = applicationConfiguration.getTextTasks();
List<WebTaskConfig> webTasks = applicationConfiguration.getWebTasks();
this.clean();
......@@ -93,7 +93,7 @@ public class TasksRepository implements Repository
this.add(new Task(
cryptoTaskConfig.getName(),
cryptoTaskConfig.getLevel(),
TaskType.CRYPTO,
TaskType.TEXT,
cryptoTaskConfig.getFlags().stream()
.map(Flag::new)
.collect(Collectors.toList()),
......
......@@ -24,41 +24,24 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
/**
* Created by gpietrus on 23.02.2016.
*/
@Singleton
@Path(value = "/task")
public class TaskResource {
public class TaskResource
{
protected TasksRepository tasksRepository;
@Inject
public TaskResource(TasksRepository tasksRepository) {
public TaskResource(TasksRepository tasksRepository)
{
this.tasksRepository = tasksRepository;
}
public String readStream(InputStream input) throws IOException {
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
return buffer.lines().collect(Collectors.joining("\n"));
}
}
//todo: remove proxy resource
private InputStream proxyRequest(String url, User user) throws IOException {
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
httpget.setHeader("CTF-User", user.getName());
CloseableHttpResponse execute = httpClient.execute(httpget);
HttpEntity entity = execute.getEntity();
return entity.getContent();
}
@Path("{task_level}")
@GET
public Response getTask(@Auth User user,
final @PathParam("task_level") int taskLevel) throws IOException {
final @PathParam("task_level") int taskLevel) throws IOException
{
Task task = tasksRepository.get(taskLevel);
if (task == null) {
return Response.status(Response.Status.BAD_REQUEST).build();
......@@ -67,7 +50,7 @@ public class TaskResource {
String taskText = null;
switch (task.getTaskType()) {
case CRYPTO:
case TEXT:
taskText = ((TaskCryptoContent) task.getTaskContent()).getText();
break;
case WEB:
......@@ -76,4 +59,22 @@ public class TaskResource {
}
return Response.ok().entity(taskText).build();
}
//todo: remove proxy resource
private InputStream proxyRequest(String url, User user) throws IOException
{
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
httpget.setHeader("CTF-User", user.getName());
CloseableHttpResponse execute = httpClient.execute(httpget);
HttpEntity entity = execute.getEntity();
return entity.getContent();
}
private String readStream(InputStream input) throws IOException
{
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(input))) {
return buffer.lines().collect(Collectors.joining("\n"));
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment