Commit f39bdd51 authored by Grzegorz Pietrusza's avatar Grzegorz Pietrusza

rename crypto tasks to text tasks

parent 2e3fb55f
...@@ -57,7 +57,7 @@ teams: ...@@ -57,7 +57,7 @@ teams:
password: "1a7fcdd5a9fd433523268883cfded9d0" #anteq1 md5 password: "1a7fcdd5a9fd433523268883cfded9d0" #anteq1 md5
email: "antonigrzanka@gmail.com" email: "antonigrzanka@gmail.com"
cryptoTasks: textTasks:
- name: "Szyfro1" - name: "Szyfro1"
text: "Odszyfruj1" text: "Odszyfruj1"
flags: flags:
......
package core; package core;
import helpers.CryptoTaskConfig; import helpers.TextTaskConfig;
import helpers.WebTaskConfig; import helpers.WebTaskConfig;
import io.dropwizard.Configuration; import io.dropwizard.Configuration;
import objects.Team; import objects.Team;
...@@ -15,7 +15,7 @@ public class ApplicationConfiguration extends Configuration ...@@ -15,7 +15,7 @@ public class ApplicationConfiguration extends Configuration
private String dbName; private String dbName;
private String flagHashMethod; private String flagHashMethod;
private List<Team> teams; private List<Team> teams;
private List<CryptoTaskConfig> cryptoTasks; private List<TextTaskConfig> textTasks;
private List<WebTaskConfig> webTasks; private List<WebTaskConfig> webTasks;
private List<User> admins; private List<User> admins;
...@@ -29,14 +29,14 @@ public class ApplicationConfiguration extends Configuration ...@@ -29,14 +29,14 @@ public class ApplicationConfiguration extends Configuration
this.admins = admins; 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() public List<WebTaskConfig> getWebTasks()
......
...@@ -5,7 +5,7 @@ package core; ...@@ -5,7 +5,7 @@ package core;
*/ */
public enum TaskType { public enum TaskType {
WEB("WEB"), WEB("WEB"),
CRYPTO("CRYPTO"), TEXT("TEXT"),
UNDEFINED("UNDEFINED"); UNDEFINED("UNDEFINED");
private final String type; private final String type;
......
...@@ -2,10 +2,8 @@ package helpers; ...@@ -2,10 +2,8 @@ package helpers;
import java.util.List; import java.util.List;
/** public class TextTaskConfig
* Created by gpietrus on 23.02.2016. {
*/
public class CryptoTaskConfig {
private String name; private String name;
private int level; private int level;
private String text; private String text;
......
...@@ -2,7 +2,7 @@ package repositories; ...@@ -2,7 +2,7 @@ package repositories;
import core.ApplicationConfiguration; import core.ApplicationConfiguration;
import core.TaskType; import core.TaskType;
import helpers.CryptoTaskConfig; import helpers.TextTaskConfig;
import helpers.WebTaskConfig; import helpers.WebTaskConfig;
import objects.Flag; import objects.Flag;
import objects.Solution; import objects.Solution;
...@@ -79,7 +79,7 @@ public class TasksRepository implements Repository ...@@ -79,7 +79,7 @@ public class TasksRepository implements Repository
@Override @Override
public void initialize() public void initialize()
{ {
List<CryptoTaskConfig> cryptoTasks = applicationConfiguration.getCryptoTasks(); List<TextTaskConfig> cryptoTasks = applicationConfiguration.getTextTasks();
List<WebTaskConfig> webTasks = applicationConfiguration.getWebTasks(); List<WebTaskConfig> webTasks = applicationConfiguration.getWebTasks();
this.clean(); this.clean();
...@@ -93,7 +93,7 @@ public class TasksRepository implements Repository ...@@ -93,7 +93,7 @@ public class TasksRepository implements Repository
this.add(new Task( this.add(new Task(
cryptoTaskConfig.getName(), cryptoTaskConfig.getName(),
cryptoTaskConfig.getLevel(), cryptoTaskConfig.getLevel(),
TaskType.CRYPTO, TaskType.TEXT,
cryptoTaskConfig.getFlags().stream() cryptoTaskConfig.getFlags().stream()
.map(Flag::new) .map(Flag::new)
.collect(Collectors.toList()), .collect(Collectors.toList()),
......
...@@ -24,41 +24,24 @@ import java.io.InputStream; ...@@ -24,41 +24,24 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/**
* Created by gpietrus on 23.02.2016.
*/
@Singleton @Singleton
@Path(value = "/task") @Path(value = "/task")
public class TaskResource { public class TaskResource
{
protected TasksRepository tasksRepository; protected TasksRepository tasksRepository;
@Inject @Inject
public TaskResource(TasksRepository tasksRepository) { public TaskResource(TasksRepository tasksRepository)
{
this.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}") @Path("{task_level}")
@GET @GET
public Response getTask(@Auth User user, 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); Task task = tasksRepository.get(taskLevel);
if (task == null) { if (task == null) {
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
...@@ -67,7 +50,7 @@ public class TaskResource { ...@@ -67,7 +50,7 @@ public class TaskResource {
String taskText = null; String taskText = null;
switch (task.getTaskType()) { switch (task.getTaskType()) {
case CRYPTO: case TEXT:
taskText = ((TaskCryptoContent) task.getTaskContent()).getText(); taskText = ((TaskCryptoContent) task.getTaskContent()).getText();
break; break;
case WEB: case WEB:
...@@ -76,4 +59,22 @@ public class TaskResource { ...@@ -76,4 +59,22 @@ public class TaskResource {
} }
return Response.ok().entity(taskText).build(); 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