Skip to content

Commit

Permalink
Add console endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
BlankParenthesis committed Nov 16, 2023
1 parent 02c1d50 commit bb564b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions resources/roles-reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ developer {
board.palette.all
board.placemap.ignore
chat.usercolor.rainbow
management.console
]
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/space/pxls/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void run() {
saveMap();
}

private static void handleCommand(String line) {
public static void handleCommand(String line) {
try {
String[] token = line.split(" ");
if (token[0].equalsIgnoreCase("reload")) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/space/pxls/server/UndertowServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void start() {
.addPermGatedPrefixPath("/sendNotificationToDiscord", "notification.discord", webHandler::sendNotificationToDiscord)
.addPermGatedPrefixPath("/setNotificationExpired", "notification.expired", webHandler::setNotificationExpired)
.addPermGatedPrefixPath("/notifications", "notification.list", webHandler::notificationsList)
.addPermGatedPrefixPath("/console", "management.console", new AllowedMethodsHandler(webHandler::webConsole, Methods.POST))
.addExactPath("/", webHandler::index)
.addExactPath("/index.html", webHandler::index)
.addExactPath("/factions", new AllowedMethodsHandler(webHandler::getRequestingUserFactions, Methods.GET))
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/space/pxls/server/WebHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,17 @@ public void whoami(HttpServerExchange exchange) {
}
}

public void webConsole(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);

try {
App.handleCommand(data.getFirst("command").getValue());
exchange.setStatusCode(StatusCodes.OK);
} catch (NullPointerException ex) {
exchange.setStatusCode(StatusCodes.BAD_REQUEST);
}
}

private User parseUserFromForm(HttpServerExchange exchange) {
FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
if (data != null) {
Expand Down

0 comments on commit bb564b0

Please sign in to comment.