Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions includes/core/load.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

<script type="text/javascript">
var userScrollPosition = 0,
debugJavascript = false;
debugJavascript = true;
let hourInMinutes = 60;


Expand Down Expand Up @@ -92,6 +92,7 @@
try {
// Retrieve the target defined by clipboard-target
const targetId = this.getAttribute('clipboard-target');
console.log('Target ID:', targetId);
if (!targetId) {
return; // Stop if no target ID is defined
}
Expand Down Expand Up @@ -1591,6 +1592,7 @@ function(data) {


function loadSettings() {
debugJavascript = true;
if (debugJavascript === true) {
console.log('Key appel get_teampass_settings : <?php echo $session->get('key'); ?>');
}
Expand Down Expand Up @@ -1628,9 +1630,25 @@ function(data) {
console.log('Loading settings result:');
console.log(data);
}

// Get settings from response
if (data.error !== false) {
// Show error
toastr.remove();
toastr.error(
data.message,
'<?php echo $lang->get('caution'); ?>', {
timeOut: 5000,
progressBar: true,
positionClass: "toast-bottom-right"
}
);
return false;
}
dataSettings = data.settings;

// Test if JSON object
if (typeof data === 'object') {
if (typeof dataSettings === 'object') {
// Store settings in localstorage
// except sensitive data
var sensitiveData = ['ldap_hosts','ldap_username','ldap_password','ldap_bdn','email','bck_script_passkey'];
Expand All @@ -1640,7 +1658,7 @@ function(data) {
store.update(
'teampassSettings', {},
function(teampassSettings) {
$.each(data, function(key, value) {
$.each(dataSettings, function(key, value) {
const containsKey = sensitiveData.some(element => {
if (key.includes(element)) {
return true;
Expand Down Expand Up @@ -1896,11 +1914,11 @@ function generateBugReport() {
data: prepareExchangedData(JSON.stringify(data), 'encode', '<?php echo $session->get('key'); ?>'),
key: '<?php echo $session->get('key'); ?>'
},
function(data) {
data = prepareExchangedData(data, 'decode', '<?php echo $session->get('key'); ?>');
function(response) {
decodedData = prepareExchangedData(response, 'decode', '<?php echo $session->get('key'); ?>');

// Show data
$('#dialog-bug-report-text').html(data.html);
$('#dialog-bug-report-text').html(decodedData.report);

// Open Github
$('#dialog-bug-report-github-button').click(function() {
Expand Down
2 changes: 1 addition & 1 deletion includes/core/login.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function(teampassUser) {
// Show tooltips
$('.infotip').tooltip();
});

store.remove('teampassSettings')
// Ensure session is ready in case of disconnection
const teampassSettings = store.get('teampassSettings');
if (teampassSettings === null || typeof teampassSettings === 'undefined' || Object.keys(teampassSettings).length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,7 @@
</div>
</div>
<div class="card-footer">
<button class="btn btn-primary mr-2 clipboard-copy" data-clipboard-text="dialog-bug-report-text" id="dialog-bug-report-select-button"><?php echo $lang->get('copy_to_clipboard'); ?></button>
<button class="btn btn-primary mr-2 clipboard-copy" clipboard-target="dialog-bug-report-text" id="dialog-bug-report-select-button"><?php echo $lang->get('copy_to_clipboard'); ?></button>
<button class="btn btn-primary" id="dialog-bug-report-github-button"><?php echo $lang->get('open_bug_report_in_github'); ?></button>
<button class="btn btn-default float-right close-element"><?php echo $lang->get('close'); ?></button>
</div>
Expand Down
6 changes: 4 additions & 2 deletions install/upgrade_run_3.0.0.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use TeampassClasses\NestedTree\NestedTree;
use Encryption\Crypt\aesctr;
use TeampassClasses\ConfigManager\ConfigManager;
use TeampassClasses\PasswordManager\PasswordManager;

// Load functions
require_once __DIR__.'/../sources/main.functions.php';
Expand Down Expand Up @@ -1987,9 +1988,10 @@

// Add account TP USER if not exist
$data = mysqli_fetch_row(mysqli_query($db_link, "SELECT COUNT(*) FROM ".$pre . "users WHERE id = '" . TP_USER_ID . "'"));
if ((int) $data[0] === 0) {
if ((int) $data[0] === 0) {
// generate key for password
$pwd = GenerateCryptKey(25, true, true, true, true);
$passwordManager = new PasswordManager();
$pwd = $passwordManager->generatePassword(25, true, true, true, true);
$encrypted_pwd = cryption(
$pwd,
'',
Expand Down
4 changes: 3 additions & 1 deletion install/upgrade_run_3.0.0_users.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use TeampassClasses\SuperGlobal\SuperGlobal;
use TeampassClasses\Language\Language;
use TeampassClasses\ConfigManager\ConfigManager;
use TeampassClasses\PasswordManager\PasswordManager;

// Load functions
require_once __DIR__.'/../sources/main.functions.php';
Expand Down Expand Up @@ -133,7 +134,8 @@
$tmp = mysqli_num_rows(mysqli_query($db_link, "SELECT * FROM `" . $pre . "users` WHERE id = '" . TP_USER_ID . "'"));
if (intval($tmp) === 0) {
// generate key for password
$pwd = GenerateCryptKey(25, true, true, true, true);
$passwordManager = new PasswordManager();
$pwd = $passwordManager->generatePassword(25, true, true, true, true);
$salt = file_get_contents(rtrim(SECUREPATH, '/') . '/' . SECUREFILE);
$encrypted_pwd = cryption(
$pwd,
Expand Down
6 changes: 4 additions & 2 deletions install/upgrade_run_3.1.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use TeampassClasses\SuperGlobal\SuperGlobal;
use TeampassClasses\Language\Language;
use TeampassClasses\ConfigManager\ConfigManager;
use TeampassClasses\PasswordManager\PasswordManager;

// Load functions
require_once __DIR__.'/../sources/main.functions.php';
Expand Down Expand Up @@ -688,8 +689,9 @@
}
$encryptionKey = file_get_contents($secureFilePath);

// Generate a random password for the user
$userPassword = GenerateCryptKey(25, true, true, true, true);
// generate key for password
$passwordManager = new PasswordManager();
$userPassword = $passwordManager->generatePassword(25, true, true, true, true);
$encryptedUserPassword = cryption(
$userPassword,
$encryptionKey,
Expand Down
5 changes: 2 additions & 3 deletions pages/backups.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,14 +348,13 @@ function updateProgressBar(offset, totalSize) {
key: '<?php echo $session->get('key'); ?>'
},
function(data) {
console.log(data);
store.update(
'teampassUser',
function(teampassUser) {
teampassUser.uploadToken = data[0].token;
teampassUser.uploadToken = data.token;
}
);
up.start();
//up.start();
},
"json"
);
Expand Down
4 changes: 2 additions & 2 deletions pages/import.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ function(data) {
store.update(
'teampassApplication',
function(teampassApplication) {
teampassApplication.uploadedFileId = data[0].token;
teampassApplication.uploadedFileId = data.token;
}
);

Expand Down Expand Up @@ -801,7 +801,7 @@ function(data) {
store.update(
'teampassApplication',
function(teampassApplication) {
teampassApplication.uploadedFileId = data[0].token;
teampassApplication.uploadedFileId = data.token;
}
);

Expand Down
3 changes: 1 addition & 2 deletions pages/items.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -3091,10 +3091,9 @@ function(data) {
store.update(
'teampassApplication',
function(teampassApplication) {
teampassApplication.attachmentToken = data[0].token;
teampassApplication.attachmentToken = data.token;
}
);
console.log('start upload')
uploader_attachments.start();
},
"json"
Expand Down
2 changes: 1 addition & 1 deletion pages/profile.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
key: '<?php echo $session->get('key'); ?>'
},
function(data) {
$('#profile-user-token').val(data[0].token);
$('#profile-user-token').val(data.token);

up.setOption('multipart_params', {
PHPSESSID: '<?php echo $session->get('key'); ?>',
Expand Down
13 changes: 9 additions & 4 deletions sources/admin.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use Duo\DuoUniversal\DuoException;
use TeampassClasses\EmailService\EmailSettings;
use TeampassClasses\EmailService\EmailService;
use TeampassClasses\PasswordManager\PasswordManager;

// Load functions
require_once 'main.functions.php';
Expand Down Expand Up @@ -190,8 +191,9 @@
}

if (!empty($return)) {
// get a token
$token = GenerateCryptKey(20, false, true, true, false, true);
// get a token// Generate password
$passwordManager = new PasswordManager();
$token = $passwordManager->generatePassword(20, false, true, true, false, true);

//save file
$filename = time() . '-' . $token . '.sql';
Expand Down Expand Up @@ -221,7 +223,9 @@
}

//generate 2d key
$session->set('user-key_tmp', GenerateCryptKey(20, false, true, true, false, true));
$passwordManager = new PasswordManager();
$newPassword = $passwordManager->generatePassword(20, false, true, true, false, true);
$session->set('user-key_tmp', $newPassword);

//update LOG
logEvents($SETTINGS, 'admin_action', 'dataBase backup', (string) $session->get('user-id'), $session->get('user-login'));
Expand Down Expand Up @@ -1587,7 +1591,8 @@
if (null !== $post_action && $post_action === 'add') {
// Generate KEY
require_once 'main.functions.php';
$key = GenerateCryptKey(39, false, true, true, false, true);
$passwordManager = new PasswordManager();
$key = $passwordManager->generatePassword(39, false, true, true, false, true);

// Generate objectKey
//$object = doDataEncryption($key, SECUREFILE.':'.$timestamp);
Expand Down
12 changes: 7 additions & 5 deletions sources/backups.queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use EZimuel\PHPSecureSession;
use TeampassClasses\PerformChecks\PerformChecks;
use TeampassClasses\ConfigManager\ConfigManager;

use TeampassClasses\PasswordManager\PasswordManager;

// Load functions
require_once 'main.functions.php';
Expand Down Expand Up @@ -141,7 +141,8 @@
require_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php';

// get a token
$token = GenerateCryptKey(20, false, true, true, false, true);
$passwordManager = new PasswordManager();
$token = $passwordManager->generatePassword(20, false, true, true, false, true);

//save file
$filename = time() . '-' . $token . '.sql';
Expand Down Expand Up @@ -255,8 +256,10 @@
}

// Generate 2d key
$session->set('user-key_tmp', GenerateCryptKey(16, false, true, true, false, true));

$passwordManager = new PasswordManager();
$newPassword = $passwordManager->generatePassword(16, false, true, true, false, true);
$session->set('user-key_tmp', $newPassword);

// Update LOG
logEvents(
$SETTINGS,
Expand Down Expand Up @@ -557,4 +560,3 @@
break;
}
}

106 changes: 106 additions & 0 deletions sources/core/services/OneTimeCodeService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

declare(strict_types=1);

/**
* Teampass - a collaborative passwords manager.
* ---
* This file is part of the TeamPass project.
*
* TeamPass is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3 of the License.
*
* TeamPass is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Certain components of this file may be under different licenses. For
* details, see the `licenses` directory or individual file headers.
* ---
* @file OneTimeCodeService.php
* @author Nils Laumaillé (nils@teampass.net)
* @copyright 2009-2025 Teampass.net
* @license GPL-3.0
* @see https://www.teampass.net
*/

use TeampassClasses\SessionManager\SessionManager;
use TeampassClasses\Language\Language;

class OneTimeCodeService
{
private Language $lang;

public function __construct()
{
$session = SessionManager::getSession();
$this->lang = new Language($session->get('user-language') ?? 'english');
}

public function generateForUser(int $userId): string
{
if (!isUserIdValid($userId)) {
return $this->respondError($this->lang->get('error_no_user'));
}

$user = $this->getUser($userId);

if (!$user || empty($user['email'])) {
return $this->respondError($this->lang->get('no_email_set'));
}

$password = generateQuickPassword();
$keys = generateUserKeys($password);

$this->storeUserKeys($userId, $keys);

return $this->respondSuccess($password);
}

private function getUser(int $userId): ?array
{
$user = DB::queryFirstRow(
'SELECT email, auth_type, login FROM ' . prefixTable('users') . ' WHERE id = %i',
$userId
);

return DB::count() > 0 ? $user : null;
}

private function storeUserKeys(int $userId, array $keys): void
{
DB::update(
prefixTable('users'),
[
'public_key' => $keys['public_key'],
'private_key' => $keys['private_key'],
'special' => 'generate-keys',
],
'id=%i',
$userId
);
}

private function respondError(string $message): string
{
return prepareExchangedData([
'error' => true,
'message' => $message,
], 'encode');
}

private function respondSuccess(string $code): string
{
return prepareExchangedData([
'error' => false,
'message' => '',
'code' => $code,
'visible_otp' => ADMIN_VISIBLE_OTP_ON_LDAP_IMPORT,
], 'encode');
}
}
Loading