diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java index b1dde197..e888b325 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/ClientPermissions.java @@ -13,4 +13,11 @@ public ClientPermissions(long data) { canAdmin = (data & (1 << 0)) != 0; canServer = (data & (1 << 1)) != 0; } + public static ClientPermissions getSuperuserAccount() + { + ClientPermissions perm = new ClientPermissions(); + perm.canServer = true; + perm.canAdmin = true; + return perm; + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java index 7f23c7d6..8136330f 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/provider/AcceptAuthProvider.java @@ -1,12 +1,16 @@ package ru.gravit.launchserver.auth.provider; +import ru.gravit.launcher.serialize.config.entry.BooleanConfigEntry; +import ru.gravit.launcher.serialize.config.entry.StringConfigEntry; import ru.gravit.launchserver.LaunchServer; import ru.gravit.utils.helper.SecurityHelper; import ru.gravit.launcher.serialize.config.entry.BlockConfigEntry; public final class AcceptAuthProvider extends AuthProvider { + private final boolean isAdminAccess; public AcceptAuthProvider(BlockConfigEntry block, LaunchServer server) { super(block,server); + isAdminAccess = block.hasEntry("admin") ? block.getEntryValue("admin", BooleanConfigEntry.class) : false; } @Override diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java index e7dfa538..67b02a06 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/WebSocketService.java @@ -18,6 +18,7 @@ import ru.gravit.launchserver.socket.websocket.json.auth.CheckServerResponse; import ru.gravit.launchserver.socket.websocket.json.auth.JoinServerResponse; import ru.gravit.launchserver.socket.websocket.json.update.LauncherResponse; +import ru.gravit.launchserver.socket.websocket.json.update.UpdateListResponse; import ru.gravit.utils.helper.LogHelper; import java.util.HashMap; @@ -70,6 +71,8 @@ public void registerResponses() registerResponse("checkServer", CheckServerResponse.class); registerResponse("joinServer", JoinServerResponse.class); registerResponse("launcherUpdate", LauncherResponse.class); + registerResponse("updateList", UpdateListResponse.class); + registerResponse("cmdExec",UpdateListResponse.class); } public void sendObject(ChannelHandlerContext ctx, Object obj) { diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java new file mode 100644 index 00000000..8094881b --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/websocket/json/admin/ExecCommandResponse.java @@ -0,0 +1,24 @@ +package ru.gravit.launchserver.socket.websocket.json.admin; + +import io.netty.channel.ChannelHandlerContext; +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.handler.CommandHandler; +import ru.gravit.launchserver.socket.Client; +import ru.gravit.launchserver.socket.websocket.WebSocketService; +import ru.gravit.launchserver.socket.websocket.json.JsonResponseInterface; + +public class ExecCommandResponse implements JsonResponseInterface { + public String cmd; + @Override + public String getType() { + return "cmdExec"; + } + + @Override + public void execute(WebSocketService service, ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth) {service.sendObject(ctx,new WebSocketService.ErrorResult("Access denied")); return; } + if(!client.permissions.canAdmin) {service.sendObject(ctx,new WebSocketService.ErrorResult("Access denied")); return; } + LaunchServer.server.commandHandler.eval(cmd,false); + service.sendObject(ctx,new WebSocketService.SuccessResult("cmdExec")); + } +}