diff --git a/README.md b/README.md index 9f6bf19..1059003 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ To integrate Jakach Login into your application: 4. **Add login button:** In your app/login page add a button like: ```html - Log in using Jakach login + Log in using Jakach login ``` --- diff --git a/app-code/account/index.php b/app-code/account/index.php index 5e3dc2a..2abd82d 100644 --- a/app-code/account/index.php +++ b/app-code/account/index.php @@ -54,6 +54,13 @@ if (!isset($_SESSION["logged_in"]) || $_SESSION["logged_in"] !== true) { + + people + '); + } + ?> @@ -96,6 +103,7 @@ if (!isset($_SESSION["logged_in"]) || $_SESSION["logged_in"] !== true) { + Delete all "remember me" sessions @@ -566,7 +574,9 @@ if (!isset($_SESSION["logged_in"]) || $_SESSION["logged_in"] !== true) { location.href = location.href.replace('http', 'https'); } } - + function delete_all_logmein(){ + fetch("/api/login/delete_keepmeloggedin.php"); + } diff --git a/app-code/api/login/delete_keepmeloggedin.php b/app-code/api/login/delete_keepmeloggedin.php new file mode 100644 index 0000000..800a08d --- /dev/null +++ b/app-code/api/login/delete_keepmeloggedin.php @@ -0,0 +1,15 @@ + diff --git a/app-code/api/login/keepmeloggedin.php b/app-code/api/login/keepmeloggedin.php new file mode 100644 index 0000000..c014627 --- /dev/null +++ b/app-code/api/login/keepmeloggedin.php @@ -0,0 +1,36 @@ + 'success' + ]; + echo(json_encode($data)); + +}else{ + $_SESSION["keepmeloggedin_asked"]=true; + $data = [ + 'status' => 'success' + ]; + echo(json_encode($data)); +} + + +?> diff --git a/app-code/api/login/redirect.php b/app-code/api/login/redirect.php index 29e536c..20f1e99 100644 --- a/app-code/api/login/redirect.php +++ b/app-code/api/login/redirect.php @@ -2,31 +2,7 @@ session_start(); header('Content-Type: application/json'); - -function get_location_from_ip($ip) { - // Use ip-api.com to fetch geolocation data - $url = "http://ip-api.com/json/$ip"; - - // Initialize curl - $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, $url); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - - // Execute curl and decode the JSON response - $response = curl_exec($ch); - curl_close($ch); - - // Convert JSON response to PHP array - $data = json_decode($response, true); - - // Check for a successful response - if ($data && $data['status'] === 'success') { - return $data; // Return the geolocation data - } - - return null; // Return null if API call fails -} - +include "../utils/get_location.php"; $send_to=$_SESSION["end_url"]; @@ -57,7 +33,16 @@ else if($_SESSION["needs_auth"]===false && $_SESSION["mfa_required"]==1 && $_SES 'redirect' => '/login/passkey.php' ]; echo(json_encode($data)); -}*/else if ($_SESSION["needs_auth"]===false && $_SESSION["mfa_authenticated"]==1 && $_SESSION["pw_authenticated"]==1){ +}*/ +else if ($_SESSION["needs_auth"]===false && $_SESSION["mfa_authenticated"]==1 && $_SESSION["pw_authenticated"]==1 && $_SESSION["keepmeloggedin_asked"]==false){ + //send to keepmelogged in question + $data=[ + 'message' => 'ask_keepmeloggedin', + 'redirect' => '/login/keepmeloggedin.php' + ]; + echo(json_encode($data)); +} +else if ($_SESSION["needs_auth"]===false && $_SESSION["mfa_authenticated"]==1 && $_SESSION["pw_authenticated"]==1){ //fully authenticated //create auth token which other services can then use to check if user logged in $user_id=$_SESSION["id"]; @@ -133,7 +118,7 @@ else{ $username=$_SESSION["username"]; $_SESSION["needs_auth"]=false; $_SESSION["logged_in"]=false; - $sql="SELECT auth_method_required_pw, auth_method_required_2fa, auth_method_required_passkey, id, user_token,last_login, login_message,telegram_id FROM users WHERE username = ?"; + $sql="SELECT auth_method_required_pw, auth_method_required_2fa, auth_method_required_passkey, id, user_token,last_login, login_message,telegram_id, permissions FROM users WHERE username = ?"; $stmt = mysqli_prepare($conn, $sql); mysqli_stmt_bind_param($stmt, 's', $username); mysqli_stmt_execute($stmt); @@ -145,8 +130,9 @@ else{ $last_login=""; $login_message=0; $telegram_id=""; + $permissions=""; if(mysqli_stmt_num_rows($stmt) == 1){ - mysqli_stmt_bind_result($stmt, $pw,$mfa,$passkey,$user_id,$user_token,$last_login,$login_message,$telegram_id); + mysqli_stmt_bind_result($stmt, $pw,$mfa,$passkey,$user_id,$user_token,$last_login,$login_message,$telegram_id,$permissions); mysqli_stmt_fetch($stmt); $_SESSION["pw_required"] = $pw; $_SESSION["pw_authenticated"] = ($pw == 0) ? 1 : 0; // If $pw is 0, set pw_authenticated to 1 @@ -159,6 +145,8 @@ else{ $_SESSION["last_login"]=$last_login; $_SESSION["telegram_id"]=$telegram_id; $_SESSION["login_message"]=$login_message; + $_SESSION["permissions"]=$permissions; + $_SESSION["keepmeloggedin_asked"]=false; $data=[ 'message' => 'prepared_start_auth', 'redirect' => '/login/' diff --git a/app-code/api/login/reset_pw.php b/app-code/api/login/reset_pw.php index 3981fcd..be1ba6b 100644 --- a/app-code/api/login/reset_pw.php +++ b/app-code/api/login/reset_pw.php @@ -53,7 +53,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { } }else { mysqli_stmt_close($stmt); - echo json_encode(['success' => false, 'message' => 'Ivalid auth token']); + echo json_encode(['success' => false, 'message' => 'Invalid auth token']); } //remove token $sql="DELETE FROM reset_tokens WHERE auth_token = ?;"; diff --git a/app-code/api/login/send_reset_link.php b/app-code/api/login/send_reset_link.php index 0821ae5..d543fdf 100644 --- a/app-code/api/login/send_reset_link.php +++ b/app-code/api/login/send_reset_link.php @@ -2,6 +2,7 @@ session_start(); header('Content-Type: application/json'); include "../../config/config.php"; +include "../utils/get_location.php"; $username=$_SESSION["username"]; $sql="SELECT id, email, telegram_id FROM users WHERE username = ?;"; $conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE); @@ -18,9 +19,10 @@ mysqli_stmt_close($stmt); //send telegram message $device = $_SERVER['HTTP_USER_AGENT']; $ip=$_SERVER["REMOTE_ADDR"]; +$location=get_location_from_ip($ip); $date=date('Y-m-d H:i:s'); $token=bin2hex(random_bytes(128)); -$link="https://jakach.duckdns.org:444/login/reset_pw.php?token=$token"; +$link="https://jakach-auth.duckdns.org:444/login/reset_pw.php?token=$token"; $message = "*Password reset token*\n\n" . "You have requested the reset of your password here is your reset link.\n\n" @@ -28,6 +30,7 @@ $message = "*Password reset token*\n\n" . "*Details of this request:*\n" . "• *Date&Time*: $date\n" . "• *Device&Browser*: $device\n" + . "*Location*: ".$location["country"].", ".$location["state"].", ".$location["city"]."\n" . "• *Account*: ".$_SESSION["username"]."\n" . "• *IP*: $ip\n\n" ."If this was you, you can reset your password. If this was not you somebody else tried to reset your password!\n" @@ -54,6 +57,7 @@ curl_exec($ch); curl_close($ch); //send mail if(!empty($mail)){ + $loc=$location["country"].", ".$location["state"].", ".$location["city"]; $content = " @@ -125,6 +129,7 @@ if(!empty($mail)){
  • Device & Browser: $device
  • Account: $mail
  • IP Address: $ip
  • +
  • Location: $loc
  • If this was you, you can reset your password. If this was not you, someone else may have tried to reset your password.

    @@ -182,7 +187,7 @@ if(!empty($mail)){ //insert the token into our db -$valid_until=time()+8600; +$valid_until=time()+(8600/2); $sql="INSERT INTO reset_tokens (auth_token, user_id,valid_until) VALUES (?,?,?);"; $stmt = mysqli_prepare($conn, $sql); mysqli_stmt_bind_param($stmt, 'sii', $token,$id,$valid_until); diff --git a/app-code/api/utils/check_keepmeloggedin.php b/app-code/api/utils/check_keepmeloggedin.php new file mode 100644 index 0000000..8e60d54 --- /dev/null +++ b/app-code/api/utils/check_keepmeloggedin.php @@ -0,0 +1,65 @@ + diff --git a/app-code/api/utils/get_location.php b/app-code/api/utils/get_location.php new file mode 100644 index 0000000..a14b824 --- /dev/null +++ b/app-code/api/utils/get_location.php @@ -0,0 +1,27 @@ + diff --git a/app-code/index.php b/app-code/index.php index 519399c..522c3cd 100644 --- a/app-code/index.php +++ b/app-code/index.php @@ -8,12 +8,20 @@ Jakach Login @@ -41,6 +49,8 @@ Account Erstellen +
    + @@ -77,7 +87,7 @@ // Get the username input value const usernameInput = document.getElementById('username'); const username = usernameInput.value; - + // Check if username is empty (just in case) if (!username) { alert('Please enter a username.'); diff --git a/app-code/install/create_db.php b/app-code/install/create_db.php index 18a91b2..2e38536 100644 --- a/app-code/install/create_db.php +++ b/app-code/install/create_db.php @@ -74,7 +74,6 @@ permissions VARCHAR(255), color_profile INT, auth_key VARCHAR(255), - keepmeloggedin_token VARCHAR(255), auth_method_keepmeloggedin_enabled INT, auth_method_enabled_2fa INT, auth_method_enabled_pw INT, @@ -135,6 +134,25 @@ '; } + $sql="CREATE TABLE IF NOT EXISTS keepmeloggedin ( + id INT AUTO_INCREMENT PRIMARY KEY, + auth_token VARCHAR(256), + user_id INT, + agent VARCHAR(255) + );"; + + + if ($conn->query($sql) === TRUE) { + echo '
    '; + } else { + $success=0; + echo '
    '; + } + if($success!==1){ diff --git a/app-code/jakach_logo.ico b/app-code/jakach_logo.ico new file mode 100644 index 0000000..9bad3de Binary files /dev/null and b/app-code/jakach_logo.ico differ diff --git a/app-code/login/keepmeloggedin.php b/app-code/login/keepmeloggedin.php new file mode 100644 index 0000000..3d8bbbd --- /dev/null +++ b/app-code/login/keepmeloggedin.php @@ -0,0 +1,69 @@ + + + + + + Jakach Login + + + +
    +
    +
    + +
    +
    +

    Jakach Login

    + +
    + + +
    +
    +
    +
    +
    +
    + + + + + + diff --git a/app-code/login/logout.php b/app-code/login/logout.php index 361dbd3..a3efd04 100644 --- a/app-code/login/logout.php +++ b/app-code/login/logout.php @@ -2,5 +2,6 @@ session_start(); session_unset(); session_destroy(); + setcookie("auth_token", "", time() - 3600, "/"); header("LOCATION:/"); ?> diff --git a/app-code/login/passkey.php b/app-code/login/passkey.php index 53addcc..d49c7ad 100644 --- a/app-code/login/passkey.php +++ b/app-code/login/passkey.php @@ -22,7 +22,9 @@
    - +
    @@ -58,6 +60,15 @@ function showErrorModal(message) { errorModal.show(); } async function checkRegistration() { + const button = document.getElementById("loginButton"); + const buttonText = document.getElementById("buttonText"); + + // Disable the button to prevent multiple clicks + button.disabled = true; + + // Change the button text and add a loading spinner + buttonText.innerHTML = 'Loading...'; + button.innerHTML += '
    Loading...
    '; try { if (!window.fetch || !navigator.credentials || !navigator.credentials.create) { diff --git a/app-code/plugins/auth.php b/app-code/plugins/auth.php index b44f0cf..0f2e739 100644 --- a/app-code/plugins/auth.php +++ b/app-code/plugins/auth.php @@ -6,7 +6,7 @@ This file can be installed in any service. If done so a user can authenticate wi $auth_token = $_GET["auth"]; // Check the auth token against Jakach login API -$check_url = "https://jakach.duckdns.org:444/api/auth/check_auth_key.php?auth_token=" . $auth_token; +$check_url = "https://jakach-auth.duckdns.org:444/api/auth/check_auth_key.php?auth_token=" . $auth_token; // Initialize cURL $ch = curl_init();