|
| 1 | +import KeyAuth from "./keyauth" |
| 2 | +import { createInterface } from "readline/promises" |
| 3 | + |
| 4 | +const readline = createInterface({ |
| 5 | + input: process.stdin, |
| 6 | + output: process.stdout, |
| 7 | + terminal: false |
| 8 | +}) |
| 9 | + |
| 10 | +const KeyAuthApp = new KeyAuth({ |
| 11 | + name: "", |
| 12 | + ownerid: "", |
| 13 | + version: "", |
| 14 | +}) |
| 15 | + |
| 16 | +async function answer() { |
| 17 | + try { |
| 18 | + await KeyAuthApp.init() |
| 19 | + |
| 20 | + console.log("[1] Login\n[2] Register\n[3] License\n[4] Upgrade") |
| 21 | + |
| 22 | + const optionRaw = await readline.question("Select an option: ") |
| 23 | + const option = parseInt(optionRaw) |
| 24 | + |
| 25 | + let username = "", |
| 26 | + password = "", |
| 27 | + license = "" |
| 28 | + |
| 29 | + switch (option) { |
| 30 | + case 1: |
| 31 | + username = await readline.question("Username: ") |
| 32 | + password = await readline.question("Password: ") |
| 33 | + await KeyAuthApp.login(username, password) |
| 34 | + dashboard() |
| 35 | + break |
| 36 | + |
| 37 | + case 2: |
| 38 | + username = await readline.question("Username: ") |
| 39 | + password = await readline.question("Password: ") |
| 40 | + license = await readline.question("License: ") |
| 41 | + await KeyAuthApp.register(username, password, license) |
| 42 | + dashboard() |
| 43 | + break |
| 44 | + |
| 45 | + case 3: |
| 46 | + license = await readline.question("License: ") |
| 47 | + await KeyAuthApp.license(license) |
| 48 | + dashboard() |
| 49 | + break |
| 50 | + |
| 51 | + case 4: |
| 52 | + username = await readline.question("Username: ") |
| 53 | + license = await readline.question("License: ") |
| 54 | + await KeyAuthApp.upgrade(username, license) |
| 55 | + dashboard() |
| 56 | + break |
| 57 | + |
| 58 | + default: |
| 59 | + console.log("Invalid option selected.") |
| 60 | + break |
| 61 | + } |
| 62 | + } catch (error) { |
| 63 | + if (error instanceof Error) { |
| 64 | + console.error("An error occurred:", error.message) |
| 65 | + } else { |
| 66 | + console.error("An unknown error occurred:", error) |
| 67 | + } |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +answer() |
| 72 | + |
| 73 | +async function dashboard() { |
| 74 | + await KeyAuthApp.fetchStats() |
| 75 | + console.log("Application data:") |
| 76 | + console.log(" App Version: ", KeyAuthApp.app_data?.app_ver) |
| 77 | + console.log(" Customer panel: ", KeyAuthApp.app_data?.customer_panel) |
| 78 | + console.log(" Number of Keys: ", KeyAuthApp.app_data?.numKeys) |
| 79 | + console.log(" Number of Users: ", KeyAuthApp.app_data?.numUsers) |
| 80 | + console.log(" Online Users: ", KeyAuthApp.app_data?.onlineUsers) |
| 81 | + |
| 82 | + console.log("\nUser data:") |
| 83 | + console.log(" Username: ", KeyAuthApp.user_data?.username) |
| 84 | + console.log(" IP Address: ", KeyAuthApp.user_data?.ip) |
| 85 | + console.log(" Hardware-id: ", KeyAuthApp.user_data?.hwid) |
| 86 | + |
| 87 | + const subs = KeyAuthApp.user_data?.subscriptions || [] |
| 88 | + |
| 89 | + for (let i = 0; i < subs.length; i++) { |
| 90 | + const sub = subs[i] |
| 91 | + const expiry = new Date(Number(sub.expiry) * 1000) |
| 92 | + |
| 93 | + console.log( |
| 94 | + `[${i + 1}/${subs.length}] | Subscription: ${ |
| 95 | + sub.subscription |
| 96 | + } - Expiry: ${expiry.toLocaleString()}` |
| 97 | + ) |
| 98 | + } |
| 99 | + |
| 100 | + console.log( |
| 101 | + `Created at: ${new Date( |
| 102 | + (KeyAuthApp.user_data?.createdate || 0) * 1000 |
| 103 | + ).toLocaleString()}` |
| 104 | + ) |
| 105 | + console.log( |
| 106 | + `Last Login: ${new Date( |
| 107 | + (KeyAuthApp.user_data?.lastlogin || 0) * 1000 |
| 108 | + ).toLocaleString()}` |
| 109 | + ) |
| 110 | + console.log( |
| 111 | + `Expires: ${new Date( |
| 112 | + (KeyAuthApp.user_data?.expires || 0) * 1000 |
| 113 | + ).toLocaleString()}` |
| 114 | + ) |
| 115 | + |
| 116 | + console.log("\n2-factor authentication:") |
| 117 | + console.log("[1] Enable\n[2] Disable") |
| 118 | + |
| 119 | + const optionRaw = await readline.question("Select an option: ") |
| 120 | + const option = parseInt(optionRaw) |
| 121 | + |
| 122 | + switch (option) { |
| 123 | + case 1: |
| 124 | + await KeyAuthApp.enable2fa() |
| 125 | + break |
| 126 | + case 2: |
| 127 | + await KeyAuthApp.disable2fa() |
| 128 | + break |
| 129 | + default: |
| 130 | + console.log("Invalid option selected.") |
| 131 | + break |
| 132 | + } |
| 133 | + |
| 134 | + console.log("Closing app in 10 seconds...") |
| 135 | + await new Promise(resolve => setTimeout(resolve, 10000)) |
| 136 | + readline.close() |
| 137 | + await KeyAuthApp.logout() |
| 138 | + process.exit(0) |
| 139 | +} |
0 commit comments