Files
itflow/admin/identity_providers.php

206 lines
14 KiB
PHP

<?php
/*
* Admin > Identity Providers - the ways agents and client contacts sign in besides their ITFlow
* password (functions/identity_provider.php): Microsoft 365, Google Workspace and Nextcloud, each
* a button on the sign-in page, and IMAP, which checks the password typed there with a mail
* server. Each row says what it is, who it signs in and on which email domains, whether it is
* required, and when it was last used. New is a menu of the kinds; Add and Edit are one window
* (modals/identity_provider/identity_provider_edit.php); the rest are
* admin/post/identity_provider.php.
*/
// Default Column Sortby Filter
$sort = "identity_provider_name";
$order = "ASC";
require_once "includes/inc_all_admin.php";
// The table arrives with the 4.2.5 database update
if (!identityProvidersReady()) { ?>
<div class="alert alert-warning"><i class="fas fa-fw fa-exclamation-triangle me-2"></i>Identity Providers arrive with a database update - run it in <a href="update.php">Maintenance &gt; Update</a> first.</div>
<?php
require_once "../includes/footer.php";
exit;
}
$kinds = identityProviderKinds();
// Only these sort - an unknown column would take the page down
$sortable_columns = [
'identity_provider_name' => "identity_provider_name $order",
'identity_provider_kind' => "identity_provider_kind $order, identity_provider_name ASC",
'identity_provider_used_at' => "identity_provider_used_at IS NULL, identity_provider_used_at $order, identity_provider_name ASC",
];
if (!isset($sortable_columns[$sort])) {
$sort = 'identity_provider_name';
}
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS * FROM identity_providers
WHERE (identity_provider_name LIKE '%$q%' OR identity_provider_domains LIKE '%$q%' OR identity_provider_kind LIKE '%$q%' OR identity_provider_url LIKE '%$q%')
ORDER BY {$sortable_columns[$sort]}, identity_provider_id ASC
LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$csrf = $_SESSION['csrf_token'];
$add_url = 'modals/identity_provider/identity_provider_edit.php?kind=';
?>
<div class="card">
<div class="card-header bg-dark py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-id-badge me-2"></i>Identity Providers</h3>
<div class="card-tools">
<div class="btn-group">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false"><i class="fas fa-plus"></i><span class="d-none d-lg-inline ms-2">New Identity Provider</span></button>
<div class="dropdown-menu dropdown-menu-end" data-identity-provider-new>
<?php foreach ($kinds as $key => $info) { ?>
<a class="dropdown-item ajax-modal py-2" href="#" data-modal-size="lg" data-modal-url="<?= $add_url . $key ?>">
<i class="<?= escapeHtml($info['icon']) ?> fa-fw text-secondary me-2"></i><?= escapeHtml($info['name']) ?>
<div class="small text-body-secondary text-wrap ms-4 ps-2" style="max-width: 20rem;"><?= escapeHtml($info['about']) ?></div>
</a>
<?php } ?>
</div>
</div>
</div>
</div>
<?php if (!$config_client_portal_enable) { ?>
<div class="card-header py-2 small text-body-secondary">
<i class="fas fa-fw fa-info-circle me-1"></i>The client portal is off in <a class="text-reset" href="settings_module.php">Modules</a>, so identity providers sign in agents only.
</div>
<?php } ?>
<div class="card-header py-3">
<form autocomplete="off">
<div class="row g-2 align-items-center">
<div class="col-lg-5 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 identity providers..." title="Name, kind, email domain or address">
<button class="btn btn-dark" title="Search"><i class="fas fa-search"></i></button>
</div>
</div>
</div>
</form>
</div>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="table-light text-nowrap <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
<tr>
<th class="ps-3"><?= sortLink('identity_provider_name', 'Identity provider') ?></th>
<th class="d-none d-lg-table-cell"><?= sortLink('identity_provider_kind', 'Kind') ?></th>
<th class="d-none d-md-table-cell">Signs in</th>
<th class="d-none d-md-table-cell">Email domains</th>
<th class="d-none d-sm-table-cell"><?= sortLink('identity_provider_used_at', 'Last used') ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($sql)) {
$identity_provider_id = intval($row['identity_provider_id']);
$name = (string) $row['identity_provider_name'];
$kind = identityProviderKind($row);
$on = intval($row['identity_provider_enabled']) === 1;
$edit_url = "modals/identity_provider/identity_provider_edit.php?id=$identity_provider_id";
$domains = identityProviderDomains($row);
$agents = intval($row['identity_provider_agents']) === 1;
$contacts = intval($row['identity_provider_contacts']) === 1;
$required = $kind && $kind['oauth'] && intval($row['identity_provider_required']) === 1 && $domains;
if ($row['identity_provider_kind'] === 'imap') {
$where = $row['identity_provider_url'] . ':' . intval($row['identity_provider_port']);
} elseif ($row['identity_provider_kind'] === 'nextcloud') {
$where = (string) parse_url(identityProviderNextcloudUrl($row), PHP_URL_HOST);
} elseif ($row['identity_provider_kind'] === 'microsoft') {
$where = trim((string) $row['identity_provider_tenant']) !== '' ? 'Tenant ' . $row['identity_provider_tenant'] : 'Any organization';
} else {
$where = '';
}
$who = array_filter([$agents ? 'Agents' : '', $contacts ? 'Client contacts' : '']);
?>
<tr data-identity-provider-id="<?= $identity_provider_id ?>" class="<?= $on ? '' : 'text-body-secondary' ?>">
<td class="ps-3">
<div class="d-flex align-items-center gap-3">
<span class="d-none d-sm-inline-flex itflow-asset-icon itflow-asset-tone-other" aria-hidden="true"><i class="<?= escapeHtml($kind['icon'] ?? 'fas fa-id-badge') ?>"></i></span>
<div class="min-w-0">
<?php if ($kind) { ?>
<a class="fw-semibold text-body ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><?= escapeHtml($name) ?></a>
<?php } else { ?>
<span class="fw-semibold"><?= escapeHtml($name) ?></span>
<span class="badge rounded-pill text-bg-warning ms-1" title="This ITFlow doesn't know its kind (<?= escapeHtml($row['identity_provider_kind']) ?>) - it signs no one in">Unknown kind</span>
<?php } ?>
<?php if ($kind && !$on) { ?>
<span class="badge rounded-pill text-bg-secondary ms-1" data-identity-provider-state="off" title="It signs no one in<?= $kind['oauth'] ? ', and has no button on the sign-in page' : '' ?>">Off</span>
<?php } ?>
<?php if ($required) { ?>
<span class="badge rounded-pill bg-warning-subtle text-warning-emphasis border border-warning-subtle fw-normal ms-1" data-identity-provider-required title="Accounts on its email domains can't sign in with a password - an administrator still can">Required</span>
<?php } ?>
<div class="small text-body-secondary text-truncate"><span class="d-lg-none"><?= escapeHtml($kind['name'] ?? $row['identity_provider_kind']) ?><?= $where !== '' ? ' &middot; ' : '' ?></span><?= escapeHtml($where) ?></div>
<div class="d-md-none small text-body-secondary"><?= escapeHtml($who ? implode(' and ', $who) : 'No one') ?> &middot; <?= escapeHtml($domains ? implode(', ', $domains) : 'Any email domain') ?></div>
</div>
</div>
</td>
<td class="d-none d-lg-table-cell small"><?= escapeHtml($kind['name'] ?? $row['identity_provider_kind']) ?></td>
<td class="d-none d-md-table-cell small">
<?php if (!$who) { ?>
<span class="text-body-secondary">No one</span>
<?php } ?>
<?php if ($agents) { ?>
<span class="badge rounded-pill text-bg-light border fw-normal"><i class="fas fa-user-tie me-1"></i>Agents</span>
<?php } ?>
<?php if ($contacts) { ?>
<span class="badge rounded-pill text-bg-light border fw-normal" <?= $config_client_portal_enable ? '' : 'title="Not while the client portal is off"' ?>><i class="fas fa-user-friends me-1"></i>Client contacts<?= $config_client_portal_enable ? '' : ' - portal off' ?></span>
<?php } ?>
</td>
<td class="d-none d-md-table-cell small"><?= $domains ? escapeHtml(implode(', ', $domains)) : '<span class="text-body-secondary">Any email domain</span>' ?></td>
<td class="d-none d-sm-table-cell small" data-identity-provider-used="<?= $row['identity_provider_used_at'] ? 'yes' : 'never' ?>">
<?php if ($row['identity_provider_used_at']) { ?>
<span class="text-nowrap" title="<?= formatDateTime($row['identity_provider_used_at']) ?>"><i class="fas fa-fw fa-check-circle text-success me-1"></i><?= escapeHtml(timeAgo($row['identity_provider_used_at'])) ?></span>
<?php } else { ?>
<span class="text-body-secondary">Not yet</span>
<?php } ?>
</td>
<td class="text-end pe-3">
<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">
<?php if ($kind) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit</a>
<?php if ($on) { ?>
<a class="dropdown-item confirm-link" href="post.php?turn_identity_provider_off=<?= $identity_provider_id ?>&amp;csrf_token=<?= $csrf ?>"
data-confirm-title="Turn <?= escapeHtml($name) ?> off?" data-confirm-button="Turn off"
data-confirm-text="No one signs in with it until it is on again<?= $required ? ' - the accounts on its email domains sign in with their password meanwhile' : '' ?>.">
<i class="fas fa-fw fa-toggle-off text-secondary me-2"></i>Turn Off
</a>
<?php } else { ?>
<a class="dropdown-item" href="post.php?turn_identity_provider_on=<?= $identity_provider_id ?>&amp;csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-toggle-on text-secondary me-2"></i>Turn On</a>
<?php } ?>
<div class="dropdown-divider"></div>
<?php } ?>
<a class="dropdown-item text-danger confirm-link" href="post.php?delete_identity_provider=<?= $identity_provider_id ?>&amp;csrf_token=<?= $csrf ?>"
data-confirm-title="Delete <?= escapeHtml($name) ?>?" data-confirm-button="Delete"
data-confirm-text="No one signs in with it any more. Their accounts stay - a contact set to sign in only through an identity provider needs another one, or a password.">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</a>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php
$empty_state = [
'thing' => 'identity providers',
'icon' => 'fa-id-badge',
'text' => 'Let agents and client contacts sign in with their Microsoft 365, Google Workspace or Nextcloud account, or with their mail password through an IMAP server - picked by the domain of their email address. No one new is added: the account has to be in ITFlow already.',
'actions' => array_map(function ($key, $info) use ($add_url) {
return ['label' => $info['name'], 'icon' => 'fa-plus', 'modal' => $add_url . $key, 'size' => 'lg'];
}, array_keys($kinds), $kinds),
];
?>
<?php require_once "../includes/filter_footer.php"; ?>
</div>
<?php
require_once "../includes/footer.php";