diff --git a/app/assets/css/banned.css b/app/assets/css/banned.css new file mode 100644 index 0000000..bd4719c --- /dev/null +++ b/app/assets/css/banned.css @@ -0,0 +1,43 @@ +@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"); + +* { + margin: 0px; + padding: 0px; + box-sizing: border-box; +} + +body { + background-color: #262626; +} + +main > article > section > img { + width: 150px; +} + +main > article { + display: flex; + flex-wrap: wrap ; + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} + +main > article > section.informations { + width: 363px; + color: #ffffff; + padding: 13px 13px 13px 13px; + font-weight: bolder; + text-align: center; + font-family: "Roboto", sans-serif; +} + +main > article > section.informations > h2 { + margin-bottom: 10px; +} + +main > article > section.informations > p { + font-weight: lighter; + text-align: left; + margin-left: 10px; +} \ No newline at end of file diff --git a/app/assets/img/Catboat_Logo-04.png b/app/assets/img/Catboat_Logo-04.png new file mode 100644 index 0000000..6d900ae Binary files /dev/null and b/app/assets/img/Catboat_Logo-04.png differ diff --git a/app/assets/js/banned.js b/app/assets/js/banned.js new file mode 100644 index 0000000..205f553 --- /dev/null +++ b/app/assets/js/banned.js @@ -0,0 +1,11 @@ +function setBannedBy(banner) { + document.querySelector("#bannedBy").innerText = banner +} + +function setBannedAt(date) { + document.querySelector("#bannedAt").innerText = date +} + +function setBannedBecause(reason) { + document.querySelector("#bannedBecause").innerText = reason +} \ No newline at end of file diff --git a/app/banned.html b/app/banned.html new file mode 100644 index 0000000..6b5d238 --- /dev/null +++ b/app/banned.html @@ -0,0 +1,49 @@ + + + + + + + Launcher banni + + + +
+
+ +
+

Votre launcher à été bannis.

+

+ + Par : + + + Administrateur + +

+

+ + Effectué le : + + + 01/01/1970 00:00 + +

+

+ + Raison : + + + Launcher non conforme aux CGU + +

+
+
+
+ + + + + \ No newline at end of file diff --git a/app/index.html b/app/index.html index e69de29..d01f779 100644 --- a/app/index.html +++ b/app/index.html @@ -0,0 +1,11 @@ + + + + + + Document + + + + + \ No newline at end of file diff --git a/config.json b/config.json index 88bc35f..b9dd8c9 100644 --- a/config.json +++ b/config.json @@ -2,7 +2,8 @@ "api": { "base": "http://localhost:8535", "endpoints": { - "fileHash": "/api/v1/file/hash/" + "fileHash": "/api/v1/file/hash/", + "checkBanStatus": "/api/v1/ban/iam" } } } \ No newline at end of file diff --git a/main.js b/main.js index 3901287..ad8d13e 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,12 @@ const { BrowserWindow, app, net, dialog } = require("electron") +const hwid = require("./modules/hwid") const path = require("node:path") +const config = require("./config.json") let launcherWindow async function createLauncherWindow() { if (net.isOnline()) { + const isLauncherNotBanned = await checkIfIAmBanned() launcherWindow = new BrowserWindow({ frame: false, width: 900, @@ -13,12 +16,43 @@ async function createLauncherWindow() { titleBarStyle: "hidden", autoHideMenuBar: true, roundedCorners: false, + resizable: false, webPreferences: { nodeIntegration: false, contextIsolation: true, preload: path.join(__dirname, "app", "index.html") } }) + if (isLauncherNotBanned.success) { + launcherWindow.loadFile(path.join(__dirname, "app", "index.html")) + } else { + launcherWindow.loadFile(path.join(__dirname, "app", "banned.html")) + launcherWindow.webContents.executeJavaScript(` + setBannedBy("${isLauncherNotBanned.banned_by}") + setBannedAt("${isLauncherNotBanned.banned_at}") + setBannedBecause("${isLauncherNotBanned.reason}") + `) + } + } else { + dialog.showErrorBox("Le launcher requiert une connexion internet.") + } +} + +async function checkIfIAmBanned() { + if (net.isOnline()) { + try { + const reponse = await fetch(config, { + body: JSON.stringify({ + hwid: hwid.getHWID() + }) + }) + const json = await reponse.json() + return json + } catch (error) { + dialog.showErrorBox("Impossible de contacter l'API, fermeture du launcher.") + console.error(error) + app.exit() + } } else { dialog.showErrorBox("Le launcher requiert une connexion internet.") } diff --git a/modules/hwid.js b/modules/hwid.js new file mode 100644 index 0000000..7551160 --- /dev/null +++ b/modules/hwid.js @@ -0,0 +1,86 @@ +const crypto = require("node:crypto") +const os = require("node:os") +const { readFileSync } = require("fs") +const { execSync } = require("child_process") + +function getDiskSerial() { + try { + let command + if (os.platform() === "win32") { + command = "wmic diskdrive get serialnumber" + const output = execSync(command).toString() + const serial = output.split("\n")[1].trim() + return serial + } else if (os.platform() === "darwin") { + command = "system_profiler SPHardwareDataType | grep 'Serial Number'" + const output = execSync(command).toString() + const serial = output.match(/Serial Number: (.+)/)?.[1]?.trim() + return serial + } else if (os.platform() === "linux") { + const serialPath = "/sys/class/block/sda/device/serial" + const serial = readFileSync(serialPath, "utf8").trim() + return serial + } else { + throw new Error("Unsupported OS") + } + } catch (error) { + console.error("Error retrieving disk serial number:", error) + return "" + } +} + +function getMotherboardSerial() { + try { + let command + if (os.platform() === "win32") { + command = "wmic baseboard get serialnumber" + const output = execSync(command).toString() + const serial = output.split("\n")[1].trim() + return serial + } else if (os.platform() === "darwin") { + command = "ioreg -l | grep IOPlatformSerialNumber" + const output = execSync(command).toString() + const serial = output.match(/"IOPlatformSerialNumber" = "(.+?)"/)?.[1]?.trim() + return serial + } else if (os.platform() === "linux") { + const serialPath = "/sys/class/dmi/id/board_serial" + const serial = readFileSync(serialPath, "utf8").trim() + return serial + } else { + throw new Error("Unsupported OS") + } + } catch (error) { + console.error("Error retrieving motherboard serial number:", error) + return "" + } +} + +function getMacAddresses() { + const networkInterfaces = os.networkInterfaces() + const macs = [] + + for (const iface of Object.values(networkInterfaces)) { + for (const nic of iface) { + if (!nic.internal && nic.mac !== "00:00:00:00:00:00") { + macs.push(nic.mac) + } + } + } + + return macs.join("") +} + +function generateHWID() { + const diskSerial = getDiskSerial() + const motherboardSerial = getMotherboardSerial() + const macAddresses = getMacAddresses() + const cpuInfo = os.cpus().map(cpu => cpu.model).join("") + const user = os.userInfo().username + + const uniqueData = `${diskSerial}-${motherboardSerial}-${macAddresses}-${cpuInfo}-${user}` + const hwid = crypto.createHash("sha256").update(uniqueData).digest("hex") + + return hwid +} + +module.exports.getHWID = generateHWID \ No newline at end of file