mirror of
https://github.com/itflow-org/itflow
synced 2026-12-05 10:39:00 +00:00
Modernize Administration > Users and the agent Account pages: new users list with Users/Admins/No MFA/Disabled/Archived views, role filter, status and MFA pills, remembered browsers, client access summary, last successful sign in with device and IP, seat badge, quick look modal, bulk role/require MFA/forget browsers/activate/disable, shared New/Edit user form with Details/Sign in/Client access tabs (icon prefixed inputs, picture preview, generated passwords, Only/Never client rules with search and set all), archive modal with ticket hand-over, restore requiring a new password, incident response limited to agents and forgetting remembered browsers, export role filter and MFA/last sign in/client access columns; Account pages reworked into Profile/Security/Preferences/Activity with current password required to change email, password or turn MFA off, inline SVG MFA QR code, remembered browser list with forget one/all, rows per page preference; adds functions/user.php shared helpers, validates email format and uniqueness, sets password hash and vault key from the exact typed password, purifies signatures, fixes Activity showing other agents' sign ins, removes dead user invite modal and user_model, and fixes the networks export link from All Clients with no filter
This commit is contained in:
116
admin/modals/user/user.php
Normal file
116
admin/modals/user/user.php
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* User quick look - from Administration > Users. Who they are, whether and
|
||||
* how they sign in, the clients they see, the work they have open, and their
|
||||
* latest sign ins.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$user = userForModal($_GET['id'] ?? 0);
|
||||
$user_id = intval($user['user_id']);
|
||||
$is_self = $user_id === intval($session_user_id);
|
||||
$is_archived = !empty($user['user_archived_at']);
|
||||
$is_admin = intval($user['role_is_admin']) === 1;
|
||||
$display_name = $is_archived ? trim(str_replace(' (archived)', '', $user['user_name'])) : $user['user_name'];
|
||||
$access = userClientAccess([$user_id])[$user_id];
|
||||
$remembered = userRememberCounts([$user_id])[$user_id];
|
||||
[$open_tickets, $recurring_tickets] = userOpenWork($user_id);
|
||||
$recent = userRecentLogins($user_id, 6);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark" data-bs-theme="dark">
|
||||
<div class="d-flex align-items-center gap-3 min-w-0">
|
||||
<?= userAvatar($user_id, $display_name, $user['user_avatar'], 'lg') ?>
|
||||
<div class="min-w-0">
|
||||
<h5 class="modal-title fw-semibold text-break"><?= escapeHtml($display_name) ?><?php if ($is_self) { ?> <span class="badge rounded-pill bg-primary-subtle text-primary-emphasis fw-normal small align-middle">You</span><?php } ?></h5>
|
||||
<div class="small text-body-secondary d-flex flex-wrap column-gap-3">
|
||||
<span><?= escapeHtml($user['user_email']) ?><button type="button" class="itflow-copy clipboardjs" title="Copy email" data-clipboard-text="<?= escapeHtml($user['user_email']) ?>"><i class="far fa-copy"></i></button></span>
|
||||
<span><i class="fas fa-fw <?= $is_admin ? 'fa-user-shield' : 'fa-user-tag' ?> me-1"></i><?= escapeHtml($user['role_name'] ?? 'No role') ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="d-flex flex-wrap gap-1 mb-3">
|
||||
<?= userStatusPill($user['user_status'], $is_archived) ?>
|
||||
<?php if (!$is_archived) { ?><?= userMfaPill($user['user_token'], $user['user_config_force_mfa']) ?><?php } ?>
|
||||
<?php if ($is_admin) { ?><span class="badge rounded-pill bg-primary-subtle text-primary-emphasis fw-normal"><i class="fas fa-user-shield me-1"></i>Admin</span><?php } ?>
|
||||
</div>
|
||||
|
||||
<dl class="itflow-asset-dl mb-0">
|
||||
<dt>Clients</dt>
|
||||
<dd>
|
||||
<?= escapeHtml(userClientAccessText($access, $is_admin)) ?>
|
||||
<?php if (!$is_admin && $access['allow']) { ?>
|
||||
<div class="small"><span class="text-success-emphasis fw-semibold">Only</span> <?= escapeHtml(implode(', ', $access['allow'])) ?></div>
|
||||
<?php } ?>
|
||||
<?php if (!$is_admin && $access['deny']) { ?>
|
||||
<div class="small"><span class="text-danger-emphasis fw-semibold">Never</span> <?= escapeHtml(implode(', ', $access['deny'])) ?></div>
|
||||
<?php } ?>
|
||||
</dd>
|
||||
|
||||
<?php if (!$is_archived) { ?>
|
||||
<dt>Remembered</dt>
|
||||
<dd>
|
||||
<?php if ($remembered) { ?>
|
||||
<?= $remembered ?> browser<?= $remembered === 1 ? '' : 's' ?> skip<?= $remembered === 1 ? 's' : '' ?> their MFA code
|
||||
<?php } else { ?>
|
||||
<span class="text-body-secondary">No browsers</span>
|
||||
<?php } ?>
|
||||
</dd>
|
||||
|
||||
<dt>Open work</dt>
|
||||
<dd>
|
||||
<?php if ($open_tickets) { ?>
|
||||
<a href="/agent/tickets.php?assigned=<?= $user_id ?>"><?= $open_tickets ?> open ticket<?= $open_tickets === 1 ? '' : 's' ?></a>
|
||||
<?php } else { ?>
|
||||
<span class="text-body-secondary">No open tickets</span>
|
||||
<?php } ?>
|
||||
<?php if ($recurring_tickets) { ?>
|
||||
<span class="text-body-secondary">· <?= $recurring_tickets ?> recurring</span>
|
||||
<?php } ?>
|
||||
</dd>
|
||||
<?php } ?>
|
||||
|
||||
<dt>Added</dt>
|
||||
<dd><span title="<?= escapeHtml($user['user_created_at']) ?>"><?= escapeHtml(timeAgo($user['user_created_at'])) ?></span></dd>
|
||||
|
||||
<?php if ($is_archived) { ?>
|
||||
<dt>Archived</dt>
|
||||
<dd><span title="<?= escapeHtml($user['user_archived_at']) ?>"><?= escapeHtml(timeAgo($user['user_archived_at'])) ?></span></dd>
|
||||
<?php } ?>
|
||||
</dl>
|
||||
|
||||
<h6 class="text-body-secondary text-uppercase small fw-semibold mt-4 mb-2">Latest sign ins</h6>
|
||||
<?php if ($recent) { ?>
|
||||
<div class="d-flex flex-column gap-2 small">
|
||||
<?php foreach ($recent as $log) { ?>
|
||||
<?= userLoginLineHtml($log) ?>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="small text-body-secondary">Never signed in.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<a class="btn btn-outline-secondary me-auto" href="audit_logs.php?user=<?= $user_id ?>"><i class="fas fa-history me-2"></i>Audit log</a>
|
||||
<?php if ($is_self) { ?>
|
||||
<a class="btn btn-primary" href="/agent/user/user_details.php"><i class="fas fa-user-cog me-2"></i>Your account</a>
|
||||
<?php } elseif ($is_archived) { ?>
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/user/user_restore.php?id=<?= $user_id ?>"><i class="fas fa-redo-alt me-2"></i>Restore</button>
|
||||
<?php } else { ?>
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/user/user_edit.php?id=<?= $user_id ?>"><i class="fas fa-user-edit me-2"></i>Edit</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal">Close</button>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
@@ -1,7 +1,19 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* New User - an agent who signs in to ITFlow. ?role= starts it on that role
|
||||
* (the role the users list is filtered to).
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$is_new = true;
|
||||
$role_id = intval($_GET['role'] ?? 0);
|
||||
$form = [
|
||||
'user_role_id' => isset(userRoles()[$role_id]) ? $role_id : 0,
|
||||
'user_config_force_mfa' => 0,
|
||||
];
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
@@ -11,148 +23,12 @@ ob_start();
|
||||
</div>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<ul class="nav nav-pills nav-justified mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#pills-user-details">Details</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#pills-user-access">Restrict Access</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="tab-content">
|
||||
|
||||
<div class="tab-pane fade show active" id="pills-user-details">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="Full Name" maxlength="200" required autofocus>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Email <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email Address" maxlength="200" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>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="password" class="form-control" data-toggle="password" name="password" id="password" placeholder="Enter a Password" autocomplete="new-password" minlength="8" required>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<span class="btn btn-default"><i class="fa fa-fw fa-question" onclick="generatePassword()"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Role <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role" required>
|
||||
<option value="">- Role -</option>
|
||||
<?php
|
||||
$sql_user_roles = mysqli_query($mysqli, "SELECT role_id, role_name FROM user_roles WHERE role_archived_at IS NULL");
|
||||
while ($row = mysqli_fetch_assoc($sql_user_roles)) {
|
||||
$role_id = intval($row['role_id']);
|
||||
$role_name = escapeHtml($row['role_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $role_id ?>"><?= $role_name ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Avatar</label>
|
||||
<input type="file" class="form-control" accept="image/*" name="file">
|
||||
</div>
|
||||
|
||||
<div class="mb-3" <?php if(empty($config_smtp_host)) { echo "hidden"; } ?>>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="sendEmailCheckBox" name="send_email" value="" checked>
|
||||
<label for="sendEmailCheckBox" class="form-check-label">
|
||||
Send user e-mail with login details?
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="forceMFACheckBox" name="force_mfa" value=1>
|
||||
<label for="forceMFACheckBox" class="form-check-label">
|
||||
Force MFA
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pills-user-access">
|
||||
|
||||
<div class="alert alert-info">
|
||||
<strong>Allow</strong> restricts the user to the selected clients (no Allow = full access). <strong>Deny</strong> blocks a client regardless of Allow. Admin users are unaffected.
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<small class="text-muted me-2">Set all:</small>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="document.querySelectorAll('#accessTable .perm-none').forEach(r => r.checked = true);">No Rule</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-success" onclick="document.querySelectorAll('#accessTable .perm-allow').forEach(r => r.checked = true);">Allow</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="document.querySelectorAll('#accessTable .perm-deny').forEach(r => r.checked = true);">Deny</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0" id="accessTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Client</th>
|
||||
<th class="text-center" style="width: 90px;">No Rule</th>
|
||||
<th class="text-center text-success" style="width: 90px;">Allow</th>
|
||||
<th class="text-center text-danger" style="width: 90px;">Deny</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
$sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_client_select)) {
|
||||
$client_id = intval($row['client_id']);
|
||||
$client_name = escapeHtml($row['client_name']);
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td class="align-middle"><?= $client_name ?></td>
|
||||
<td class="text-center align-middle">
|
||||
<input type="radio" class="form-check-input perm-none" name="client_permission[<?= $client_id ?>]" value="" checked>
|
||||
</td>
|
||||
<td class="text-center align-middle">
|
||||
<input type="radio" class="form-check-input perm-allow" name="client_permission[<?= $client_id ?>]" value="allow">
|
||||
</td>
|
||||
<td class="text-center align-middle">
|
||||
<input type="radio" class="form-check-input perm-deny" name="client_permission[<?= $client_id ?>]" value="deny">
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php if (agentUserLimitReached()) { ?>
|
||||
<div class="alert alert-danger small"><?= agentUserLimitMessage() ?></div>
|
||||
<?php } ?>
|
||||
<?php require 'user_form.php'; ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="add_user" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Create</button>
|
||||
@@ -160,21 +36,5 @@ ob_start();
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
|
||||
function generatePassword() {
|
||||
itflowGet(
|
||||
"/agent/ajax.php", {
|
||||
get_readable_pass: 'true'
|
||||
},
|
||||
function(data) {
|
||||
const password = JSON.parse(data);
|
||||
document.getElementById("password").value = password;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
|
||||
@@ -1,33 +1,46 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Incident response - when an agent's account may be in someone else's
|
||||
* hands: every other agent gets a new password, shown once on the next page,
|
||||
* and their remembered browsers are forgotten so MFA is asked for again.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$agent_count = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM users WHERE user_type = 1 AND user_archived_at IS NULL AND user_id <> " . intval($session_user_id)))[0]);
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-body">
|
||||
<div class="mb-4" style="text-align: center;">
|
||||
<i class="far fas fa-10x fa-skull-crossbones text-danger mb-3 mt-3"></i>
|
||||
<h2>Incident Response: Agent Password Reset</h2>
|
||||
<br>
|
||||
<div class="alert alert-danger" role="alert">
|
||||
<b>This is a potentially destructive function.<br>It is intended to be used as part of a potential security incident.</b>
|
||||
</div>
|
||||
<h6 class="mb-4 text-secondary"><b>All ITFlow agent passwords will be reset and shown to you </b><i>(except yours - change yours first!)</i>.<br/><br/>You should communicate temporary passwords to agents out of band (e.g. via a phone call) and require they are changed ASAP.</h6>
|
||||
<form action="post.php" method="POST">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<div class="row col-7 offset-4">
|
||||
<div class="input-group">
|
||||
<input type="password" class="form-control" placeholder="Enter your account password to continue" name="admin_password" required>
|
||||
</div>
|
||||
</div>
|
||||
<br>
|
||||
<button class="btn btn-danger" type="submit" name="ir_reset_user_password"><i class="fas fa-fw fa-key me-2"></i>Reset passwords</button>
|
||||
</form>
|
||||
</div>
|
||||
<button type="button" class="btn btn-outline-secondary btn-lg px-5 me-4" data-bs-dismiss="modal">Cancel</button>
|
||||
|
||||
<div class="modal-header bg-danger">
|
||||
<h5 class="modal-title text-white"><i class="fas fa-fw fa-skull-crossbones me-2"></i>Incident response</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
<p class="fw-semibold mb-2">Reset the password of every other agent - <?= $agent_count ?> of them.</p>
|
||||
<ul class="small mb-3 ps-3">
|
||||
<li>Each gets a new password, shown to you once on the next page - give them out by phone, not email, and have them changed.</li>
|
||||
<li>Their remembered browsers are forgotten, so anyone with MFA is asked for a code again.</li>
|
||||
<li>Not yours - change your own first, from your account.</li>
|
||||
<li>Client portal logins are left alone.</li>
|
||||
</ul>
|
||||
|
||||
<label class="form-label">Your password <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-lock"></i></span>
|
||||
<input type="password" class="form-control" data-toggle="password" name="admin_password" placeholder="To confirm it's you" autocomplete="current-password" required autofocus>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="ir_reset_user_password" class="btn btn-danger text-bold" <?= $agent_count ? '' : 'disabled' ?>><i class="fas fa-key me-2"></i>Reset <?= $agent_count ?> password<?= $agent_count === 1 ? '' : 's' ?></button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
|
||||
@@ -1,76 +1,79 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Archive User - they can no longer sign in, and their open tickets and
|
||||
* recurring tickets go to another agent (or to nobody).
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$user_id = intval($_GET['id']);
|
||||
$user = userForModal($_GET['id'] ?? 0);
|
||||
$user_id = intval($user['user_id']);
|
||||
[$open_tickets, $recurring_tickets] = userOpenWork($user_id);
|
||||
$is_last_admin = userIsLastAdmin($user);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT user_avatar, user_email, user_name FROM users WHERE users.user_id = $user_id LIMIT 1");
|
||||
// Who can take their work - active agents, not them
|
||||
$agents = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT user_id, user_name, user_avatar FROM users
|
||||
WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL AND user_id <> $user_id ORDER BY user_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$agents[] = $row;
|
||||
}
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$user_name = escapeHtml($row['user_name']);
|
||||
$user_email = escapeHtml($row['user_email']);
|
||||
$user_avatar = escapeHtml($row['user_avatar']);
|
||||
$user_initials = escapeHtml(initials($user_name));
|
||||
|
||||
$sql_related_tickets = mysqli_query($mysqli, "SELECT 1 FROM tickets
|
||||
WHERE ticket_assigned_to = $user_id AND ticket_resolved_at IS NULL AND ticket_closed_at IS NULL");
|
||||
|
||||
$ticket_count = mysqli_num_rows($sql_related_tickets);
|
||||
|
||||
// Related Recurring Tickets Query
|
||||
$sql_related_recurring_tickets = mysqli_query($mysqli, "SELECT 1 FROM recurring_tickets WHERE recurring_ticket_assigned_to = $user_id");
|
||||
|
||||
$recurring_ticket_count = mysqli_num_rows($sql_related_recurring_tickets);
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-user-slash me-2"></i>Archiving user:
|
||||
<strong><?= $user_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-archive me-2"></i>Archive <?= escapeHtml($user['user_name']) ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="user_id" value="<?= $user_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
|
||||
<center class="mb-3">
|
||||
<?php if (!empty($user_avatar)) { ?>
|
||||
<img class="img-fluid" src="<?= "../uploads/users/$user_id/$user_avatar" ?>">
|
||||
<?php } else { ?>
|
||||
<span class="fa-stack fa-4x">
|
||||
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
|
||||
<span class="fa fa-stack-1x text-white"><?= $user_initials ?></span>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</center>
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Reassign <?= $ticket_count ?> Open Tickets and <?= $recurring_ticket_count ?> Recurring Tickets To:</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
<select class="form-select select2" name="ticket_assign" required>
|
||||
<option value="0">No one</option>
|
||||
<?php
|
||||
$sql_users = mysqli_query($mysqli, "SELECT user_id, user_name, user_avatar FROM users WHERE user_type = 1 AND user_archived_at IS NULL");
|
||||
while ($row = mysqli_fetch_assoc($sql_users)) {
|
||||
$user_id_select = intval($row['user_id']);
|
||||
$user_name_select = escapeHtml($row['user_name']);
|
||||
|
||||
?>
|
||||
<option value="<?= $user_id_select ?>"<?= selectOptionUser($row['user_id'], $row['user_name'], $row['user_avatar'] ?? '') ?>><?= $user_name_select ?></option>
|
||||
<?php } ?>
|
||||
|
||||
</select>
|
||||
<div class="d-flex align-items-center gap-3 mb-3">
|
||||
<?= userAvatar($user_id, $user['user_name'], $user['user_avatar'], 'lg') ?>
|
||||
<div class="min-w-0">
|
||||
<div class="fw-semibold"><?= escapeHtml($user['user_name']) ?></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($user['user_email']) ?> · <?= escapeHtml($user['role_name'] ?? 'No role') ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($user_id === intval($session_user_id)) { ?>
|
||||
<div class="alert alert-danger small mb-0">You can't archive yourself.</div>
|
||||
<?php } elseif ($is_last_admin) { ?>
|
||||
<div class="alert alert-danger small mb-0"><i class="fas fa-user-shield me-2"></i>The only active admin - archived, there would be nobody to run ITFlow. Make someone else an admin first.</div>
|
||||
<?php } else { ?>
|
||||
<ul class="small mb-3 ps-3">
|
||||
<li>They're signed out, and can't sign in.</li>
|
||||
<li>Their password and their copy of the credential vault key are wiped - restoring them sets a new password.</li>
|
||||
<li>Everything they did stays, under their name.</li>
|
||||
</ul>
|
||||
|
||||
<label class="form-label">
|
||||
<?php if ($open_tickets || $recurring_tickets) { ?>
|
||||
Hand over <?= $open_tickets ?> open ticket<?= $open_tickets === 1 ? '' : 's' ?><?= $recurring_tickets ? " and $recurring_tickets recurring" : '' ?> to
|
||||
<?php } else { ?>
|
||||
Their open tickets go to <span class="fw-normal text-body-secondary">(they have none now)</span>
|
||||
<?php } ?>
|
||||
</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-user-check"></i></span>
|
||||
<select class="form-select select2" name="ticket_assign">
|
||||
<option value="0" data-icon="fas fa-user-slash">Nobody - unassigned</option>
|
||||
<?php foreach ($agents as $row) { ?>
|
||||
<option value="<?= intval($row['user_id']) ?>"<?= selectOptionUser($row['user_id'], $row['user_name'], $row['user_avatar'] ?? '') ?>><?= escapeHtml($row['user_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">Each ticket's history says who it went to, and why.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="archive_user" class="btn btn-danger text-bold"><i class="fas fa-archive me-2"></i>Archive</button>
|
||||
<?php if ($user_id !== intval($session_user_id) && !$is_last_admin) { ?>
|
||||
<button type="submit" name="archive_user" class="btn btn-danger text-bold"><i class="fas fa-archive me-2"></i>Archive</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
45
admin/modals/user/user_bulk_role.php
Normal file
45
admin/modals/user/user_bulk_role.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Bulk - give the users ticked on the users list one role. Never the admin
|
||||
* themselves, and the only active admin keeps an admin role.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$user_ids = array_values(array_diff(array_unique(array_filter(array_map('intval', (array) ($_GET['user_ids'] ?? [])))), [intval($session_user_id)]));
|
||||
$count = count($user_ids);
|
||||
$roles = userRoles();
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-user-tag me-2"></i>Role for <strong><?= $count ?></strong> user<?= $count === 1 ? '' : 's' ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<?php foreach ($user_ids as $user_id) { ?><input type="hidden" name="user_ids[]" value="<?= $user_id ?>"><?php } ?>
|
||||
|
||||
<div class="modal-body">
|
||||
<label class="form-label">Role <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role" required>
|
||||
<option value="">- Pick a role -</option>
|
||||
<?php foreach ($roles as $role_id => $role) { ?>
|
||||
<option value="<?= $role_id ?>"<?= selectOptionRole($role) ?>><?= escapeHtml($role['role_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">The only active admin keeps an admin role, so there is always someone to run ITFlow.</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="bulk_role_users" class="btn btn-primary text-bold" <?= $count ? '' : 'disabled' ?>><i class="fas fa-check me-2"></i>Set role</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
@@ -1,233 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Edit User - their details, role, password, MFA and the clients they see.
|
||||
* Not the admin's own account: that is changed from their Account pages.
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$user_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT user_avatar, user_config_force_mfa, user_email, user_name, user_role_id, user_token FROM users
|
||||
LEFT JOIN user_settings ON users.user_id = user_settings.user_id
|
||||
WHERE users.user_id = $user_id LIMIT 1"
|
||||
);
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$user_name = escapeHtml($row['user_name']);
|
||||
$user_email = escapeHtml($row['user_email']);
|
||||
$user_avatar = escapeHtml($row['user_avatar']);
|
||||
$user_token = escapeHtml($row['user_token']);
|
||||
$user_config_force_mfa = intval($row['user_config_force_mfa']);
|
||||
$user_role_id = intval($row['user_role_id']);
|
||||
$user_initials = escapeHtml(initials($user_name));
|
||||
|
||||
// Get User Client Access Permissions (allow + deny)
|
||||
$user_client_access_sql = mysqli_query($mysqli,"SELECT client_id, permission_type FROM user_client_permissions WHERE user_id = $user_id");
|
||||
$client_allow_array = []; // allow
|
||||
$client_deny_array = []; // deny
|
||||
while ($row = mysqli_fetch_assoc($user_client_access_sql)) {
|
||||
if ($row['permission_type'] === 'deny') {
|
||||
$client_deny_array[] = intval($row['client_id']);
|
||||
} else {
|
||||
$client_allow_array[] = intval($row['client_id']);
|
||||
}
|
||||
}
|
||||
$form = userForModal($_GET['id'] ?? 0);
|
||||
$user_id = intval($form['user_id']);
|
||||
$is_new = false;
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-user-edit me-2"></i>Editing user:
|
||||
<strong><?= $user_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-user-edit me-2"></i><?= escapeHtml($form['user_name']) ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="user_id" value="<?= $user_id ?>">
|
||||
<?php if ($user_id === intval($session_user_id)) { ?>
|
||||
<div class="modal-body">
|
||||
|
||||
<ul class="nav nav-pills nav-justified mb-3">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#pills-user-details<?= $user_id ?>">Details</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#pills-user-access<?= $user_id ?>">Restrict Access</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<div class="tab-content">
|
||||
|
||||
<div class="tab-pane fade show active" id="pills-user-details<?= $user_id ?>">
|
||||
|
||||
<center class="mb-3">
|
||||
<?php if (!empty($user_avatar)) { ?>
|
||||
<img class="img-fluid" src="<?= "../uploads/users/$user_id/$user_avatar" ?>">
|
||||
<?php } else { ?>
|
||||
<span class="fa-stack fa-4x">
|
||||
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
|
||||
<span class="fa fa-stack-1x text-white"><?= $user_initials ?></span>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</center>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="Full Name" maxlength="200"
|
||||
value="<?= $user_name ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Email <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email Address" maxlength="200"
|
||||
value="<?= $user_email ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>New Password</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
|
||||
<input type="password" class="form-control" data-toggle="password" name="new_password" id="password"
|
||||
placeholder="Leave Blank For No Password Change" autocomplete="new-password">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<span class="btn btn-default"><i class="fa fa-fw fa-question" onclick="generatePassword()"></i></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Role <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role" required>
|
||||
<?php
|
||||
$sql_user_roles = mysqli_query($mysqli, "SELECT role_id, role_name FROM user_roles WHERE role_archived_at IS NULL");
|
||||
while ($row = mysqli_fetch_assoc($sql_user_roles)) {
|
||||
$role_id = intval($row['role_id']);
|
||||
$role_name = escapeHtml($row['role_name']);
|
||||
|
||||
?>
|
||||
<option <?php if ($role_id == $user_role_id) {echo "selected";} ?> value="<?= $role_id ?>"><?= $role_name ?></option>
|
||||
<?php } ?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Avatar</label>
|
||||
<input type="file" class="form-control" accept="image/*" name="file">
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" id="forceMFACheckBox<?= $user_id ?>" name="force_mfa" value="1" <?php if($user_config_force_mfa == 1){ echo "checked"; } ?>>
|
||||
<label for="forceMFACheckBox<?= $user_id ?>" class="form-check-label">
|
||||
Force MFA
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($user_token)) { ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>2FA</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-id-card"></i></span>
|
||||
<select class="form-select" name="2fa">
|
||||
<option value="">Keep enabled</option>
|
||||
<option value="disable">Disable</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<div class="tab-pane fade" id="pills-user-access<?= $user_id ?>">
|
||||
|
||||
<div class="alert alert-info">
|
||||
<strong>Allow</strong> restricts the user to the selected clients (no Allow = full access). <strong>Deny</strong> blocks a client regardless of Allow. Admin users are unaffected.
|
||||
</div>
|
||||
|
||||
<div class="mb-2">
|
||||
<small class="text-muted me-2">Set all:</small>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="document.querySelectorAll('#accessTable<?= $user_id ?> .perm-none').forEach(r => r.checked = true);">No Rule</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-success" onclick="document.querySelectorAll('#accessTable<?= $user_id ?> .perm-allow').forEach(r => r.checked = true);">Allow</button>
|
||||
<button type="button" class="btn btn-sm btn-outline-danger" onclick="document.querySelectorAll('#accessTable<?= $user_id ?> .perm-deny').forEach(r => r.checked = true);">Deny</button>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-sm table-hover mb-0" id="accessTable<?= $user_id ?>">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Client</th>
|
||||
<th class="text-center" style="width: 90px;">No Rule</th>
|
||||
<th class="text-center text-success" style="width: 90px;">Allow</th>
|
||||
<th class="text-center text-danger" style="width: 90px;">Deny</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
<?php
|
||||
$sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL ORDER BY client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql_client_select)) {
|
||||
$client_id_select = intval($row['client_id']);
|
||||
$client_name_select = escapeHtml($row['client_name']);
|
||||
$client_is_allow = in_array($client_id_select, $client_allow_array);
|
||||
$client_is_deny = in_array($client_id_select, $client_deny_array);
|
||||
?>
|
||||
|
||||
<tr>
|
||||
<td class="align-middle"><?= $client_name_select ?></td>
|
||||
<td class="text-center align-middle">
|
||||
<input type="radio" class="form-check-input perm-none" name="client_permission[<?= $client_id_select ?>]" value="" <?php if (!$client_is_allow && !$client_is_deny) { echo "checked"; } ?>>
|
||||
</td>
|
||||
<td class="text-center align-middle">
|
||||
<input type="radio" class="form-check-input perm-allow" name="client_permission[<?= $client_id_select ?>]" value="allow" <?php if ($client_is_allow) { echo "checked"; } ?>>
|
||||
</td>
|
||||
<td class="text-center align-middle">
|
||||
<input type="radio" class="form-check-input perm-deny" name="client_permission[<?= $client_id_select ?>]" value="deny" <?php if ($client_is_deny) { echo "checked"; } ?>>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<p class="mb-0">That's you - change your own details, password and MFA from <a href="/agent/user/user_details.php">your account</a>, so you can't lock yourself out from here.</p>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="edit_user" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Close</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php } else { ?>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="user_id" value="<?= $user_id ?>">
|
||||
|
||||
<script>
|
||||
|
||||
function generatePassword() {
|
||||
// Send a GET request to ajax.php as ajax.php?get_readable_pass=true
|
||||
itflowGet(
|
||||
"/agent/ajax.php", {
|
||||
get_readable_pass: 'true'
|
||||
},
|
||||
function(data) {
|
||||
//If we get a response from post.php, parse it as JSON
|
||||
const password = JSON.parse(data);
|
||||
document.getElementById("password").value = password;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
</script>
|
||||
<div class="modal-body">
|
||||
<?php require 'user_form.php'; ?>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="edit_user" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Save</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php } ?>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
|
||||
@@ -1,21 +1,13 @@
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceAdminPermission();
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
// Pre-filled from the users page's current filters. Everything here is editable -
|
||||
// the export runs whatever this form posts, not whatever the page happened to show.
|
||||
$client_id = intval($_GET['client_id'] ?? 0);
|
||||
if ($client_id) {
|
||||
enforceClientAccess();
|
||||
}
|
||||
|
||||
// Search Filter
|
||||
$q_filter = $_GET['q'] ?? '';
|
||||
|
||||
// Archived Filter
|
||||
$archived_filter = (isset($_GET['archived']) && $_GET['archived'] == 1) ? 1 : 0;
|
||||
$roles = userRoles();
|
||||
$role_filter = isset($roles[intval($_GET['role'] ?? 0)]) ? intval($_GET['role']) : 0;
|
||||
|
||||
ob_start();
|
||||
|
||||
@@ -36,19 +28,32 @@ ob_start();
|
||||
<?php exportTabsFiltersOpen(); ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Search</label>
|
||||
<label class="form-label">Search</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-search"></i></span>
|
||||
<input type="text" class="form-control" name="q" value="<?= stripslashes(escapeHtml($q_filter)) ?>" placeholder="Name or email">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-search"></i></span>
|
||||
<input type="text" class="form-control" name="q" value="<?= escapeHtml($q_filter) ?>" placeholder="Name, email or role">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Archived</label>
|
||||
<label class="form-label">Role</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-archive"></i></span>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role">
|
||||
<option value="">- Any role -</option>
|
||||
<?php foreach ($roles as $role_id => $role) { ?>
|
||||
<option value="<?= $role_id ?>" <?= $role_filter === $role_id ? 'selected' : '' ?><?= selectOptionRole($role) ?>><?= escapeHtml($role['role_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">Archived</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-archive"></i></span>
|
||||
<select class="form-select select2" name="archived">
|
||||
<option <?php if (!$archived_filter) { echo "selected"; } ?> value="0">Active only</option>
|
||||
<option <?php if (!$archived_filter) { echo "selected"; } ?> value="0">Not archived</option>
|
||||
<option <?php if ($archived_filter) { echo "selected"; } ?> value="1">Archived only</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
377
admin/modals/user/user_form.php
Normal file
377
admin/modals/user/user_form.php
Normal file
@@ -0,0 +1,377 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* The fields of New User and Edit User - included by user_add.php and
|
||||
* user_edit.php, which set $form (the user, raw - or the defaults for a new
|
||||
* one) and $is_new. Posts what admin/post/users.php add_user / edit_user read.
|
||||
*
|
||||
* Tabs: Details (picture, name, email, role), Sign in (password, MFA) and
|
||||
* Client access - which clients a role without admin is limited to or kept
|
||||
* from. An admin sees every client, so for an admin role that tab just says
|
||||
* so (any rules are kept, in case the role changes back).
|
||||
*/
|
||||
|
||||
isset($mysqli) || die("Direct file access is not allowed");
|
||||
|
||||
$form_user_id = intval($form['user_id'] ?? 0);
|
||||
$form_id = 'userForm' . ($is_new ? 'New' : $form_user_id);
|
||||
$form_role_id = intval($form['user_role_id'] ?? 0);
|
||||
$form_roles = userRoles($form_role_id);
|
||||
$form_has_mfa = trim((string) ($form['user_token'] ?? '')) !== '';
|
||||
$form_has_avatar = trim((string) ($form['user_avatar'] ?? '')) !== '';
|
||||
$form_access = $form_user_id ? userClientAccess([$form_user_id])[$form_user_id] : ['allow' => [], 'deny' => []];
|
||||
|
||||
// Every client - and an archived one only when it has a rule, so saving does not drop it. Those with a rule first.
|
||||
$form_clients = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation, client_archived_at FROM clients
|
||||
WHERE client_archived_at IS NULL OR client_id IN (SELECT client_id FROM user_client_permissions WHERE user_id = $form_user_id)
|
||||
ORDER BY client_id IN (SELECT client_id FROM user_client_permissions WHERE user_id = $form_user_id) DESC, client_archived_at IS NOT NULL, client_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$form_clients[] = $row;
|
||||
}
|
||||
|
||||
$value = function ($key) use ($form) {
|
||||
return escapeHtml($form[$key] ?? '');
|
||||
};
|
||||
|
||||
?>
|
||||
|
||||
<ul class="nav nav-pills nav-fill flex-nowrap overflow-auto mb-3 itflow-asset-form-tabs" role="tablist">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link active" data-bs-toggle="pill" href="#<?= $form_id ?>Details"><i class="fas fa-fw fa-user me-2 d-none d-lg-inline"></i>Details</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Security"><i class="fas fa-fw fa-key me-2 d-none d-lg-inline"></i>Sign in</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" data-bs-toggle="pill" href="#<?= $form_id ?>Access"><i class="fas fa-fw fa-building me-2 d-none d-lg-inline"></i>Client access</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content" id="<?= $form_id ?>">
|
||||
|
||||
<!-- Who they are -->
|
||||
<div class="tab-pane fade show active" id="<?= $form_id ?>Details">
|
||||
<div class="d-flex align-items-center gap-3 mb-3">
|
||||
<span data-user-avatar-preview><?= userAvatar($form_user_id ?: 0, $form['user_name'] ?? '', $form['user_avatar'] ?? '', 'lg') ?></span>
|
||||
<div class="flex-grow-1 min-w-0">
|
||||
<label class="form-label mb-1">Picture</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-image"></i></span>
|
||||
<input type="file" class="form-control" name="avatar" accept="image/jpeg,image/png,image/gif,image/webp" data-user-avatar-input>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap align-items-center column-gap-3 mt-1">
|
||||
<span class="form-text mt-0">JPG, PNG, GIF or WebP, up to 5 MB. Without one, their initials.</span>
|
||||
<?php if ($form_has_avatar) { ?>
|
||||
<div class="form-check small mb-0">
|
||||
<input class="form-check-input" type="checkbox" name="remove_avatar" value="1" id="<?= $form_id ?>RemoveAvatar" data-user-avatar-remove>
|
||||
<label class="form-check-label" for="<?= $form_id ?>RemoveAvatar">Remove the picture</label>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Name <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-user"></i></span>
|
||||
<input type="text" class="form-control" name="name" placeholder="First and last name" maxlength="200" value="<?= $value('user_name') ?>" required <?= $is_new ? 'autofocus' : '' ?> data-user-name>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Email <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-envelope"></i></span>
|
||||
<input type="email" class="form-control" name="email" placeholder="They sign in with this" maxlength="200" value="<?= $value('user_email') ?>" required>
|
||||
</div>
|
||||
<?php if (!$is_new) { ?>
|
||||
<div class="form-text">Changed, they sign in with the new one - the old address is told.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="col-12">
|
||||
<label class="form-label">Role <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role" required data-user-role>
|
||||
<?php if (!isset($form_roles[$form_role_id])) { ?>
|
||||
<option value="">- Pick a role -</option>
|
||||
<?php } ?>
|
||||
<?php foreach ($form_roles as $role_id => $role) { ?>
|
||||
<option value="<?= $role_id ?>" <?= $form_role_id === $role_id ? 'selected' : '' ?> data-role-admin="<?= intval($role['role_is_admin']) ?>"<?= selectOptionRole($role) ?>><?= escapeHtml($role['role_name']) ?><?= $role['role_archived_at'] ? ' (archived)' : '' ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-text">What they can see and change. <a href="roles.php" target="_blank">Roles <i class="fas fa-external-link-alt small"></i></a></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- How they sign in -->
|
||||
<div class="tab-pane fade" id="<?= $form_id ?>Security">
|
||||
<div class="row g-3">
|
||||
<div class="col-12">
|
||||
<label class="form-label"><?= $is_new ? 'Password <strong class="text-danger">*</strong>' : 'New password' ?></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-lock"></i></span>
|
||||
<input type="password" class="form-control font-monospace" data-toggle="password" name="<?= $is_new ? 'password' : 'new_password' ?>" id="<?= $form_id ?>Password"
|
||||
placeholder="<?= $is_new ? 'At least ' . USER_PASSWORD_MIN . ' characters' : 'Leave blank to keep their password' ?>" minlength="<?= USER_PASSWORD_MIN ?>" autocomplete="new-password" <?= $is_new ? 'required' : '' ?> data-user-password>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<button class="btn btn-outline-secondary clipboardjs" type="button" title="Copy password" data-clipboard-target="#<?= $form_id ?>Password"><i class="far fa-fw fa-copy"></i></button>
|
||||
<button class="btn btn-outline-secondary" type="button" title="Make one up - words that are easy to read out" data-user-generate><i class="fas fa-fw fa-magic"></i></button>
|
||||
</div>
|
||||
<div class="form-text">
|
||||
<?php if ($is_new) { ?>
|
||||
Give it to them yourself, or have it emailed - either way, they should change it once they're in.
|
||||
<?php } else { ?>
|
||||
Set, they're emailed that it changed. It also unlocks their copy of the credential vault, so it is set here rather than reset by email.
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ($is_new) { ?>
|
||||
<div class="col-12">
|
||||
<?php if (!empty($config_smtp_host)) { ?>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="send_email" value="1" id="<?= $form_id ?>SendEmail" checked>
|
||||
<label class="form-check-label" for="<?= $form_id ?>SendEmail">Email them their sign in details</label>
|
||||
<div class="form-text mt-0">The address, the password and where to sign in.</div>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
<div class="small text-body-secondary"><i class="fas fa-fw fa-envelope me-1"></i>Mail isn't set up, so nothing is emailed - give them their password yourself.</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="col-12">
|
||||
<div class="border rounded p-3">
|
||||
<div class="d-flex align-items-center gap-2 mb-2">
|
||||
<span class="fw-semibold"><i class="fas fa-fw fa-mobile-alt text-body-secondary me-1"></i>Multi-factor authentication</span>
|
||||
<?php if (!$is_new) { ?><?= userMfaPill($form['user_token'] ?? '', $form['user_config_force_mfa'] ?? 0) ?><?php } ?>
|
||||
</div>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="force_mfa" value="1" id="<?= $form_id ?>ForceMfa" <?= intval($form['user_config_force_mfa'] ?? 0) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="<?= $form_id ?>ForceMfa">Require it</label>
|
||||
<div class="form-text mt-0">Without it set up, they set it up at their next sign in - and they cannot turn it off.</div>
|
||||
</div>
|
||||
<?php if ($form_has_mfa) { ?>
|
||||
<div class="form-check mt-2">
|
||||
<input class="form-check-input" type="checkbox" name="reset_mfa" value="1" id="<?= $form_id ?>ResetMfa">
|
||||
<label class="form-check-label" for="<?= $form_id ?>ResetMfa">Reset it</label>
|
||||
<div class="form-text mt-0">For a lost or replaced phone - their authenticator app is forgotten, and so are their remembered browsers.</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- The clients they see -->
|
||||
<div class="tab-pane fade" id="<?= $form_id ?>Access">
|
||||
<input type="hidden" name="client_permission_shown" value="1">
|
||||
|
||||
<div data-user-access-admin hidden>
|
||||
<div class="alert alert-info small d-flex gap-2">
|
||||
<i class="fas fa-user-shield mt-1"></i>
|
||||
<div>An admin sees every client, so these rules don't apply to them. Rules already set are kept, in case the role changes back.</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div data-user-access-rules>
|
||||
<div class="small text-body-secondary mb-2">
|
||||
<strong class="text-success-emphasis">Only</strong> limits them to those clients - with none, they see every client.
|
||||
<strong class="text-danger-emphasis">Never</strong> keeps them out of a client, whatever else is set.
|
||||
</div>
|
||||
<div class="d-flex flex-wrap gap-2 align-items-center mb-2">
|
||||
<div class="input-group input-group-sm flex-grow-1" style="max-width: 18rem">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-search"></i></span>
|
||||
<input type="search" class="form-control" placeholder="Find a client" data-user-access-filter aria-label="Find a client">
|
||||
</div>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Set every client shown">
|
||||
<button type="button" class="btn btn-outline-secondary" data-user-access-all="" title="Every client shown">Clear</button>
|
||||
<button type="button" class="btn btn-outline-success" data-user-access-all="allow" title="Every client shown">All only</button>
|
||||
<button type="button" class="btn btn-outline-danger" data-user-access-all="deny" title="Every client shown">All never</button>
|
||||
</div>
|
||||
<span class="small fw-semibold ms-auto" data-user-access-summary></span>
|
||||
</div>
|
||||
|
||||
<div class="border rounded itflow-user-access">
|
||||
<table class="table table-sm table-hover align-middle mb-0">
|
||||
<tbody>
|
||||
<?php foreach ($form_clients as $client) {
|
||||
$cid = intval($client['client_id']);
|
||||
$rule = isset($form_access['allow'][$cid]) ? 'allow' : (isset($form_access['deny'][$cid]) ? 'deny' : '');
|
||||
$tone = clientInitialsTone($cid);
|
||||
$radio = "{$form_id}Client{$cid}";
|
||||
?>
|
||||
<tr data-user-access-row data-name="<?= escapeHtml(mb_strtolower($client['client_name'] . ' ' . $client['client_abbreviation'])) ?>">
|
||||
<td class="ps-2">
|
||||
<span class="itflow-client-avatar itflow-client-avatar-xs bg-<?= $tone ?>-subtle text-<?= $tone ?>-emphasis me-2" aria-hidden="true"><?= escapeHtml(clientInitials($client['client_abbreviation'], $client['client_name'])) ?></span><?= escapeHtml($client['client_name']) ?>
|
||||
<?php if ($client['client_archived_at']) { ?><span class="badge rounded-pill text-bg-secondary fw-normal ms-1">Archived</span><?php } ?>
|
||||
</td>
|
||||
<td class="text-end pe-2 text-nowrap">
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="<?= escapeHtml($client['client_name']) ?>">
|
||||
<input type="radio" class="btn-check" name="client_permission[<?= $cid ?>]" value="" id="<?= $radio ?>None" <?= $rule === '' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-secondary" for="<?= $radio ?>None" title="No rule">-</label>
|
||||
<input type="radio" class="btn-check" name="client_permission[<?= $cid ?>]" value="allow" id="<?= $radio ?>Allow" <?= $rule === 'allow' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-success" for="<?= $radio ?>Allow">Only</label>
|
||||
<input type="radio" class="btn-check" name="client_permission[<?= $cid ?>]" value="deny" id="<?= $radio ?>Deny" <?= $rule === 'deny' ? 'checked' : '' ?>>
|
||||
<label class="btn btn-outline-danger" for="<?= $radio ?>Deny">Never</label>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php if (!$form_clients) { ?>
|
||||
<tr><td class="text-body-secondary p-3">No clients yet.</td></tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var root = document.getElementById(<?= json_encode($form_id) ?>);
|
||||
if (!root) {
|
||||
return;
|
||||
}
|
||||
var form = root.closest('form');
|
||||
|
||||
// The picture - shown as soon as it is picked
|
||||
var avatarInput = root.querySelector('[data-user-avatar-input]');
|
||||
var avatarPreview = root.querySelector('[data-user-avatar-preview]');
|
||||
var avatarOriginal = avatarPreview.innerHTML;
|
||||
var avatarRemove = root.querySelector('[data-user-avatar-remove]');
|
||||
avatarInput.addEventListener('change', function () {
|
||||
var file = avatarInput.files && avatarInput.files[0];
|
||||
if (file && /^image\//.test(file.type)) {
|
||||
var img = document.createElement('img');
|
||||
img.className = 'itflow-contact-avatar itflow-contact-avatar-lg';
|
||||
img.alt = '';
|
||||
img.src = URL.createObjectURL(file);
|
||||
avatarPreview.replaceChildren(img);
|
||||
if (avatarRemove) {
|
||||
avatarRemove.checked = false;
|
||||
}
|
||||
} else {
|
||||
avatarPreview.innerHTML = avatarOriginal;
|
||||
}
|
||||
});
|
||||
if (avatarRemove) {
|
||||
avatarRemove.addEventListener('change', function () {
|
||||
avatarPreview.classList.toggle('opacity-25', avatarRemove.checked);
|
||||
if (avatarRemove.checked) {
|
||||
avatarInput.value = '';
|
||||
avatarPreview.innerHTML = avatarOriginal;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// No picture - their initials, as the name is typed
|
||||
var nameInput = root.querySelector('[data-user-name]');
|
||||
nameInput.addEventListener('input', function () {
|
||||
var initials = avatarPreview.querySelector('span.itflow-contact-avatar');
|
||||
if (initials && !(avatarInput.files && avatarInput.files.length)) {
|
||||
var words = nameInput.value.trim().split(/\s+/).filter(Boolean).slice(0, 2);
|
||||
initials.textContent = words.map(function (w) { return w.charAt(0).toUpperCase(); }).join('') || '?';
|
||||
}
|
||||
});
|
||||
|
||||
// Make up a password - words, easy to read out over the phone
|
||||
var password = root.querySelector('[data-user-password]');
|
||||
root.querySelector('[data-user-generate]').addEventListener('click', function () {
|
||||
itflowGet('/agent/ajax.php', { get_readable_pass: 'true' }, function (data) {
|
||||
password.value = JSON.parse(data);
|
||||
password.type = 'text';
|
||||
var eye = password.closest('.input-group').querySelector('.fa-eye');
|
||||
if (eye) {
|
||||
eye.classList.replace('fa-eye', 'fa-eye-slash');
|
||||
}
|
||||
password.dispatchEvent(new Event('input'));
|
||||
});
|
||||
});
|
||||
|
||||
// Client access: an admin sees everything, so the rules are put away
|
||||
var role = root.querySelector('[data-user-role]');
|
||||
var adminNote = root.querySelector('[data-user-access-admin]');
|
||||
var rules = root.querySelector('[data-user-access-rules]');
|
||||
function roleChanged() {
|
||||
var option = role.options[role.selectedIndex];
|
||||
var isAdmin = option && option.dataset.roleAdmin === '1';
|
||||
adminNote.hidden = !isAdmin;
|
||||
rules.classList.toggle('opacity-50', isAdmin);
|
||||
}
|
||||
role.addEventListener('change', roleChanged);
|
||||
roleChanged();
|
||||
|
||||
// What the rules add up to
|
||||
var summary = root.querySelector('[data-user-access-summary]');
|
||||
function summarize() {
|
||||
var allow = root.querySelectorAll('[data-user-access-row] input[value="allow"]:checked').length;
|
||||
var deny = root.querySelectorAll('[data-user-access-row] input[value="deny"]:checked').length;
|
||||
var text, tone;
|
||||
if (allow) {
|
||||
text = 'Sees ' + allow + ' client' + (allow === 1 ? '' : 's') + ' only';
|
||||
tone = 'text-warning-emphasis';
|
||||
} else if (deny) {
|
||||
text = 'Sees all but ' + deny + ' client' + (deny === 1 ? '' : 's');
|
||||
tone = 'text-warning-emphasis';
|
||||
} else {
|
||||
text = 'Sees every client';
|
||||
tone = 'text-success-emphasis';
|
||||
}
|
||||
summary.textContent = text;
|
||||
summary.className = 'small fw-semibold ms-auto ' + tone;
|
||||
}
|
||||
root.addEventListener('change', function (e) {
|
||||
if (e.target.matches('[data-user-access-row] input')) {
|
||||
summarize();
|
||||
}
|
||||
});
|
||||
summarize();
|
||||
|
||||
// Find a client, and set every one shown at once
|
||||
var filter = root.querySelector('[data-user-access-filter]');
|
||||
filter.addEventListener('input', function () {
|
||||
var term = filter.value.trim().toLowerCase();
|
||||
root.querySelectorAll('[data-user-access-row]').forEach(function (row) {
|
||||
row.hidden = term !== '' && row.dataset.name.indexOf(term) === -1;
|
||||
});
|
||||
});
|
||||
// Enter in the filter would submit the whole form
|
||||
filter.addEventListener('keydown', function (e) {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
root.querySelectorAll('[data-user-access-all]').forEach(function (button) {
|
||||
button.addEventListener('click', function () {
|
||||
var value = button.dataset.userAccessAll;
|
||||
root.querySelectorAll('[data-user-access-row]').forEach(function (row) {
|
||||
if (!row.hidden) {
|
||||
var radio = row.querySelector('input[value="' + value + '"]');
|
||||
if (radio) {
|
||||
radio.checked = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
summarize();
|
||||
});
|
||||
});
|
||||
|
||||
// A required field on a tab not showing - show that tab, so the browser can point at it
|
||||
form.addEventListener('invalid', function (e) {
|
||||
var pane = e.target.closest('.tab-pane');
|
||||
if (pane && !pane.classList.contains('active')) {
|
||||
var link = form.querySelector('[href="#' + pane.id + '"]');
|
||||
if (link) {
|
||||
bootstrap.Tab.getOrCreateInstance(link).show();
|
||||
}
|
||||
}
|
||||
}, true);
|
||||
})();
|
||||
</script>
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-user-plus"></i>Invite User</h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Email <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
|
||||
<input type="email" class="form-control" name="email" placeholder="Email Address" maxlength="200" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Role <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role" required>
|
||||
<option value="">- Role -</option>
|
||||
<!-- //TODO: Pull from roles -->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="invite_user" class="btn btn-primary text-bold"><i class="fas fa-paper-plane me-2"></i>Send Invite</button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
@@ -1,73 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Restore User - back from the archive, with a role and a new password (the
|
||||
* old one, and their copy of the vault key, were wiped when archived).
|
||||
*/
|
||||
|
||||
require_once '../../includes/modal_header.php';
|
||||
|
||||
$user_id = intval($_GET['id']);
|
||||
$user = userForModal($_GET['id'] ?? 0);
|
||||
$user_id = intval($user['user_id']);
|
||||
$name = trim(str_replace(' (archived)', '', $user['user_name']));
|
||||
$role_id = intval($user['user_role_id']);
|
||||
$roles = userRoles($role_id);
|
||||
$email_taken = mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM users WHERE user_email = '" . escapeSql($user['user_email']) . "' AND user_archived_at IS NULL AND user_id <> $user_id"));
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT user_avatar, user_email, user_name, user_role_id FROM users WHERE user_id = $user_id AND user_archived_at IS NOT NULL LIMIT 1");
|
||||
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$user_name = str_replace(" (archived)", "", $row['user_name']); //Removed (archived) from user_name
|
||||
$user_name = escapeHtml($user_name);
|
||||
$user_email = escapeHtml($row['user_email']);
|
||||
$user_avatar = escapeHtml($row['user_avatar']);
|
||||
$user_initials = initials($user_name);
|
||||
$user_role_id = intval($row['user_role_id']);
|
||||
|
||||
// Generate the HTML form content using output buffering.
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="modal-header bg-dark">
|
||||
<h5 class="modal-title"><i class="fas fa-fw fa-redo-alt me-2"></i>Restoring user:
|
||||
<strong><?= $user_name ?></strong></h5>
|
||||
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-redo-alt me-2"></i>Restore <?= escapeHtml($name) ?></h5>
|
||||
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
|
||||
</div>
|
||||
<form action="post.php" method="post" autocomplete="off">
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="user_id" value="<?= $user_id ?>">
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
|
||||
<center class="mb-3">
|
||||
<?php if (!empty($user_avatar)) { ?>
|
||||
<img class="img-fluid" src="<?= "../uploads/users/$user_id/$user_avatar" ?>">
|
||||
<?php } else { ?>
|
||||
<span class="fa-stack fa-4x">
|
||||
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
|
||||
<span class="fa fa-stack-1x text-white"><?= $user_initials ?></span>
|
||||
</span>
|
||||
<?php } ?>
|
||||
</center>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Set a New Password</label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
|
||||
<input type="password" class="form-control" data-toggle="password" name="new_password"
|
||||
placeholder="Enter a new password" autocomplete="new-password" required>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<div class="d-flex align-items-center gap-3 mb-3">
|
||||
<?= userAvatar($user_id, $name, $user['user_avatar'], 'lg') ?>
|
||||
<div class="min-w-0">
|
||||
<div class="fw-semibold"><?= escapeHtml($name) ?></div>
|
||||
<div class="small text-body-secondary"><?= escapeHtml($user['user_email']) ?> · archived <?= escapeHtml(timeAgo($user['user_archived_at'])) ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (agentUserLimitReached()) { ?>
|
||||
<div class="alert alert-danger small"><?= agentUserLimitMessage() ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($email_taken) { ?>
|
||||
<div class="alert alert-warning small"><i class="fas fa-exclamation-triangle me-2"></i><strong><?= escapeHtml($user['user_email']) ?></strong> signs in to another account now - change that one's email first.</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="mb-3">
|
||||
<label>Role <strong class="text-danger">*</strong></label>
|
||||
<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-user-shield"></i></span>
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-lock"></i></span>
|
||||
<input type="password" class="form-control font-monospace" data-toggle="password" name="new_password" id="userRestorePassword<?= $user_id ?>"
|
||||
placeholder="At least <?= USER_PASSWORD_MIN ?> characters" minlength="<?= USER_PASSWORD_MIN ?>" autocomplete="new-password" required>
|
||||
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
|
||||
<button class="btn btn-outline-secondary clipboardjs" type="button" title="Copy password" data-clipboard-target="#userRestorePassword<?= $user_id ?>"><i class="far fa-fw fa-copy"></i></button>
|
||||
<button class="btn btn-outline-secondary" type="button" title="Make one up - words that are easy to read out" data-user-restore-generate><i class="fas fa-fw fa-magic"></i></button>
|
||||
</div>
|
||||
<div class="form-text">Their old password was wiped when they were archived - give them this one, and have them change it.</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label class="form-label">Role <strong class="text-danger">*</strong></label>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-user-shield"></i></span>
|
||||
<select class="form-select select2" name="role" required>
|
||||
<?php
|
||||
$sql_user_roles = mysqli_query($mysqli, "SELECT role_id, role_name FROM user_roles WHERE role_archived_at IS NULL");
|
||||
while ($row = mysqli_fetch_assoc($sql_user_roles)) {
|
||||
$role_id = intval($row['role_id']);
|
||||
$role_name = escapeHtml($row['role_name']);
|
||||
|
||||
?>
|
||||
<option <?php if ($role_id == $user_role_id) {echo "selected";} ?> value="<?= $role_id ?>"><?= $role_name ?></option>
|
||||
<?php if (!isset($roles[$role_id])) { ?>
|
||||
<option value="">- Pick a role -</option>
|
||||
<?php } ?>
|
||||
<?php foreach ($roles as $id => $role) { ?>
|
||||
<option value="<?= $id ?>" <?= $id === $role_id ? 'selected' : '' ?><?= selectOptionRole($role) ?>><?= escapeHtml($role['role_name']) ?><?= $role['role_archived_at'] ? ' (archived)' : '' ?></option>
|
||||
<?php } ?>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="restore_user" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Restore</button>
|
||||
@@ -75,5 +75,17 @@ ob_start();
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
var password = document.getElementById('userRestorePassword<?= $user_id ?>');
|
||||
password.closest('form').querySelector('[data-user-restore-generate]').addEventListener('click', function () {
|
||||
itflowGet('/agent/ajax.php', { get_readable_pass: 'true' }, function (data) {
|
||||
password.value = JSON.parse(data);
|
||||
password.type = 'text';
|
||||
});
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
require_once "../../../includes/modal_footer.php";
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
<?php
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
$name = escapeSql($_POST['name']);
|
||||
$email = escapeSql($_POST['email']);
|
||||
$role = intval($_POST['role']);
|
||||
$force_mfa = intval($_POST['force_mfa'] ?? 0);
|
||||
@@ -2,10 +2,25 @@
|
||||
|
||||
/*
|
||||
* ITFlow - GET/POST request handler for user (agent) management
|
||||
*
|
||||
* Every change goes through functions/user.php: an email no other account
|
||||
* signs in with, a role that exists, a password of at least
|
||||
* USER_PASSWORD_MIN characters set together with the agent's vault key, a
|
||||
* picture that really is one. An admin changes their own account from their
|
||||
* Account pages, not here, and the last active admin cannot be demoted,
|
||||
* disabled or archived - there would be nobody left to undo it.
|
||||
*/
|
||||
|
||||
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
|
||||
|
||||
/** Refuse a change that would leave no active admin. */
|
||||
function userGuardLastAdmin($row, $what) {
|
||||
if (userIsLastAdmin($row)) {
|
||||
flashAlert("<strong>" . $row['user_name'] . "</strong> is the only active admin - $what would leave nobody to run ITFlow. Make someone else an admin first.", 'error');
|
||||
redirect();
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_POST['add_user'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
@@ -15,97 +30,57 @@ if (isset($_POST['add_user'])) {
|
||||
redirect();
|
||||
}
|
||||
|
||||
require_once 'user_model.php';
|
||||
|
||||
$password = password_hash(trim($_POST['password']), PASSWORD_DEFAULT);
|
||||
$user_specific_encryption_ciphertext = encryptUserSpecificKey(trim($_POST['password']));
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO users SET user_name = '$name', user_email = '$email', user_password = '$password', user_specific_encryption_ciphertext = '$user_specific_encryption_ciphertext', user_role_id = $role");
|
||||
$error = '';
|
||||
$identity = userCheckIdentity($_POST, 0, $error);
|
||||
$role = $identity ? userCheckRole($_POST['role'] ?? 0, 0, $error) : null;
|
||||
$password = (string) ($_POST['password'] ?? '');
|
||||
if ($role && ($problem = userPasswordProblem($password))) {
|
||||
$error = $problem;
|
||||
}
|
||||
if (!$identity || !$role || $error !== '') {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
[$name, $email] = $identity;
|
||||
$role_id = intval($role['role_id']);
|
||||
|
||||
mysqli_query($mysqli, "INSERT INTO users SET user_name = '" . escapeSql($name) . "', user_email = '" . escapeSql($email) . "', user_password = '', user_role_id = $role_id");
|
||||
$user_id = mysqli_insert_id($mysqli);
|
||||
userSetPassword($user_id, $password);
|
||||
|
||||
// Add Client Access (allow / deny per client)
|
||||
if (isset($_POST['client_permission'])) {
|
||||
foreach ($_POST['client_permission'] as $perm_client_id => $perm_type) {
|
||||
$perm_client_id = intval($perm_client_id);
|
||||
if ($perm_type === 'allow' || $perm_type === 'deny') {
|
||||
mysqli_query($mysqli, "INSERT INTO user_client_permissions SET user_id = $user_id, client_id = $perm_client_id, permission_type = '$perm_type'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!file_exists("../uploads/users/$user_id/")) {
|
||||
mkdir("../uploads/users/$user_id");
|
||||
}
|
||||
|
||||
// Check for and process image/photo
|
||||
$extended_alert_description = '';
|
||||
if (isset($_FILES['file']['tmp_name'])) {
|
||||
if ($new_file_name = checkFileUpload($_FILES['file'], array('jpg', 'jpeg', 'gif', 'png', 'webp'))) {
|
||||
|
||||
$file_tmp_path = $_FILES['file']['tmp_name'];
|
||||
|
||||
// directory in which the uploaded file will be moved
|
||||
$upload_file_dir = "../uploads/users/$user_id/";
|
||||
$dest_path = $upload_file_dir . $new_file_name;
|
||||
move_uploaded_file($file_tmp_path, $dest_path);
|
||||
|
||||
// Set Avatar
|
||||
mysqli_query($mysqli, "UPDATE users SET user_avatar = '$new_file_name' WHERE user_id = $user_id");
|
||||
$extended_alert_description = '. File successfully uploaded.';
|
||||
}
|
||||
}
|
||||
|
||||
// Create Settings
|
||||
$force_mfa = !empty($_POST['force_mfa']) ? 1 : 0;
|
||||
mysqli_query($mysqli, "INSERT INTO user_settings SET user_id = $user_id, user_config_force_mfa = $force_mfa");
|
||||
|
||||
$sql = mysqli_query($mysqli,"SELECT company_name FROM companies WHERE company_id = 1");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$company_name = escapeSql($row['company_name']);
|
||||
|
||||
// Sanitize Config vars from load_global_settings.php
|
||||
$config_mail_from_name = escapeSql($config_mail_from_name);
|
||||
$config_mail_from_email = escapeSql($config_mail_from_email);
|
||||
$config_ticket_from_email = escapeSql($config_ticket_from_email);
|
||||
$config_login_key_secret = mysqli_real_escape_string($mysqli, $config_login_key_secret);
|
||||
$config_base_url = escapeSql($config_base_url);
|
||||
|
||||
// Send user e-mail, if specified
|
||||
if (isset($_POST['send_email']) && !empty($config_smtp_host) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
|
||||
$password = mysqli_real_escape_string($mysqli, $_POST['password']);
|
||||
|
||||
// Only hand out the login key when the gate is actually enabled - same test as post/logout.php
|
||||
$login_url = "https://$config_base_url/login.php";
|
||||
if ($config_login_key_required == 1) {
|
||||
$login_url .= "?key=$config_login_key_secret";
|
||||
}
|
||||
|
||||
$subject = "Your new $company_name ITFlow account";
|
||||
$body = "Hello $name,<br><br>An ITFlow account has been setup for you. Please change your password upon login. <br><br>Username: $email <br>Password: $password<br>Login URL: $login_url<br><br>--<br>$company_name - Support<br>$config_ticket_from_email";
|
||||
|
||||
$data = [
|
||||
[
|
||||
'from' => $config_mail_from_email,
|
||||
'from_name' => $config_mail_from_name,
|
||||
'recipient' => $email,
|
||||
'recipient_name' => $name,
|
||||
'subject' => $subject,
|
||||
'body' => $body
|
||||
]
|
||||
];
|
||||
$mail = addToMailQueue($data);
|
||||
|
||||
if ($mail !== true) {
|
||||
mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Mail', notification = 'Failed to send email to $email'");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Mail', log_action = 'Error', log_description = 'Failed to send email to $email regarding $subject. $mail', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id, log_entity_id = $user_id");
|
||||
}
|
||||
|
||||
if (!intval($role['role_is_admin'])) {
|
||||
userSetClientAccess($user_id, $_POST['client_permission'] ?? []);
|
||||
}
|
||||
|
||||
logAudit("User", "Create", "$session_name created user $name", 0, $user_id);
|
||||
$notes = [];
|
||||
$avatar_error = '';
|
||||
if (!empty($_FILES['avatar']['tmp_name']) && !userSaveAvatar($user_id, $_FILES['avatar'], $avatar_error)) {
|
||||
$notes[] = $avatar_error . ' The user was created without one';
|
||||
}
|
||||
|
||||
flashAlert("User <strong>$name</strong> created" . $extended_alert_description);
|
||||
// Their sign in details by email - the password goes as typed, so it is theirs to change
|
||||
if (!empty($_POST['send_email']) && !empty($config_smtp_host)) {
|
||||
$company_name = (string) mysqli_fetch_row(mysqli_query($mysqli, "SELECT company_name FROM companies WHERE company_id = 1"))[0];
|
||||
$login_url = "https://$config_base_url/login.php" . ($config_login_key_required == 1 ? "?key=$config_login_key_secret" : '');
|
||||
$mail = userQueueMail($email, $name, "Your new $company_name ITFlow account",
|
||||
'Hello ' . escapeHtml($name) . ',<br><br>An ITFlow account has been set up for you. Please change your password after you sign in'
|
||||
. ($force_mfa ? ', and have an authenticator app ready - you will set up multi-factor authentication the first time' : '') . '.<br><br>'
|
||||
. 'Email: ' . escapeHtml($email) . '<br>Password: ' . escapeHtml($password) . '<br>Sign in at: ' . escapeHtml($login_url)
|
||||
. '<br><br>--<br>' . escapeHtml($company_name) . ' - Support<br>' . escapeHtml($config_ticket_from_email));
|
||||
if ($mail === true) {
|
||||
$notes[] = 'their sign in details were emailed to them';
|
||||
} else {
|
||||
$notes[] = 'the email with their sign in details could not be queued';
|
||||
logApp('Mail', 'error', 'Failed to queue the new account email for ' . $email . ": $mail");
|
||||
}
|
||||
}
|
||||
|
||||
logAudit("User", "Create", "$session_name created user " . escapeSql($name), 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$name</strong> created" . ($notes ? ' - ' . implode('; ', $notes) : ''), $avatar_error ? 'warning' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -115,80 +90,62 @@ if (isset($_POST['edit_user'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
require_once 'user_model.php';
|
||||
$row = userForRequest($_POST['user_id'] ?? 0);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
$user_id = intval($_POST['user_id']);
|
||||
$error = '';
|
||||
$identity = userCheckIdentity($_POST, $user_id, $error);
|
||||
$role = $identity ? userCheckRole($_POST['role'] ?? 0, $row['user_role_id'], $error) : null;
|
||||
$new_password = (string) ($_POST['new_password'] ?? '');
|
||||
if ($role && $new_password !== '' && ($problem = userPasswordProblem($new_password))) {
|
||||
$error = $problem;
|
||||
}
|
||||
if (!$identity || !$role || $error !== '') {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
[$name, $email] = $identity;
|
||||
if (intval($row['role_is_admin']) && !intval($role['role_is_admin'])) {
|
||||
userGuardLastAdmin($row, 'a role without admin');
|
||||
}
|
||||
|
||||
$new_password = trim($_POST['new_password']);
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '" . escapeSql($name) . "', user_email = '" . escapeSql($email) . "', user_role_id = " . intval($role['role_id']) . " WHERE user_id = $user_id");
|
||||
$force_mfa = !empty($_POST['force_mfa']) ? 1 : 0;
|
||||
mysqli_query($mysqli, "INSERT INTO user_settings SET user_id = $user_id, user_config_force_mfa = $force_mfa ON DUPLICATE KEY UPDATE user_config_force_mfa = $force_mfa");
|
||||
|
||||
// Update Client Access (allow / deny per client)
|
||||
mysqli_query($mysqli,"DELETE FROM user_client_permissions WHERE user_id = $user_id");
|
||||
if (isset($_POST['client_permission'])) {
|
||||
foreach ($_POST['client_permission'] as $perm_client_id => $perm_type) {
|
||||
$perm_client_id = intval($perm_client_id);
|
||||
if ($perm_type === 'allow' || $perm_type === 'deny') {
|
||||
mysqli_query($mysqli, "INSERT INTO user_client_permissions SET user_id = $user_id, client_id = $perm_client_id, permission_type = '$perm_type'");
|
||||
}
|
||||
// An admin sees every client - their rules are left as they were, in case the role changes back
|
||||
if (!intval($role['role_is_admin']) && isset($_POST['client_permission_shown'])) {
|
||||
userSetClientAccess($user_id, $_POST['client_permission'] ?? []);
|
||||
}
|
||||
|
||||
$changes = [];
|
||||
if ($new_password !== '') {
|
||||
userSetPassword($user_id, $new_password);
|
||||
$changes[] = 'password changed';
|
||||
userNotifyChange($name, $email, 'an administrator set a new password');
|
||||
}
|
||||
if (!empty($_POST['reset_mfa']) && trim((string) $row['user_token']) !== '') {
|
||||
userResetMfa($user_id);
|
||||
$changes[] = 'MFA reset';
|
||||
userNotifyChange($name, $email, 'an administrator turned off multi-factor authentication' . ($force_mfa ? ' - you will set it up again at your next sign in' : ''));
|
||||
}
|
||||
if (strcasecmp($email, $row['user_email']) !== 0) {
|
||||
$changes[] = 'email changed';
|
||||
userNotifyChange($name, $row['user_email'], 'its email address is now ' . $email);
|
||||
}
|
||||
$avatar_error = '';
|
||||
if (!empty($_POST['remove_avatar'])) {
|
||||
userRemoveAvatar($user_id);
|
||||
$changes[] = 'avatar removed';
|
||||
} elseif (!empty($_FILES['avatar']['tmp_name'])) {
|
||||
if (userSaveAvatar($user_id, $_FILES['avatar'], $avatar_error)) {
|
||||
$changes[] = 'avatar updated';
|
||||
}
|
||||
}
|
||||
|
||||
// Get current Avatar
|
||||
$sql = mysqli_query($mysqli, "SELECT user_avatar FROM users WHERE user_id = $user_id");
|
||||
$row = mysqli_fetch_assoc($sql);
|
||||
$existing_file_name = escapeSql($row['user_avatar']);
|
||||
logAudit("User", "Edit", "$session_name edited user " . escapeSql($name) . ($changes ? ' - ' . escapeSql(implode(', ', $changes)) : ''), 0, $user_id);
|
||||
|
||||
$extended_log_description = '';
|
||||
if (!empty($_POST['2fa'])) {
|
||||
$two_fa = $_POST['2fa'];
|
||||
}
|
||||
|
||||
if (!file_exists("../uploads/users/$user_id/")) {
|
||||
mkdir("../uploads/users/$user_id");
|
||||
}
|
||||
|
||||
// Check for and process image/photo
|
||||
$extended_alert_description = '';
|
||||
if (isset($_FILES['file']['tmp_name'])) {
|
||||
if ($new_file_name = checkFileUpload($_FILES['file'], array('jpg', 'jpeg', 'gif', 'png', 'webp'))) {
|
||||
|
||||
$file_tmp_path = $_FILES['file']['tmp_name'];
|
||||
|
||||
// directory in which the uploaded file will be moved
|
||||
$upload_file_dir = "../uploads/users/$user_id/";
|
||||
$dest_path = $upload_file_dir . $new_file_name;
|
||||
move_uploaded_file($file_tmp_path, $dest_path);
|
||||
|
||||
// Delete old file
|
||||
unlink("../uploads/users/$user_id/$existing_file_name");
|
||||
|
||||
// Set Avatar
|
||||
mysqli_query($mysqli, "UPDATE users SET user_avatar = '$new_file_name' WHERE user_id = $user_id");
|
||||
$extended_alert_description = '. File successfully uploaded.';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '$name', user_email = '$email', user_role_id = $role WHERE user_id = $user_id");
|
||||
|
||||
if (!empty($new_password)) {
|
||||
$new_password = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
$user_specific_encryption_ciphertext = encryptUserSpecificKey(trim($_POST['new_password']));
|
||||
mysqli_query($mysqli, "UPDATE users SET user_password = '$new_password', user_specific_encryption_ciphertext = '$user_specific_encryption_ciphertext' WHERE user_id = $user_id");
|
||||
//Extended Logging
|
||||
$extended_log_description .= ", password changed";
|
||||
}
|
||||
|
||||
if (!empty($two_fa) && $two_fa == 'disable') {
|
||||
mysqli_query($mysqli, "UPDATE users SET user_token = '' WHERE user_id = '$user_id'");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'User', log_action = 'Modify', log_description = '$session_name disabled 2FA for $name', log_ip = '$session_ip', log_user_agent = '$session_user_agent', log_user_id = $session_user_id");
|
||||
}
|
||||
|
||||
//Update User Settings
|
||||
mysqli_query($mysqli, "UPDATE user_settings SET user_config_force_mfa = $force_mfa WHERE user_id = $user_id");
|
||||
|
||||
logAudit("User", "Edit", "$session_name edited user $name", 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$name</strong> updated" . $extended_alert_description);
|
||||
flashAlert("User <strong>$name</strong> saved" . ($changes ? ' - ' . implode(', ', $changes) : '') . ($avatar_error ? ". $avatar_error" : ''), $avatar_error ? 'warning' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -198,22 +155,20 @@ if (isset($_GET['activate_user'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$user_id = intval($_GET['activate_user']);
|
||||
$row = userForRequest($_GET['activate_user']);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
// Only a user who isn't already using a seat can push the count over the limit
|
||||
$seat_row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(user_id) FROM users WHERE user_id = $user_id AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL"));
|
||||
if (intval($seat_row[0]) === 0 && agentUserLimitReached()) {
|
||||
if ((intval($row['user_status']) !== 1 || $row['user_archived_at']) && agentUserLimitReached()) {
|
||||
flashAlert(agentUserLimitMessage(), 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$user_name = escapeSql(getFieldById('users', $user_id, 'user_name'));
|
||||
|
||||
mysqli_query($mysqli, "UPDATE users SET user_status = 1 WHERE user_id = $user_id");
|
||||
|
||||
logAudit("User", "Activate", "$session_name activated user $user_name", 0, $user_id);
|
||||
logAudit("User", "Activate", "$session_name activated user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$user_name</strong> activated");
|
||||
flashAlert("User <strong>" . $row['user_name'] . "</strong> can sign in again");
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -223,30 +178,16 @@ if (isset($_GET['disable_user'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$user_id = intval($_GET['disable_user']);
|
||||
|
||||
$user_name = escapeSql(getFieldById('users', $user_id, 'user_name'));
|
||||
$row = userForRequest($_GET['disable_user']);
|
||||
$user_id = intval($row['user_id']);
|
||||
userGuardLastAdmin($row, 'disabling them');
|
||||
|
||||
mysqli_query($mysqli, "UPDATE users SET user_status = 0 WHERE user_id = $user_id");
|
||||
userHandOverWork($user_id, 0, 'when ' . escapeSql($row['user_name']) . ' was disabled');
|
||||
|
||||
// Un-assign tickets. Collect them first so each one gets a history entry -
|
||||
// otherwise a whole queue silently goes unassigned with nothing to explain it
|
||||
$affected_ticket_ids = array();
|
||||
$sql_affected_tickets = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_assigned_to = $user_id AND ticket_closed_at IS NULL");
|
||||
while ($affected_ticket_row = mysqli_fetch_assoc($sql_affected_tickets)) {
|
||||
$affected_ticket_ids[] = intval($affected_ticket_row['ticket_id']);
|
||||
}
|
||||
logAudit("User", "Disable", "$session_name disabled user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE tickets SET ticket_assigned_to = 0 WHERE ticket_assigned_to = $user_id AND ticket_closed_at IS NULL");
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_assigned_to = 0 WHERE recurring_ticket_assigned_to = $user_id");
|
||||
|
||||
foreach ($affected_ticket_ids as $affected_ticket_id) {
|
||||
logTicketHistory($affected_ticket_id, "$session_name unassigned the ticket when $user_name was disabled");
|
||||
}
|
||||
|
||||
logAudit("User", "Disable", "$session_name disabled user $user_name", 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$user_name</strong> disabled", 'error');
|
||||
flashAlert("User <strong>" . $row['user_name'] . "</strong> disabled - they are signed out, and their open tickets are unassigned", 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -256,15 +197,32 @@ if (isset($_GET['revoke_remember_me'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$user_id = intval($_GET['revoke_remember_me']);
|
||||
|
||||
$user_name = escapeSql(getFieldById('users', $user_id, 'user_name'));
|
||||
$row = userForRequest($_GET['revoke_remember_me']);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = $user_id");
|
||||
|
||||
logAudit("User", "Edit", "$session_name revoked all remember me tokens for user $user_name", 0, $user_id);
|
||||
logAudit("User", "Edit", "$session_name revoked all remember me tokens for user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$user_name</strong> remember me tokens revoked", 'error');
|
||||
flashAlert("Remembered browsers forgotten for <strong>" . $row['user_name'] . "</strong> - every browser asks for their MFA code again");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_GET['reset_user_mfa'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$row = userForRequest($_GET['reset_user_mfa']);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
userResetMfa($user_id);
|
||||
userNotifyChange($row['user_name'], $row['user_email'], 'an administrator turned off multi-factor authentication' . (intval($row['user_config_force_mfa']) ? ' - you will set it up again at your next sign in' : ''));
|
||||
|
||||
logAudit("User", "Edit", "$session_name reset MFA for user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
|
||||
flashAlert("MFA reset for <strong>" . $row['user_name'] . "</strong>" . (intval($row['user_config_force_mfa']) ? ' - they set it up again at their next sign in' : ' - they sign in with their password alone until they turn it on'));
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -274,38 +232,26 @@ if (isset($_POST['archive_user'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$user_id = intval($_POST['user_id']);
|
||||
$ticket_assign = intval($_POST['ticket_assign']);
|
||||
$password = password_hash(randomString(), PASSWORD_DEFAULT);
|
||||
$row = userForRequest($_POST['user_id'] ?? 0);
|
||||
$user_id = intval($row['user_id']);
|
||||
userGuardLastAdmin($row, 'archiving them');
|
||||
|
||||
$user_name = escapeSql(getFieldById('users', $user_id, 'user_name'));
|
||||
|
||||
// Un-assign / Re-assign tickets. Same as above - collect them first so the
|
||||
// move shows up on each ticket's history
|
||||
$affected_ticket_ids = array();
|
||||
$sql_affected_tickets = mysqli_query($mysqli, "SELECT ticket_id FROM tickets WHERE ticket_assigned_to = $user_id AND ticket_closed_at IS NULL AND ticket_resolved_at IS NULL");
|
||||
while ($affected_ticket_row = mysqli_fetch_assoc($sql_affected_tickets)) {
|
||||
$affected_ticket_ids[] = intval($affected_ticket_row['ticket_id']);
|
||||
// Their work to an active agent, or to nobody
|
||||
$to_user_id = intval($_POST['ticket_assign'] ?? 0);
|
||||
if ($to_user_id && ($to_user_id === $user_id || !mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM users WHERE user_id = $to_user_id AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL")))) {
|
||||
$to_user_id = 0;
|
||||
}
|
||||
userHandOverWork($user_id, $to_user_id, 'when ' . escapeSql($row['user_name']) . ' was archived');
|
||||
|
||||
mysqli_query($mysqli, "UPDATE tickets SET ticket_assigned_to = $ticket_assign WHERE ticket_assigned_to = $user_id AND ticket_closed_at IS NULL AND ticket_resolved_at IS NULL");
|
||||
mysqli_query($mysqli, "UPDATE recurring_tickets SET recurring_ticket_assigned_to = $ticket_assign WHERE recurring_ticket_assigned_to = $user_id");
|
||||
// They can no longer sign in, and their copy of the vault key is gone - restoring sets a new password
|
||||
$archived_name = escapeSql(mb_substr($row['user_name'], 0, 189) . ' (archived)');
|
||||
$scrambled = escapeSql(password_hash(randomString(), PASSWORD_DEFAULT));
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '$archived_name', user_password = '$scrambled', user_status = 0, user_specific_encryption_ciphertext = '', user_archived_at = NOW() WHERE user_id = $user_id");
|
||||
mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = $user_id");
|
||||
|
||||
$reassigned_to_name = $ticket_assign ? escapeSql(getFieldById('users', $ticket_assign, 'user_name')) : '';
|
||||
foreach ($affected_ticket_ids as $affected_ticket_id) {
|
||||
if ($reassigned_to_name) {
|
||||
logTicketHistory($affected_ticket_id, "$session_name reassigned the ticket to $reassigned_to_name when $user_name was archived");
|
||||
} else {
|
||||
logTicketHistory($affected_ticket_id, "$session_name unassigned the ticket when $user_name was archived");
|
||||
}
|
||||
}
|
||||
logAudit("User", "Archive", "$session_name archived user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
|
||||
// Archive user query
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '$user_name (archived)', user_password = '$password', user_status = 0, user_specific_encryption_ciphertext = '', user_archived_at = NOW() WHERE user_id = $user_id");
|
||||
|
||||
logAudit("User", "Archive", "$session_name archived user $user_name", 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$user_name</strong> archived", 'error');
|
||||
flashAlert("User <strong>" . $row['user_name'] . "</strong> archived" . ($to_user_id ? ' - their open tickets went to ' . getFieldById('users', $to_user_id, 'user_name') : ''), 'error');
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -315,34 +261,133 @@ if (isset($_POST['restore_user'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$user_id = intval($_POST['user_id']);
|
||||
$row = userForRequest($_POST['user_id'] ?? 0);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
// Only a user who isn't already using a seat can push the count over the limit
|
||||
$seat_row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(user_id) FROM users WHERE user_id = $user_id AND user_type = 1 AND user_status = 1 AND user_archived_at IS NULL"));
|
||||
if (intval($seat_row[0]) === 0 && agentUserLimitReached()) {
|
||||
if (agentUserLimitReached()) {
|
||||
flashAlert(agentUserLimitMessage(), 'error');
|
||||
redirect();
|
||||
}
|
||||
$new_password = trim($_POST['new_password']);
|
||||
$role = intval($_POST['role']);
|
||||
|
||||
$user_name = getFieldById('users', $user_id, 'user_name');
|
||||
$user_name = escapeSql(str_replace(" (archived)", "", $user_name)); //Removed (archived) from user_name
|
||||
|
||||
// Restore user query
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '$user_name', user_status = 1, user_role_id = $role, user_archived_at = NULL WHERE user_id = $user_id");
|
||||
|
||||
if (!empty($new_password)) {
|
||||
$new_password = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
$user_specific_encryption_ciphertext = encryptUserSpecificKey(trim($_POST['new_password']));
|
||||
mysqli_query($mysqli, "UPDATE users SET user_password = '$new_password', user_specific_encryption_ciphertext = '$user_specific_encryption_ciphertext' WHERE user_id = $user_id");
|
||||
//Extended Logging
|
||||
$extended_log_description .= ", password changed";
|
||||
$error = '';
|
||||
$role = userCheckRole($_POST['role'] ?? 0, $row['user_role_id'], $error);
|
||||
$password = (string) ($_POST['new_password'] ?? '');
|
||||
if ($role && ($problem = userPasswordProblem($password))) {
|
||||
$error = $problem;
|
||||
}
|
||||
$name = trim(str_replace(' (archived)', '', $row['user_name']));
|
||||
if ($role && mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM users WHERE user_email = '" . escapeSql($row['user_email']) . "' AND user_archived_at IS NULL AND user_id <> $user_id"))) {
|
||||
$error = '<strong>' . $row['user_email'] . '</strong> signs in to another account now - change that one\'s email first.';
|
||||
}
|
||||
if (!$role || $error !== '') {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
logAudit("User", "Restored", "$session_name restored user $user_name", 0, $user_id);
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '" . escapeSql($name) . "', user_status = 1, user_role_id = " . intval($role['role_id']) . ", user_archived_at = NULL WHERE user_id = $user_id");
|
||||
userSetPassword($user_id, $password);
|
||||
|
||||
flashAlert("User <strong>$user_name</strong> restored");
|
||||
logAudit("User", "Restore", "$session_name restored user " . escapeSql($name), 0, $user_id);
|
||||
|
||||
flashAlert("User <strong>$name</strong> restored - give them their new password");
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_role_users'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$error = '';
|
||||
$role = userCheckRole($_POST['role'] ?? 0, 0, $error);
|
||||
if (!$role) {
|
||||
flashAlert($error, 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$kept = [];
|
||||
foreach (usersForBulk() as $user_id => $row) {
|
||||
if (intval($row['role_is_admin']) && !intval($role['role_is_admin']) && userIsLastAdmin($row)) {
|
||||
$kept[] = $row['user_name'];
|
||||
continue;
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE users SET user_role_id = " . intval($role['role_id']) . " WHERE user_id = $user_id");
|
||||
logAudit("User", "Edit", "$session_name set the role of user " . escapeSql($row['user_name']) . " to " . escapeSql($role['role_name']), 0, $user_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert("<strong>$count</strong> user" . ($count === 1 ? '' : 's') . " now " . ($count === 1 ? 'has' : 'have') . " the <strong>" . $role['role_name'] . "</strong> role" . ($kept ? ' - ' . implode(', ', $kept) . ' kept theirs, as the only admin' : ''), $kept ? 'warning' : 'success');
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_require_mfa_users']) || isset($_POST['bulk_unrequire_mfa_users'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$force = isset($_POST['bulk_require_mfa_users']) ? 1 : 0;
|
||||
$count = 0;
|
||||
foreach (usersForBulk() as $user_id => $row) {
|
||||
mysqli_query($mysqli, "INSERT INTO user_settings SET user_id = $user_id, user_config_force_mfa = $force ON DUPLICATE KEY UPDATE user_config_force_mfa = $force");
|
||||
logAudit("User", "Edit", "$session_name " . ($force ? 'required' : 'stopped requiring') . " MFA for user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert(($force ? "MFA required for" : "MFA no longer required for") . " <strong>$count</strong> user" . ($count === 1 ? '' : 's') . ($force ? ' - anyone without it sets it up at their next sign in' : ''));
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_revoke_remember_users'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$count = 0;
|
||||
foreach (usersForBulk() as $user_id => $row) {
|
||||
mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = $user_id");
|
||||
logAudit("User", "Edit", "$session_name revoked all remember me tokens for user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
flashAlert("Remembered browsers forgotten for <strong>$count</strong> user" . ($count === 1 ? '' : 's'));
|
||||
|
||||
redirect();
|
||||
|
||||
}
|
||||
|
||||
if (isset($_POST['bulk_disable_users']) || isset($_POST['bulk_activate_users'])) {
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
$activate = isset($_POST['bulk_activate_users']);
|
||||
$count = 0;
|
||||
$kept = [];
|
||||
foreach (usersForBulk() as $user_id => $row) {
|
||||
if ($row['user_archived_at'] || intval($row['user_status']) === ($activate ? 1 : 0)) {
|
||||
continue;
|
||||
}
|
||||
if ($activate && agentUserLimitReached()) {
|
||||
$kept[] = $row['user_name'];
|
||||
continue;
|
||||
}
|
||||
if (!$activate && userIsLastAdmin($row)) {
|
||||
$kept[] = $row['user_name'];
|
||||
continue;
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE users SET user_status = " . ($activate ? 1 : 0) . " WHERE user_id = $user_id");
|
||||
if (!$activate) {
|
||||
userHandOverWork($user_id, 0, 'when ' . escapeSql($row['user_name']) . ' was disabled');
|
||||
}
|
||||
logAudit("User", $activate ? "Activate" : "Disable", "$session_name " . ($activate ? 'activated' : 'disabled') . " user " . escapeSql($row['user_name']), 0, $user_id);
|
||||
$count++;
|
||||
}
|
||||
|
||||
$why = $activate ? 'the agent user limit is reached' : 'the only admin';
|
||||
flashAlert(($activate ? 'Activated' : 'Disabled') . " <strong>$count</strong> user" . ($count === 1 ? '' : 's') . ($kept ? ' - not ' . implode(', ', $kept) . " ($why)" : ''), $kept ? 'warning' : ($activate ? 'success' : 'error'));
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -359,7 +404,6 @@ if (isExportRequest('export_users')) {
|
||||
// Filters inherited from the users page - mirrors admin/users.php
|
||||
$filter_summary = [];
|
||||
|
||||
// Archived Filter
|
||||
if (isset($_POST['archived']) && $_POST['archived'] == 1) {
|
||||
$archive_query = "user_archived_at IS NOT NULL";
|
||||
$filter_summary['Archived'] = 'Archived only';
|
||||
@@ -367,23 +411,33 @@ if (isExportRequest('export_users')) {
|
||||
$archive_query = "user_archived_at IS NULL";
|
||||
}
|
||||
|
||||
// Search Filter
|
||||
$q = escapeSql($_POST['q'] ?? '');
|
||||
if (!empty($q)) {
|
||||
if ($q !== '') {
|
||||
$filter_summary['Search'] = $_POST['q'];
|
||||
}
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT role_name, user_created_at, user_email, user_name, user_status FROM users
|
||||
LEFT JOIN user_roles ON user_role_id = role_id
|
||||
WHERE (user_name LIKE '%$q%' OR user_email LIKE '%$q%')
|
||||
AND user_type = 1
|
||||
AND $archive_query
|
||||
ORDER BY user_name ASC"
|
||||
);
|
||||
$role_query = '';
|
||||
$role = userRoles()[intval($_POST['role'] ?? 0)] ?? null;
|
||||
if ($role) {
|
||||
$role_query = 'AND user_role_id = ' . intval($role['role_id']);
|
||||
$filter_summary['Role'] = $role['role_name'];
|
||||
}
|
||||
|
||||
$num_rows = mysqli_num_rows($sql);
|
||||
$rows = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT users.user_id, role_name, role_is_admin, user_created_at, user_email, user_name, user_status, user_token, user_config_force_mfa FROM users
|
||||
LEFT JOIN user_roles ON user_role_id = role_id
|
||||
LEFT JOIN user_settings ON user_settings.user_id = users.user_id
|
||||
WHERE (user_name LIKE '%$q%' OR user_email LIKE '%$q%' OR role_name LIKE '%$q%')
|
||||
AND user_type = 1
|
||||
AND $archive_query $role_query
|
||||
ORDER BY user_name ASC");
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$rows[intval($row['user_id'])] = $row;
|
||||
}
|
||||
$logins = userLastLogins(array_keys($rows));
|
||||
$access = userClientAccess(array_keys($rows));
|
||||
|
||||
$num_rows = count($rows);
|
||||
|
||||
if ($num_rows > 0) {
|
||||
|
||||
@@ -391,17 +445,11 @@ if (isExportRequest('export_users')) {
|
||||
|
||||
$export = beginExport('users', $format, "$session_company_name-Users", 'Users', summarizeExportFilters($filter_summary));
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
|
||||
$user_status = intval($row['user_status']);
|
||||
if ($user_status == 2) {
|
||||
$row['user_status_display'] = "Invited";
|
||||
} elseif ($user_status == 1) {
|
||||
$row['user_status_display'] = "Active";
|
||||
} else {
|
||||
$row['user_status_display'] = "Disabled";
|
||||
}
|
||||
|
||||
foreach ($rows as $user_id => $row) {
|
||||
$row['user_status_display'] = USER_STATUSES[intval($row['user_status'])][0] ?? 'Disabled';
|
||||
$row['user_mfa_display'] = trim((string) $row['user_token']) !== '' ? 'On' : (intval($row['user_config_force_mfa']) ? 'Required, not set up' : 'Off');
|
||||
$row['user_last_login'] = $logins[$user_id]['log_created_at'] ?? 'Never';
|
||||
$row['user_client_access'] = userClientAccessText($access[$user_id], intval($row['role_is_admin']));
|
||||
addExportRow($export, $row);
|
||||
}
|
||||
|
||||
@@ -416,40 +464,77 @@ if (isExportRequest('export_users')) {
|
||||
|
||||
if (isset($_POST['ir_reset_user_password'])) {
|
||||
|
||||
// Incident response: allow mass reset of agent passwords
|
||||
// Incident response: every other agent gets a new password, shown once here
|
||||
|
||||
validateCSRFToken();
|
||||
|
||||
// Confirm logged-in user password, for security
|
||||
$admin_password = $_POST['admin_password'];
|
||||
$sql = mysqli_query($mysqli, "SELECT user_password FROM users WHERE user_id = $session_user_id");
|
||||
$userRow = mysqli_fetch_assoc($sql);
|
||||
|
||||
if (!password_verify($admin_password, $userRow['user_password'])) {
|
||||
flashAlert("Incorrect password.", 'error');
|
||||
$user_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT user_password FROM users WHERE user_id = $session_user_id"));
|
||||
if (!password_verify((string) ($_POST['admin_password'] ?? ''), $user_row['user_password'])) {
|
||||
flashAlert("Incorrect password - nothing was reset.", 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Get agents/users, other than the current user
|
||||
$sql_users = mysqli_query($mysqli, "SELECT user_email, user_id FROM users WHERE (user_archived_at IS NULL AND user_id != $session_user_id)");
|
||||
|
||||
// Reset passwords
|
||||
// Agents only - client portal logins have their own reset, and no vault key to rewrite
|
||||
$reset = [];
|
||||
$sql_users = mysqli_query($mysqli, "SELECT user_id, user_name, user_email FROM users WHERE user_type = 1 AND user_archived_at IS NULL AND user_id <> $session_user_id ORDER BY user_name");
|
||||
while ($row = mysqli_fetch_assoc($sql_users)) {
|
||||
$user_id = intval($row['user_id']);
|
||||
$user_email = escapeSql($row['user_email']);
|
||||
$new_password = randomString();
|
||||
$user_specific_encryption_ciphertext = encryptUserSpecificKey(trim($new_password));
|
||||
|
||||
echo $user_email . " -- " . $new_password; // Show
|
||||
$new_password = password_hash($new_password, PASSWORD_DEFAULT);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE users SET user_password = '$new_password', user_specific_encryption_ciphertext = '$user_specific_encryption_ciphertext' WHERE user_id = $user_id");
|
||||
|
||||
echo "<br><br>";
|
||||
$new_password = generateReadablePassword(4);
|
||||
userSetPassword($row['user_id'], $new_password);
|
||||
// A remembered browser would skip their MFA code - in an incident, it must not
|
||||
mysqli_query($mysqli, "DELETE FROM remember_tokens WHERE remember_token_user_id = " . intval($row['user_id']));
|
||||
$reset[] = $row + ['password' => $new_password];
|
||||
}
|
||||
|
||||
logAudit("User", "Edit", "$session_name reset ALL user passwords");
|
||||
logAudit("User", "Edit", "$session_name reset the passwords of " . count($reset) . " agent(s) and forgot their remembered browsers (incident response)");
|
||||
|
||||
exit; // Stay on the plain text password page
|
||||
// Shown once, not kept - a plain page to read out or copy, and nothing else on it
|
||||
header('Cache-Control: no-store');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex">
|
||||
<title>Incident response - new agent passwords</title>
|
||||
<link rel="stylesheet" href="/libs/fontawesome-free/css/all.min.css">
|
||||
<link rel="stylesheet" href="/libs/adminlte/css/adminlte.min.css">
|
||||
</head>
|
||||
<body class="bg-body-tertiary">
|
||||
<div class="container py-4" style="max-width: 52rem">
|
||||
<div class="alert alert-danger d-flex gap-3">
|
||||
<i class="fas fa-skull-crossbones fa-2x"></i>
|
||||
<div>
|
||||
<div class="fw-semibold">New passwords for <?= count($reset) ?> agent<?= count($reset) === 1 ? '' : 's' ?> - shown once</div>
|
||||
<div class="small">Give each one to its agent out of band (a phone call, not email), and have them change it. Their remembered browsers were forgotten, so MFA is asked for again. Leave this page and the passwords are gone.</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<table class="table table-hover align-middle mb-0">
|
||||
<thead class="table-light"><tr><th>Agent</th><th>Email</th><th>New password</th></tr></thead>
|
||||
<tbody>
|
||||
<?php foreach ($reset as $row) { ?>
|
||||
<tr>
|
||||
<td class="fw-semibold"><?= escapeHtml($row['user_name']) ?></td>
|
||||
<td><?= escapeHtml($row['user_email']) ?></td>
|
||||
<td class="font-monospace user-select-all"><?= escapeHtml($row['password']) ?></td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php if (!$reset) { ?>
|
||||
<tr><td colspan="3" class="text-body-secondary">There are no other agents.</td></tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="mt-3 d-flex gap-2">
|
||||
<button type="button" class="btn btn-outline-secondary" onclick="window.print()"><i class="fas fa-print me-2"></i>Print</button>
|
||||
<a class="btn btn-primary" href="/admin/users.php"><i class="fas fa-arrow-left me-2"></i>Back to Users</a>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
exit;
|
||||
|
||||
}
|
||||
|
||||
526
admin/users.php
526
admin/users.php
@@ -1,260 +1,386 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Administration > Users - the agents who sign in to ITFlow. Each row is who
|
||||
* they are, their role, whether they can sign in and how (MFA, browsers that
|
||||
* skip the code), the clients they can see and when they last signed in. The
|
||||
* pills split them: everyone, admins, no MFA, disabled - and the archived.
|
||||
*
|
||||
* The admin's own row is shown but not changed here: that is their Account
|
||||
* pages, so nobody locks themselves out by mistake.
|
||||
*/
|
||||
|
||||
// Default Column Sortby Filter
|
||||
$sort = "user_name";
|
||||
$order = "ASC";
|
||||
|
||||
require_once "includes/inc_all_admin.php";
|
||||
|
||||
$sql = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT SQL_CALC_FOUND_ROWS role_name, user_archived_at, user_avatar, user_config_force_mfa, user_email,
|
||||
user_settings.user_id, user_name, user_role_id, user_status, user_token FROM users
|
||||
LEFT JOIN user_roles ON user_role_id = role_id
|
||||
LEFT JOIN user_settings ON users.user_id = user_settings.user_id
|
||||
WHERE (user_name LIKE '%$q%' OR user_email LIKE '%$q%')
|
||||
AND user_type = 1
|
||||
AND user_$archive_query
|
||||
ORDER BY $sort $order LIMIT $record_from, $record_to"
|
||||
);
|
||||
// filter_header.php fills in canned_date=custom when no range was asked for - not a filter here, so not carried into links
|
||||
if (($_GET['canned_date'] ?? '') === 'custom' && empty($_GET['dtf'])) {
|
||||
unset($_GET['canned_date']);
|
||||
}
|
||||
|
||||
$roles = userRoles();
|
||||
$role_filter = isset($roles[intval($_GET['role'] ?? 0)]) ? intval($_GET['role']) : 0;
|
||||
|
||||
$filters = "user_type = 1 AND (user_name LIKE '%$q%' OR user_email LIKE '%$q%' OR role_name LIKE '%$q%')" . ($role_filter ? " AND user_role_id = $role_filter" : '');
|
||||
$joins = "LEFT JOIN user_roles ON user_role_id = role_id
|
||||
LEFT JOIN user_settings ON user_settings.user_id = users.user_id";
|
||||
|
||||
// The views
|
||||
$shows = [
|
||||
'' => ['label' => 'Users', 'icon' => 'fa-users', 'where' => 'user_archived_at IS NULL', 'title' => 'Everyone not archived'],
|
||||
'admins' => ['label' => 'Admins', 'icon' => 'fa-user-shield', 'where' => 'user_archived_at IS NULL AND role_is_admin = 1', 'title' => 'Every client and every setting'],
|
||||
'nomfa' => ['label' => 'No MFA', 'icon' => 'fa-unlock', 'where' => "user_archived_at IS NULL AND user_status = 1 AND (user_token IS NULL OR user_token = '')", 'title' => 'Active, and signing in with a password alone'],
|
||||
'disabled' => ['label' => 'Disabled', 'icon' => 'fa-ban', 'where' => 'user_archived_at IS NULL AND user_status <> 1', 'title' => 'Cannot sign in'],
|
||||
'archived' => ['label' => 'Archived', 'icon' => 'fa-archive', 'where' => 'user_archived_at IS NOT NULL', 'title' => 'Gone - restore one with a new password'],
|
||||
];
|
||||
$show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : '';
|
||||
|
||||
// Only these sort - an unknown column would take the page down
|
||||
$last_login_sql = "(SELECT MAX(log_id) FROM logs WHERE log_user_id = users.user_id AND log_type = 'Login' AND log_action = 'Success')";
|
||||
$sortable_columns = [
|
||||
'user_name' => "user_name $order",
|
||||
'user_email' => "user_email $order",
|
||||
'role_name' => "role_is_admin DESC, role_name $order, user_name ASC",
|
||||
'user_status' => "user_status $order, user_name ASC",
|
||||
'last_login' => "$last_login_sql IS NULL, $last_login_sql $order, user_name ASC",
|
||||
'user_created_at' => "user_created_at $order, user_name ASC",
|
||||
];
|
||||
if (!isset($sortable_columns[$sort])) {
|
||||
$sort = 'user_name';
|
||||
}
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS users.user_id, user_name, user_email, user_status, user_token, user_avatar, user_created_at, user_archived_at,
|
||||
user_role_id, role_name, role_is_admin, user_config_force_mfa
|
||||
FROM users $joins
|
||||
WHERE $filters AND {$shows[$show]['where']}
|
||||
ORDER BY {$sortable_columns[$sort]}, users.user_id ASC
|
||||
LIMIT $record_from, $record_to");
|
||||
|
||||
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
|
||||
|
||||
$users = [];
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$users[intval($row['user_id'])] = $row;
|
||||
}
|
||||
$logins = userLastLogins(array_keys($users));
|
||||
$access = userClientAccess(array_keys($users));
|
||||
$remembered = userRememberCounts(array_keys($users));
|
||||
|
||||
// How many in each view, over what the search and role leave
|
||||
$view_counts = [];
|
||||
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', array_map(function ($s) {
|
||||
return "COALESCE(SUM({$s['where']}), 0)";
|
||||
}, $shows)) . " FROM users $joins WHERE $filters"));
|
||||
foreach (array_keys($shows) as $i => $key) {
|
||||
$view_counts[$key] = intval($row[$i]);
|
||||
}
|
||||
|
||||
// Agent user limit (set in config.php, 0 / unset = unlimited)
|
||||
$agent_user_limit = getAgentUserLimit();
|
||||
$agent_user_count = getActiveAgentUserCount();
|
||||
$agent_user_limit_reached = $agent_user_limit > 0 && $agent_user_count >= $agent_user_limit;
|
||||
|
||||
$filter_url = function ($changes) {
|
||||
$params = array_merge($_GET, $changes);
|
||||
unset($params['page']);
|
||||
return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; }));
|
||||
};
|
||||
|
||||
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
|
||||
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&sort=' . $column . '&order=' . $disp . '">'
|
||||
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
|
||||
};
|
||||
|
||||
$csrf = $_SESSION['csrf_token'];
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark py-2">
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-users me-2"></i>Users
|
||||
<?php if ($agent_user_limit > 0) { ?>
|
||||
<span class="badge text-bg-<?= $agent_user_limit_reached ? 'danger' : 'secondary' ?> ms-2" title="Active agent users / agent user limit">
|
||||
<?= $agent_user_count ?> of <?= $agent_user_limit ?> agent users
|
||||
<span class="badge rounded-pill text-bg-<?= $agent_user_limit_reached ? 'danger' : 'secondary' ?> fw-normal ms-2" title="Active agents, of the agent user limit set for this installation">
|
||||
<?= $agent_user_count ?> of <?= $agent_user_limit ?> seats
|
||||
</span>
|
||||
<?php } ?>
|
||||
</h3>
|
||||
<div class="card-tools">
|
||||
<div class="btn-group">
|
||||
<?php if ($agent_user_limit_reached) { ?>
|
||||
<button type="button" class="btn btn-primary" disabled title="Agent user limit reached">
|
||||
<i class="fas fa-fw fa-user-plus me-2"></i>New User
|
||||
<button type="button" class="btn btn-primary" disabled title="Every seat is taken - disable or archive a user first">
|
||||
<i class="fas fa-user-plus"></i><span class="d-none d-lg-inline ms-2">New User</span>
|
||||
</button>
|
||||
<?php } else { ?>
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/user/user_add.php">
|
||||
<i class="fas fa-fw fa-user-plus me-2"></i>New User
|
||||
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/user/user_add.php?role=<?= $role_filter ?>">
|
||||
<i class="fas fa-user-plus"></i><span class="d-none d-lg-inline ms-2">New User</span>
|
||||
</button>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown"></button>
|
||||
<div class="dropdown-menu">
|
||||
<!--<a class="dropdown-item text-dark ajax-modal" href="#" data-modal-url="modals/user/user_invite.php"><i class="fas fa-paper-plane me-2"></i>Invite User</a>-->
|
||||
<?php if ($num_rows[0] > 1) { ?>
|
||||
<a class="dropdown-item text-dark ajax-modal" href="#"
|
||||
data-modal-url="<?= buildExportModalUrl('modals/user/user_export.php', ['archived', 'q']) ?>">
|
||||
<i class="fa fa-fw fa-download me-2"></i>Export
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger ajax-modal" href="#"
|
||||
data-modal-url="modals/user/user_all_reset_password.php"
|
||||
data-modal-size="lg">
|
||||
<i class="fas fa-skull-crossbones me-2"></i>IR
|
||||
</a>
|
||||
<?php } ?>
|
||||
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown" aria-label="More"></button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= buildExportModalUrl('modals/user/user_export.php', ['q', 'role'], ['archived' => $show === 'archived' ? 1 : null]) ?>">
|
||||
<i class="fa fa-fw fa-download text-secondary me-2"></i>Export
|
||||
</a>
|
||||
<a class="dropdown-item" href="roles.php">
|
||||
<i class="fa fa-fw fa-user-tag text-secondary me-2"></i>Roles
|
||||
</a>
|
||||
<a class="dropdown-item" href="settings_security.php">
|
||||
<i class="fa fa-fw fa-shield-alt text-secondary me-2"></i>Security settings
|
||||
</a>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger ajax-modal" href="#" data-modal-url="modals/user/user_all_reset_password.php">
|
||||
<i class="fas fa-fw fa-skull-crossbones me-2"></i>Incident response
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-header py-3">
|
||||
<form autocomplete="off">
|
||||
<input type="hidden" name="show" value="<?= escapeHtml($show) ?>">
|
||||
<div class="row g-2 align-items-center">
|
||||
<div class="col-md-4">
|
||||
<div class="col-lg-4 col-md-6">
|
||||
<div class="input-group">
|
||||
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) {echo stripslashes(escapeHtml($q));} ?>" placeholder="Search Users">
|
||||
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
|
||||
<input type="search" class="form-control" name="q" value="<?= escapeHtml($_GET['q'] ?? '') ?>" placeholder="Search users..." title="Name, email or role">
|
||||
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="btn-group float-end">
|
||||
<a href="?archived=<?php if($archived == 1){ echo 0; } else { echo 1; } ?>"
|
||||
class="btn btn-<?php if($archived == 1){ echo"primary"; } else { echo "default"; } ?>">
|
||||
<i class="fa fa-fw fa-archive me-2"></i>Archived
|
||||
</a>
|
||||
<div class="col-lg-3 col-md-6">
|
||||
<select class="form-select select2" name="role" onchange="this.form.submit()">
|
||||
<option value="">- Any role -</option>
|
||||
<?php foreach ($roles as $role_id => $role) { ?>
|
||||
<option value="<?= $role_id ?>" <?= $role_filter === $role_id ? 'selected' : '' ?><?= selectOptionRole($role) ?>><?= escapeHtml($role['role_name']) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-lg-5 col-md-12">
|
||||
<div class="d-flex justify-content-end gap-2">
|
||||
<div class="dropdown" id="bulkActionButton" hidden>
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-fw fa-layer-group me-2"></i>Bulk Action (<span id="selectedCount">0</span>)
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-end">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/user/user_bulk_role.php" data-bulk="true">
|
||||
<i class="fas fa-fw fa-user-tag text-secondary me-2"></i>Role
|
||||
</a>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_require_mfa_users">
|
||||
<i class="fas fa-fw fa-lock text-secondary me-2"></i>Require MFA
|
||||
</button>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_unrequire_mfa_users">
|
||||
<i class="fas fa-fw fa-lock-open text-secondary me-2"></i>Stop requiring MFA
|
||||
</button>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_revoke_remember_users">
|
||||
<i class="fas fa-fw fa-laptop text-secondary me-2"></i>Forget remembered browsers
|
||||
</button>
|
||||
<?php if ($show !== 'archived') { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_activate_users">
|
||||
<i class="fas fa-fw fa-user-check text-secondary me-2"></i>Activate
|
||||
</button>
|
||||
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_disable_users"
|
||||
data-confirm-text="They are signed out and cannot sign in, and their open tickets and recurring tickets are unassigned. Activating them again does not give those back."
|
||||
data-confirm-button="Disable">
|
||||
<i class="fas fa-fw fa-user-slash me-2"></i>Disable
|
||||
</button>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<nav class="nav nav-pills itflow-asset-tabs mt-2 flex-nowrap overflow-auto">
|
||||
<?php foreach ($shows as $key => $view) {
|
||||
if ($key === 'archived') { ?><span class="vr mx-1 my-1"></span><?php } ?>
|
||||
<a class="nav-link text-nowrap <?= $show === $key ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => $key === '' || $show === $key ? null : $key])) ?>" title="<?= escapeHtml($view['title']) ?>">
|
||||
<i class="fas fa-fw <?= $view['icon'] ?> me-1"></i><?= $view['label'] ?> <span class="badge rounded-pill ms-1"><?= $view_counts[$key] ?></span>
|
||||
</a>
|
||||
<?php } ?>
|
||||
</nav>
|
||||
</div>
|
||||
<div class="table-responsive-sm">
|
||||
<table class="table table-striped table-borderless table-hover mb-0">
|
||||
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
|
||||
<tr>
|
||||
<th class="text-center">
|
||||
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=user_name&order=<?= $disp ?>">
|
||||
Name <?php if ($sort == 'user_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=user_email&order=<?= $disp ?>">
|
||||
Email <?php if ($sort == 'user_email') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=role_name&order=<?= $disp ?>">
|
||||
Role <?php if ($sort == 'role_name') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th>
|
||||
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=user_status&order=<?= $disp ?>">
|
||||
Status <?php if ($sort == 'user_status') { echo $order_icon; } ?>
|
||||
</a>
|
||||
</th>
|
||||
<th class="text-center">MFA</th>
|
||||
<th>
|
||||
Last Login
|
||||
</th>
|
||||
<th class="text-center">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
|
||||
while ($row = mysqli_fetch_assoc($sql)) {
|
||||
$user_id = intval($row['user_id']);
|
||||
$user_name = escapeHtml($row['user_name']);
|
||||
$user_email = escapeHtml($row['user_email']);
|
||||
$user_status = intval($row['user_status']);
|
||||
if ($user_status == 2) {
|
||||
$user_status_display = "<span class='text-info'>Invited</span>";
|
||||
} elseif ($user_status == 1) {
|
||||
$user_status_display = "<span class='text-success'>Active</span>";
|
||||
} else{
|
||||
$user_status_display = "<span class='text-danger'>Disabled</span>";
|
||||
}
|
||||
$user_avatar = escapeHtml($row['user_avatar']);
|
||||
$user_token = escapeHtml($row['user_token']);
|
||||
if(empty($user_token)) {
|
||||
$mfa_status_display = "<i class='fas fa-fw fa-unlock text-danger'></i>";
|
||||
} else {
|
||||
$mfa_status_display = "<i class='fas fa-fw fa-lock text-success'></i>";
|
||||
}
|
||||
$user_config_force_mfa = intval($row['user_config_force_mfa']);
|
||||
$user_role = intval($row['user_role_id']);
|
||||
$user_role_display = escapeHtml($row['role_name']);
|
||||
$user_archived_at = escapeHtml($row['user_archived_at']);
|
||||
$user_initials = escapeHtml(initials($user_name));
|
||||
<form id="bulkActions" action="post.php" method="post">
|
||||
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
|
||||
|
||||
|
||||
$sql_last_login = mysqli_query(
|
||||
$mysqli,
|
||||
"SELECT log_created_at, log_ip, log_user_agent FROM logs
|
||||
WHERE log_user_id = $user_id AND log_type = 'Login'
|
||||
ORDER BY log_id DESC LIMIT 1"
|
||||
);
|
||||
if (mysqli_num_rows($sql_last_login) == 0) {
|
||||
$last_login = "<span class='text-bold'>Never logged in</span>";
|
||||
} else {
|
||||
$row = mysqli_fetch_assoc($sql_last_login);
|
||||
$log_created_at = escapeHtml($row['log_created_at']);
|
||||
$log_ip = escapeHtml($row['log_ip']);
|
||||
$log_user_agent = escapeHtml($row['log_user_agent']);
|
||||
$log_user_os = getOS($log_user_agent);
|
||||
$log_user_browser = getWebBrowser($log_user_agent);
|
||||
$last_login = "$log_created_at<small class='text-secondary'><div class='mt-1'>$log_user_os</div><div class='mt-1'>$log_user_browser</div><div class='mt-1'><i class='fa fa-fw fa-globe'></i> $log_ip</div></small>";
|
||||
}
|
||||
|
||||
// Get User Client Access Permissions
|
||||
$user_client_access_sql = mysqli_query($mysqli,"SELECT client_id FROM user_client_permissions WHERE user_id = $user_id");
|
||||
$client_access_array = [];
|
||||
while ($row = mysqli_fetch_assoc($user_client_access_sql)) {
|
||||
$client_access_array[] = intval($row['client_id']);
|
||||
}
|
||||
|
||||
$sql_remember_tokens = mysqli_query($mysqli, "SELECT 1 FROM remember_tokens WHERE remember_token_user_id = $user_id");
|
||||
$remember_token_count = mysqli_num_rows($sql_remember_tokens);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover align-middle mb-0 itflow-asset-table itflow-ticket-list itflow-user-list">
|
||||
<thead class="<?php if (!$users) { echo "d-none"; } ?> text-nowrap table-light">
|
||||
<tr>
|
||||
<td class="text-center">
|
||||
<a href="#" title="UserID: <?= $user_id ?>"
|
||||
<?php if ($user_id !== $session_user_id) { // Prevent modifying self ?>
|
||||
class="ajax-modal"
|
||||
data-modal-url="modals/user/user_edit.php?id=<?= $user_id ?>"
|
||||
<?php } ?>
|
||||
>
|
||||
<?php if (!empty($user_avatar)) { ?>
|
||||
<img class="img-size-50 rounded-circle" src="<?= "../uploads/users/$user_id/$user_avatar" ?>">
|
||||
<?php } else { ?>
|
||||
<span class="fa-stack fa-2x">
|
||||
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
|
||||
<span class="fa fa-stack-1x text-white"><?= $user_initials ?></span>
|
||||
</span>
|
||||
<br>
|
||||
<?php } ?>
|
||||
|
||||
<div class="text-secondary"><?= $user_name ?></div>
|
||||
</a>
|
||||
</td>
|
||||
<td><a href="mailto:<?= $user_email ?>"><?= $user_email ?></a></td>
|
||||
<td><?= $user_role_display ?></td>
|
||||
<td><?= $user_status_display ?></td>
|
||||
<td class="text-center"><?= $mfa_status_display ?></td>
|
||||
<td><?= $last_login ?></td>
|
||||
<td>
|
||||
<?php if ($user_id !== $session_user_id) { // Prevent modifying self ?>
|
||||
<div class="dropdown dropstart text-center">
|
||||
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#"
|
||||
data-modal-url="modals/user/user_edit.php?id=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-user-edit me-2"></i>Edit
|
||||
</a>
|
||||
<?php if ($remember_token_count > 0) { ?>
|
||||
<a class="dropdown-item" href="post.php?revoke_remember_me=<?= $user_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-fw fa-ban me-2"></i>Revoke <?= $remember_token_count ?> Remember Tokens
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($user_status == 0) { ?>
|
||||
<a class="dropdown-item text-success" href="post.php?activate_user=<?= $user_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-user-check me-2"></i>Activate
|
||||
</a>
|
||||
<?php }elseif ($user_status == 1) { ?>
|
||||
<a class="dropdown-item text-danger confirm-link" data-confirm-text="Their open tickets and recurring tickets will be unassigned. Activating them again does not reassign anything." data-confirm-button="Disable" href="post.php?disable_user=<?= $user_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
|
||||
<i class="fas fa-fw fa-user-slash me-2"></i>Disable
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($user_archived_at) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-info ajax-modal" href="#" data-modal-url="modals/user/user_restore.php?id=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-redo-alt me-2"></i>Restore
|
||||
</a>
|
||||
<th class="checkbox-column border-end">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)" title="Select all on this page">
|
||||
</div>
|
||||
</th>
|
||||
<th><?= $sort_link('user_name', 'User') ?> <span class="fw-normal text-body-secondary small ms-2"><?= $sort_link('user_email', 'by email') ?></span></th>
|
||||
<th class="d-none d-md-table-cell"><?= $sort_link('role_name', 'Role') ?></th>
|
||||
<th class="d-none d-md-table-cell"><?= $sort_link('user_status', 'Sign in') ?></th>
|
||||
<th class="d-none d-xl-table-cell">Clients</th>
|
||||
<th class="d-none d-lg-table-cell"><?= $sort_link('last_login', 'Last signed in') ?></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($users as $user_id => $row) {
|
||||
$is_self = $user_id === intval($session_user_id);
|
||||
$is_archived = !empty($row['user_archived_at']);
|
||||
$is_active = intval($row['user_status']) === 1 && !$is_archived;
|
||||
$is_admin = intval($row['role_is_admin']) === 1;
|
||||
$has_mfa = trim((string) $row['user_token']) !== '';
|
||||
$display_name = $is_archived ? trim(str_replace(' (archived)', '', $row['user_name'])) : $row['user_name'];
|
||||
$name = escapeHtml($display_name);
|
||||
$quick_url = "modals/user/user.php?id=$user_id";
|
||||
$user_access = $access[$user_id];
|
||||
$access_title = $is_admin ? 'Admins see every client' : trim(
|
||||
($user_access['allow'] ? 'Only: ' . implode(', ', $user_access['allow']) . '. ' : '')
|
||||
. ($user_access['deny'] ? 'Kept out of: ' . implode(', ', $user_access['deny']) . '.' : '')
|
||||
);
|
||||
$remember_count = $remembered[$user_id] ?? 0;
|
||||
?>
|
||||
<tr class="itflow-ticket-row <?= !$has_mfa && $is_active ? 'is-warning' : '' ?>">
|
||||
<td class="checkbox-column bg-light border-end">
|
||||
<div class="form-check">
|
||||
<?php if ($is_self) { ?>
|
||||
<input class="form-check-input" type="checkbox" disabled title="That's you - change your own account from Account">
|
||||
<?php } else { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item text-danger ajax-modal" href="#" data-modal-url="modals/user/user_archive.php?id=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<input class="form-check-input bulk-select" type="checkbox" name="user_ids[]" value="<?= $user_id ?>" aria-label="Select <?= $name ?>">
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
</tr>
|
||||
</td>
|
||||
|
||||
<?php
|
||||
}
|
||||
<!-- Who -->
|
||||
<td class="itflow-ticket-main itflow-user-main">
|
||||
<div class="d-flex align-items-center gap-3">
|
||||
<a class="ajax-modal text-decoration-none <?= $is_active ? '' : 'opacity-50' ?>" href="#" data-modal-url="<?= $quick_url ?>" tabindex="-1" aria-hidden="true"><?= userAvatar($user_id, $display_name, $row['user_avatar']) ?></a>
|
||||
<div class="min-w-0">
|
||||
<a class="ajax-modal <?= $is_active ? 'fw-semibold text-body' : 'text-body-secondary' ?>" href="#" data-modal-url="<?= $quick_url ?>"><?= $name ?></a>
|
||||
<?php if ($is_self) { ?><span class="badge rounded-pill bg-primary-subtle text-primary-emphasis fw-normal ms-1">You</span><?php } ?>
|
||||
<div class="small text-body-secondary text-truncate">
|
||||
<?= escapeHtml($row['user_email']) ?><button type="button" class="itflow-copy clipboardjs" title="Copy email" data-clipboard-text="<?= escapeHtml($row['user_email']) ?>"><i class="far fa-copy"></i></button>
|
||||
</div>
|
||||
<!-- On a phone the role and sign in columns are off to the side - they come along -->
|
||||
<div class="d-md-none small text-body-secondary"><i class="fas fa-fw <?= $is_admin ? 'fa-user-shield' : 'fa-user-tag' ?> me-1"></i><?= escapeHtml($row['role_name'] ?? 'No role') ?></div>
|
||||
<div class="d-md-none d-flex flex-wrap gap-1 mt-1">
|
||||
<?= userStatusPill($row['user_status'], $is_archived) ?>
|
||||
<?php if (!$is_archived) { ?><?= userMfaPill($row['user_token'], $row['user_config_force_mfa']) ?><?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
?>
|
||||
<td class="d-none d-md-table-cell text-nowrap">
|
||||
<?php if ($row['role_name'] === null) { ?>
|
||||
<span class="text-danger-emphasis small"><i class="fas fa-exclamation-triangle me-1"></i>No role</span>
|
||||
<?php } else { ?>
|
||||
<i class="fas fa-fw <?= $is_admin ? 'fa-user-shield text-primary' : 'fa-user-tag text-body-secondary' ?> me-1"></i><?= escapeHtml($row['role_name']) ?>
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php require_once "../includes/filter_footer.php";
|
||||
?>
|
||||
<!-- Can they sign in, and how -->
|
||||
<td class="d-none d-md-table-cell">
|
||||
<div class="d-flex flex-wrap gap-1">
|
||||
<?= userStatusPill($row['user_status'], $is_archived) ?>
|
||||
<?php if (!$is_archived) { ?><?= userMfaPill($row['user_token'], $row['user_config_force_mfa']) ?><?php } ?>
|
||||
</div>
|
||||
<?php if ($remember_count && !$is_archived) { ?>
|
||||
<div class="small text-body-secondary mt-1 text-nowrap" title="Browsers that skip the MFA code - remember me, at sign in"><i class="fas fa-fw fa-laptop me-1"></i><?= $remember_count ?> remembered browser<?= $remember_count === 1 ? '' : 's' ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($is_archived) { ?>
|
||||
<div class="small text-body-secondary mt-1" title="<?= escapeHtml($row['user_archived_at']) ?>"><?= escapeHtml(timeAgo($row['user_archived_at'])) ?></div>
|
||||
<?php } ?>
|
||||
</td>
|
||||
|
||||
<td class="d-none d-xl-table-cell small <?= $is_admin ? 'text-body-secondary' : '' ?>" title="<?= escapeHtml($access_title) ?>">
|
||||
<?php if (!$is_admin && ($user_access['allow'] || $user_access['deny'])) { ?><i class="fas fa-fw fa-filter text-warning me-1"></i><?php } ?><?= escapeHtml(userClientAccessText($user_access, $is_admin)) ?>
|
||||
</td>
|
||||
|
||||
<td class="d-none d-lg-table-cell small"><?= userLoginHtml($logins[$user_id] ?? null) ?></td>
|
||||
|
||||
<td class="text-end">
|
||||
<div class="dropdown dropstart">
|
||||
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $quick_url ?>">
|
||||
<i class="fas fa-fw fa-eye text-secondary me-2"></i>Quick look
|
||||
</a>
|
||||
<a class="dropdown-item" href="audit_logs.php?user=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-history text-secondary me-2"></i>Audit log
|
||||
</a>
|
||||
<?php if ($is_self) { ?>
|
||||
<a class="dropdown-item" href="/agent/user/user_details.php">
|
||||
<i class="fas fa-fw fa-user-cog text-secondary me-2"></i>Your account
|
||||
</a>
|
||||
<?php } elseif ($is_archived) { ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/user/user_restore.php?id=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-redo-alt text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/user/user_edit.php?id=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-user-edit text-secondary me-2"></i>Edit
|
||||
</a>
|
||||
<?php if ($has_mfa) { ?>
|
||||
<a class="dropdown-item confirm-link" href="post.php?reset_user_mfa=<?= $user_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-text="<?= $name ?> signs in with their password alone<?= intval($row['user_config_force_mfa']) ? ' until they set MFA up again, which they are asked to at their next sign in' : ' until they turn MFA on again' ?>. For a lost or replaced phone."
|
||||
data-confirm-button="Reset MFA">
|
||||
<i class="fas fa-fw fa-mobile-alt text-secondary me-2"></i>Reset MFA
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($remember_count) { ?>
|
||||
<a class="dropdown-item" href="post.php?revoke_remember_me=<?= $user_id ?>&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-laptop text-secondary me-2"></i>Forget <?= $remember_count ?> remembered browser<?= $remember_count === 1 ? '' : 's' ?>
|
||||
</a>
|
||||
<?php } ?>
|
||||
<div class="dropdown-divider"></div>
|
||||
<?php if ($is_active) { ?>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?disable_user=<?= $user_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-text="<?= $name ?> is signed out and cannot sign in, and their open tickets and recurring tickets are unassigned. Activating them again does not give those back."
|
||||
data-confirm-button="Disable">
|
||||
<i class="fas fa-fw fa-user-slash me-2"></i>Disable
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item" href="post.php?activate_user=<?= $user_id ?>&csrf_token=<?= $csrf ?>">
|
||||
<i class="fas fa-fw fa-user-check text-secondary me-2"></i>Activate
|
||||
</a>
|
||||
<?php } ?>
|
||||
<a class="dropdown-item text-danger ajax-modal" href="#" data-modal-url="modals/user/user_archive.php?id=<?= $user_id ?>">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
<?php if (!$users) { ?>
|
||||
<div class="itflow-asset-empty">
|
||||
<i class="fas fa-users fa-2x mb-2 opacity-50"></i>
|
||||
<div>
|
||||
<?php if ($q !== '' || $role_filter) { ?>
|
||||
No users match.
|
||||
<?php } elseif ($show === 'nomfa') { ?>
|
||||
Everyone active signs in with MFA.
|
||||
<?php } elseif ($show === 'archived') { ?>
|
||||
No archived users.
|
||||
<?php } elseif ($show === 'disabled') { ?>
|
||||
Nobody is disabled.
|
||||
<?php } else { ?>
|
||||
No users here.
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<?php require_once "../includes/filter_footer.php"; ?>
|
||||
</div>
|
||||
|
||||
<script src="../js/bulk_actions.js"></script>
|
||||
|
||||
<?php
|
||||
require_once "../includes/footer.php";
|
||||
|
||||
Reference in New Issue
Block a user