Files
itflow/agent/modals/credential/credential_rotate.php
johnnyq fecd1cabff Credentials makeover: rebuilt credentials list with kind icons, username copy, password show/copy and live 2FA code buttons fetched on demand, where it opens, what it is for (asset, contact, vendors, licenses, services), password age pills and last used, filters for Starred, With 2FA, No 2FA, Not changed in 90 days and Shared with counts, search across notes, second link, tags, asset and contact, open straight to a credential with ?open=ID; new credential quick look with login, age, last viewed by, links with unlink, notes, open share links with turn off, and history; tabbed new/edit form with password generator (passphrase or random), strength meter, 2FA secret that accepts spaces or an otpauth:// link and shows the current code to check, copy buttons on both links, prefill from asset, contact or vendor; new Change password window that dates and logs the change; new Share window from anywhere (contact or email, 1 hour to 1 month, gone after opened once by default, link copied); same login controls on asset and contact pages and quick looks, vendor Logins tab, license page and quick look, service quick look, client overview favourites and search; credential pickers show icons and say when a credential moves from another asset or contact; client overview Passwords due for a change attention item and Active share links limited to live links; rotation report with selectable span, per client counts and oldest first; more export columns; demo data gets 2FA secrets, varied password ages and logins attached to their assets. Fixes passwords being blanked when the vault session had expired, other clients' assets, contacts and tags accepted on save, bulk star using the wrong permission, credential links to assets and contacts not checking the client, the edit or link permission, or which asset or contact an unlink was for, credentials left pointing at deleted assets and contacts, share links left open after a credential was deleted, import carrying values between rows and accepting any file type, 2FA secrets saved with spaces or lowercase giving no code, the service quick look listing credentials without credential access and repeating assets, an asset login with only a username being lost, and the API not dating new passwords. Adds functions/credential.php and js/credentials.js; removes credential_model.php and the old credential show password/OTP scripts. No DB change.
2026-10-14 23:33:29 -04:00

104 lines
5.3 KiB
PHP

<?php
/*
* Change a credential's password - the rotation every MSP owes its clients.
* Make one up (a passphrase, or random characters), copy it to set it on
* the device or site, and save it: the password and the date it changed are
* updated and the change is logged. Nothing else about the credential moves.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_credential', 2);
$credential_id = intval($_GET['id'] ?? 0);
$credential = credentialRow($credential_id);
if (!$credential) {
echo json_encode(['error' => 'That credential no longer exists.']);
exit;
}
$client_id = intval($credential['credential_client_id']);
enforceClientAccess();
$age = credentialAge($credential['credential_password_changed_at']);
$vault_open = encryptCredentialEntry('') !== false;
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fa fa-fw fa-sync-alt me-2"></i>Change password: <strong><?= escapeHtml($credential['credential_name']) ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off" data-credential-rotate>
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="credential_id" value="<?= $credential_id ?>">
<div class="modal-body">
<?php if (!$vault_open) { ?>
<div class="alert alert-warning small"><i class="fas fa-lock me-2"></i>Your vault session has expired, so the new password cannot be encrypted. Sign out and back in first.</div>
<?php } ?>
<div class="d-flex flex-wrap align-items-center gap-2 mb-3 small text-body-secondary">
<?= credentialAgePill($age) ?>
<?php $username = credentialUsername($credential); if ($username !== '') { ?>
<span class="d-inline-flex align-items-center"><i class="fas fa-user me-1"></i><?= credentialUsernameHtml($username) ?></span>
<?php } ?>
</div>
<label class="form-label">New password <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
<input type="text" class="form-control font-monospace" name="password" maxlength="350" required autocomplete="new-password" data-rotate-password>
<button class="btn btn-outline-secondary" type="button" title="Copy" data-rotate-copy><i class="far fa-fw fa-copy"></i></button>
<button class="btn btn-outline-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" title="Make one up"><i class="fas fa-fw fa-magic"></i></button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item" href="#" data-rotate-generate="passphrase"><i class="fas fa-fw fa-font text-secondary me-2"></i>Passphrase</a>
<a class="dropdown-item" href="#" data-rotate-generate="20"><i class="fas fa-fw fa-random text-secondary me-2"></i>Random, 20 characters</a>
<a class="dropdown-item" href="#" data-rotate-generate="32"><i class="fas fa-fw fa-random text-secondary me-2"></i>Random, 32 characters</a>
</div>
</div>
<div class="form-text">Set it on the device or site first, then save it here - the old one is gone once you do.</div>
</div>
<div class="modal-footer">
<button type="submit" name="rotate_credential" class="btn btn-primary text-bold" <?= $vault_open ? '' : 'disabled' ?>><i class="fa fa-check me-2"></i>Save new password</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<script>
itflowReady(function () {
var form = document.querySelector('form[data-credential-rotate]:not([data-wired])');
if (!form) {
return;
}
form.dataset.wired = '1';
var input = form.querySelector('[data-rotate-password]');
var copy = form.querySelector('[data-rotate-copy]');
function randomPassword(length) {
var chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789!@#$%^&*-_=+?';
var bytes = new Uint32Array(length);
window.crypto.getRandomValues(bytes);
return Array.prototype.map.call(bytes, function (b) { return chars[b % chars.length]; }).join('');
}
form.querySelectorAll('[data-rotate-generate]').forEach(function (item) {
item.addEventListener('click', function (e) {
e.preventDefault();
if (item.dataset.rotateGenerate === 'passphrase') {
itflowGet('ajax.php', { get_readable_pass: 'true' }, function (data) {
input.value = JSON.parse(data);
});
} else {
input.value = randomPassword(parseInt(item.dataset.rotateGenerate, 10));
}
});
});
copy.addEventListener('click', function () {
itflowCopyText(input.value, copy).then(
function () { flashTooltip(copy, 'Copied!'); },
function () {}
);
});
});
</script>
<?php
require_once '../../../includes/modal_footer.php';