ε - Fix logs in c2

This commit is contained in:
Eun0us 2026-01-25 15:16:24 +01:00
parent 425e3422cf
commit 8540ee16f5
3 changed files with 18 additions and 95 deletions

View File

@ -1,94 +0,0 @@
name: Discord - Commits
on:
push:
branches:
- "**"
workflow_dispatch:
jobs:
notify:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Post to Discord (embed)
env:
DISCORD_WEBHOOK: ${{ secrets.WEBHOOK_URL }}
EVENT_JSON: ${{ toJson(github.event) }}
run: |
node - <<'NODE'
const event = JSON.parse(process.env.EVENT_JSON);
const webhook = process.env.DISCORD_WEBHOOK;
if (!webhook) {
console.error("❌ Secret WEBHOOK_URL manquant. (Repo Settings > Secrets and variables > Actions)");
process.exit(1);
}
const repoName = event.repository?.full_name || "unknown/repo";
const repoUrl = event.repository?.html_url || "";
const branch = (event.ref || "").replace("refs/heads/", "");
const compareUrl = event.compare || repoUrl;
const pusher = event.pusher?.name || event.sender?.login || "someone";
const commits = (event.commits || []).slice(0, 10).map(c => {
const sha = (c.id || "").slice(0, 7);
const msg = (c.message || "").split("\n")[0];
const author = c.author?.name || "unknown";
const url = c.url
? c.url.replace("api.github.com/repos", "github.com").replace("/commits/", "/commit/")
: "";
return { sha, msg, author, url };
});
const description = commits.length
? commits.map(c => `• **[${c.sha}](${c.url})** ${c.msg} — _${c.author}_`).join("\n")
: "• (Pas de détails de commits fournis par l'événement)";
// Discord embed limits: description max ~4096 chars
const safeDescription = description.length > 3900
? description.slice(0, 3900) + "\n…"
: description;
const payload = {
content: null,
embeds: [
{
title: `📌 Push sur ${repoName}`,
url: compareUrl,
description: safeDescription,
color: 0x7289DA,
author: {
name: pusher,
url: `https://github.com/${event.sender?.login || ""}`
},
fields: [
{ name: "Branche", value: `\`${branch || "?"}\``, inline: true },
{ name: "Commits", value: `${event.commits?.length ?? commits.length}`, inline: true }
],
footer: { text: "GitHub Actions → Discord" },
timestamp: new Date().toISOString()
}
]
};
fetch(webhook, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload)
})
.then(async (res) => {
const txt = await res.text();
if (!res.ok) {
console.error(`❌ Discord error ${res.status}: ${txt}`);
process.exit(1);
}
console.log("✅ Notification envoyée sur Discord.");
})
.catch((err) => {
console.error("❌ Fetch error:", err);
process.exit(1);
});
NODE

View File

@ -1,7 +1,7 @@
from core.crypto import CryptoContext from core.crypto import CryptoContext
from core.device import Device from core.device import Device
from core.registry import DeviceRegistry from core.registry import DeviceRegistry
from logs.manager import LogManager from logging.manager import LogManager
from utils.display import Display from utils.display import Display
from proto.c2_pb2 import Command, AgentMessage, AgentMsgType from proto.c2_pb2 import Command, AgentMessage, AgentMsgType

View File

@ -0,0 +1,17 @@
from utils.constant import _color
class LogManager:
def handle(self, log):
level = "INFO"
color = "GREEN"
if log.log_error_code != 0:
level = f"ERROR:{log.log_error_code}"
color = "RED"
print(
f"{_color(color)}"
f"[ESP:{log.id}][{log.tag}][{level}] {log.log_message}"
f"{_color('RESET')}"
)