Удаленный вызов комманд

This commit is contained in:
Gravit 2018-10-05 15:36:50 +07:00
parent f9aecb5036
commit 7ae32bf1e7
4 changed files with 38 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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)
{

View file

@ -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"));
}
}