From 5a0dd87cf58b87bdfcb46d7641143f91e209bce3 Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Sun, 29 May 2022 02:38:36 +0200 Subject: [PATCH 1/7] Update KeyAuth.js --- src/KeyAuth.js | 703 +++++++++++++++++++++++-------------------------- 1 file changed, 323 insertions(+), 380 deletions(-) diff --git a/src/KeyAuth.js b/src/KeyAuth.js index a4e21bc..98f8e08 100644 --- a/src/KeyAuth.js +++ b/src/KeyAuth.js @@ -1,23 +1,140 @@ -import axios from "axios" -import { stringify } from "querystring" -import systeminformation from "systeminformation" +const axios = require("axios"); +const { stringify } = require("querystring"); +const systeminformation = require("systeminformation"); var datastore = { - name: null, - ownerid: null, - secret: null, - version: null, - sessionid: null + name: null, + ownerid: null, + secret: null, + version: null, + sessionid: null, }; var msg = { - message: null, - author: null, - timestamp: null -} + message: null, + author: null, + timestamp: null, +}; let intialized = false; +var response = { + success: null, + message: null, +}; + +var app_data = { + numUsers: null, + numOnlineUsers: null, + numKeys: null, + version: null, + customerPanelLInk: null, + downloadLink: null, +}; + +var user_data = { + username: null, + ip: null, + hwid: null, + createdate: null, + lastlogin: null, + subscriptions: null, +}; + +let sys = { + username: null, + hwid: null, +}; + +async function error(message) { + console.log(message); + loginWindow.webContents.send("notify:error", message); + return process.exit(0); +} + +async function checkvalues() { + if ( + !datastore.name || + !datastore.ownerid || + !datastore.secret || + !datastore.version + ) { + error("Application not setup correctly."); + } +} + +async function req(post_data) { + var returndata = null; + + await axios + .get("https://keyauth.win/api/1.1/" + post_data, { + headers: { + "Content-Type": "application/x-www-form-urlencoded", + }, + }) + .then((res) => { + returndata = res.data; + }) + .catch((err) => { + if (err.response.status == 429) { + error("Rate Limited! - KeyAuth"); + } else if (err.response.status == 502) { + error("502 Bad Gateway! - KeyAuth"); + } else { + if (err.response.status == 200) { + } else { + error(`${err.response.status} ${err.response.statusText}! - KeyAuth`); + } + } + }); + return returndata; +} + +async function load_response_struct(data) { + response.success = data.success; + response.message = data.message; +} + +async function load_app_data(data) { + app_data.numUsers = data.numUsers; + app_data.numOnlineUsers = data.numOnlineUsers; + app_data.numKeys = data.numKeys; + app_data.version = data.version; + app_data.customerPanelLInk = data.customerPanelLink; +} + +async function load_user_data(data) { + user_data.username = data.username; + user_data.ip = data.ip; + user_data.hwid = data.hwid; + user_data.createdate = data.createdate; + user_data.lastlogin = data.lastlogin; + user_data.subscriptions = data.subscriptions; +} + +async function checkinit() { + if (!intialized) { + error("Please initzalize first"); + } +} + +function Sleep(ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); +} + +async function getHWID() { + //Credits to https://github.com/sebhildebrandt/systeminformation + await systeminformation.blockDevices((data) => { + sys.hwid = data[0].serial; + }); +} + +async function getUSER() { + //Credits to https://github.com/sebhildebrandt/systeminformation + await systeminformation.users((data) => { + sys.username = data[0].user; + }); +} /// -------------> CHANGE THESE ON INDEX.JS NOT HERE <------------- /// Application Name /// Your OwnerID, can be found in your account settings. @@ -25,76 +142,53 @@ let intialized = false; /// Application Version, if version doesnt match it will open the download link you set up in your application settings and close the app, if empty the app will close /// -------------> CHANGE THESE ON INDEX.JS NOT HERE <------------- -async function api(name, ownerid, secret, version) { - - if (!name || !ownerid || !secret || !version ) { - error("Application not setup correctly."); +module.exports = { + api: async function (name, ownerid, secret, version) { + if (!name || !ownerid || !secret || !version) { + error("Application not setup correctly."); } - + datastore.name = name; datastore.ownerid = ownerid; datastore.secret = secret; datastore.version = version; -} - -/// -/// Initializes the connection with keyauth in order to use any of the functions -/// -async function init() { + }, + init: async function () { await checkvalues(); //makes sure that api values are filled. const values_to_upload = { - 'type': 'init', - 'name': datastore.name, - 'ownerid': datastore.ownerid, - 'ver': datastore.version - } + type: "init", + name: datastore.name, + ownerid: datastore.ownerid, + ver: datastore.version, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); if (response === "KeyAuth_Invalid") { - error("Application not found") + error("Application not found"); } - if (response === "This program hash does not match, make sure you're using latest version") { - error("Please Disable Program Hash, Thanks!") + if ( + response === + "This program hash does not match, make sure you're using latest version" + ) { + error("Please Disable Program Hash, Thanks!"); } var json = response; load_response_struct(json); if (json.success) { - await load_app_data(json.appinfo); - datastore.sessionid = json.sessionid; - intialized = true; + await load_app_data(json.appinfo); + datastore.sessionid = json.sessionid; + intialized = true; } else if (json.message == "invalider") { - app_data.downloadLink = json.download; + app_data.downloadLink = json.download; } -} - -//#region Response Strings - -var response = { - success: null, - message: null -} - - -async function load_response_struct(data) { - response.success = data.success; - response.message = data.message; -} - -//#endregion - -/// -/// Authenticates the user using their username and password -/// -/// Username -/// Password - -async function Login(username, password) { + }, + Login: async function (username, password) { checkvalues(); checkinit(); @@ -104,39 +198,31 @@ async function Login(username, password) { const hwid = sys.hwid; const values_to_upload = { - 'type': 'login', - 'username': username, - 'pass': password, - 'hwid': hwid, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "login", + username: username, + pass: password, + hwid: hwid, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); if (response === "KeyAuth_Invalid") { - error("Application not found") + error("Application not found"); } var json = response; load_response_struct(json); if (json.success) { - load_user_data(json.info) + load_user_data(json.info); } -} - -/// -/// Registers the user using a license and gives the user a subscription that matches their license level -/// -/// Username -/// Password -/// License - -async function Register(username, password, key) { + }, + Register: async function (username, password, key) { checkvalues(); checkinit(); @@ -146,38 +232,31 @@ async function Register(username, password, key) { const hwid = sys.hwid; const values_to_upload = { - 'type': 'register', - 'username': username, - 'pass': password, - 'key': key, - 'hwid': hwid, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "register", + username: username, + pass: password, + key: key, + hwid: hwid, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); if (response === "KeyAuth_Invalid") { - error("Application not found") + error("Application not found"); } var json = response; load_response_struct(json); if (json.success) { - load_user_data(json.info) + load_user_data(json.info); } -} - - -/// -/// Authenticate without using usernames and passwords -/// -/// Licence used to login with - -async function License(key) { + }, + License: async function (key) { checkvalues(); checkinit(); @@ -187,93 +266,84 @@ async function License(key) { const hwid = sys.hwid; const values_to_upload = { - 'type': 'license', - 'key': key, - 'hwid': hwid, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "license", + key: key, + hwid: hwid, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); if (response === "KeyAuth_Invalid") { - error("Application not found") + error("Application not found"); } var json = response; load_response_struct(json); if (json.success) { - load_user_data(json.info) + load_user_data(json.info); } -} - -/// -/// Gives the user a subscription that has the same level as the key -/// -/// Username of the user thats going to get upgraded -/// License with the same level as the subscription you want to give the user - -async function Upgrade(username, key) { + }, + Upgrade: async function (username, key) { checkvalues(); await getHWID(); const hwid = sys.hwid; const values_to_upload = { - 'type': 'upgrade', - 'username': username, - 'key': key, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "upgrade", + username: username, + key: key, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); if (response === "KeyAuth_Invalid") { - error("Application not found") + error("Application not found"); } var json = response; json.success = false; load_response_struct(json); -} - -async function check() { + }, + check: async function () { checkinit(); const values_to_upload = { - 'type': 'check', - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "check", + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); var json = response; - load_response_struct(json) -} - -async function checkblacklist() { + load_response_struct(json); + }, + checkblacklist: async function () { checkinit(); await getHWID(); const hwid = sys.hwid; const values_to_upload = { - 'type': 'checkblacklist', - 'hwid': hwid, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "checkblacklist", + hwid: hwid, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); @@ -282,41 +352,39 @@ async function checkblacklist() { load_response_struct(json); if (json.success) { - return true; + return true; } else { - return false; + return false; } -} - -async function setvar(varname, data) { + }, + setvar: async function (varname, data) { checkinit(); const values_to_upload = { - 'type': 'setvar', - 'var': varname, - 'data': data, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "setvar", + var: varname, + data: data, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); var json = response; load_response_struct(json); -} - -async function getvar(varname) { + }, + getvar: async function (varname) { checkinit(); const values_to_upload = { - 'type': 'getvar', - 'var': varname, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "getvar", + var: varname, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); @@ -325,84 +393,79 @@ async function getvar(varname) { load_response_struct(json); if (json.success) { - return json.response; + return json.response; } else { - return null; + return null; } -} - - -async function SetJSON_var(VarName, data) { + }, + SetJSON_var: async function (VarName, data) { checkinit(); - if(!VarName || !data) { - try { - throw new Exception("SetJSON_var | User Variable name / Data is empty / null"); - } catch (e) { } + if (!VarName || !data) { + try { + throw new Exception( + "SetJSON_var | User Variable name / Data is empty / null" + ); + } catch (e) {} } var json = JSON.stringify(data); await setvar(VarName, json); if (!response.success) { - error(`\nStatus: ${KeyAuth.response.message}`) + error(`\nStatus: ${KeyAuth.response.message}`); } else { - return "Successfully set up JSON on User Variable"; + return "Successfully set up JSON on User Variable"; } - -} - -export { SetJSON_var, GetJSON_var } - -async function GetJSON_var(result, value) { - if(!result || !value) { - try { - throw new Exception("GetJSON_var | Result / Value is empty / null"); - } catch (e) { } + }, + GetJSON_var: async function (result, value) { + if (!result || !value) { + try { + throw new Exception("GetJSON_var | Result / Value is empty / null"); + } catch (e) {} } if (result === null) { - var lol = "Result is null!, Please check that this variable is existing..."; - return lol; + var lol = + "Result is null!, Please check that this variable is existing..."; + return lol; } else { - var lol = JSON.parse(result); + var lol = JSON.parse(result); - if (value === "all") { - lol = lol; - } else { - lol = lol[value]; - } - return lol; + if (value === "all") { + lol = lol; + } else { + lol = lol[value]; + } + return lol; } -} - -async function ban() { + }, + ban: async function () { checkinit(); const values_to_upload = { - 'type': 'ban', - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "ban", + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); var response = await req(parameters); var json = response; load_response_struct(json); -} - -async function variable(varid) { + }, + variable: async function (varid) { checkinit(); const values_to_upload = { - 'type': 'var', - 'varid': varid, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "var", + varid: varid, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); @@ -412,25 +475,24 @@ async function variable(varid) { load_response_struct(json); if (json.success) { - return json.message; + return json.message; } else { - return null; + return null; } -} - -async function webhook(webid, param, body = "", conttype = "") { + }, + webhook: async function (webid, param, body = "", conttype = "") { checkinit(); const values_to_upload = { - 'type': 'webhook', - 'webid': webid, - 'params': param, - 'body': body, - 'conttype': conttype, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "webhook", + webid: webid, + params: param, + body: body, + conttype: conttype, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); @@ -440,22 +502,21 @@ async function webhook(webid, param, body = "", conttype = "") { load_response_struct(json); if (json.success) { - return json.message; + return json.message; } else { - return null; + return null; } -} - -async function download(fileid) { + }, + download: async function (fileid) { checkinit(); const values_to_upload = { - 'type': 'file', - 'fileid': fileid, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "file", + fileid: fileid, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); @@ -463,160 +524,42 @@ async function download(fileid) { var json = response; load_response_struct(json); - if (json.success) { - return str_to_byte_arr(json.contents); + return str_to_byte_arr(json.contents); } else { - return null; + return null; } - -} - -async function log(message) { + }, + log: async function (message) { checkinit(); await getUSER(); let pcuser = sys.username; const values_to_upload = { - 'type': 'log', - 'pcuser': pcuser, - 'message': message, - 'sessionid': datastore.sessionid, - 'name': datastore.name, - 'ownerid': datastore.ownerid, - } + type: "log", + pcuser: pcuser, + message: message, + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + }; const parameters = "?" + stringify(values_to_upload); await req(parameters); -} - -//#region app_data - -var app_data = { - numUsers: null, - numOnlineUsers: null, - numKeys: null, - version: null, - customerPanelLInk: null, - downloadLink: null + }, + Sleep: function (ms) { + return new Promise((resolve) => setTimeout(resolve, ms)); + }, + Title: function (title) { + process.stdout.write( + String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7) + ); + }, + response: response, + user_data: user_data, + app_data: app_data, + sys: sys, + datastore: datastore, }; - -async function load_app_data(data) { - app_data.numUsers = data.numUsers; - app_data.numOnlineUsers = data.numOnlineUsers; - app_data.numKeys = data.numKeys; - app_data.version = data.version; - app_data.customerPanelLInk = data.customerPanelLink; -} - -//#endregion - -//#region user_data - -var user_data = { - username: null, - ip: null, - hwid: null, - createdate: null, - lastlogin: null, - subscriptions: null -} - -async function load_user_data(data) { - user_data.username = data.username; - user_data.ip = data.ip; - user_data.hwid = data.hwid; - user_data.createdate = data.createdate; - user_data.lastlogin = data.lastlogin; - user_data.subscriptions = data.subscriptions; -} -//#endregion - -//#region Functions -async function checkvalues() { - if (!datastore.name || !datastore.ownerid || !datastore.secret || !datastore.version ) { - error("Application not setup correctly."); - } -} - -async function error(message) { - console.log(message); - return process.exit(0); -} - -async function checkinit() { - if (!intialized) { - error("Please initzalize first") - } -} - -let sys = { - username: null, - hwid: null, -} - -async function getHWID() { - //Credits to https://github.com/sebhildebrandt/systeminformation - await systeminformation.blockDevices((data) => { - sys.hwid = data[0].serial; - }) -} - -async function getUSER() { - //Credits to https://github.com/sebhildebrandt/systeminformation - await systeminformation.users((data) => { - sys.username = data[0].user - }) -} -//#endregion - -export { api, app_data, user_data, init, Login, Register, License, Upgrade, log, webhook, getvar, setvar, ban, download, variable, check, checkblacklist } //KEYAUTH API - -async function req(post_data) { - - var returndata = null; - - await axios.get('https://keyauth.win/api/1.1/' + post_data, { - headers: { - 'Content-Type': 'application/x-www-form-urlencoded', - } - }) - .then((res) => { - returndata = res.data; - }).catch((err) => { - if (err.response.status == 429) { - error("Rate Limited! - KeyAuth"); - } - else if (err.response.status == 502) { - error("502 Bad Gateway! - KeyAuth"); - } - else { - if (err.response.status == 200) { } else { - error(`${err.response.status} ${err.response.statusText}! - KeyAuth`); - } - } - }); - return returndata; -} - -//#region ADDONS - -function Title(title) -{ - process.stdout.write( - String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7) - ); -} - -function cls() { - console.clear(); -} - -function Sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -export { Title, Sleep, response, error, cls } //CUSTOM STUFF -//#endregion From fe50ac1d8c9725602c3834db5e00d6d2071050de Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Sun, 29 May 2022 02:39:01 +0200 Subject: [PATCH 2/7] Update index.js --- src/index.js | 318 ++++++++++++++++++++------------------------------- 1 file changed, 127 insertions(+), 191 deletions(-) diff --git a/src/index.js b/src/index.js index 88f5c6b..b8829d8 100644 --- a/src/index.js +++ b/src/index.js @@ -1,206 +1,142 @@ -import * as KeyAuth from './KeyAuth.js' -import readline from "readline"; -import moment from "moment" +/* + Based on: https://github.com/mazk5145/KeyAuth-JS-Example +*/ + +const KeyAuth = require("./KeyAuth"); +const readline = require("readline"); +const moment = require("moment"); const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout -}) + input: process.stdin, + output: process.stdout, +}); KeyAuth.api( - "", // Application Name - "", // OwnerID - "", // Application Secret - "1.0" // Application Version -) - -await KeyAuth.cls(); -await KeyAuth.init(); - -if (!KeyAuth.response.success) { - KeyAuth.error("Status: " + KeyAuth.response.message) + "", // Application Name + "", // OwnerID + "", // Application Secret + "1.0" // Application Version +); + +load(); + +async function load() { + await console.clear(); + await KeyAuth.init(); + + if (!KeyAuth.response.success) { + KeyAuth.error("Status: " + KeyAuth.response.message); + } + + KeyAuth.Title("KeyAuth JS Example - 1.1 API"); + console.log("\n Application Data:"); + console.log(` Number of users: ${KeyAuth.app_data.numUsers}`); + console.log(` Number of online users: ${KeyAuth.app_data.numOnlineUsers}`); + console.log(` Number of keys: ${KeyAuth.app_data.numKeys}`); + console.log(` Application Version: ${KeyAuth.app_data.version}`); + console.log(` Customer panel link: ${KeyAuth.app_data.customerPanelLInk}\n`); + await KeyAuth.check(); + await KeyAuth.Sleep(1200); + console.log( + ` Current Session Validation Status: ${KeyAuth.response.message}` + ); + console.log(` Blacklisted: ${await KeyAuth.checkblacklist()}`); + + question(); } -KeyAuth.Title("KeyAuth JS Example - 1.1 API") -console.log("\n Application Data:") -console.log(` Number of users: ${KeyAuth.app_data.numUsers}`) -console.log(` Number of online users: ${KeyAuth.app_data.numOnlineUsers}`) -console.log(` Number of keys: ${KeyAuth.app_data.numKeys}`) -console.log(` Application Version: ${KeyAuth.app_data.version}`) -console.log(` Customer panel link: ${KeyAuth.app_data.customerPanelLInk}\n`) -await KeyAuth.check(); -await KeyAuth.Sleep(1200); -console.log(` Current Session Validation Status: ${KeyAuth.response.message}`); -console.log(` Blacklisted: ${await KeyAuth.checkblacklist()}`); - -await rl.question("\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n\n Choose option: ", async function(choice) { - if (choice === "1") { - rl.question("Whats your username: ", async function(username) { - rl.question("Whats your password: ", async function(password) { - await KeyAuth.Login(username, password); - if (!KeyAuth.response.success) { - KeyAuth.error("Status: " + KeyAuth.response.message) - } - loggedin(); - rl.close(); - }) - }) - } - else if (choice === "2") { - rl.question("Whats your username: ", async function(username) { - rl.question("Whats your password: ", async function(password) { - rl.question("Whats your License: ", async function(key) { - await KeyAuth.Register(username, password, key); - if (!KeyAuth.response.success) { - KeyAuth.error("Status: " + KeyAuth.response.message) - } - loggedin(); - rl.close(); - }) - }) - }) - } - else if (choice === "3") { - rl.question("Whats your username: ", async function(username) { - rl.question("Whats your License: ", async function(key) { - await KeyAuth.Upgrade(username, key); - if (!KeyAuth.response.success) { - KeyAuth.error("Status: " + KeyAuth.response.message) - } - loggedin(); - rl.close(); - }) - }) - } - else if (choice === "4") { - rl.question("Whats your License: ", async function(key) { - await KeyAuth.License(key); +async function question() { + await rl.question( + "\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n\n Choose option: ", + async function (choice) { + if (choice === "1") { + rl.question("Whats your username: ", async function (username) { + rl.question("Whats your password: ", async function (password) { + await KeyAuth.Login(username, password); if (!KeyAuth.response.success) { - KeyAuth.error("Status: " + KeyAuth.response.message) + KeyAuth.error("Status: " + KeyAuth.response.message); } loggedin(); rl.close(); - }) - } - else { - console.log("?") + }); + }); + } else if (choice === "2") { + rl.question("Whats your username: ", async function (username) { + rl.question("Whats your password: ", async function (password) { + rl.question("Whats your License: ", async function (key) { + await KeyAuth.Register(username, password, key); + if (!KeyAuth.response.success) { + KeyAuth.error("Status: " + KeyAuth.response.message); + } + loggedin(); + rl.close(); + }); + }); + }); + } else if (choice === "3") { + rl.question("Whats your username: ", async function (username) { + rl.question("Whats your License: ", async function (key) { + await KeyAuth.Upgrade(username, key); + if (!KeyAuth.response.success) { + KeyAuth.error("Status: " + KeyAuth.response.message); + } + loggedin(); + rl.close(); + }); + }); + } else if (choice === "4") { + rl.question("Whats your License: ", async function (key) { + await KeyAuth.License(key); + if (!KeyAuth.response.success) { + KeyAuth.error("Status: " + KeyAuth.response.message); + } + loggedin(); + rl.close(); + }); + } else { + console.log("?"); rl.close(); + } } -}) - -//#region Extra Stuff -/* - // - // --> set user variable 'discord' to 'test#0001' (if the user variable with name 'discord' doesn't exist, it'll be created) <-- - - await KeyAuth.setvar("discord", "test#0000"); - if (!KeyAuth.response.success) { - KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) - } else { - console.log("\n Succesfully set user variable.") - } - - // - // --> display the user variable 'discord' <-- - - let uservar = await KeyAuth.getvar("discord"); - if (!KeyAuth.response.success) { - KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) - } else { - console.log(`\n User variable value: ${uservar}`) - } - - // KeyAuth.log("User logged in") // log text to website and discord webhook (if set) - - - // let's say you want to send request to https://keyauth.com/api/seller/?sellerkey=f43795eb89d6060b74cdfc56978155ef&type=black&ip=1.1.1.1&hwid=abc - // but doing that from inside the loader is a bad idea as the link could get leaked. - // Instead, you should create a webhook with the https://keyauth.com/api/seller/?sellerkey=f43795eb89d6060b74cdfc56978155ef part as the URL - // then in your loader, put the rest of the link (the other paramaters) in your loader. And then it will send request from KeyAuth server and return response in string resp Credits to mak. - - // - // --> example to send normal request with no POST data <-- - string resp = await KeyAuthApp.webhook("7kR0UedlVI", "&type=black&ip=1.1.1.1&hwid=abc"); - - // - // --> example to send form data <-- - resp = KeyAuth.webhook("7kR0UedlVI", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded"); - - // - // --> example to send JSON <-- - - let resp = await KeyAuth.webhook("HTeP5e21OC", "", "{\"content\": \"webhook message here\", \"embeds\": null}", "application/json") // if Discord webhook message successful, response will be empty - if (!KeyAuth.response.success) { - KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) - } else { - console.log(`\n Response recieved from webhook request: ${resp}`) - } - - // - // --> FILEID Downloads <-- - var result = await KeyAuth.download("763996"); - if (!KeyAuth.response.success) { - KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) - } else { - console.log(result); // Show's Byte Array on console - // --> FILE Save <-- not yet - } - - // - // --> Application Variables <-- - let appvar = await KeyAuth.variable("test"); - if (!KeyAuth.response.success) { - KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) - } else { - console.log(`\n App variable data: ${appvar}`); - } - - // - // --> Set up JSON User Variables <-- - const JSONArray = { - 'version': '1.25', - 'Profile_picURI': 'https://example.com/lol.png' - } - - /// KeyAuth user variabl - change "JSON" to your user JSON Variable name - await KeyAuth.SetJSON_var("JSON", JSONArray); - - - // - // --> Fetch JSON User Variable <-- - // CHANGE "JSON" To your User JSON Variable Name ^^^^ - var result = await KeyAuth.getvar("JSON"); - var deserialized = KeyAuth.GetJSON_var(result, "all"); // (result ^^, and you can enter json value to get the json value out of req | or | put "all" to get full json array.) - console.log(desrialized); - - -*/ - -//#endregion - + ); +} async function loggedin() { - console.log("\n Logged In!") - - //User Data - console.log(` Username: ${KeyAuth.user_data.username}`) - console.log(` IP address: ${KeyAuth.user_data.ip}`) - console.log(` Hardware-Id: ${KeyAuth.user_data.hwid}`) - console.log(` Created at: ${moment.unix(KeyAuth.user_data.createdate).format("DD-MM-YYYY - HH:mm:ss")}`) - console.log(` Last Login: ${moment.unix(KeyAuth.user_data.lastlogin).format("DD-MM-YYYY - HH:mm:ss")}`) - - - for (var i = 0; i < KeyAuth.user_data.subscriptions.length; i++) - { - console.log(` [${i}] Subscription name: ${KeyAuth.user_data.subscriptions[i].subscription} | Expires at: ${moment.unix(KeyAuth.user_data.subscriptions[i].expiry).format("DD-MM-YYYY - HH:mm:ss")} | Time left in seconds ${KeyAuth.user_data.subscriptions[i].timeleft}`) - } - - - KeyAuth.check(); - console.log(` Current Session Validation Status: ${KeyAuth.response.message}`); - - console.log("\n\n Closing in 10 seconds...") - await KeyAuth.Sleep(10000); - process.exit(0); - + console.log("\n Logged In!"); + + //User Data + console.log(` Username: ${KeyAuth.user_data.username}`); + console.log(` IP address: ${KeyAuth.user_data.ip}`); + console.log(` Hardware-Id: ${KeyAuth.user_data.hwid}`); + console.log( + ` Created at: ${moment + .unix(KeyAuth.user_data.createdate) + .format("DD-MM-YYYY - HH:mm:ss")}` + ); + console.log( + ` Last Login: ${moment + .unix(KeyAuth.user_data.lastlogin) + .format("DD-MM-YYYY - HH:mm:ss")}` + ); + + for (var i = 0; i < KeyAuth.user_data.subscriptions.length; i++) { + console.log( + ` [${i}] Subscription name: ${ + KeyAuth.user_data.subscriptions[i].subscription + } | Expires at: ${moment + .unix(KeyAuth.user_data.subscriptions[i].expiry) + .format("DD-MM-YYYY - HH:mm:ss")} | Time left in seconds ${ + KeyAuth.user_data.subscriptions[i].timeleft + }` + ); + } + + KeyAuth.check(); + console.log( + ` Current Session Validation Status: ${KeyAuth.response.message}` + ); + + console.log("\n\n Closing in 10 seconds..."); + await KeyAuth.Sleep(10000); + process.exit(0); } From 365701a3bdb6148247a8d18c8a87e7ff015e2a26 Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Sun, 29 May 2022 02:41:15 +0200 Subject: [PATCH 3/7] Update package.json --- src/package.json | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/package.json b/src/package.json index e20fd32..b91301a 100644 --- a/src/package.json +++ b/src/package.json @@ -1,20 +1,22 @@ { - "name": "keyauth-js-example", - "version": "1.2.5", - "description": "KeyAuth Javascript Example", + "name": "keyauth-js-example-commonjs", + "version": "1.0.0", + "description": "", "main": "index.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "echo \"Error: no test specified\" && exit 1", + "start": "src/index.js" }, - "author": "mazk#9154", + "keywords": [ + "KeyAuth" + ], + "author": "Displayray", "license": "ISC", - "type": "module", - "module": "commonjs", "dependencies": { - "axios": "^0.26.0", - "cli-select": "^1.1.2", - "moment": "^2.29.1", + "axios": "^0.27.2", + "moment": "^2.29.3", + "querystring": "^0.2.1", "readline": "^1.3.0", - "systeminformation": "^5.11.6" + "systeminformation": "^5.11.15" } } From ae79b6df287979c566155718c55b6a02736d0f82 Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Sun, 29 May 2022 02:48:16 +0200 Subject: [PATCH 4/7] Update README.md --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index be352ab..f1f7677 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# KeyAuth-JS-Example +# KeyAuth-JS-Example-CommonJS ## **Example Details** ``` @@ -16,10 +16,11 @@ Encrypted Version of KeyAuth JS Example [KeyAuth API 1.0], Is coming soon as Dev ## **How to Install?** ``` 1: Install node.js -2: Download this and put it on desktop -3: Run CMD in that folder and put npm install -4: Put your KeyAuth Details to 11-14 Lines - https://keyauth.win -5: Run the Example - node index.js +2: Setup a node project +3: Download this and put it in your project +4: Run CMD in that folder and put npm install +5: Put your KeyAuth Details to 11-14 Lines - https://keyauth.win +6: Run the Example - node index.js ``` ## **NPM Module Versions** From af6b95ef9ff8d41c8e5f2d7a370d061c356880ba Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Sun, 29 May 2022 02:50:29 +0200 Subject: [PATCH 5/7] Update README.md --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f1f7677..b8e214a 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,10 @@ Encrypted Version of KeyAuth JS Example [KeyAuth API 1.0], Is coming soon as Dev ## **How to Install?** ``` 1: Install node.js -2: Setup a node project -3: Download this and put it in your project -4: Run CMD in that folder and put npm install -5: Put your KeyAuth Details to 11-14 Lines - https://keyauth.win -6: Run the Example - node index.js +2: Download this and put it on desktop +3: Run CMD in that folder and put npm install +4: Put your KeyAuth Details to 11-14 Lines - https://keyauth.win +5: Run the Example - node index.js ``` ## **NPM Module Versions** From 02c314c43ee78a787b9cb1a65fc756a0c5620753 Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Thu, 9 Jun 2022 04:48:41 +0200 Subject: [PATCH 6/7] Update KeyAuth.js --- src/KeyAuth.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/src/KeyAuth.js b/src/KeyAuth.js index 98f8e08..18076ac 100644 --- a/src/KeyAuth.js +++ b/src/KeyAuth.js @@ -48,7 +48,6 @@ let sys = { async function error(message) { console.log(message); - loginWindow.webContents.send("notify:error", message); return process.exit(0); } @@ -93,6 +92,13 @@ async function req(post_data) { async function load_response_struct(data) { response.success = data.success; response.message = data.message; + response.response = data.response; +} + +async function load_channel_struct(data) { + response.success = data.success; + response.message = data.message; + response.messages = data.messages; } async function load_app_data(data) { @@ -357,6 +363,53 @@ module.exports = { return false; } }, + chatsend: async function (message, channel) { + checkinit(); + + const values_to_upload = { + type: "chatsend", + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + message: message, + channel: channel, + }; + + const parameters = "?" + stringify(values_to_upload); + + var response = await req(parameters); + var json = response; + + load_response_struct(json); + if (json.success) { + return true; + } else { + return false; + } + }, + chatget: async function (channel) { + checkinit(); + + const values_to_upload = { + type: "chatget", + sessionid: datastore.sessionid, + name: datastore.name, + ownerid: datastore.ownerid, + channel: channel, + }; + + const parameters = "?" + stringify(values_to_upload); + + var response = await req(parameters); + var json = response; + + load_channel_struct(json); + if (json.success) { + return true; + } else { + return false; + } + }, setvar: async function (varname, data) { checkinit(); @@ -557,6 +610,10 @@ module.exports = { String.fromCharCode(27) + "]0;" + title + String.fromCharCode(7) ); }, + error: function (message) { + console.log(message); + return process.exit(0); + }, response: response, user_data: user_data, app_data: app_data, From 56448eaacf7dfd9c848e970e57c3af3354771afb Mon Sep 17 00:00:00 2001 From: Displayray <68347382+Displayray@users.noreply.github.com> Date: Thu, 9 Jun 2022 04:49:08 +0200 Subject: [PATCH 7/7] Update index.js --- src/index.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index b8829d8..c469269 100644 --- a/src/index.js +++ b/src/index.js @@ -57,7 +57,7 @@ async function question() { KeyAuth.error("Status: " + KeyAuth.response.message); } loggedin(); - rl.close(); + //rl.close(); }); }); } else if (choice === "2") { @@ -140,3 +140,120 @@ async function loggedin() { await KeyAuth.Sleep(10000); process.exit(0); } + +//#region Extra Stuff +/* + // + // --> set user variable 'discord' to 'test#0001' (if the user variable with name 'discord' doesn't exist, it'll be created) <-- + + await KeyAuth.setvar("discord", "test#0000"); + if (!KeyAuth.response.success) { + KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) + } else { + console.log("\n Succesfully set user variable.") + } + + // + // --> display the user variable 'discord' <-- + + let uservar = await KeyAuth.getvar("discord"); + if (!KeyAuth.response.success) { + KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) + } else { + console.log(`\n User variable value: ${uservar}`) + } + + // KeyAuth.log("User logged in") // log text to website and discord webhook (if set) + + // let's say you want to send request to https://keyauth.com/api/seller/?sellerkey=f43795eb89d6060b74cdfc56978155ef&type=black&ip=1.1.1.1&hwid=abc + // but doing that from inside the loader is a bad idea as the link could get leaked. + // Instead, you should create a webhook with the https://keyauth.com/api/seller/?sellerkey=f43795eb89d6060b74cdfc56978155ef part as the URL + // then in your loader, put the rest of the link (the other paramaters) in your loader. And then it will send request from KeyAuth server and return response in string resp Credits to mak. + + // + // --> example to send normal request with no POST data <-- + string resp = await KeyAuthApp.webhook("7kR0UedlVI", "&type=black&ip=1.1.1.1&hwid=abc"); + + // + // --> example to send form data <-- + resp = KeyAuth.webhook("7kR0UedlVI", "", "type=init&name=test&ownerid=j9Gj0FTemM", "application/x-www-form-urlencoded"); + // + // --> example to send JSON <-- + let resp = await KeyAuth.webhook("HTeP5e21OC", "", "{\"content\": \"webhook message here\", \"embeds\": null}", "application/json") // if Discord webhook message successful, response will be empty + if (!KeyAuth.response.success) { + KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) + } else { + console.log(`\n Response recieved from webhook request: ${resp}`) + } + + // + // --> FILEID Downloads <-- + var result = await KeyAuth.download("763996"); + if (!KeyAuth.response.success) { + KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) + } else { + // FILE save using inbuild FileSystem + try { + fs.writeFileSync( + pathtobuild, + Buffer.from(byteArray) + ); + } catch (error) { + console.log(error) + } + } + + // + // --> Application Variables <-- + let appvar = await KeyAuth.variable("test"); + if (!KeyAuth.response.success) { + KeyAuth.error(`\nStatus: ${KeyAuth.response.message}`) + } else { + console.log(`\n App variable data: ${appvar}`); + } + + // + // --> Set up JSON User Variables <-- + const JSONArray = { + 'version': '1.25', + 'Profile_picURI': 'https://example.com/lol.png' + } + + /// KeyAuth user variabl - change "JSON" to your user JSON Variable name + await KeyAuth.SetJSON_var("JSON", JSONArray); + + // + // --> Fetch JSON User Variable <-- + // CHANGE "JSON" To your User JSON Variable Name ^^^^ + var result = await KeyAuth.getvar("JSON"); + var deserialized = KeyAuth.GetJSON_var(result, "all"); // (result ^^, and you can enter json value to get the json value out of req | or | put "all" to get full json array.) + console.log(desrialized); + + // + // --> Send Message <-- + await KeyAuth.chatsend(message, channel) + if(!KeyAuth.response.success) { + KeyAuth.error("Status: " + KeyAuth.response.message); + } else { + console.log("Message has been sent"); + } + + // + // --> Get Channel Messages <-- + await KeyAuth.chatget(channel) + if(!KeyAuth.response.success) { + KeyAuth.error("Status: " + KeyAuth.response.message); + } else { + KeyAuth.response.messages.forEach(async (m) => { + let timestampt = await formatTime(m.timestamp) + console.log(`\nFrom: ${m.author}\nContent: ${m.message}\nAt: ${timestamp}\n`) + }) + } + + //Format unix timestampt to date & time using moment + async function formatTime(unix_timestamp) { + let newdate = moment.unix(unix_timestamp).format("HH:mm:ss - DD/MM/YYYY"); + return newdate; + } +*/ +//#endregion