diff --git a/.gitignore b/.gitignore index ea9cf22..4f30706 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ purge-redis/ reset/ resetUser/ whoami/ -vendor/ login/accShare/ login/emailVerify/ sitemap.xml diff --git a/README.md b/README.md index 6a8df11..355af38 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,16 @@ -# KeyAuth Source Code -> Please star :star2: - -> [!WARNING] -> AS OF JANUARY 29th, 2024 - THIS REPOSITORY IS NO LONGER BEING UPDATED! - -[KeyAuth](https://keyauth.win) is an open source authentication system with [cloud-hosted subscriptions](https://keyauth.win/app/?page=upgrade) available as well. +# KeyAuth-Source-Code +KeyAuth is an open source authentication system with cloud-hosted subscriptions available aswell https://keyauth.cc
*You're not allowed to sell KeyAuth. source made avaliable only for you to use* To submit a suggestion or a bug, please go to https://keyauth.cc/app/?page=forms and submit a form! [![CodeFactor](https://www.codefactor.io/repository/github/keyauth/keyauth-source-code/badge)](https://www.codefactor.io/repository/github/keyauth/keyauth-source-code) +[![Discord](https://img.shields.io/discord/1125387048979795988?label=Discord&cacheSeconds=3600)](https://discord.com/invite/keyauth) [![Telegram Chat](https://img.shields.io/endpoint?color=neon&style=flat-square&url=https%3A%2F%2Ftg.sumanjay.workers.dev%2Fkeyauth)](https://t.me/KeyAuth) [![Twitter](https://img.shields.io/twitter/follow/KeyAuth?cacheSeconds=3600)](https://twitter.com/KeyAuth) -[![Screenshot](https://cdn.keyauth.cc/v3/imgs/Screenshot%20from%202025-07-04%2012-07-30.png)](https://keyauth.cc) +[![Screenshot](https://i.imgur.com/rige1nM.png)](https://keyauth.cc) ## Bugs ## @@ -46,12 +43,12 @@ Thank you for your compliance, we work hard on the development of KeyAuth and do - Redis - PHP -No setup support given to non-enterprise users. However for $79.99 you can purchase access to the source code of paid features (developer and seller plan features), setup support 1-on-1 with the owner of KeyAuth, and a tutorial video on how to host KeyAuth for 100% free forever (good preformance & secure also) +No setup support given to non-enterprise users. However for $79.99 you can purchase access to the source code of paid features (developer and seller plan features), setup support one-on-one with the Founder of KeyAuth, and a tutorial video on how to host KeyAuth for 100% free forever (good preformance & secure also) -Purchase enterprise today --> https://keyauth.win/app/?page=upgrade +Purchase enterprise today --> https://shop.keyauth.cc/product/6361c20e415e9 -## Updates ## +Some pages such as the API endpoint that upgrades users after they purchase a subscription have been omitted to prevent violation of the license (No Commercial Access Allowed) -https://keyauth.canny.io/changelog +## Updates ## -Looking for a Discord bot made by the KeyAuth & RestoreCord founder that you can use to backup your Discord members, server settings, and messages? Go to https://vaultcord.com +https://headwayapp.co/keyauth-changelog/ diff --git a/api/1.0/index.php b/api/1.0/index.php index 7c56d9a..80d219b 100644 --- a/api/1.0/index.php +++ b/api/1.0/index.php @@ -1,19 +1,15 @@ getMessage()); - die(json_encode(array("success" => false, "message" => "Error: " . $errorMsg))); + http_response_code(500); + die(json_encode(array("success" => false, "message" => "Error: " . $exception->getMessage()))); }); if(empty($_POST['ownerid'])) { @@ -28,6 +24,10 @@ die(json_encode(array("success" => false, "message" => "OwnerID should be 10 characters long. Select app & copy code snippet from https://keyauth.cc/app/"))); } +include '../../includes/misc/autoload.phtml'; +include '../../includes/api/shared/autoload.phtml'; +include '../../includes/api/1.0/autoload.phtml'; + $ownerid = misc\etc\sanitize(hex2bin($_POST['ownerid'])); // ownerid of account that owns application $name = misc\etc\sanitize(hex2bin($_POST['name'])); // application name $row = misc\cache\fetch('KeyAuthApp:' . $name . ':' . $ownerid, "SELECT * FROM `apps` WHERE `ownerid` = ? AND `name` = ?", [$ownerid, $name], 0); @@ -87,13 +87,6 @@ )), $secret)); } -if ($_GET['host'] == "keyauth.business") { - die(api\v1_0\Encrypt(json_encode(array( - "success" => false, - "message" => "Please tell the developer of this program to use latest API domain. This domain is old, it will expire in a month." - )), $secret)); -} - switch (hex2bin($_POST['type'])) { case 'init': $ip = api\shared\primary\getIp(); @@ -169,9 +162,9 @@ // $row = misc\cache\fetch('KeyAuthAppStats:' . $secret, "SELECT (SELECT COUNT(1) FROM `users` WHERE `app` = ?) AS 'numUsers', (SELECT COUNT(1) FROM `sessions` WHERE `app` = ? AND `validated` = 1 AND `expiry` > ?) AS 'numOnlineUsers', (SELECT COUNT(1) FROM `keys` WHERE `app` = ?) AS 'numKeys' FROM dual", [$secret, $secret, time(), $secret], 0, 3600); - $numUsers = "N/A - Use fetchStats() function in latest example"; - $numOnlineUsers = "N/A - Use fetchStats() function in latest example"; - $numKeys = "N/A - Use fetchStats() function in latest example"; + $numUsers = "N/A Temporarily Disabled"; + $numOnlineUsers = "N/A Temporarily Disabled"; + $numKeys = "N/A Temporarily Disabled"; echo api\v1_0\Encrypt(json_encode(array( "success" => true, @@ -875,10 +868,6 @@ die(); } - if(strlen($msg) > 275) { - die("Log data too long"); - } - $pcuser = misc\etc\sanitize(api\v1_0\Decrypt($_POST['pcuser'], $enckey)); if (is_null($webhook)) { @@ -903,6 +892,13 @@ $ip = api\shared\primary\getIp(); $json_data = json_encode([ + // Username + "username" => "KeyAuth", + + // Avatar URL. + // Uncoment to replace image set in webhook + "avatar_url" => "https://cdn.keyauth.cc/front/assets/img/favicon.png", + // Embeds Array "embeds" => [ [ diff --git a/api/1.1/index.php b/api/1.1/index.php index 40dd0e9..398ba45 100644 --- a/api/1.1/index.php +++ b/api/1.1/index.php @@ -1,20 +1,16 @@ getMessage()); - die(json_encode(array("success" => false, "message" => "Error: " . $errorMsg))); + http_response_code(500); + die(json_encode(array("success" => false, "message" => "Error: " . $exception->getMessage()))); }); if(empty(($_POST['ownerid'] ?? $_GET['ownerid']))) { @@ -29,6 +25,10 @@ die(json_encode(array("success" => false, "message" => "OwnerID should be 10 characters long. Select app & copy code snippet from https://keyauth.cc/app/"))); } +include '../../includes/misc/autoload.phtml'; +include '../../includes/api/shared/autoload.phtml'; +include '../../includes/api/1.0/autoload.phtml'; + $ownerid = misc\etc\sanitize($_POST['ownerid'] ?? $_GET['ownerid']); // ownerid of account that owns application $name = misc\etc\sanitize($_POST['name'] ?? $_GET['name']); // application name $row = misc\cache\fetch('KeyAuthApp:' . $name . ':' . $ownerid, "SELECT * FROM `apps` WHERE `ownerid` = ? AND `name` = ?", [$ownerid, $name], 0); @@ -162,9 +162,9 @@ // $row = misc\cache\fetch('KeyAuthAppStats:' . $secret, "SELECT (SELECT COUNT(1) FROM `users` WHERE `app` = ?) AS 'numUsers', (SELECT COUNT(1) FROM `sessions` WHERE `app` = ? AND `validated` = 1 AND `expiry` > ?) AS 'numOnlineUsers', (SELECT COUNT(1) FROM `keys` WHERE `app` = ?) AS 'numKeys' FROM dual", [$secret, $secret, time(), $secret], 0, 3600); - $numUsers = "N/A - Use fetchStats() function in latest example"; - $numOnlineUsers = "N/A - Use fetchStats() function in latest example"; - $numKeys = "N/A - Use fetchStats() function in latest example"; + $numUsers = "N/A Temporarily Disabled"; + $numOnlineUsers = "N/A Temporarily Disabled"; + $numKeys = "N/A Temporarily Disabled"; echo json_encode(array( "success" => true, @@ -870,10 +870,6 @@ die(); } - if(strlen($msg) > 275) { - die("Log data too long"); - } - $pcuser = misc\etc\sanitize($_POST['pcuser'] ?? $_GET['pcuser']); if (is_null($webhook)) { @@ -898,6 +894,13 @@ $ip = api\shared\primary\getIp(); $json_data = json_encode([ + // Username + "username" => "KeyAuth", + + // Avatar URL. + // Uncoment to replace image set in webhook + "avatar_url" => "https://cdn.keyauth.cc/front/assets/img/favicon.png", + // Embeds Array "embeds" => [ [ diff --git a/api/1.2/index.php b/api/1.2/index.php index 7c701e5..2245b1b 100644 --- a/api/1.2/index.php +++ b/api/1.2/index.php @@ -1,20 +1,16 @@ getMessage()); - die(json_encode(array("success" => false, "message" => "Error: " . $errorMsg))); + http_response_code(500); + die(json_encode(array("success" => false, "message" => "Error: " . $exception->getMessage()))); }); if(empty(($_POST['ownerid'] ?? $_GET['ownerid']))) { @@ -29,6 +25,10 @@ die(json_encode(array("success" => false, "message" => "OwnerID should be 10 characters long. Select app & copy code snippet from https://keyauth.cc/app/"))); } +include '../../includes/misc/autoload.phtml'; +include '../../includes/api/shared/autoload.phtml'; +include '../../includes/api/1.0/autoload.phtml'; + if (misc\cache\rateLimit("KeyAuthAppLimit:" . ($_POST['ownerid'] ?? $_GET['ownerid']), 1, 60, 200)) { die(json_encode(array("success" => false, "message" => "This application has sent too many requests. Try again in a minute."))); } @@ -56,7 +56,6 @@ $sessionexpiry = $row['session']; $forceEncryption = $row['forceEncryption']; $forceHwid = $row['forceHwid']; -$tokensystem = $row['tokensystem']; $banned = $row['banned']; $owner = $row['owner']; @@ -78,7 +77,6 @@ $userbanned = $row['userbanned']; $sessionunauthed = $row['sessionunauthed']; $hashcheckfail = $row['hashcheckfail']; -$invalid_token = $row['tokeninvalid']; // why using null coalescing operators? because if I add a field and it's not in redis cache, it'll be NULL $loggedInMsg = $row['loggedInMsg'] ?? "Logged in!"; @@ -88,18 +86,6 @@ $chatHitDelay = $row['chatHitDelay'] ?? "Chat slower, you've hit the delay limit"; $minHwid = $row['minHwid'] ?? 20; -if($ownerid == "hTmfnZOYPe") { - $response = json_encode(array( - "success" => false, - "message" => "Jao é um golpista, prova aqui https://keyauth.cc/jao/" - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); -} - if ($banned) { die(json_encode(array( "success" => false, @@ -109,18 +95,6 @@ switch ($_POST['type'] ?? $_GET['type']) { case 'init': - if(strlen($_POST['enckey']) > 35) { - $response = json_encode(array( - "success" => false, - "message" => "The paramater \"enckey\" is too long. Must be 35 characters or less." - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - } - if ($forceEncryption) { if (!isset($_POST['enckey']) && !isset($_GET['enckey'])) { $response = json_encode(array( @@ -176,91 +150,6 @@ die($response); } - if ($tokensystem) { - - list($token, $thash) = [misc\etc\sanitize($_POST["token"] ?? $_GET["token"]) , misc\etc\sanitize($_POST["thash"] ?? $_GET["thash"])]; - - if (!isset($token)) { - - $response = json_encode(array( - "success" => false, - "message" => "Token Must Be Provided" - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - } - - if (!isset($thash)) { - $response = json_encode(array( - "success" => false, - "message" => "Hash Must Be Provided" - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - } - - $verification = misc\token\checktoken("check_data", $token, $secret, null, $thash); - - switch ($verification) { - case str_contains($verification, 'token_blacklisted'): - $reason = str_ireplace("token_blacklisted, ", "", $verification); - $response = json_encode(array( - "success" => false, - "message" => "The Token Has Been Blacklisted For The Following Reason: " . $reason . " Contact Application Developer If This Is A Mistake" - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - case 'invalid_token': - - $response = json_encode(array( - "success" => false, - "message" => $invalid_token - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - - case 'hash_mismatch': - - $response = json_encode(array( - "success" => false, - "message" => "Token File Hashes Must Be The Same" - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - - case 'success': - break; - - default: - - $response = json_encode(array( - "success" => false, - "message" => "Unknown Error Occured" - )); - - $sig = hash_hmac('sha256', $response, $secret); - header("signature: {$sig}"); - - die($response); - - } - } - $ver = misc\etc\sanitize($_POST['ver'] ?? $_GET['ver']); if (!empty($ver)) { if ($ver != $currentver) { @@ -318,9 +207,9 @@ // $row = misc\cache\fetch('KeyAuthAppStats:' . $secret, "SELECT (SELECT COUNT(1) FROM `users` WHERE `app` = ?) AS 'numUsers', (SELECT COUNT(1) FROM `sessions` WHERE `app` = ? AND `validated` = 1 AND `expiry` > ?) AS 'numOnlineUsers', (SELECT COUNT(1) FROM `keys` WHERE `app` = ?) AS 'numKeys' FROM dual", [$secret, $secret, time(), $secret], 0, 3600); - $numUsers = "N/A - Use fetchStats() function in latest example"; - $numOnlineUsers = "N/A - Use fetchStats() function in latest example"; - $numKeys = "N/A - Use fetchStats() function in latest example"; + $numUsers = "N/A Temporarily Disabled"; + $numOnlineUsers = "N/A Temporarily Disabled"; + $numKeys = "N/A Temporarily Disabled"; $resp = json_encode(array( "success" => true, @@ -333,7 +222,6 @@ "version" => "$currentver", "customerPanelLink" => "https://keyauth.cc/panel/$owner/$name/" ), - "newSession" => $newSession, "nonce" => misc\etc\generateRandomString(32) )); @@ -910,18 +798,10 @@ $emailHashed = $row['email']; if (sha1($email) != $emailHashed) { - if(is_null($emailHashed)) { - $response = json_encode(array( - "success" => false, - "message" => "Email address not provided during register, ask developer to edit your account and change email." - )); - } - else { - $response = json_encode(array( - "success" => false, - "message" => "Email address doesn't match!" - )); - } + $response = json_encode(array( + "success" => false, + "message" => "Email address do not match!" + )); } else { $algos = array( 'ripemd128', @@ -935,28 +815,15 @@ $emailSecret = hash($algos[array_rand($algos)], misc\etc\generateRandomString()); misc\mysql\query("INSERT INTO `resetUsers` (`secret`, `email`, `username`, `app`, `time`) VALUES (?, SHA1(?), ?, ?, ?)", [$emailSecret, $email, $un, $secret, time()]); - - $body = '
-

Hello '.$un.',

-

You recently requested to reset your password for the software '.$name.'. Use the button below to reset it. The link is only valid for the next 24 hours.

- - - - - - -

Thanks, -
The KeyAuth team

-
'; - misc\email\send($un, $email, $body, "KeyAuth - Password Reset for {$name}"); + $htmlContent = " + +

You requested a password reset through the app {$name}

+

Please go to https://keyauth.cc/resetUser/?secret={$emailSecret}

+

Also, in case you forgot, your username is: {$un}

+

Thanks,
KeyAuth.

+ + "; + misc\email\send($un, $email, $htmlContent, "KeyAuth - Password Reset for {$name}"); $response = json_encode(array( "success" => true, "message" => "Successfully sent email to change password.", @@ -993,34 +860,6 @@ $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; header("signature: {$sig}"); - die($response); - case 'fetchStats': - $sessionid = misc\etc\sanitize($_POST['sessionid'] ?? $_GET['sessionid']); - $session = api\shared\primary\getSession($sessionid, $secret); - $enckey = $session["enckey"]; - - $row = misc\cache\fetch('KeyAuthAppStats:' . $secret, "SELECT (SELECT COUNT(1) FROM `users` WHERE `app` = ?) AS 'numUsers', (SELECT COUNT(1) FROM `sessions` WHERE `app` = ? AND `validated` = 1 AND `expiry` > ?) AS 'numOnlineUsers', (SELECT COUNT(1) FROM `keys` WHERE `app` = ?) AS 'numKeys' FROM dual", [$secret, $secret, time(), $secret], 0, 3600); - - $numUsers = $row['numUsers']; - $numOnlineUsers = $row['numOnlineUsers']; - $numKeys = $row['numKeys']; - - $response = json_encode(array( - "success" => true, - "message" => "Successfully fetched stats", - "appinfo" => array( - "numUsers" => "$numUsers", - "numOnlineUsers" => "$numOnlineUsers", - "numKeys" => "$numKeys", - "version" => "$currentver", - "customerPanelLink" => "https://keyauth.cc/panel/$owner/$name/" - ), - "nonce" => misc\etc\generateRandomString(32) - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - die($response); case 'setvar': $sessionid = misc\etc\sanitize($_POST['sessionid'] ?? $_GET['sessionid']); @@ -1380,11 +1219,7 @@ $msg = misc\etc\sanitize($_POST['message'] ?? $_GET['message']); if(is_null($msg)) { - die("No log data specified"); - } - - if(strlen($msg) > 275) { - die("Log data too long"); + die(); } $pcuser = misc\etc\sanitize($_POST['pcuser'] ?? $_GET['pcuser']); @@ -1411,6 +1246,13 @@ $ip = api\shared\primary\getIp(); $json_data = json_encode([ + // Username + "username" => "KeyAuth", + + // Avatar URL. + // Uncoment to replace image set in webhook + "avatar_url" => "https://cdn.keyauth.cc/front/assets/img/favicon.png", + // Embeds Array "embeds" => [ [ @@ -1732,216 +1574,40 @@ header("signature: {$sig}"); die($response); - case 'logout': - $sessionid = misc\etc\sanitize($_POST['sessionid'] ?? $_GET['sessionid']); - $session = api\shared\primary\getSession($sessionid, $secret); - $enckey = $session["enckey"]; - misc\session\killSingular($sessionid, $secret); - $response = json_encode(array( - "success" => true, - "message" => "Successfully logged out.", - "nonce" => misc\etc\generateRandomString(32) - )); - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - case '2faenable': - list($sessionid, $code) = [misc\etc\sanitize($_POST['sessionid'] ?? $_GET['sessionid']), misc\etc\sanitize($_POST["code"] ?? $_GET["code"])]; - $session = api\shared\primary\getSession($sessionid, $secret); - $enckey = $session["enckey"]; - - if (!$session["validated"]) { - $response = json_encode(array( - "success" => false, - "message" => "$sessionunauthed" - )); - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - } - - $row = misc\cache\fetch('KeyAuthUser:' . $secret . ':' . $session["credential"], "SELECT * FROM `users` WHERE `username` = ? AND `app` = ?", [$session["credential"], $secret], 0); - - if ($row["2fa"]) { - - $response = json_encode(array( - "success" => false, - "message" => "2fa is already enabled on this account" - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - - include_once '../../auth/GoogleAuthenticator.php'; - - $_2fa = new GoogleAuthenticator(); - - if (empty($code) || is_null($code)) { - - $secret_code = $_2fa->createSecret(); - - misc\cache\insert('KeyAuthTwoFactorAuthentication:' . $session["credential"], $secret_code, 300); - - $qrcode = str_replace(urlencode("https://chart.googleapis.com/chart?chs=200x200&chld=M|0&cht=qr&chl="), " ", $_2fa->getQRCodeGoogleUrl($session["credential"], $secret_code, 'KeyAuth')); - - $response = json_encode(array( - "success" => true, - "2fa" => array( - "secret_code" => $secret_code, - "QRCode" => "otpauth://totp/" . $session["credential"] . "?secret=" . $secret_code . "&issuer=KeyAuth" - ) - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - else { - - $secret_code = misc\cache\select('KeyAuthTwoFactorAuthentication:' . $session["credential"]); - - if (!$secret_code) { - - $response = json_encode(array( - "success" => true, - "message" => "2fa session has expired" - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - - if ($_2fa->verifyCode($secret_code, $code, 2)) { - - misc\mysql\query("UPDATE `users` SET `2fa` = ?, `googleAuthCode` = ? WHERE `app` = ? AND `username` = ?", [1, $secret_code, $secret, $session["credential"]]); - misc\cache\purge('KeyAuthUser:' . $secret . ':' . $session["credential"]); - misc\cache\purge('KeyAuthTwoFactorAuthentication: ' . $session["credential"]); - - $response = json_encode(array( - "success" => true, - "message" => "2fa successfully activated" - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - else { - - $response = json_encode(array( - "success" => true, - "message" => "Invalid code please try again" - )); + case 'logout': - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - - } - case '2fadisable': - - list($sessionid, $code) = [misc\etc\sanitize($_POST['sessionid'] ?? $_GET['sessionid']), misc\etc\sanitize($_POST["code"] ?? $_GET["code"])]; - - if (empty($code) || is_null($code)) { - - $response = json_encode(array( - "success" => false, - "message" => "Please provide the 2fa code to disable 2fa" - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - + $sessionid = misc\etc\sanitize($_POST['sessionid'] ?? $_GET['sessionid']); $session = api\shared\primary\getSession($sessionid, $secret); $enckey = $session["enckey"]; + $killsession = misc\mysql\query("DELETE FROM `sessions` WHERE `id` = ?", [$sessionid]); - if (!$session["validated"]) { - $response = json_encode(array( - "success" => false, - "message" => "$sessionunauthed" - )); - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - } - - $row = misc\cache\fetch('KeyAuthUser:' . $secret . ':' . $session["credential"], "SELECT * FROM `users` WHERE `username` = ? AND `app` = ?", [$session["credential"], $secret], 0); - - if (!$row["2fa"]) { - - $response = json_encode(array( - "success" => false, - "message" => "2fa is not enabled on this account" - )); - - $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; - header("signature: {$sig}"); - - die($response); - - } - - include_once '../../auth/GoogleAuthenticator.php'; - - $_2fa = new GoogleAuthenticator(); - - $secret_code = $row["googleAuthCode"]; - - if ($_2fa->verifyCode($secret_code, $code, 2)) { - - misc\mysql\query("UPDATE `users` SET `2fa` = ?, `googleAuthCode` = ? WHERE `app` = ? AND `username` = ?", [0, NULL, $secret, $row["username"]]); - misc\cache\purge('KeyAuthUser:' . $secret . ':' . $session["credential"]); + if ($killsession->affected_rows > 0) { $response = json_encode(array( "success" => true, - "message" => "2fa successfully activated" + "message" => "Successfully logged out." )); $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; header("signature: {$sig}"); - + die($response); - } else { - $response = json_encode(array( - "success" => true, - "message" => "Invalid code please try again" + "success" => false, + "message" => "Failed to logout." )); $sig = !is_null($enckey) ? hash_hmac('sha256', $response, $enckey) : 'No encryption key supplied'; header("signature: {$sig}"); - + die($response); - } - - default: - die(json_encode(array( - "success" => false, - "message" => "The value inputted for type paramater was not found" - ))); - } + default: + die(json_encode(array( + "success" => false, + "message" => "The value inputted for type paramater was not found" + ))); +} diff --git a/api/dashboard/webauthn.php b/api/dashboard/webauthn.php index 161e7be..26548a4 100644 --- a/api/dashboard/webauthn.php +++ b/api/dashboard/webauthn.php @@ -37,16 +37,16 @@ try { // read get argument and post body $fn = filter_input(INPUT_GET, 'fn'); - if(empty($fn)) { - die("Can't access directly"); - } + if(empty($fn)) { + die("Can't access directly"); + } $post = trim(file_get_contents('php://input')); - $userId = bin2hex(openssl_random_pseudo_bytes(10)); + $userId = bin2hex(openssl_random_pseudo_bytes(10)); if ($post) { $post = json_decode($post); } - - session_start(); + + session_start(); // Formats $formats = array(); $formats[] = 'none'; @@ -86,13 +86,13 @@ $ids = array(); // load registrations from session stored there by processCreate. - + $query = misc\mysql\query("SELECT * FROM `securityKeys` WHERE `username` = ?", [$_SESSION['pendingUsername']]); - if ($query->num_rows > 0) { - while ($row = mysqli_fetch_array($query->result)) { - $ids[] = base64_decode($row["credentialId"]); - } - } + if ($query->num_rows > 0) { + while ($row = mysqli_fetch_array($query->result)) { + $ids[] = base64_decode($row["credentialId"]); + } + } if (count($ids) === 0) { throw new Exception('No security key registrations found for this user!'); @@ -121,8 +121,8 @@ $data = $WebAuthn->processCreate($clientDataJSON, $attestationObject, $challenge, 0, false, false); unset($_SESSION['challenge']); // disgard challenge array from session file, no longer needed - - $name = misc\etc\sanitize($_GET['name']); + + $name = misc\etc\sanitize($_GET['name']); misc\mysql\query("INSERT INTO `securityKeys` (`username`, `name`, `credentialId`, `credentialPublicKey`) VALUES (?, ?, ?, ?)", [$_SESSION['username'], $name, base64_encode($data->credentialId), $data->credentialPublicKey]); misc\mysql\query("UPDATE `accounts` SET `securityKey` = 1 WHERE `username` = ?", [$_SESSION['username']]); @@ -152,16 +152,16 @@ // looking up correspondending public key of the credential id // you should also validate that only ids of the given user name // are taken for the login. - + $query = misc\mysql\query("SELECT * FROM `securityKeys` WHERE `username` = ?", [$_SESSION['pendingUsername']]); - if ($query->num_rows > 0) { - while ($row = mysqli_fetch_array($query->result)) { - if(base64_decode($row["credentialId"]) === $id) { - $credentialPublicKey = $row["credentialPublicKey"]; + if ($query->num_rows > 0) { + while ($row = mysqli_fetch_array($query->result)) { + if(base64_decode($row["credentialId"]) === $id) { + $credentialPublicKey = $row["credentialPublicKey"]; break; - } - } - } + } + } + } if ($credentialPublicKey === null) { throw new Exception('This security key wasn\'t found!'); @@ -169,10 +169,10 @@ // process the get request. throws WebAuthnException if it fails $WebAuthn->processGet($clientDataJSON, $authenticatorData, $signature, $credentialPublicKey, $challenge, null, 0); - - unset($_SESSION['challenge']); // disgard challenge array from session file, no longer needed - $_SESSION['username'] = $_SESSION['pendingUsername']; - unset($_SESSION['pendingUsername']); + + unset($_SESSION['challenge']); // disgard challenge array from session file, no longer needed + $_SESSION['username'] = $_SESSION['pendingUsername']; + unset($_SESSION['pendingUsername']); $return = new stdClass(); $return->success = true; diff --git a/app/black-fetch.php b/app/black-fetch.php index 16bc522..d163b47 100644 --- a/app/black-fetch.php +++ b/app/black-fetch.php @@ -2,95 +2,67 @@ include '../includes/misc/autoload.phtml'; set_exception_handler(function ($exception) { - error_log("\n--------------------------------------------------------------\n"); - error_log($exception); - error_log("\nRequest data:"); - error_log(print_r($_POST, true)); - error_log("\n--------------------------------------------------------------"); - http_response_code(500); - $errorMsg = str_replace($databaseUsername, "REDACTED", $exception->getMessage()); - die("Error: " . $errorMsg); + error_log("\n--------------------------------------------------------------\n"); + error_log($exception); + error_log("\nRequest data:"); + error_log(print_r($_POST, true)); + error_log("\n--------------------------------------------------------------"); + http_response_code(500); + die("Error: " . $exception->getMessage()); }); if (session_status() === PHP_SESSION_NONE) { - session_start(); + session_start(); } if ($_SESSION['role'] == "Reseller") { - die("Resellers can't access this."); + die("Resellers can't access this."); } if (!isset($_SESSION['app'])) { - die("Application not selected."); + die("Application not selected."); } if (isset($_POST['draw'])) { - // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ + // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ - $draw = intval($_POST['draw']); - $row = intval($_POST['start']); - $rowperpage = intval($_POST['length']); // Rows display per page - $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index - $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name - $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc - $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value + $draw = intval($_POST['draw']); + $row = intval($_POST['start']); + $rowperpage = intval($_POST['length']); // Rows display per page + $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index + $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name + $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc + $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value - // whitelist certain column names and sort orders to prevent SQL injection - if (!in_array($columnName, array("type"))) { - die("Column name is not whitelisted."); - } + // whitelist certain column names and sort orders to prevent SQL injection + if (!in_array($columnName, array("type"))) { + die("Column name is not whitelisted."); + } - if (!in_array($columnSortOrder, array("desc", "asc"))) { - die("Column sort order is not whitelisted."); - } + if (!in_array($columnSortOrder, array("desc", "asc"))) { + die("Column sort order is not whitelisted."); + } - if (!is_null($searchValue)) { - $query = misc\mysql\query("select * from `bans` WHERE (`ip` like ? or `hwid` like ? or `type` like ? ) and app = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app']]); - } - else { - $query = misc\mysql\query("select * from `bans` WHERE app = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, [$_SESSION['app']]); - } - - $data = array(); + ## Fetch records + $query = misc\mysql\query("select * from `bans` WHERE 1 and (`ip` like ? or `hwid` like ? or `type` like ? ) and app = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app']]); + $data = array(); - while ($row = mysqli_fetch_assoc($query->result)) { - $data[] = array( - "data" => '' . ($row["hwid"] ?? $row["ip"]) . '', - "type" => $row["type"], - "actions" => - '
- -
- -
- - - - - -
', - ); - } + while ($row = mysqli_fetch_assoc($query->result)) { + $data[] = array( + "data" => '' . ($row["hwid"] ?? $row["ip"]) . '', + "type" => $row["type"], + "actions" => '
', + ); + } - ## Response - $response = array( - "draw" => intval($draw), - "aaData" => $data - ); + ## Response + $response = array( + "draw" => intval($draw), + "aaData" => $data + ); - die(json_encode($response)); + die(json_encode($response)); } die("Request not from datatables, aborted."); diff --git a/app/download-types.php b/app/download-types.php deleted file mode 100644 index fdb3a75..0000000 --- a/app/download-types.php +++ /dev/null @@ -1,169 +0,0 @@ - array(), - "subscription" => array() - ) - ); - - $jsondata = json_decode($jsonarray); - - $userquery = misc\mysql\query("SELECT * FROM `users` WHERE `app` = ?", [$_SESSION['app']]); - - while ($row = mysqli_fetch_array($userquery->result)) { - - $userjson = array( - "username" => $row["username"], - "email" => $row["email"], - "password" => $row["password"], - "hwid" => $row["hwid"], - "banned" => $row["banned"], - "ip" => $row["ip"] - ); - - array_push($jsondata->users, $userjson); - } - - $subscriptionquery = misc\mysql\query("SELECT * FROM `subs` WHERE `app` = ? ", [$_SESSION['app']]); - - while ($row = mysqli_fetch_array($subscriptionquery->result)) { - - $subjson = array( - "user" => $row["user"], - "subscription" => "default", - "expiry" => $row["expiry"] - ); - - array_push($jsondata->subscription, $subjson); - } - - $newjson = json_encode($jsondata); - - header('Content-Description: File Transfer'); - header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename="KeyAuthUsers.json"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate'); - header('Pragma: public'); - header('Content-Length: ' . strlen($newjson)); - - - die($newjson); - case 'licenses': - $query = misc\mysql\query("SELECT * FROM `keys` WHERE `app` = ?",[$_SESSION['app']]); - - // Create an array to hold the keys - $keysArray = array(); - - while ($row = mysqli_fetch_array($query->result)) { - // Add each key to the array - $keysArray[] = array( - "key" => $row['key'], - "level" => $row['level'], - "expiry" => $row['expires'] / 86400 - ); - } - - // Convert the array to a JSON string - $jsonData = json_encode($keysArray); - - header('Content-Description: File Transfer'); - header('Content-Type: application/json'); // Set the content type to JSON - header('Content-Disposition: attachment; filename="KeyAuthKeys.json"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate'); - header('Pragma: public'); - header('Content-Length: ' . strlen($jsonData)); - - echo $jsonData; - - die($stringData); - case 'logs': - $jsonarray = json_encode( - array( - "logs" => array() - ) - ); - - $jsondata = json_decode($jsonarray); - - $userlogquery = misc\mysql\query("SELECT * FROM `logs` WHERE `logapp` = ?", [$_SESSION['app']]); - - while ($row = mysqli_fetch_array($userlogquery->result)) { - - $userlogjson = array( - "logdate" => $row["logdate"], - "logdata" => $row["logdata"], - "credential" => $row["credential"], - "pcuser" => $row["pcuser"] - ); - - array_push($jsondata->logs, $userlogjson); - } - - - $newjson = json_encode($jsondata); - - header('Content-Description: File Transfer'); - header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename="KeyAuthUserLogs.json"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate'); - header('Pragma: public'); - header('Content-Length: ' . strlen($newjson)); - - - die($newjson); - case 'auditLog': - $jsonarray = json_encode( - array( - "auditLog" => array() - ) - ); - - $jsondata = json_decode($jsonarray); - - $userquery = misc\mysql\query("SELECT * FROM `auditLog` WHERE `app` = ?", [$_SESSION['app']]); - - while ($row = mysqli_fetch_array($userquery->result)) { - - $userjson = array( - "id" => $row["id"], - "user" => $row["user"], - "event" => $row["event"], - "time" => $row["time"], - ); - - array_push($jsondata->auditLog, $userjson); - } - - - $newjson = json_encode($jsondata); - - header('Content-Description: File Transfer'); - header('Content-Type: application/octet-stream'); - header('Content-Disposition: attachment; filename="KeyAuthAuditLogs.json"'); - header('Expires: 0'); - header('Cache-Control: must-revalidate'); - header('Pragma: public'); - header('Content-Length: ' . strlen($newjson)); - - die($newjson); - default: - echo 'Invalid Type or Type does not Exist'; -} diff --git a/app/index.php b/app/index.php index 017960d..6ec68b5 100644 --- a/app/index.php +++ b/app/index.php @@ -16,13 +16,12 @@ set_exception_handler(function ($exception) { error_log("\n--------------------------------------------------------------\n"); - error_log($exception); + error_log($exception); error_log("\nRequest data:"); error_log(print_r($_POST, true)); error_log("\n--------------------------------------------------------------"); - http_response_code(500); - $errorMsg = str_replace($databaseUsername, "REDACTED", $exception->getMessage()); - \dashboard\primary\error($errorMsg); + http_response_code(500); + \dashboard\primary\error($exception->getMessage()); }); $username = $_SESSION['username']; @@ -52,14 +51,13 @@ if (!$_SESSION['app']) // no app selected yet { - $query = misc\mysql\query("SELECT `secret`, `name`, `banned`, `sellerkey` FROM `apps` WHERE `owner` = ? AND `ownerid` = ?",[$_SESSION['username'], $_SESSION['ownerid']]); // select all apps where owner is current user + $query = misc\mysql\query("SELECT * FROM `apps` WHERE `owner` = ? AND `ownerid` = ?",[$_SESSION['username'], $_SESSION['ownerid']]); // select all apps where owner is current user if ($query->num_rows == 1) // if the user only owns one app, load that app (they can still change app after it's loaded) { $row = mysqli_fetch_array($query->result); $_SESSION['name'] = $row["name"]; $_SESSION["selectedApp"] = $row["name"]; $_SESSION['app'] = $row["secret"]; - $_SESSION['sellerkey'] = $row["sellerkey"]; } } ?> @@ -68,88 +66,87 @@ - - - - - - - - - - - - - + + Keyauth - Open Source Auth + + + + + + + + + + + - - - - - - - - - + - -
-
-
- -
-
- - Loading taking a while? Please - feel free to return. - -
- - - -
-
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/layout/_footer.php b/app/layout/_footer.php new file mode 100644 index 0000000..5982213 --- /dev/null +++ b/app/layout/_footer.php @@ -0,0 +1,16 @@ + + + \ No newline at end of file diff --git a/app/layout/_loader.php b/app/layout/_loader.php new file mode 100644 index 0000000..7187055 --- /dev/null +++ b/app/layout/_loader.php @@ -0,0 +1,9 @@ + +
+ Logo +
+ + Loading... +
+
+ \ No newline at end of file diff --git a/app/layout/_scrolltop.php b/app/layout/_scrolltop.php new file mode 100644 index 0000000..a9d0a55 --- /dev/null +++ b/app/layout/_scrolltop.php @@ -0,0 +1,14 @@ + +
+ + + + + + + + +
+ \ No newline at end of file diff --git a/app/layout/aside.php b/app/layout/aside.php deleted file mode 100644 index f78d9d5..0000000 --- a/app/layout/aside.php +++ /dev/null @@ -1,190 +0,0 @@ - - - - -
diff --git a/app/layout/aside/_base.php b/app/layout/aside/_base.php new file mode 100644 index 0000000..e32e62e --- /dev/null +++ b/app/layout/aside/_base.php @@ -0,0 +1,53 @@ + + + +
+ + + + + +
+ + + + + +
+ + +
+ \ No newline at end of file diff --git a/app/layout/aside/_menu.php b/app/layout/aside/_menu.php new file mode 100644 index 0000000..12c0ae4 --- /dev/null +++ b/app/layout/aside/_menu.php @@ -0,0 +1,398 @@ + + + + + + + + + + + + +
+ + + + +
+ + + + \ No newline at end of file diff --git a/app/layout/aside/resellermenu.php b/app/layout/aside/resellermenu.php new file mode 100644 index 0000000..2ce2507 --- /dev/null +++ b/app/layout/aside/resellermenu.php @@ -0,0 +1,72 @@ + + + + + + + + + + + + +
+ + + + +
+ + + + \ No newline at end of file diff --git a/app/layout/breadcrumb.php b/app/layout/breadcrumb.php deleted file mode 100644 index 924b92f..0000000 --- a/app/layout/breadcrumb.php +++ /dev/null @@ -1,22 +0,0 @@ - diff --git a/app/layout/footer.php b/app/layout/footer.php deleted file mode 100644 index 0d0603f..0000000 --- a/app/layout/footer.php +++ /dev/null @@ -1,17 +0,0 @@ - diff --git a/app/layout/header/_base.php b/app/layout/header/_base.php new file mode 100644 index 0000000..8ba6ae1 --- /dev/null +++ b/app/layout/header/_base.php @@ -0,0 +1,52 @@ + +
+ +
+ +
+
+ + + + + + + + +
+
+ + +
+ + Logo + +
+ + +
+ +
+ + + +
+ + +
+ + + +
+ +
+ +
+ +
+ \ No newline at end of file diff --git a/app/layout/header/_menu.php b/app/layout/header/_menu.php new file mode 100644 index 0000000..0cac633 --- /dev/null +++ b/app/layout/header/_menu.php @@ -0,0 +1,31 @@ + + +
+ + + +
+ \ No newline at end of file diff --git a/app/layout/master.php b/app/layout/master.php index 7abcf05..8544bb2 100644 --- a/app/layout/master.php +++ b/app/layout/master.php @@ -1,39 +1,45 @@ - - -
- - - - - - -
-
- - -
- - + + + +
+ +
+ + + + +
+ + + + +
+ + + + +
+ + + +
+ +
+ + + + +
+
+
+ + + \ No newline at end of file diff --git a/app/layout/page-title/_default.php b/app/layout/page-title/_default.php new file mode 100644 index 0000000..3a32f72 --- /dev/null +++ b/app/layout/page-title/_default.php @@ -0,0 +1,13 @@ + + +
+ +

+ + +

+ +
+ \ No newline at end of file diff --git a/app/layout/profile.php b/app/layout/profile.php deleted file mode 100644 index c03531d..0000000 --- a/app/layout/profile.php +++ /dev/null @@ -1,92 +0,0 @@ -num_rows > 0) { - while ($row_ = mysqli_fetch_array($query->result)) { - $acclogs = $row_['acclogs']; - $expiry = $row_["expires"]; - $emailVerify = $row_["emailVerify"]; - } -} - -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - if (isset($_POST['logout'])) { - session_destroy(); - header('Location: /login'); - exit; - } -} - -?> - -
-
- - -
- -
-
-
- " alt="profile image" /> - -
- -
- - - " . strtoupper($role) . " PLAN

"; - ?> - - '', - 'developer' => '', - 'seller' => '', - 'Reseller' => '', - 'Manager' => '', - 'default' => '' - }; - echo $display; - - if ($role === 'developer' || $role === 'seller') { - echo ''; - } - ?> -
-
-
diff --git a/app/layout/toolbars/_toolbar-1.php b/app/layout/toolbars/_toolbar-1.php new file mode 100644 index 0000000..651d46b --- /dev/null +++ b/app/layout/toolbars/_toolbar-1.php @@ -0,0 +1,11 @@ + +
+ +
+ + + + +
+ +
\ No newline at end of file diff --git a/app/layout/topbar.php b/app/layout/topbar.php deleted file mode 100644 index 978bce8..0000000 --- a/app/layout/topbar.php +++ /dev/null @@ -1,133 +0,0 @@ - - - diff --git a/app/layout/topbar/_base.php b/app/layout/topbar/_base.php new file mode 100644 index 0000000..a3ff659 --- /dev/null +++ b/app/layout/topbar/_base.php @@ -0,0 +1,49 @@ + +
+ +
+

+
+ +
+ + +
+ + + + + + + + +
+
+ + + + + + + + +
+
+ +
+ \ No newline at end of file diff --git a/app/layout/topbar/partials/_user-menu.php b/app/layout/topbar/partials/_user-menu.php new file mode 100644 index 0000000..4d8b78a --- /dev/null +++ b/app/layout/topbar/partials/_user-menu.php @@ -0,0 +1,43 @@ + + + \ No newline at end of file diff --git a/app/license-download.php b/app/license-download.php new file mode 100644 index 0000000..bfa32b3 --- /dev/null +++ b/app/license-download.php @@ -0,0 +1,48 @@ +result)) + + + + $stringData .= "" . $row['key'] . "\n"; + + + +$stringData = preg_replace( + + '~[\r\n]+~', + + "\r\n", + + trim($stringData) + +); + + + +header('Content-Description: File Transfer'); +header('Content-Type: application/octet-stream'); +header('Content-Disposition: attachment; filename="KeyAuthKeys.txt"'); +header('Expires: 0'); +header('Cache-Control: must-revalidate'); +header('Pragma: public'); +header('Content-Length: ' . strlen($stringData)); + + +die($stringData); \ No newline at end of file diff --git a/app/license-fetch.php b/app/license-fetch.php index 89793b6..83c8801 100644 --- a/app/license-fetch.php +++ b/app/license-fetch.php @@ -1,131 +1,90 @@ getMessage()); + error_log("\n--------------------------------------------------------------\n"); + error_log($exception); + error_log("\nRequest data:"); + error_log(print_r($_POST, true)); + error_log("\n--------------------------------------------------------------"); + http_response_code(500); + die("Error: " . $exception->getMessage()); }); if (session_status() === PHP_SESSION_NONE) { - session_start(); + session_start(); } if ($_SESSION['role'] == "Reseller") { - die("Resellers can't access this."); + die("Resellers can't access this."); } if (!isset($_SESSION['app'])) { - dashboard\primary\error("Application not selected"); - die("Application not selected."); + die("Application not selected."); } if (isset($_POST['draw'])) { - // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ - - $draw = intval($_POST['draw']); - $row = intval($_POST['start']); - $rowperpage = intval($_POST['length']); // Rows display per page - $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index - $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name - $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc - $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value - - // whitelist certain column names and sort orders to prevent SQL injection - if (!in_array($columnName, array("key", "gendate", "genby", "expires", "note", "usedon", "usedby", "status"))) { - die("Column name is not whitelisted."); - } - - if (!in_array($columnSortOrder, array("desc", "asc"))) { - die("Column sort order is not whitelisted."); - } - - if (!is_null($searchValue)) { - $query = misc\mysql\query("select * from `keys` WHERE (`key` like ? or `note` like ? or `genby` like ? or `usedby` like ? ) and app = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app']]); - } - else { - $query = misc\mysql\query("select * from `keys` WHERE app = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, [$_SESSION['app']]); - } - - $data = array(); - - while ($row = mysqli_fetch_assoc($query->result)) { - - ## If only one or two keys exists then we will use custom margin to fix the bugging menu - $banBtns = ""; - if ($row['status'] == "Banned") { - $banBtns = ''; - } else { - $banBtns = ''; - } - - $MarginManager = ""; - if ($query->num_rows < 2) { - $MarginManager = "margin-bottom: 20px;"; - } else { - $MarginManager = "margin-bottom: 0px;"; - } - - $data[] = array( - "key" => $row['key'], - "gendate" => '
', - "genby" => $row['genby'], - "expires" => timeconversion($row["expires"]), - "note" => $row['note'] ?? 'N/A', - "usedon" => (!is_null($row["usedon"])) ? '
' : 'N/A', - "usedby" => ($row["usedby"] == $row['key']) ? 'Same as key' : $row["usedby"] ?? 'N/A', - "status" => '' . $row['status'] . '', - - "actions" => ' -
- -
- -
    -
  • - -
  • -
  • - ' . $banBtns . ' -
  • -
  • - -
  • -
-
- - -
- ', - ); - } - - ## Response - $response = array( - "draw" => intval($draw), - "aaData" => $data - ); - - die(json_encode($response)); + // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ + + $draw = intval($_POST['draw']); + $row = intval($_POST['start']); + $rowperpage = intval($_POST['length']); // Rows display per page + $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index + $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name + $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc + $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value + + // whitelist certain column names and sort orders to prevent SQL injection + if (!in_array($columnName, array("key", "gendate", "genby", "expires", "note", "usedon", "usedby", "status"))) { + die("Column name is not whitelisted."); + } + + if (!in_array($columnSortOrder, array("desc", "asc"))) { + die("Column sort order is not whitelisted."); + } + + ## Fetch records + $query = misc\mysql\query("select * from `keys` WHERE 1 and (`key` like ? or `note` like ? or `genby` like ? or `usedby` like ? ) and app = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app']]); + $data = array(); + + while ($row = mysqli_fetch_assoc($query->result)) { + + ## If only one or two keys exists then we will use custom margin to fix the bugging menu + $banBtns = ""; + if ($row['status'] == "Banned") { + $banBtns = ''; + } else { + $banBtns = 'Ban'; + } + + $MarginManager = ""; + if ($totalRecordwithFilter < 2) { + $MarginManager = "margin-bottom: 20px;"; + } else { + $MarginManager = "margin-bottom: 0px;"; + } + + $data[] = array( + "key" => $row['key'], + "gendate" => '
', + "genby" => $row['genby'], + "expires" => ($row["expires"] / 86400) . ' Day(s)', + "note" => $row['note'] ?? 'N/A', + "usedon" => (!is_null($row["usedon"])) ? '
' : 'N/A', + "usedby" => ($row["usedby"] == $row['key']) ? 'Same as key' : $row["usedby"] ?? 'N/A', + "status" => '', + "actions" => '
', + ); + } + + ## Response + $response = array( + "draw" => intval($draw), + "aaData" => $data + ); + + die(json_encode($response)); } die("Request not from datatables, aborted."); diff --git a/app/log-fetch.php b/app/log-fetch.php index f89fc05..2e88524 100644 --- a/app/log-fetch.php +++ b/app/log-fetch.php @@ -2,74 +2,68 @@ include '../includes/misc/autoload.phtml'; set_exception_handler(function ($exception) { - error_log("\n--------------------------------------------------------------\n"); - error_log($exception); - error_log("\nRequest data:"); - error_log(print_r($_POST, true)); - error_log("\n--------------------------------------------------------------"); - http_response_code(500); - die("Error: " . $exception->getMessage()); + error_log("\n--------------------------------------------------------------\n"); + error_log($exception); + error_log("\nRequest data:"); + error_log(print_r($_POST, true)); + error_log("\n--------------------------------------------------------------"); + http_response_code(500); + die("Error: " . $exception->getMessage()); }); if (session_status() === PHP_SESSION_NONE) { - session_start(); + session_start(); } if ($_SESSION['role'] == "Reseller") { - die("Resellers can't access this."); + die("Resellers can't access this."); } if (!isset($_SESSION['app'])) { - dashboard\primary\error("Application not selected"); - die("Application not selected."); + die("Application not selected."); } if (isset($_POST['draw'])) { - // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ + // credits to https://makitweb.com/datatables-ajax-pagination-with-search-and-sort-php/ - $draw = intval($_POST['draw']); - $row = intval($_POST['start']); - $rowperpage = intval($_POST['length']); // Rows display per page - $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index - $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name - $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc - $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value + $draw = intval($_POST['draw']); + $row = intval($_POST['start']); + $rowperpage = intval($_POST['length']); // Rows display per page + $columnIndex = misc\etc\sanitize($_POST['order'][0]['column']); // Column index + $columnName = misc\etc\sanitize($_POST['columns'][$columnIndex]['data']); // Column name + $columnSortOrder = misc\etc\sanitize($_POST['order'][0]['dir']); // asc or desc + $searchValue = misc\etc\sanitize($_POST['search']['value']); // Search value - // whitelist certain column names and sort orders to prevent SQL injection - if (!in_array($columnName, array("logdate", "logdata", "credential", "pcuser"))) { - die("Column name is not whitelisted."); - } + // whitelist certain column names and sort orders to prevent SQL injection + if (!in_array($columnName, array("logdate", "logdata", "credential", "pcuser"))) { + die("Column name is not whitelisted."); + } - if (!in_array($columnSortOrder, array("desc", "asc"))) { - die("Column sort order is not whitelisted."); - } + if (!in_array($columnSortOrder, array("desc", "asc"))) { + die("Column sort order is not whitelisted."); + } - if (!is_null($searchValue)) { - $query = misc\mysql\query("select * from `logs` WHERE (`logdata` like ? or `credential` like ? or `pcuser` like ? ) and logapp = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app']]); - } - else { - $query = misc\mysql\query("select * from `logs` WHERE logapp = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, [$_SESSION['app']]); - } - - $data = array(); + ## Fetch records + $query = misc\mysql\query("select * from `logs` WHERE 1 and (`logdata` like ? or `credential` like ? or `pcuser` like ? ) and logapp = ? order by `" . $columnName . "` " . $columnSortOrder . " limit " . $row . "," . $rowperpage, ["%" . $searchValue . "%", "%" . $searchValue . "%", "%" . $searchValue . "%", $_SESSION['app']]); + $data = array(); - while ($row = mysqli_fetch_assoc($query->result)) { - $data[] = array( - "logdate" => '
', - "logdata" => $row['logdata'], - "credential" => $row['credential'] ?? 'N/A', - "pcuser" => $row['pcuser'] ?? 'N/A', - ); - } + while ($row = mysqli_fetch_assoc($query->result)) { + $data[] = array( + "logdate" => '
', + "logdata" => $row['logdata'], + "credential" => $row['credential'] ?? 'N/A', + "pcuser" => $row['pcuser'] ?? 'N/A', + ); + } - ## Response - $response = array( - "draw" => intval($draw), - "aaData" => $data - ); + ## Response + $response = array( + "draw" => intval($draw), + "aaData" => $data + ); - die(json_encode($response)); + die(json_encode($response)); } die("Request not from datatables, aborted."); diff --git a/app/pages/account-logs.php b/app/pages/account-logs.php index 2f9dde5..7f11168 100644 --- a/app/pages/account-logs.php +++ b/app/pages/account-logs.php @@ -1,53 +1,45 @@ - -
-
-
- -

Account Logs

-

View the event history of your account.

-
-
- -
- - - - - - - - - - result)) - { - $rows[] = $r; - } + +
+ - foreach ($rows as $row) - { - ?> -
- +
DateIPUser-Agent
- -
+ + + + + + + - - - - - -
DateIP AddressUser Agent
+ + result)) + { + $rows[] = $r; + } + + foreach ($rows as $row) + { + ?> + + + + + + + + + + + + + +
+ \ No newline at end of file diff --git a/app/pages/account-settings.php b/app/pages/account-settings.php index 3c0f7ec..361cfd6 100644 --- a/app/pages/account-settings.php +++ b/app/pages/account-settings.php @@ -1,8 +1,7 @@ that's the only thing you need on this page."); } $twofactor = $row['twofactor']; @@ -20,20 +19,29 @@ } $google_QR_Code = $gauth->getQRCodeGoogleUrl($_SESSION['username'], $code_2factor, 'KeyAuth'); +?> -$query = misc\mysql\query("SELECT * FROM `accounts` WHERE `username` = ?", [$_SESSION['username']]); + +
+ + + + + num_rows > 0) -{ - while ($row = mysqli_fetch_array($query->result)) + $query = misc\mysql\query("SELECT * FROM `accounts` WHERE `username` = ?", [$_SESSION['username']]); + + if ($query->num_rows > 0) { - $acclogs = $row['acclogs']; - $expiry = $row["expires"]; - $emailVerify = $row["emailVerify"]; + while ($row = mysqli_fetch_array($query->result)) + { + $acclogs = $row['acclogs']; + $expiry = $row["expires"]; + $emailVerify = $row["emailVerify"]; + } } -} -if (isset($_POST['updatesettings'])) + if (isset($_POST['updatesettings'])) { $pfp = misc\etc\sanitize($_POST['pfp']); $acclogs = misc\etc\sanitize($_POST['acclogs']); @@ -67,7 +75,12 @@ if (isset($_POST['submit_code'])) { - $code = misc\etc\sanitize($_POST['scan_code1'] . ($_POST['scan_code2']) . ($_POST['scan_code3']) . ($_POST['scan_code4']) . ($_POST['scan_code5']) . ($_POST['scan_code6'])); + if (empty($_POST['scan_code'])) + { + dashboard\primary\error("You forgot to enter 2FA code!"); + } + + $code = misc\etc\sanitize($_POST['scan_code']); $query = misc\mysql\query("SELECT `googleAuthCode` from `accounts` WHERE `username` = ?", [$_SESSION['username']]); @@ -102,7 +115,12 @@ if (isset($_POST['submit_code_disable'])) { - $code = misc\etc\sanitize($_POST['scan_code1'] . ($_POST['scan_code2']) . ($_POST['scan_code2']) . ($_POST['scan_code3']) . ($_POST['scan_code4']) . ($_POST['scan_code5'])); + if (empty($_POST['scan_code'])) + { + dashboard\primary\error("You forgot to enter 2FA code!"); + } + + $code = misc\etc\sanitize($_POST['scan_code']); $query = misc\mysql\query("SELECT `googleAuthCode` from `accounts` WHERE `username` = ?", [$_SESSION['username']]); @@ -152,343 +170,331 @@ dashboard\primary\error("Failed to delete security key!"); } } + ?> + +
+
+
+
+
+
+ +
+ +
+
-?> +
+ +
+ +
+ +
+
-
-
-
- -

Account Settings

-

Manage your account.

-
-
-
-
- -
-
- -
+
+ +
-
- -
-
- - -
+
- -
- " - readonly> - +
+ +
+
Change password here + https://' . ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME']) . '/forgot/'; ?> +
+
- - -
- Free Forever " - autocomplete="on" readonly> - - - - + +
+ +
+ +
+ +
- - -
- - +
+ +
+ +
+
Change email here + https://' . ($_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME']) . '/changeEmail/'; ?> +
+
- - - - Enable 2FA'; - } else { - echo 'Disable 2FA'; - } - ?> +
- - - - Change Password - - - Change Email - - - Change Username - - - Delete Account - - - - - - -