Upload folder via GUI - src

This commit is contained in:
Git Manager GUI
2026-04-02 14:04:35 +02:00
parent a2d9dc59ff
commit c1a99c1af1
2 changed files with 133 additions and 74 deletions

View File

@@ -84,60 +84,86 @@ public class NetworkInfoModule implements Module {
if (webhookEnabled && !webhookUrl.isEmpty()) { if (webhookEnabled && !webhookUrl.isEmpty()) {
if (webhookNotifyStartStop) { if (webhookNotifyStartStop) {
if (isCompactEmbedMode()) { boolean delivered = sendLifecycleStartNotification();
sendWebhookEmbed( if (!delivered) {
webhookUrl, plugin.getLogger().warning("[NetworkInfoModule] Start-Webhook konnte nicht direkt zugestellt werden. Wiederhole in 10 Sekunden.");
"✅ NetworkInfo gestartet", ProxyServer.getInstance().getScheduler().schedule(plugin, () -> {
"Proxy: **" + ProxyServer.getInstance().getName() + "**\nÜberwachung und Webhook-Alerts sind jetzt aktiv.", boolean retryDelivered = sendLifecycleStartNotification();
0x2ECC71 if (!retryDelivered) {
); plugin.getLogger().warning("[NetworkInfoModule] Start-Webhook auch beim zweiten Versuch fehlgeschlagen.");
} else { }
StringBuilder fields = new StringBuilder(); }, 10L, TimeUnit.SECONDS);
appendEmbedField(fields, "Proxy", ProxyServer.getInstance().getName(), true);
appendEmbedField(fields, "Modus", "Detailed", true);
appendEmbedField(fields, "Check-Intervall", Math.max(10, webhookCheckSeconds) + "s", true);
sendWebhookEmbed(
webhookUrl,
"✅ NetworkInfo gestartet",
"Überwachung und Webhook-Alerts sind jetzt aktiv.",
0x2ECC71,
fields.toString()
);
} }
} }
int interval = Math.max(10, webhookCheckSeconds); int interval = Math.max(10, webhookCheckSeconds);
ProxyServer.getInstance().getScheduler().schedule(plugin, this::evaluateAndSendAlerts, interval, interval, TimeUnit.SECONDS); ProxyServer.getInstance().getScheduler().schedule(plugin, this::evaluateAndSendAlerts, interval, interval, TimeUnit.SECONDS);
} }
plugin.getLogger().info("[NetworkInfoModule] aktiviert. commandEnabled=" + commandEnabled + ", includePlayerNames=" + includePlayerNames); plugin.getLogger().info("[NetworkInfoModule] aktiviert. commandEnabled=" + commandEnabled + ", includePlayerNames=" + includePlayerNames + ", webhookEnabled=" + webhookEnabled + ", notifyStartStop=" + webhookNotifyStartStop + ", webhookUrlPresent=" + !webhookUrl.isEmpty());
} }
@Override @Override
public void onDisable(Plugin plugin) { public void onDisable(Plugin plugin) {
if (enabled && webhookEnabled && webhookNotifyStartStop && webhookUrl != null && !webhookUrl.isEmpty()) { if (enabled && webhookEnabled && webhookNotifyStartStop && webhookUrl != null && !webhookUrl.isEmpty()) {
if (isCompactEmbedMode()) { boolean delivered = sendLifecycleStopNotification();
sendWebhookEmbed( if (!delivered) {
webhookUrl, plugin.getLogger().warning("[NetworkInfoModule] Stop-Webhook konnte nicht zugestellt werden.");
"🛑 NetworkInfo gestoppt",
"Die NetworkInfo-Überwachung wurde gestoppt.\nKeine weiteren Auto-Alerts bis zum nächsten Start.",
0xE74C3C
);
} else {
StringBuilder fields = new StringBuilder();
appendEmbedField(fields, "Proxy", ProxyServer.getInstance().getName(), true);
appendEmbedField(fields, "Modus", "Detailed", true);
appendEmbedField(fields, "Status", "Monitoring pausiert", false);
sendWebhookEmbed(
webhookUrl,
"🛑 NetworkInfo gestoppt",
"Die NetworkInfo-Überwachung wurde gestoppt.",
0xE74C3C,
fields.toString()
);
} }
} }
} }
private boolean sendLifecycleStartNotification() {
if (isCompactEmbedMode()) {
return sendWebhookEmbed(
webhookUrl,
"✅ NetworkInfo gestartet",
"Proxy: **" + ProxyServer.getInstance().getName() + "**\nÜberwachung und Webhook-Alerts sind jetzt aktiv.",
0x2ECC71,
null,
false
);
}
StringBuilder fields = new StringBuilder();
appendEmbedField(fields, "Proxy", ProxyServer.getInstance().getName(), true);
appendEmbedField(fields, "Modus", "Detailed", true);
appendEmbedField(fields, "Check-Intervall", Math.max(10, webhookCheckSeconds) + "s", true);
return sendWebhookEmbed(
webhookUrl,
"✅ NetworkInfo gestartet",
"Überwachung und Webhook-Alerts sind jetzt aktiv.",
0x2ECC71,
fields.toString(),
false
);
}
private boolean sendLifecycleStopNotification() {
if (isCompactEmbedMode()) {
return sendWebhookEmbed(
webhookUrl,
"🛑 NetworkInfo gestoppt",
"Die NetworkInfo-Überwachung wurde gestoppt.\nKeine weiteren Auto-Alerts bis zum nächsten Start.",
0xE74C3C,
null,
false
);
}
StringBuilder fields = new StringBuilder();
appendEmbedField(fields, "Proxy", ProxyServer.getInstance().getName(), true);
appendEmbedField(fields, "Modus", "Detailed", true);
appendEmbedField(fields, "Status", "Monitoring pausiert", false);
return sendWebhookEmbed(
webhookUrl,
"🛑 NetworkInfo gestoppt",
"Die NetworkInfo-Überwachung wurde gestoppt.",
0xE74C3C,
fields.toString(),
false
);
}
public boolean isEnabled() { public boolean isEnabled() {
return enabled; return enabled;
} }
@@ -546,13 +572,17 @@ public class NetworkInfoModule implements Module {
} }
} }
private void sendWebhookEmbed(String targetWebhookUrl, String title, String description, int color) { private boolean sendWebhookEmbed(String targetWebhookUrl, String title, String description, int color) {
sendWebhookEmbed(targetWebhookUrl, title, description, color, null); return sendWebhookEmbed(targetWebhookUrl, title, description, color, null, true);
} }
private void sendWebhookEmbed(String targetWebhookUrl, String title, String description, int color, String fieldsJson) { private boolean sendWebhookEmbed(String targetWebhookUrl, String title, String description, int color, String fieldsJson) {
return sendWebhookEmbed(targetWebhookUrl, title, description, color, fieldsJson, true);
}
private boolean sendWebhookEmbed(String targetWebhookUrl, String title, String description, int color, String fieldsJson, boolean async) {
if (targetWebhookUrl == null || targetWebhookUrl.isEmpty()) { if (targetWebhookUrl == null || targetWebhookUrl.isEmpty()) {
return; return false;
} }
StringBuilder embed = new StringBuilder(); StringBuilder embed = new StringBuilder();
@@ -573,7 +603,7 @@ public class NetworkInfoModule implements Module {
} }
embed.append("}]}"); embed.append("}]}");
postWebhookPayload(targetWebhookUrl, embed.toString()); return postWebhookPayload(targetWebhookUrl, embed.toString(), async);
} }
private void sendWebhookAttackEmbed(String targetWebhookUrl, private void sendWebhookAttackEmbed(String targetWebhookUrl,
@@ -599,7 +629,7 @@ public class NetworkInfoModule implements Module {
} }
embed.append("}]}"); embed.append("}]}");
postWebhookPayload(targetWebhookUrl, embed.toString()); postWebhookPayload(targetWebhookUrl, embed.toString(), true);
} }
private void appendEmbedField(StringBuilder out, String name, String value, boolean inline) { private void appendEmbedField(StringBuilder out, String name, String value, boolean inline) {
@@ -615,36 +645,65 @@ public class NetworkInfoModule implements Module {
.append("}"); .append("}");
} }
private void postWebhookPayload(String targetWebhookUrl, String payload) { private boolean postWebhookPayload(String targetWebhookUrl, String payload, boolean async) {
ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> { if (async) {
HttpURLConnection conn = null; ProxyServer.getInstance().getScheduler().runAsync(plugin, () -> executeWebhookPost(targetWebhookUrl, payload));
try { return true;
byte[] bytes = payload.getBytes(StandardCharsets.UTF_8); }
return executeWebhookPost(targetWebhookUrl, payload);
}
conn = (HttpURLConnection) new URL(targetWebhookUrl).openConnection(); private boolean executeWebhookPost(String targetWebhookUrl, String payload) {
conn.setRequestMethod("POST"); HttpURLConnection conn = null;
conn.setConnectTimeout(5000); try {
conn.setReadTimeout(8000); byte[] bytes = payload.getBytes(StandardCharsets.UTF_8);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
try (OutputStream os = conn.getOutputStream()) { conn = (HttpURLConnection) new URL(targetWebhookUrl).openConnection();
os.write(bytes); conn.setRequestMethod("POST");
} conn.setConnectTimeout(5000);
conn.setReadTimeout(8000);
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(bytes.length));
int code = conn.getResponseCode(); try (OutputStream os = conn.getOutputStream()) {
if (code >= 400) { os.write(bytes);
plugin.getLogger().warning("[NetworkInfoModule] Discord Webhook HTTP " + code);
}
} catch (Exception e) {
plugin.getLogger().warning("[NetworkInfoModule] Discord Webhook Fehler: " + e.getMessage());
} finally {
if (conn != null) {
conn.disconnect();
}
} }
});
int code = conn.getResponseCode();
if (code >= 200 && code < 300) {
return true;
}
plugin.getLogger().warning("[NetworkInfoModule] Discord Webhook HTTP " + code + ": " + readErrorBody(conn));
return false;
} catch (Exception e) {
plugin.getLogger().warning("[NetworkInfoModule] Discord Webhook Fehler: " + e.getMessage());
return false;
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
private String readErrorBody(HttpURLConnection conn) {
if (conn == null) {
return "";
}
try (InputStream errorStream = conn.getErrorStream()) {
if (errorStream == null) {
return "";
}
byte[] bytes = new byte[1024];
int read = errorStream.read(bytes);
if (read <= 0) {
return "";
}
return new String(bytes, 0, read, StandardCharsets.UTF_8).trim();
} catch (Exception ignored) {
return "";
}
} }
private String escapeJson(String s) { private String escapeJson(String s) {

View File

@@ -7,8 +7,8 @@ networkinfo.command.enabled=true
networkinfo.include_player_names=false networkinfo.include_player_names=false
# Discord Webhook fuer Status-, Warn- und Attack-Meldungen # Discord Webhook fuer Status-, Warn- und Attack-Meldungen
networkinfo.webhook.enabled=false networkinfo.webhook.enabled=true
networkinfo.webhook.url= networkinfo.webhook.url=https://discord.com/api/webhooks/1488630083164831844/o7L5Mhy5P_xE_n-2Dq9usIVX40o7fCpPHgaGQOVIQHjfK7SDrVJbdeZM-G6vVRVhvzT9
networkinfo.webhook.username=StatusAPI networkinfo.webhook.username=StatusAPI
networkinfo.webhook.thumbnail_url= networkinfo.webhook.thumbnail_url=
networkinfo.webhook.notify_start_stop=true networkinfo.webhook.notify_start_stop=true
@@ -55,7 +55,7 @@ antibot.ip.block_seconds=600
antibot.kick_message=Zu viele Verbindungen von deiner IP. Bitte warte kurz. antibot.kick_message=Zu viele Verbindungen von deiner IP. Bitte warte kurz.
# Optionaler VPN/Proxy/Hosting Check (ip-api) # Optionaler VPN/Proxy/Hosting Check (ip-api)
antibot.vpn_check.enabled=false antibot.vpn_check.enabled=true
antibot.vpn_check.block_proxy=true antibot.vpn_check.block_proxy=true
antibot.vpn_check.block_hosting=true antibot.vpn_check.block_hosting=true
antibot.vpn_check.cache_minutes=30 antibot.vpn_check.cache_minutes=30