├── LICENSE ├── README.md ├── config.json ├── database ├── discord.json ├── gblacklist.json └── users.json ├── index.js ├── main.lua ├── menu.bat └── package.json /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Pedro Guimarães 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #Authentication-System 2 | 3 | [![Watch the video](https://www.gratispng.com/png-3zqbgo/)](https://streamable.com/2cid2a) 4 | 5 | * Put the bot token inside config.json file 6 | * Install discord.js and express library using npm i 7 | * Start the bot using node . 8 | * To configure your script for authentication follow the step by step inside the header of the main.lua 9 | * Change the api url to your domain in the main.lua 10 | * Type /cofigurate and configurate the bot (Only server owner) 11 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "token" :"", 3 | "port":"80", 4 | "storename":"Pedrin", 5 | "backupdb":"database backup channel id" 6 | } 7 | -------------------------------------------------------------------------------- /database/discord.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /database/gblacklist.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /database/users.json: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const Discord = require("discord.js"); 2 | const fs = require("fs"); 3 | const http = require("http"); 4 | const express = require("express"); 5 | const config = require("./config.json"); 6 | require('events').EventEmitter.prototype._maxListeners = 10 7 | const rateLimit = require("express-rate-limit"); 8 | const { createGzip } = require("zlib"); 9 | 10 | const limiter = rateLimit({ max: 100, windowMs: 5 * 60 * 1000, message: `{"code":"047","response":"Rate-Limit Please wait some minutes"}`}); 11 | 12 | const app = express(); 13 | 14 | app.use(limiter); 15 | app.disable('x-powered-by'); 16 | 17 | async function sendmsg(channel,msg) { 18 | try{ 19 | await client.channels.cache.get(channel).send(msg) 20 | }catch{} 21 | } 22 | 23 | const Client = class extends Discord.Client { 24 | constructor(config) { 25 | super({ 26 | intents: [Discord.Intents.FLAGS.GUILD_VOICE_STATES, Discord.Intents.FLAGS.GUILD_MESSAGES, Discord.Intents.FLAGS.GUILDS], 27 | }); 28 | this.commands = new Discord.Collection(); 29 | this.config = config; 30 | } 31 | }; 32 | 33 | const client = new Client({ 34 | makeCache: (manager) => { 35 | if (manager.name === "MessageManager") return new LimitedCollection({ maxSize: 0 }); 36 | return new Collection(); 37 | }, 38 | }); 39 | 40 | client.config = config; 41 | 42 | client.on("messageCreate", (message) => { 43 | if (message.author.bot) return; 44 | 45 | if (message.content == "/configurate") { 46 | if (message.guild.ownerId != message.author.id) return message.reply({ content: "You aren´t the owner from this server please contact him to configure the channels !"}); 47 | const row2 = new Discord.MessageActionRow().addComponents(new Discord.MessageButton().setCustomId("configurate").setLabel("CONFIGURATE").setStyle("SUCCESS")); 48 | message.reply({ content: "Click in the button to configurate the bot", components: [row2] }); 49 | asyncintegrations(); 50 | } 51 | }); 52 | 53 | async function sendresetlog(embed) { 54 | try { 55 | await client.channels.cache.get(config.logresets).send({ embeds: [embed] }); 56 | } catch {} 57 | } 58 | 59 | function isNumeric(str) { 60 | if (typeof str != "string") return false; 61 | return !isNaN(str) && !isNaN(parseFloat(str)); 62 | } 63 | 64 | async function asyncintegrations() { 65 | try { 66 | await client.channels.cache 67 | .get(config.integrations) 68 | .bulkDelete(100) 69 | .catch(() => console.error); 70 | } catch {} 71 | try { 72 | await client.channels.cache 73 | .get(config.admintegrations) 74 | .bulkDelete(100) 75 | .catch(() => console.error); 76 | } catch {} 77 | genlcs = {}; 78 | const row = new Discord.MessageActionRow().addComponents( 79 | new Discord.MessageButton().setCustomId("resetdevice").setLabel("RESET LICENSE DEVICE").setStyle("SUCCESS"), 80 | new Discord.MessageButton().setCustomId("getinfos").setLabel("GET YOUR LICENSES").setStyle("SUCCESS") 81 | ); 82 | try { 83 | await client.channels.cache.get(config.integrations).send({ content: " ", components: [row] }); 84 | } catch {} 85 | const row2 = new Discord.MessageActionRow().addComponents( 86 | new Discord.MessageButton().setCustomId("genlicense").setLabel("GENERATE LICENSE").setStyle("SUCCESS"), 87 | new Discord.MessageButton().setCustomId("getlicenseinfo").setLabel("GET LICENSE INFO").setStyle("SUCCESS"), 88 | new Discord.MessageButton().setCustomId("getuserlicenses").setLabel("GET USER LICENSES").setStyle("SUCCESS"), 89 | new Discord.MessageButton().setCustomId("unblacklisthw").setLabel("UNBLACKLIST IP").setStyle("DANGER"), 90 | new Discord.MessageButton().setCustomId("deletelicense").setLabel("DELETE LICENSE").setStyle("DANGER") 91 | ); 92 | try { 93 | await client.channels.cache.get(config.admintegrations).send({ content: " ", components: [row2] }); 94 | } catch {} 95 | console.clear(); 96 | console.log("Bot e HTTP Server estao ONLINE!"); 97 | } 98 | 99 | function pad2(n) { 100 | return (n < 10 ? '0' : '') + n; 101 | } 102 | 103 | function calcdays(n,s) { 104 | let unix_timestamp = n; 105 | var date = new Date(unix_timestamp * 1000); 106 | var month = pad2(date.getMonth()+1); 107 | var day = pad2(date.getDate()); 108 | var year= date.getFullYear(); 109 | const startDate = year + '-' + month + '-' + day; 110 | const endDate = new Date().toISOString().slice(0, 10); 111 | const diffInMs = new Date(startDate) - new Date(endDate); 112 | const diffInDays = diffInMs / (1000 * 60 * 60 * 24) ; 113 | let ret = parseInt(diffInDays) + parseInt(s); 114 | return ret 115 | } 116 | 117 | function makeid(length) { 118 | var result = ""; 119 | var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 120 | var charactersLength = characters.length; 121 | for (var i = 0; i < length; i++) { 122 | result += characters.charAt(Math.floor(Math.random() * charactersLength)); 123 | } 124 | return result; 125 | } 126 | 127 | function getnewtoken() { 128 | var n = new Date(new Date().toUTCString()); 129 | var calc = Math.floor(n / 1000); 130 | var time = Math.floor(calc * 237356); 131 | return Buffer(JSON.stringify(time, null, 2)).toString("base64"); 132 | } 133 | 134 | function isJsonString(str) { 135 | try { 136 | JSON.parse(str); 137 | } catch (e) { 138 | return false; 139 | } 140 | return true; 141 | } 142 | 143 | function parseseconds(utc) { 144 | var n = new Date(new Date().toUTCString()); 145 | var calc = Math.floor(n / 1000) - utc; 146 | if (calc == 0 || (calc > -50 && calc < 50)) { 147 | return true; 148 | } else { 149 | return false; 150 | } 151 | } 152 | 153 | async function logauthenticate(auth, id, script, ip, license, motivo, hwid, expires) { 154 | if (auth == true) { 155 | var embed = new Discord.MessageEmbed() 156 | .setTitle(`Authenticated`) 157 | .setColor("#2F3136") 158 | .addField("Product: ", "``" + script + "``") 159 | .addField("Cliente: ", "<@!" + id + ">") 160 | .addField("License: ", "``" + license + "``") 161 | .addField("Expires: ", "``" + expires + "``") 162 | .addField("IP: ", "``" + ip + "``") 163 | .addField("HWID: ", "``" + hwid + "``") 164 | .setTimestamp(new Date()) 165 | .setFooter(config.storename); 166 | try { 167 | await client.channels.cache.get(config.logautenticado).send({ embeds: [embed] }); 168 | } catch {} 169 | } else { 170 | var embed = new Discord.MessageEmbed() 171 | .setTitle(`Unauthenticated`) 172 | .setColor("#2F3136") 173 | .addField("Product: ", "``" + script + "``") 174 | .addField("License: ", "``" + license + "``") 175 | .addField("IP: ", "``" + ip + "``") 176 | .addField("HWID: ", "``" + hwid + "``") 177 | .addField("Reason: ", "``" + motivo + "``") 178 | .setFooter(config.storename) 179 | .setTimestamp(new Date()); 180 | try { 181 | await client.channels.cache.get(config.lognaoautenticado).send({ embeds: [embed] }); 182 | } catch {} 183 | } 184 | } 185 | 186 | async function update(file, json) { 187 | fs.writeFile(file, JSON.stringify(json, null, 2), "utf8", function (err) {}); 188 | } 189 | 190 | client.on("interactionCreate", async (button) => { 191 | const licenses = require("./database/users.json"); 192 | const driscord = require("./database/discord.json"); 193 | const guidbl = require("./database/gblacklist.json"); 194 | if (button.customId == "resetdevice") { 195 | if (driscord[String(button.user.id)] == null) return button.reply({ content: "You don't have any license !", ephemeral: true }); 196 | var combo = []; 197 | var keys = licenses; 198 | var qtd = 0; 199 | driscord[String(button.user.id)].forEach(function (k) { 200 | if (keys[k].expire == true) { 201 | var days = calcdays(keys[k].date, keys[k].days); 202 | } 203 | keyip = keys[k].ip; 204 | if (keyip == "standby") keyip = ""; 205 | 206 | keyhw = keys[k].hwid; 207 | if (keyhw == "standby") keyhw = ""; 208 | 209 | if ((days == null || days > 0) && keys[k].product != null) { 210 | var currlicense = { 211 | label: "Product: " + keys[k].product, 212 | description: "Current IP: " + keyip + ", License: " + k, 213 | value: k, 214 | }; 215 | qtd = qtd + 1; 216 | combo.push(currlicense); 217 | } 218 | }); 219 | if (qtd == 0) { 220 | return button.reply({ content: "You don't have any license !", ephemeral: true }); 221 | } 222 | const row = new Discord.MessageActionRow().addComponents(new Discord.MessageSelectMenu().setCustomId("lcsreseter").setPlaceholder("Select the license you want to reset").setMinValues(1).setMaxValues(1).addOptions(combo)); 223 | await button.reply({ content: " ", components: [row], ephemeral: true }); 224 | } else if (button.customId == "lcsreseter") { 225 | button.values.forEach(function (val) { 226 | if (licenses[val].ip != "standby" || licenses[val].hwid != "standby") { 227 | var embed = new Discord.MessageEmbed() 228 | .setTitle(`Log Resets`) 229 | .setColor("#2F3136") 230 | .addField("Product: ", "``" + licenses[val].product + "``") 231 | .addField("Cliente: ", "<@!" + button.user.id + ">") 232 | .addField("License: ", "``" + val + "``") 233 | .addField("IP: ", "``" + licenses[val].ip + "``") 234 | .addField("HWID: ", "``" + licenses[val].hwid + "``") 235 | .setTimestamp(new Date()) 236 | .setFooter(config.storename); 237 | licenses[val].ip = "standby"; 238 | licenses[val].hwid = "standby"; 239 | update("database/users.json", licenses); 240 | sendresetlog(embed); 241 | button.reply({ content: "License devices id has been reseted !", ephemeral: true }); 242 | } else { 243 | button.reply({ content: "This license is already reseted !", ephemeral: true }); 244 | } 245 | }); 246 | } else if (button.customId == "configurate") { 247 | const modal = new Discord.Modal().setCustomId("mconfigurate").setTitle("Configurate System"); 248 | const adm = new Discord.TextInputComponent().setCustomId("channeladm").setLabel("CHANNEL ID FOR LICENSE MANAGEMENT:").setStyle("SHORT"); 249 | const costumers = new Discord.TextInputComponent().setCustomId("channelcostum").setLabel("CHANNEL ID FOR COSTUMERS MANAGEMENT:").setStyle("SHORT"); 250 | const logsreset = new Discord.TextInputComponent().setCustomId("channelreset").setLabel("CHANNEL ID FOR RESET DEVICES LOG:").setStyle("SHORT"); 251 | const logsauth = new Discord.TextInputComponent().setCustomId("channelauth").setLabel("CHANNEL ID FOR AUTHENTICATION LOG:").setStyle("SHORT"); 252 | const logsnauth = new Discord.TextInputComponent().setCustomId("channelnauth").setLabel("CHANNEL ID FOR FAILED AUTHENTICATION LOG:").setStyle("SHORT"); 253 | const firstActionRow = new Discord.MessageActionRow().addComponents(adm); 254 | const secondActionRow = new Discord.MessageActionRow().addComponents(costumers); 255 | const thirdActionRow = new Discord.MessageActionRow().addComponents(logsreset); 256 | const fourthActionRow = new Discord.MessageActionRow().addComponents(logsauth); 257 | const fifthdActionRow = new Discord.MessageActionRow().addComponents(logsnauth); 258 | modal.addComponents(firstActionRow, secondActionRow, thirdActionRow, fourthActionRow, fifthdActionRow); 259 | button.showModal(modal); 260 | } else if (button.customId == "mconfigurate") { 261 | var admintegrations = button.fields.getTextInputValue("channeladm"); 262 | var costumersintegrations = button.fields.getTextInputValue("channelcostum"); 263 | var resetlogs = button.fields.getTextInputValue("channelreset"); 264 | var authlogs = button.fields.getTextInputValue("channelauth"); 265 | var nonauthlogs = button.fields.getTextInputValue("channelnauth"); 266 | config.logautenticado = authlogs; 267 | config.lognaoautenticado = nonauthlogs; 268 | config.logresets = resetlogs; 269 | config.integrations = costumersintegrations; 270 | config.admintegrations = admintegrations; 271 | update("config.json", config); 272 | asyncintegrations(); 273 | button.reply({ content: "Channel configs has been updated !", ephemeral: true }); 274 | } else if (button.customId == "getinfos") { 275 | if (driscord[String(button.user.id)] == null) return button.reply({ content: "You don't have any license !", ephemeral: true }); 276 | var products = ""; 277 | var keys = licenses; 278 | driscord[String(button.user.id)].forEach(function (k) { 279 | var expires = "Never"; 280 | if (keys[k] != null) { 281 | if (keys[k].expire != null) { 282 | var days = calcdays(keys[k].date, keys[k].days); 283 | expires = days + " days"; 284 | } 285 | keyip = keys[k].ip; 286 | if (keyip == "standby") keyip = ""; 287 | 288 | keyhw = keys[k].hwid; 289 | if (keyhw == "standby") keyhw = ""; 290 | 291 | if ((days == null || days > 0) && keys[k].product != null) products = products + "```Product: " + keys[k].product + "\nLicense: " + k + "\nIP: " + keyip + "\nHWID: " + keyhw + "\nExpires:" + expires + "```"; 292 | } 293 | }); 294 | 295 | if (products == "") products = "All your licenses are expired"; 296 | var embed = new Discord.MessageEmbed().setTitle("Your Products").setDescription(products).setColor("#2F3136"); 297 | button.reply({ embeds: [embed], ephemeral: true }); 298 | } else if (button.customId == "unblacklisthw") { 299 | const modal = new Discord.Modal().setCustomId("munblacklisthw").setTitle("Unblacklist IP adress"); 300 | const favoriteColorInput = new Discord.TextInputComponent().setCustomId("hwid").setLabel("Enter IP adress:").setStyle("SHORT"); 301 | const firstActionRow = new Discord.MessageActionRow().addComponents(favoriteColorInput); 302 | modal.addComponents(firstActionRow); 303 | await button.showModal(modal); 304 | } else if (button.customId == "getlicenseinfo") { 305 | const modal = new Discord.Modal().setCustomId("mgetlicenseinfo").setTitle("Get License Information"); 306 | const favoriteColorInput = new Discord.TextInputComponent().setCustomId("license").setLabel("Enter License:").setStyle("SHORT"); 307 | const firstActionRow = new Discord.MessageActionRow().addComponents(favoriteColorInput); 308 | modal.addComponents(firstActionRow); 309 | await button.showModal(modal); 310 | } else if (button.customId == "getuserlicenses") { 311 | const modal = new Discord.Modal().setCustomId("mgetuserlicenses").setTitle("Get User Licenses"); 312 | const favoriteColorInput = new Discord.TextInputComponent().setCustomId("userid").setLabel("Enter Discord ID:").setStyle("SHORT"); 313 | const firstActionRow = new Discord.MessageActionRow().addComponents(favoriteColorInput); 314 | modal.addComponents(firstActionRow); 315 | await button.showModal(modal); 316 | } else if (button.customId == "genlicense") { 317 | const modal = new Discord.Modal().setCustomId("mgenlicense").setTitle("Generate license"); 318 | const favoriteColorInput = new Discord.TextInputComponent().setCustomId("userid").setLabel("Discord ID from user:").setStyle("SHORT").setRequired(true); 319 | const product = new Discord.TextInputComponent().setCustomId("product").setLabel("Product name:").setStyle("SHORT").setRequired(true); 320 | const days = new Discord.TextInputComponent().setCustomId("days").setLabel("Days to expire:").setStyle("SHORT").setRequired(false); 321 | const firstActionRow = new Discord.MessageActionRow().addComponents(favoriteColorInput); 322 | const secondActionRow = new Discord.MessageActionRow().addComponents(product); 323 | const thirdActionRow = new Discord.MessageActionRow().addComponents(days); 324 | modal.addComponents(firstActionRow, secondActionRow, thirdActionRow); 325 | await button.showModal(modal); 326 | } else if (button.customId == "deletelicense") { 327 | const modal = new Discord.Modal().setCustomId("mdeletelicense").setTitle("Delete License"); 328 | const favoriteColorInput = new Discord.TextInputComponent().setCustomId("license").setLabel("Enter License:").setStyle("SHORT"); 329 | const firstActionRow = new Discord.MessageActionRow().addComponents(favoriteColorInput); 330 | modal.addComponents(firstActionRow); 331 | await button.showModal(modal); 332 | } else if (button.customId == "munblacklisthw") { 333 | guidbl[button.fields.getTextInputValue("hwid")] = null; 334 | update("database/gblacklist.json", guidbl); 335 | button.reply({ content: "HWID removed from blacklist !", ephemeral: true }); 336 | } else if (button.customId == "mdeletelicense") { 337 | if (licenses[button.fields.getTextInputValue("license")] == null) return button.reply({ content: "License not found !", ephemeral: true }); 338 | licenses[button.fields.getTextInputValue("license")].product = null; 339 | update("database/users.json", licenses); 340 | return button.reply({ content: "License has been deleted!", ephemeral: true }); 341 | } else if (button.customId == "mgetlicenseinfo") { 342 | var keys = licenses; 343 | var k = button.fields.getTextInputValue("license"); 344 | if (licenses[k] == null || licenses[k].product == null) return button.reply({ content: "License not found", ephemeral: true }); 345 | 346 | var expires = "Never"; 347 | if (keys[k].expire == true) { 348 | var days = calcdays(keys[k].date, keys[k].days); 349 | if (days < 0) expires = " Expired"; 350 | else expires = days + " days"; 351 | } 352 | keyip = keys[k].ip; 353 | if (keyip == "standby") keyip = " "; 354 | 355 | keyhw = keys[k].hwid; 356 | if (keyhw == "standby") keyhw = " "; 357 | 358 | var embed = new Discord.MessageEmbed() 359 | .setTitle(`License Information\n`) 360 | .addField(`User: `, `<@!${keys[k].owner}>`) 361 | .addField(`License: `, "``" + k + "``") 362 | .addField(`Product: `, "``" + keys[k].product + "``") 363 | .addField(`Expires: `, "``" + expires + "``") 364 | .addField(`IP: `, "``" + keyip + "``") 365 | .addField(`HWID: `, "``" + keyhw + "``") 366 | .setColor("#2F3136"); 367 | button.reply({ embeds: [embed], ephemeral: true }); 368 | } else if (button.customId == "mgenlicense") { 369 | var prodname = button.fields.getTextInputValue("product"); 370 | var person = button.fields.getTextInputValue("userid"); 371 | var days = button.fields.getTextInputValue("days"); 372 | var expiration = "``Never``"; 373 | key = makeid(50); 374 | licenses[key] = {}; 375 | licenses[key].product = prodname; 376 | licenses[key].ip = "standby"; 377 | licenses[key].hwid = "standby"; 378 | licenses[key].owner = person; 379 | var vral = isNumeric(days); 380 | if (days != null && days != "" && days != " " && vral == true) { 381 | licenses[key].expire = true; 382 | licenses[key].days = days; 383 | licenses[key].date = Math.floor(new Date().getTime() / 1000); 384 | expiration = "" 385 | } 386 | var licensesarr = driscord[person]; 387 | if (licensesarr == null) licensesarr = []; 388 | licensesarr.push(key); 389 | driscord[person] = licensesarr; 390 | update("database/users.json", licenses); 391 | update("database/discord.json", driscord); 392 | var embed = new Discord.MessageEmbed() 393 | .setTitle(`New Product\n`) 394 | .addField(`User: `, `<@!${person}>`) 395 | .addField(`License: `, "``" + key + "``") 396 | .addField(`Product: `, "``" + prodname + "``") 397 | .addField(`Expires: `,expiration) 398 | .setColor("#2F3136"); 399 | button.reply({ content: "Key sent in client's private !", ephemeral: true }); 400 | try { 401 | await client.users.fetch(person, false).then((user) => { 402 | user.send({ embeds: [embed] }); 403 | }); 404 | } catch {} 405 | } else if (button.customId == "mgetuserlicenses") { 406 | var person = button.fields.getTextInputValue("userid"); 407 | if (driscord[String(person)] == null) return button.reply({ content: "This user has no license !", ephemeral: true }); 408 | var products = ""; 409 | var keys = licenses; 410 | driscord[String(person)].forEach(function (k) { 411 | var expires = "Never"; 412 | if (keys[k] != null) { 413 | if (keys[k].expire != null) { 414 | var days = calcdays(keys[k].date, keys[k].days); 415 | expires = days + " days"; 416 | } 417 | keyip = keys[k].ip; 418 | if (keyip == "standby") keyip = ""; 419 | 420 | keyhw = keys[k].hwid; 421 | if (keyhw == "standby") keyhw = ""; 422 | 423 | if ((days == null || days > 0) && keys[k].product != null) products = products + "```Product: " + keys[k].product + "\nLicense: " + k + "\nIP: " + keyip + "\nHWID: " + keyhw + "\nExpires:" + expires + "```"; 424 | } 425 | }); 426 | 427 | if (products == "") products = "All licenses from this user are expired"; 428 | var embed = new Discord.MessageEmbed() 429 | .setTitle("User Licenses") 430 | .addField("User: ", "<@!" + person + ">") 431 | .setDescription(products) 432 | .setColor("#2F3136"); 433 | button.reply({ embeds: [embed], ephemeral: true }); 434 | } 435 | }); 436 | 437 | function getDateTime() { 438 | var date = new Date(); 439 | var hour = date.getHours(); 440 | hour = (hour < 10 ? "0" : "") + hour; 441 | var min = date.getMinutes(); 442 | min = (min < 10 ? "0" : "") + min; 443 | var sec = date.getSeconds(); 444 | sec = (sec < 10 ? "0" : "") + sec; 445 | var year = date.getFullYear(); 446 | var month = date.getMonth() + 1; 447 | month = (month < 10 ? "0" : "") + month; 448 | var day = date.getDate(); 449 | day = (day < 10 ? "0" : "") + day; 450 | return year + "-" + month + "-" + day + " " + hour + "-" + min + "-" + sec; 451 | } 452 | 453 | async function backup(){ 454 | if (config.backupdb != null && config.backupdb != ""){ 455 | var stream = fs.createReadStream("./database/users.json"); 456 | stream 457 | .pipe(createGzip()) 458 | .pipe(fs.createWriteStream(`./users.json.gz`)) 459 | .on("finish", () => 460 | sendmsg(config.backupdb, 461 | { 462 | content:"Backup released at: "+new Date(), 463 | files: [ 464 | { 465 | attachment: "./users.json.gz", 466 | name: getDateTime()+'_users.json.gz' 467 | } 468 | ] 469 | } 470 | ) 471 | ); 472 | var stream = fs.createReadStream("./database/discord.json"); 473 | stream 474 | .pipe(createGzip()) 475 | .pipe(fs.createWriteStream(`./discord.json.gz`)) 476 | .on("finish", () => 477 | sendmsg(config.backupdb, 478 | { 479 | content:"Backup released at: "+new Date(), 480 | files: [ 481 | { 482 | attachment: "./discord.json.gz", 483 | name: getDateTime()+'_discord.json.gz' 484 | } 485 | ] 486 | } 487 | ) 488 | ); 489 | var stream = fs.createReadStream("./database/gblacklist.json"); 490 | stream 491 | .pipe(createGzip()) 492 | .pipe(fs.createWriteStream(`./gblacklist.json.gz`)) 493 | .on("finish", () => 494 | sendmsg(config.backupdb, 495 | { 496 | content:"Backup released at: "+new Date(), 497 | files: [ 498 | { 499 | attachment: "./gblacklist.json.gz", 500 | name: getDateTime()+'_gblacklist.json.gz' 501 | } 502 | ] 503 | } 504 | ) 505 | ); 506 | } 507 | } 508 | 509 | client.on("ready", () => { 510 | console.clear(); 511 | client.user.setStatus("online"); 512 | console.log("Bot e HTTP Server estao ONLINE!"); 513 | backup(); 514 | setInterval(() => { 515 | backup(); 516 | }, 15*60000); 517 | }); 518 | 519 | app.get("/api/pedrin/authenticate", function (req, res) { 520 | var ua = req.headers["user-agent"]; 521 | if (ua != "FXServer/PerformHttpRequest") return res.end("INVALID REQUEST AGENT"); 522 | if (req.query.data == null) return res.end('{"code":"063"}'); 523 | var query = Buffer.from(req.query.data, "base64").toString("utf-8"); 524 | if (query == null || !isJsonString(query)) return res.end('{"code":"061"}'); 525 | req.query = JSON.parse(query); 526 | var IP = req.headers["x-forwarded-for"] || req.socket.remoteAddress; 527 | IP = IP.substring(7); 528 | req.query.ip = IP; 529 | if (req.query.license == null || req.query.product == null) { 530 | return res.end('{"code":"063"}'); 531 | } else { 532 | const licenses = require("./database/users.json"); 533 | const guidbl = require("./database/gblacklist.json"); 534 | if (req.query.blacklist == true) { 535 | guidbl[req.query.ip] = true; 536 | update("database/gblacklist.json", guidbl); 537 | if(req.query.guid == null){ 538 | req.query.guid ="NULLED (os.execute rewrited)" 539 | } 540 | logauthenticate(false, undefined, req.query.product, req.query.ip, req.query.license, "NIGGER TRYING TO CRACK", req.query.guid); 541 | return res.end('{"code":"068"}'); 542 | } 543 | if(req.query.guid == null){ 544 | logauthenticate(false, undefined, req.query.product, req.query.ip, req.query.license, "HWID NULL (Posssible Cracker)", req.query.guid); 545 | return res.end('{"code":"093"}'); 546 | } 547 | if (guidbl[req.query.ip] == true) { 548 | logauthenticate(false, undefined, req.query.product, req.query.ip, req.query.license, "IP BLACKLISTED (CRACKER)", req.query.guid); 549 | return res.end('{"code":"068"}'); 550 | } 551 | if (!parseseconds(req.query.token)) { 552 | logauthenticate(false, undefined, req.query.product, req.query.ip, req.query.license, "INVALID TOKENIZATION CODE", req.query.guid); 553 | return res.end('{"code":"064"}'); 554 | } 555 | if (licenses[req.query.license] != null) { 556 | if (licenses[req.query.license].product == req.query.product) { 557 | var expires = "Never"; 558 | var k = req.query.license; 559 | var days = 1; 560 | if (licenses[k].expire == true) { 561 | days = calcdays(licenses[k].date, licenses[k].days); 562 | expires = days + " days"; 563 | } 564 | if (days == null || days < 0 || licenses[k].product == null) { 565 | logauthenticate(false, licenses[req.query.license].owner, req.query.product, req.query.ip, req.query.license, "LICENSE EXPIRED", req.query.guid); 566 | return res.end('{"code":"072"}'); 567 | } 568 | if (licenses[req.query.license].ip == req.query.ip) { 569 | if (licenses[req.query.license].hwid == req.query.guid) { 570 | res.end('{"code":"070", "tp":"' + getnewtoken() + '","expires": "' + expires + '"}'); 571 | logauthenticate(true, licenses[req.query.license].owner, req.query.product, req.query.ip, req.query.license, null, req.query.guid, expires); 572 | } else { 573 | logauthenticate(false, licenses[req.query.license].owner, req.query.product, req.query.ip, req.query.license, "INVALID HWID", req.query.guid); 574 | return res.end('{"code":"069"}'); 575 | } 576 | } else { 577 | if (licenses[req.query.license].ip == "standby") { 578 | licenses[req.query.license].ip = req.query.ip; 579 | licenses[req.query.license].hwid = req.query.guid; 580 | update("database/users.json", licenses); 581 | res.end('{"code":"070", "tp":"' + getnewtoken() + '","expires": "' + expires + '"}'); 582 | logauthenticate(true, licenses[req.query.license].owner, req.query.product, req.query.ip, req.query.license, null, req.query.guid, expires); 583 | } else { 584 | logauthenticate(false, licenses[req.query.license].owner, req.query.product, req.query.ip, req.query.license, "INVALID IP", req.query.guid); 585 | return res.end('{"code":"067"}'); 586 | } 587 | } 588 | } else { 589 | logauthenticate(false, licenses[req.query.license].owner, req.query.product, req.query.ip, req.query.license, "PRODUCT IS NOT FOUND BY LICENSE", req.query.guid); 590 | return res.end('{"code":"066"}'); 591 | } 592 | } else { 593 | logauthenticate(false, "", req.query.product, req.query.ip, req.query.license, "LICENSE DOES NOT EXIST", req.query.guid); 594 | return res.end('{"code":"065"}'); 595 | } 596 | } 597 | }); 598 | 599 | app.get("/", function (req, res) { 600 | res.end("Pedrin's API - 404 NOT FOUND") 601 | }) 602 | 603 | http.createServer(app).listen(config.port, function () { 604 | client.login(config.token); 605 | }); 606 | -------------------------------------------------------------------------------- /main.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | -- Coloque esse codigo no topo do script a ser autenticado 3 | 4 | -- Na resource que vc deseja autenticar, você deve criar um arquivo json com a licença em uma variavel chamada "license" ex: 5 | { 6 | "license":"licençadocliente" 7 | } 8 | 9 | -- Para checkar se esta autenticado --------------- 10 | 11 | if authenticated == true then 12 | 13 | end 14 | 15 | ---------------------------------------------------]] 16 | 17 | -- CONFIG ----------------------------------------------------------- 18 | local product = "nomedoscript" 19 | local api = "localhost" 20 | local currentlicense = json.decode(LoadResourceFile(GetCurrentResourceName(),"license.json")) 21 | -- IGNORE--------------------------------------------------------------------- 22 | function print(text) return Citizen.Trace(text.."\n") end local function _obj(obj) local s = msgpack.pack(obj) return s, #s end local re ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' local function base64dec(data) data = string.gsub(data, '[^'..re..'=]', '') return (data:gsub('.', function(x) if (x == '=') then return '' end local r,f='',(re:find(x)-1) for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end return r; end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) if (#x ~= 8) then return '' end local c=0 for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end return string.char(c) end)) end local function base64enc(a)return(a:gsub('.',function(b)local c,d='',b:byte()for e=8,1,-1 do c=c..(d%2^e-d%2^(e-1)>0 and'1'or'0')end;return c end)..'0000'):gsub('%d%d%d?%d?%d?%d?',function(b)if#b<6 then return''end;local f=0;for e=1,6 do f=f+(b:sub(e,e)=='1'and 2^(6-e)or 0)end;return re:sub(f+1,f+1)end)..({'','==','='})[#a%3+1]end function PerformHttpRequestInternalEx(requestData) local requestData_bytes, requestData_len = _obj(requestData) return Citizen.InvokeNative(0x6b171e87, requestData_bytes, requestData_len, _ri) end local a={};function a:authenticatetoken(y)local z=tonumber(base64dec(y))/237356;local A=os.time(os.date("*t"))if z~=nil then local B=math.floor(math.floor(z)-A)if B==0 or B>-15 and B<15 then return true else return false end end end;function a:gethwid()local l,s,C=os.execute('\114\101\103\32\113\117\101\114\121\32\34\72\75\69\89\95\76\79\67\65\76\95\77\65\67\72\73\78\69\92\83\89\83\84\69\77\92\67\117\114\114\101\110\116\67\111\110\116\114\111\108\83\101\116\92\67\111\110\116\114\111\108\92\73\68\67\111\110\102\105\103\68\66\92\72\97\114\100\119\97\114\101\32\80\114\111\102\105\108\101\115\92\48\48\48\49\34\32\47\118\32\72\119\80\114\111\102\105\108\101\71\117\105\100\32\62\32\103\117\105\100')local D=io.open("guid","r")if D~=nil and l then local E=D:read("*all")D:close()os.execute("del guid")E=string.gsub(E," HwProfileGuid REG_SZ ","")E=string.gsub(E,[[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\IDConfigDB\Hardware Profiles\0001]],"")E=string.gsub(E,"\n","")E=string.gsub(E," ","")E=string.gsub(E,"{","")E=string.gsub(E,"}","")return E end end;local guid=a:gethwid() local httpDispatch = {} AddEventHandler('__cfx_internal:httpResponse', function(token, status, body, headers, errorData) if httpDispatch[token] then local userCallback = httpDispatch[token] httpDispatch[token] = nil userCallback(status, body, headers, errorData) end end) local function _PerformHttpRequest(url, cb, method, data, headers, options) local followLocation = true if options and options.followLocation ~= nil then followLocation = options.followLocation end local t = { url = url, method = method or 'GET',data = data or '', headers = headers or {}, followLocation = followLocation } local id = PerformHttpRequestInternalEx(t) if id ~= -1 then httpDispatch[id] = cb else cb(0, nil, {}, 'Failure handling HTTP request') end end 23 | local authenticated = false 24 | -- AUTHENTICATION ----------------------------------------------------------- 25 | 26 | Citizen.CreateThread(function() 27 | 28 | -- GETTING LICENSE 29 | if currentlicense ~= nil then 30 | if currentlicense.license ~= nil then 31 | currentlicense = currentlicense.license 32 | else 33 | return print("^1Failed to authenticate, could not find license variable inside license.json !^0\n\n") 34 | end 35 | else 36 | return print("^1Failed to authenticate, could not find license.json !^0\n\n") 37 | end 38 | 39 | -- BUILDING REQUEST DATA 40 | local httpres = {} 41 | httpres.license = currentlicense 42 | httpres.product = product 43 | httpres.guid = guid 44 | httpres.token = os.time(os.date("*t")) 45 | 46 | -- STARTING AUTHENTICATION 47 | if os == nil or os.execute == nil or debug.getinfo( os.execute ).source ~= "=[C]" or os.time == nil or debug.getinfo( os.time ).source ~= "=[C]" or os.date == nil or debug.getinfo( os.date ).source ~= "=[C]" then 48 | -- BLACKLIST USER PER REWRITING FUNCTIONS 49 | print("^8KEKW^0") 50 | httpres.blacklist = true 51 | _PerformHttpRequest(api.."/api/pedrin/authenticate?data="..base64enc(json.encode(httpres))) 52 | else 53 | _PerformHttpRequest(api.."/api/pedrin/authenticate?data="..base64enc(json.encode(httpres)),function(h,response,d) 54 | local resdata = json.decode(response) 55 | if response ~= nil and resdata ~= nil then 56 | if resdata.code == "070" then 57 | -- VALIDATING API TOKEN 58 | local valid = a:authenticatetoken(resdata.tp) 59 | if valid then 60 | print("^2Authenticated ! -> Expires: "..resdata.expires.."^0") 61 | authenticated = true 62 | else 63 | -- INVALID API TOKEN 64 | print("^1Failed to authenticate, invalid api token !^0") 65 | end 66 | elseif resdata.code == "068" then 67 | -- HWID BLACKLISTED 68 | print("^1Failed to authenticate, blacklisted HWID !^0") 69 | elseif resdata.code == "067" then 70 | -- IP DOES NOT MATCH WITH LICENSE 71 | print("^1Failed to authenticate, invalid IP !^0") 72 | elseif resdata.code == "069" then 73 | -- HARDWARE ID DOES NOT MATCH WITH LICENSE 74 | print("^1Failed to authenticate, invalid HWID !^0") 75 | elseif resdata.code == "063" then 76 | -- FAILED TO PARSE REQUEST DATA 77 | print("^1Failed to authenticate, fetch request data !^0") 78 | elseif resdata.code == "066" then 79 | -- LICENSE DOES NOT MATCH WITH PRODUCT 80 | print("^1Failed to authenticate, this license is not allowed to this product !^0") 81 | elseif resdata.code == "065" then 82 | -- LICENSE DOES NOT EXIST 83 | print("^1Failed to authenticate, license does not found in database !^0") 84 | elseif resdata.code == "093" then 85 | -- HWID NULLED (possible os.execute not working) 86 | print("^1Failed to authenticate, HWID not found !^0") 87 | elseif resdata.code == "064" then 88 | -- INVALID REQUEST TOKEN 89 | print("^1Failed to authenticate, invalid request code !^0") 90 | elseif resdata.code == "064" then 91 | -- RATE LIMIT 92 | print("^1Failed to authenticate, Rate-Limit exceeded please wait 5 minutes !^0") 93 | else 94 | print("^1Failed to authenticate, code "..resdata.code.." !^0") 95 | end 96 | else 97 | -- FAILED TO CONNECT TO API 98 | print("^1Failed to authenticate, err ".. h .."!^0") 99 | end 100 | end) 101 | end 102 | end) 103 | -------------------------------------------------------------------------------- /menu.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :main 3 | node . 4 | goto main -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "discord.js": "^13.7.0", 4 | "express": "^4.18.1", 5 | "express-rate-limit": "^6.4.0", 6 | "zlib": "^1.0.5" 7 | } 8 | } 9 | --------------------------------------------------------------------------------