Upload folder via GUI - StatusAPI.java
This commit is contained in:
@@ -268,6 +268,32 @@ public class StatusAPI extends Plugin implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
// --- GET /network/backendguard/config ---
|
||||
if ("GET".equalsIgnoreCase(method) && path.equalsIgnoreCase("/network/backendguard/config")) {
|
||||
Properties guardProps = loadNetworkGuardProperties();
|
||||
String requiredApiKey = guardProps.getProperty("backendguard.sync.api_key", "").trim();
|
||||
String providedApiKey = headers.getOrDefault("x-api-key", headers.getOrDefault("x-apikey", ""));
|
||||
|
||||
if (!requiredApiKey.isEmpty() && !requiredApiKey.equals(providedApiKey == null ? "" : providedApiKey.trim())) {
|
||||
sendHttpResponse(out, "{\"success\":false,\"error\":\"bad_api_key\"}", 403);
|
||||
return;
|
||||
}
|
||||
|
||||
Map<String, Object> payload = new LinkedHashMap<String, Object>();
|
||||
payload.put("success", true);
|
||||
|
||||
Map<String, Object> guard = new LinkedHashMap<String, Object>();
|
||||
guard.put("enforcement_enabled", Boolean.parseBoolean(guardProps.getProperty("backendguard.enforcement_enabled", "true")));
|
||||
guard.put("log_blocked_attempts", Boolean.parseBoolean(guardProps.getProperty("backendguard.log_blocked_attempts", "true")));
|
||||
guard.put("kick_message", guardProps.getProperty("backendguard.kick_message", "&cBitte verbinde dich nur ueber den Proxy."));
|
||||
guard.put("allowed_proxy_ips", parseCommaListProperty(guardProps.getProperty("backendguard.allowed_proxy_ips", "127.0.0.1,::1")));
|
||||
guard.put("allowed_proxy_cidrs", parseCommaListProperty(guardProps.getProperty("backendguard.allowed_proxy_cidrs", "")));
|
||||
|
||||
payload.put("backend_guard", guard);
|
||||
sendHttpResponse(out, buildJsonString(payload), 200);
|
||||
return;
|
||||
}
|
||||
|
||||
// --- POST /forum/notify ---
|
||||
if ("POST".equalsIgnoreCase(method) && path.equalsIgnoreCase("/forum/notify")) {
|
||||
int contentLength = 0;
|
||||
@@ -631,6 +657,37 @@ public class StatusAPI extends Plugin implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private Properties loadNetworkGuardProperties() {
|
||||
Properties props = new Properties();
|
||||
File file = new File(getDataFolder(), "network-guard.properties");
|
||||
if (!file.exists()) {
|
||||
return props;
|
||||
}
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file)) {
|
||||
props.load(new InputStreamReader(fis, StandardCharsets.UTF_8));
|
||||
} catch (Exception e) {
|
||||
getLogger().warning("Konnte network-guard.properties nicht laden: " + e.getMessage());
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
private List<String> parseCommaListProperty(String raw) {
|
||||
List<String> out = new ArrayList<String>();
|
||||
if (raw == null || raw.trim().isEmpty()) {
|
||||
return out;
|
||||
}
|
||||
|
||||
String[] parts = raw.split(",");
|
||||
for (String p : parts) {
|
||||
String trimmed = p == null ? "" : p.trim();
|
||||
if (!trimmed.isEmpty()) {
|
||||
out.add(trimmed);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
private void sendHttpResponse(OutputStream out, String json, int code) throws IOException {
|
||||
byte[] jsonBytes = json.getBytes(StandardCharsets.UTF_8);
|
||||
StringBuilder response = new StringBuilder();
|
||||
|
||||
Reference in New Issue
Block a user