Improved security
This commit is contained in:
@ -24,7 +24,7 @@ function openServer(serverName){
|
||||
|
||||
//Change server name and related info
|
||||
$("#serverTitle").text(serverName);
|
||||
$("#consoleTextArea").text("Connecting...");
|
||||
$("#consoleTextArea").text("");
|
||||
$("#commandInput").prop("disabled", false);
|
||||
$("#sendCommandButton").prop("disabled", false);
|
||||
|
||||
|
@ -9,6 +9,7 @@ class WebConsoleConnector {
|
||||
constructor(serverName, serverURI) {
|
||||
this.serverName = serverName;
|
||||
this.serverURI = serverURI;
|
||||
this.token;
|
||||
this.subscribers = []; //List of functions called when a new message arrive
|
||||
this.messages = []; //All messages retrieved since connection start
|
||||
this.commands = []; //EXEC Commands sent by user to this server
|
||||
@ -32,7 +33,7 @@ class WebConsoleConnector {
|
||||
* Internal function
|
||||
*/
|
||||
onOpen(evt){
|
||||
//TODO Check que la version es correcta, y que es un WebSocket del plugin y no de otra cosa
|
||||
//TODO Check version is correct, and this websocket server is a WebConsole WebSocket
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,6 +49,11 @@ class WebConsoleConnector {
|
||||
*/
|
||||
onMessage(evt){
|
||||
var obj = JSON.parse(evt.data);
|
||||
|
||||
|
||||
if(obj.status === 200) //If is a LoggedIn response, save our token
|
||||
this.token = obj.token;
|
||||
|
||||
this.notify(obj); //Notify all subscribers
|
||||
this.messages.push(obj);
|
||||
}
|
||||
@ -63,7 +69,7 @@ class WebConsoleConnector {
|
||||
* Sends a WebSocket command to Server
|
||||
*/
|
||||
sendToServer(message){
|
||||
this.websocket.send(message);
|
||||
this.websocket.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,14 +60,22 @@ class WebConsoleManager {
|
||||
* Send password to server
|
||||
*/
|
||||
sendPassword(pwd){
|
||||
this.activeConnection.sendToServer("LOGIN " + pwd);
|
||||
this.activeConnection.sendToServer({
|
||||
command: "LOGIN",
|
||||
params: pwd
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Send console command to server
|
||||
*/
|
||||
sendConsoleCmd(cmd){
|
||||
this.activeConnection.sendToServer("EXEC " + cmd);
|
||||
this.activeConnection.sendToServer({
|
||||
command: "EXEC",
|
||||
token: this.activeConnection.token,
|
||||
params: cmd
|
||||
});
|
||||
|
||||
this.activeConnection.commands.push(cmd);
|
||||
}
|
||||
|
||||
@ -75,16 +83,30 @@ class WebConsoleManager {
|
||||
* Asks server for CPU, RAM and players info
|
||||
*/
|
||||
askForInfo(){
|
||||
this.activeConnection.sendToServer("PLAYERS");
|
||||
this.activeConnection.sendToServer("CPUUSAGE");
|
||||
this.activeConnection.sendToServer("RAMUSAGE");
|
||||
this.activeConnection.sendToServer({
|
||||
command: "PLAYERS",
|
||||
token: this.activeConnection.token,
|
||||
});
|
||||
|
||||
this.activeConnection.sendToServer({
|
||||
command: "CPUUSAGE",
|
||||
token: this.activeConnection.token,
|
||||
});
|
||||
|
||||
this.activeConnection.sendToServer({
|
||||
command: "RAMUSAGE",
|
||||
token: this.activeConnection.token,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks server for full latest.log
|
||||
*/
|
||||
askForLogs(){
|
||||
this.activeConnection.sendToServer("READLOGFILE");
|
||||
this.activeConnection.sendToServer({
|
||||
command: "READLOGFILE",
|
||||
token: this.activeConnection.token,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user