|
8 | 8 |
|
9 | 9 | require_once "config.php"; |
10 | 10 | require_once "functions.php"; |
11 | | -require_once "check_login.php"; |
| 11 | +require_once "includes/check_login.php"; |
12 | 12 | require_once "plugins/totp/totp.php"; |
13 | 13 |
|
14 | 14 | /* |
|
165 | 165 | } |
166 | 166 |
|
167 | 167 | /* |
168 | | - * Generates public/guest links for sharing logins/docs |
| 168 | + * Generates public/guest links for sharing credentials/docs |
169 | 169 | */ |
170 | 170 | if (isset($_GET['share_generate_link'])) { |
171 | 171 | enforceUserPermission('module_support', 2); |
|
207 | 207 | $item_name = sanitizeInput($row['file_name']); |
208 | 208 | } |
209 | 209 |
|
210 | | - if ($item_type == "Login") { |
211 | | - $login = mysqli_query($mysqli, "SELECT login_name, login_username, login_password FROM logins WHERE login_id = $item_id AND login_client_id = $client_id LIMIT 1"); |
212 | | - $row = mysqli_fetch_array($login); |
| 210 | + if ($item_type == "Credential") { |
| 211 | + $credential = mysqli_query($mysqli, "SELECT credential_name, credential_username, credential_password FROM credentials WHERE credential_id = $item_id AND credential_client_id = $client_id LIMIT 1"); |
| 212 | + $row = mysqli_fetch_array($credential); |
213 | 213 |
|
214 | | - $item_name = sanitizeInput($row['login_name']); |
| 214 | + $item_name = sanitizeInput($row['credential_name']); |
215 | 215 |
|
216 | 216 | // Decrypt & re-encrypt username/password for sharing |
217 | | - $login_encryption_key = randomString(); |
| 217 | + $credential_encryption_key = randomString(); |
218 | 218 |
|
219 | | - $login_username_cleartext = decryptLoginEntry($row['login_username']); |
| 219 | + $credential_username_cleartext = decryptCredentialEntry($row['credential_username']); |
220 | 220 | $iv = randomString(); |
221 | | - $username_ciphertext = openssl_encrypt($login_username_cleartext, 'aes-128-cbc', $login_encryption_key, 0, $iv); |
| 221 | + $username_ciphertext = openssl_encrypt($credential_username_cleartext, 'aes-128-cbc', $credential_encryption_key, 0, $iv); |
222 | 222 | $item_encrypted_username = $iv . $username_ciphertext; |
223 | 223 |
|
224 | | - $login_password_cleartext = decryptLoginEntry($row['login_password']); |
| 224 | + $credential_password_cleartext = decryptCredentialEntry($row['credential_password']); |
225 | 225 | $iv = randomString(); |
226 | | - $password_ciphertext = openssl_encrypt($login_password_cleartext, 'aes-128-cbc', $login_encryption_key, 0, $iv); |
| 226 | + $password_ciphertext = openssl_encrypt($credential_password_cleartext, 'aes-128-cbc', $credential_encryption_key, 0, $iv); |
227 | 227 | $item_encrypted_credential = $iv . $password_ciphertext; |
228 | 228 | } |
229 | 229 |
|
|
232 | 232 | $share_id = $mysqli->insert_id; |
233 | 233 |
|
234 | 234 | // Return URL |
235 | | - if ($item_type == "Login") { |
236 | | - $url = "https://$config_base_url/guest/guest_view_item.php?id=$share_id&key=$item_key&ek=$login_encryption_key"; |
| 235 | + if ($item_type == "Credential") { |
| 236 | + $url = "https://$config_base_url/guest/guest_view_item.php?id=$share_id&key=$item_key&ek=$credential_encryption_key"; |
237 | 237 | } |
238 | 238 | else { |
239 | 239 | $url = "https://$config_base_url/guest/guest_view_item.php?id=$share_id&key=$item_key"; |
|
333 | 333 | if (isset($_GET['get_totp_token_via_id'])) { |
334 | 334 | enforceUserPermission('module_credential'); |
335 | 335 |
|
336 | | - $login_id = intval($_GET['login_id']); |
| 336 | + $credential_id = intval($_GET['credential_id']); |
337 | 337 |
|
338 | | - $sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT login_name, login_otp_secret, login_client_id FROM logins WHERE login_id = $login_id")); |
339 | | - $name = sanitizeInput($sql['login_name']); |
340 | | - $totp_secret = $sql['login_otp_secret']; |
341 | | - $client_id = intval($sql['login_client_id']); |
| 338 | + $sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT credential_name, credential_otp_secret, credential_client_id FROM credentials WHERE credential_id = $credential_id")); |
| 339 | + $name = sanitizeInput($sql['credential_name']); |
| 340 | + $totp_secret = $sql['credential_otp_secret']; |
| 341 | + $client_id = intval($sql['credential_client_id']); |
342 | 342 |
|
343 | 343 | $otp = TokenAuth6238::getTokenCode(strtoupper($totp_secret)); |
344 | 344 | echo json_encode($otp); |
345 | 345 |
|
346 | 346 | // Logging |
347 | 347 | // Only log the TOTP view if the user hasn't already viewed this specific login entry recently, this prevents logs filling if a user hovers across an entry a few times |
348 | | - $check_recent_totp_view_logged_sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(log_id) AS recent_totp_view FROM logs WHERE log_type = 'Login' AND log_action = 'View TOTP' AND log_user_id = $session_user_id AND log_entity_id = $login_id AND log_client_id = $client_id AND log_created_at > (NOW() - INTERVAL 5 MINUTE)")); |
| 348 | + $check_recent_totp_view_logged_sql = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(log_id) AS recent_totp_view FROM logs WHERE log_type = 'Credential' AND log_action = 'View TOTP' AND log_user_id = $session_user_id AND log_entity_id = $credential_id AND log_client_id = $client_id AND log_created_at > (NOW() - INTERVAL 5 MINUTE)")); |
349 | 349 | $recent_totp_view_logged_count = intval($check_recent_totp_view_logged_sql['recent_totp_view']); |
350 | 350 |
|
351 | 351 | if ($recent_totp_view_logged_count == 0) { |
352 | 352 | // Logging |
353 | | - logAction("Credential", "View TOTP", "$session_name viewed credential TOTP code for $name", $client_id, $login_id); |
| 353 | + logAction("Credential", "View TOTP", "$session_name viewed credential TOTP code for $name", $client_id, $credential_id); |
354 | 354 |
|
355 | 355 | } |
356 | 356 | } |
|
0 commit comments