Merge pull request #1 from awesomemoder316/feature/command-whitelist&blacklist
Update to Version 2.2
This commit is contained in:
commit
896e659e93
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Attempted to send a message to a discon
|
|||||||
cpu-usage-message = Usage is {0}%
|
cpu-usage-message = Usage is {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} tried to run {1} without permission.
|
no-send-permission-console = [WebConsole] {0} tried to run {1} without permission.
|
||||||
cmd-executed-console = [WebConsole] {0} executed "{1}".
|
cmd-executed-console = [WebConsole] {0} executed "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Pokus o odeslání zprávy odpojenému
|
|||||||
cpu-usage-message = Využití je {0}%
|
cpu-usage-message = Využití je {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} se pokusil spustit {1} bez povolení.
|
no-send-permission-console = [WebConsole] {0} se pokusil spustit {1} bez povolení.
|
||||||
cmd-executed-console = [WebConsole] {0} spustil "{1}".
|
cmd-executed-console = [WebConsole] {0} spustil "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Es wurde versucht, eine Nachricht an ei
|
|||||||
cpu-usage-message = Die CPU Auslastung liegt bei {0}%.
|
cpu-usage-message = Die CPU Auslastung liegt bei {0}%.
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} hat versucht, {1} ohne Erlaubnis auszuführen.
|
no-send-permission-console = [WebConsole] {0} hat versucht, {1} ohne Erlaubnis auszuführen.
|
||||||
cmd-executed-console = [WebConsole] {0} hat "{1}" ausgeführt.
|
cmd-executed-console = [WebConsole] {0} hat "{1}" ausgeführt.
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Attempted to send a message to a discon
|
|||||||
cpu-usage-message = Usage is {0}%
|
cpu-usage-message = Usage is {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} tried to run {1} without permission.
|
no-send-permission-console = [WebConsole] {0} tried to run {1} without permission.
|
||||||
cmd-executed-console = [WebConsole] {0} executed "{1}".
|
cmd-executed-console = [WebConsole] {0} executed "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Se intentó enviar un mensaje a un clie
|
|||||||
cpu-usage-message = En uso {0}%
|
cpu-usage-message = En uso {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} intentó ejecutar {1} sin permiso.
|
no-send-permission-console = [WebConsole] {0} intentó ejecutar {1} sin permiso.
|
||||||
cmd-executed-console = [WebConsole] {0} ejecutó "{1}".
|
cmd-executed-console = [WebConsole] {0} ejecutó "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Vous avez tenté d'envoyer un message
|
|||||||
cpu-usage-message = L'utilisation est {0}%
|
cpu-usage-message = L'utilisation est {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} a tenté d'exécuter {1} sans autorisation.
|
no-send-permission-console = [WebConsole] {0} a tenté d'exécuter {1} sans autorisation.
|
||||||
cmd-executed-console = [WebConsole] {0} a exécuté "{1}".
|
cmd-executed-console = [WebConsole] {0} a exécuté "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Tentativo di inviare un messaggio a un
|
|||||||
cpu-usage-message = L''uso è {0}%
|
cpu-usage-message = L''uso è {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} ha provato a eseguire {1} senza autorizzazione.
|
no-send-permission-console = [WebConsole] {0} ha provato a eseguire {1} senza autorizzazione.
|
||||||
cmd-executed-console = [WebConsole] {0} eseguito "{1}".
|
cmd-executed-console = [WebConsole] {0} eseguito "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] 연결이 끊긴 WebSocket 클라이언
|
|||||||
cpu-usage-message = 사용량은 {0}%입니다
|
cpu-usage-message = 사용량은 {0}%입니다
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0}이(가) {1}을(를) 권한 없이 실행하려고 했습니다.
|
no-send-permission-console = [WebConsole] {0}이(가) {1}을(를) 권한 없이 실행하려고 했습니다.
|
||||||
cmd-executed-console = [WebConsole] {0}이(가) "{1}"을(를) 실행하였습니다.
|
cmd-executed-console = [WebConsole] {0}이(가) "{1}"을(를) 실행하였습니다.
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Poging om een bericht te sturen naar ee
|
|||||||
cpu-usage-message = Verbruik is {0}%
|
cpu-usage-message = Verbruik is {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} heeft geprobeerd {1} uit te voeren zonder toestemming.
|
no-send-permission-console = [WebConsole] {0} heeft geprobeerd {1} uit te voeren zonder toestemming.
|
||||||
cmd-executed-console = [WebConsole] {0} voerde "{1}" uit.
|
cmd-executed-console = [WebConsole] {0} voerde "{1}" uit.
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Tentativa de enviar uma mensagem para u
|
|||||||
cpu-usage-message = Consumindo {0}%
|
cpu-usage-message = Consumindo {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} tentou executar o {1} sem permissão.
|
no-send-permission-console = [WebConsole] {0} tentou executar o {1} sem permissão.
|
||||||
cmd-executed-console = [WebConsole] {0} executou "{1}".
|
cmd-executed-console = [WebConsole] {0} executou "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Попытка отправить со
|
|||||||
cpu-usage-message = Использование {0}%
|
cpu-usage-message = Использование {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0} попытался запустить {1} без разрешения.
|
no-send-permission-console = [WebConsole] {0} попытался запустить {1} без разрешения.
|
||||||
cmd-executed-console = [WebConsole] {0} выполнил "{1}".
|
cmd-executed-console = [WebConsole] {0} выполнил "{1}".
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] Bağlantısı kesilmiş bir WebSocket'a
|
|||||||
cpu-usage-message = Şuanki kullanım %{0}
|
cpu-usage-message = Şuanki kullanım %{0}
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0}, {1}'ı yetkisiz olarak çalıştırmayı denedi.
|
no-send-permission-console = [WebConsole] {0}, {1}'ı yetkisiz olarak çalıştırmayı denedi.
|
||||||
cmd-executed-console = [WebConsole] {0}, "{1}" çalıştırdı.
|
cmd-executed-console = [WebConsole] {0}, "{1}" çalıştırdı.
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -19,7 +19,7 @@ error-disconnected-client = [WebConsole] 尝试向断开连接的WebSocket客户
|
|||||||
cpu-usage-message = 已使用 {0}%
|
cpu-usage-message = 已使用 {0}%
|
||||||
|
|
||||||
# ExecCommand.java
|
# ExecCommand.java
|
||||||
viewer-error-console = [WebConsole] {0}试图未经许可而运行{1}。
|
no-send-permission-console = [WebConsole] {0}试图未经许可而运行{1}。
|
||||||
cmd-executed-console = [網站控制台] {0} 執行 '{1}'.
|
cmd-executed-console = [網站控制台] {0} 執行 '{1}'.
|
||||||
|
|
||||||
# LogInCommand.java
|
# LogInCommand.java
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: WebConsole
|
name: WebConsole
|
||||||
main: es.mesacarlos.webconsole.WebConsole
|
main: es.mesacarlos.webconsole.WebConsole
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
version: 2.1
|
version: 2.2
|
||||||
description: WebSocket-based web console
|
description: WebSocket-based web console
|
||||||
author: Carlos Mesa
|
author: Carlos Mesa
|
||||||
commands:
|
commands:
|
||||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>WebConsole</groupId>
|
<groupId>WebConsole</groupId>
|
||||||
<artifactId>WebConsole</artifactId>
|
<artifactId>WebConsole</artifactId>
|
||||||
<version>2.1</version>
|
<version>2.2</version>
|
||||||
<build>
|
<build>
|
||||||
<sourceDirectory>src</sourceDirectory>
|
<sourceDirectory>src</sourceDirectory>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package es.mesacarlos.webconsole.config;
|
package es.mesacarlos.webconsole.config;
|
||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
@ -47,7 +45,12 @@ public class ConfigManager {
|
|||||||
if(config.getConfigurationSection("passwords") == null) {
|
if(config.getConfigurationSection("passwords") == null) {
|
||||||
ConfigurationSection passwordsSection = config.createSection("passwords");
|
ConfigurationSection passwordsSection = config.createSection("passwords");
|
||||||
ConfigurationSection adminPasswordSection = passwordsSection.createSection("admin");
|
ConfigurationSection adminPasswordSection = passwordsSection.createSection("admin");
|
||||||
adminPasswordSection.addDefault("user1", "mySecurePassword");
|
ConfigurationSection individualAdminPasswordSection = adminPasswordSection.createSection("user1");
|
||||||
|
individualAdminPasswordSection.addDefault("password", "mySecurePassword");
|
||||||
|
ConfigurationSection commandWhitelist = individualAdminPasswordSection.createSection("commandWhitelist");
|
||||||
|
commandWhitelist.addDefault("enabled", false);
|
||||||
|
commandWhitelist.addDefault("commandWhitelistActsAsBlacklist", false);
|
||||||
|
commandWhitelist.addDefault("whitelist", Arrays.asList("whisper", "gamemode survival"));
|
||||||
passwordsSection.createSection("viewer");
|
passwordsSection.createSection("viewer");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,11 +99,19 @@ public class ConfigManager {
|
|||||||
* @return list of admin users
|
* @return list of admin users
|
||||||
*/
|
*/
|
||||||
private List<UserData> getAdmins() {
|
private List<UserData> getAdmins() {
|
||||||
Map<String, Object> passwords = plugin.getConfig().getConfigurationSection("passwords").getConfigurationSection("admin").getValues(false);
|
Set<String> adminConfig = plugin.getConfig().getConfigurationSection("passwords").getConfigurationSection("admin").getKeys(false);
|
||||||
List<UserData> adminUsers = new ArrayList<UserData>();
|
|
||||||
|
|
||||||
for(Map.Entry<String, Object> entry : passwords.entrySet())
|
List<UserData> adminUsers = new ArrayList<>();
|
||||||
adminUsers.add(new UserData(entry.getKey(), entry.getValue().toString(), UserType.ADMIN));
|
|
||||||
|
for(String username : adminConfig) {
|
||||||
|
adminUsers.add(new UserData(
|
||||||
|
username,
|
||||||
|
plugin.getConfig().getString("passwords.admin." + username + ".password"),
|
||||||
|
UserType.ADMIN,
|
||||||
|
plugin.getConfig().getBoolean("passwords.admin." + username + ".commandWhitelist.enabled"),
|
||||||
|
plugin.getConfig().getBoolean("passwords.admin." + username + ".commandWhitelist.commandWhitelistActsAsBlacklist"),
|
||||||
|
plugin.getConfig().getStringList("passwords.admin." + username + ".commandWhitelist.whitelist")));
|
||||||
|
}
|
||||||
|
|
||||||
return adminUsers;
|
return adminUsers;
|
||||||
}
|
}
|
||||||
@ -111,10 +122,10 @@ public class ConfigManager {
|
|||||||
*/
|
*/
|
||||||
private List<UserData> getViewers() {
|
private List<UserData> getViewers() {
|
||||||
Map<String, Object> passwords = plugin.getConfig().getConfigurationSection("passwords").getConfigurationSection("viewer").getValues(false);
|
Map<String, Object> passwords = plugin.getConfig().getConfigurationSection("passwords").getConfigurationSection("viewer").getValues(false);
|
||||||
List<UserData> viewerUsers = new ArrayList<UserData>();
|
List<UserData> viewerUsers = new ArrayList<>();
|
||||||
|
|
||||||
for(Map.Entry<String, Object> entry : passwords.entrySet())
|
for(Map.Entry<String, Object> entry : passwords.entrySet())
|
||||||
viewerUsers.add(new UserData(entry.getKey(), entry.getValue().toString(), UserType.VIEWER));
|
viewerUsers.add(new UserData(entry.getKey(), entry.getValue().toString(), UserType.VIEWER, false, false, new ArrayList<>()));
|
||||||
|
|
||||||
return viewerUsers;
|
return viewerUsers;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,23 @@
|
|||||||
package es.mesacarlos.webconsole.config;
|
package es.mesacarlos.webconsole.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class UserData {
|
public class UserData {
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
private UserType userType;
|
private UserType userType;
|
||||||
|
private boolean isWhitelistEnabled;
|
||||||
|
private boolean isWhitelistActsAsBlacklist;
|
||||||
|
private List<String> whitelistedCommands;
|
||||||
|
|
||||||
public UserData(String username, String password, UserType userType) {
|
public UserData(String username, String password, UserType userType,
|
||||||
|
boolean isWhitelistEnabled, boolean isWhitelistActsAsBlacklist, List<String> whitelistedCommands) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.userType = userType;
|
this.userType = userType;
|
||||||
|
this.isWhitelistEnabled = isWhitelistEnabled;
|
||||||
|
this.isWhitelistActsAsBlacklist = isWhitelistActsAsBlacklist;
|
||||||
|
this.whitelistedCommands = whitelistedCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsername() {
|
public String getUsername() {
|
||||||
@ -22,4 +31,16 @@ public class UserData {
|
|||||||
public UserType getUserType() {
|
public UserType getUserType() {
|
||||||
return userType;
|
return userType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isWhitelistEnabled() {
|
||||||
|
return isWhitelistEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isWhitelistActsAsBlacklist() {
|
||||||
|
return isWhitelistActsAsBlacklist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getWhitelistedCommands() {
|
||||||
|
return whitelistedCommands;
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package es.mesacarlos.webconsole.websocket.command;
|
|||||||
|
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
import es.mesacarlos.webconsole.config.ConfigManager;
|
||||||
|
import es.mesacarlos.webconsole.config.UserData;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.java_websocket.WebSocket;
|
import org.java_websocket.WebSocket;
|
||||||
@ -14,13 +16,56 @@ import es.mesacarlos.webconsole.util.Internationalization;
|
|||||||
import es.mesacarlos.webconsole.websocket.WSServer;
|
import es.mesacarlos.webconsole.websocket.WSServer;
|
||||||
|
|
||||||
public class ExecCommand implements WSCommand {
|
public class ExecCommand implements WSCommand {
|
||||||
|
LoginManager loginManager = LoginManager.getInstance();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(WSServer wsServer, WebSocket conn, String command) {
|
public void execute(WSServer wsServer, WebSocket conn, String command) {
|
||||||
ConnectedUser u = LoginManager.getInstance().getUser(conn.getRemoteSocketAddress());
|
ConnectedUser u = LoginManager.getInstance().getUser(conn.getRemoteSocketAddress());
|
||||||
if(u == null || u.getUserType() != UserType.ADMIN) {
|
if(u == null || u.getUserType() != UserType.ADMIN) {
|
||||||
if(u != null)
|
if(u != null)
|
||||||
Bukkit.getLogger().warning(Internationalization.getPhrase("viewer-error-console", u, command));
|
Bukkit.getLogger().warning(Internationalization.getPhrase("no-send-permission-console", u, command));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean allowCommand = false;
|
||||||
|
|
||||||
|
for(UserData ud : ConfigManager.getInstance().getAllUsers()) {
|
||||||
|
if (ud.getUsername().equals(loginManager.getUser(conn.getRemoteSocketAddress()).getUsername())) {
|
||||||
|
|
||||||
|
if (!ud.isWhitelistEnabled()) { //Skip whitelist check.
|
||||||
|
allowCommand = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] splitCommand = command.split(" ");
|
||||||
|
|
||||||
|
for (String whitelistedCommand : ud.getWhitelistedCommands()) {
|
||||||
|
String[] splitWhitelistedCommand = whitelistedCommand.split(" ");
|
||||||
|
|
||||||
|
for (int x = 0; x < splitWhitelistedCommand.length; x ++) {
|
||||||
|
|
||||||
|
if (!ud.isWhitelistActsAsBlacklist()) {
|
||||||
|
|
||||||
|
if (splitCommand[x].equalsIgnoreCase(splitWhitelistedCommand[x])) { //cmd is whitelisted.
|
||||||
|
allowCommand = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
allowCommand = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowCommand //Check if was detected by whitelist
|
||||||
|
&& ud.isWhitelistActsAsBlacklist()) allowCommand = true; //cmd is not blacklisted.
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allowCommand) {
|
||||||
|
Bukkit.getLogger().warning(Internationalization.getPhrase("no-send-permission-console", u, command));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user