API Keys - the keys other systems use the API with. Each acts as * an agent, so each shows who, what their role opens and which clients * they see, whether the key works (it expires, and an agent who is * disabled, archived or has no role turns every call away) and when it was * last used. A revoked key has expired, so it moves to Expired, where it can * be deleted. The work is in functions/api_keys.php; the handlers are * admin/post/api_keys.php. */ // Default Column Sortby Filter $sort = "api_key_name"; $order = "ASC"; require_once "includes/inc_all_admin.php"; $show_expired = ($_GET['show'] ?? '') === 'expired'; // Only these sort - an unknown column would take the page down $sortable_columns = [ 'api_key_name' => "api_key_name $order", 'api_key_expire' => "api_key_expire $order, api_key_name ASC", 'user_name' => "user_name IS NULL, user_name $order, api_key_name ASC", 'api_key_last_used_at' => "api_key_last_used_at IS NULL, api_key_last_used_at $order, api_key_name ASC", ]; if (!isset($sortable_columns[$sort])) { $sort = 'api_key_name'; } // It works until the start of its expiry date - as apiKeyExpired() has it $today = date('Y-m-d'); $search = "(api_key_name LIKE '%$q%' OR user_name LIKE '%$q%')"; $sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS api_key_id, api_key_name, api_key_secret, api_key_created_at, api_key_expire, api_key_user_id, api_key_last_used_at, user_name, user_avatar, user_type, user_status, user_archived_at, user_role_id FROM api_keys LEFT JOIN users ON user_id = api_key_user_id WHERE $search AND api_key_expire " . ($show_expired ? '<=' : '>') . " '$today' ORDER BY {$sortable_columns[$sort]}, api_key_id ASC LIMIT $record_from, $record_to"); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); $keys = []; while ($row = mysqli_fetch_assoc($sql)) { $keys[intval($row['api_key_id'])] = $row; } $roles = roleRows(); $access = userClientAccess(array_filter(array_map('intval', array_column($keys, 'api_key_user_id')))); $counts = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(SUM(api_key_expire > '$today'), 0), COALESCE(SUM(api_key_expire <= '$today'), 0) FROM api_keys LEFT JOIN users ON user_id = api_key_user_id WHERE $search")); $sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) { return '' . $label . ($sort === $column ? " $order_icon" : '') . ''; }; $csrf = $_SESSION['csrf_token']; ?>

API Keys

"> $row) { $name = escapeHtml($row['api_key_name']); $role = $roles[intval($row['user_role_id'])] ?? null; $expired = apiKeyExpired($row); $agent_name = trim(str_replace(' (archived)', '', (string) $row['user_name'])); $last_used = $row['api_key_last_used_at'] ? '' . escapeHtml(timeAgo($row['api_key_last_used_at'])) . '' : 'Never'; ob_start(); ?>
Nobody' . escapeHtml(userClientAccessText($access[intval($row['api_key_user_id'])] ?? ['allow' => [], 'deny' => []], intval($role['role_is_admin']))) . '' : 'Nothing'; ?>
Can open
•••• · made
Last used
'API keys', 'icon' => 'fa-key', 'filtered' => $q !== '', 'archived' => $show_expired, 'archived_title' => 'No expired API keys', 'views' => ['show'], 'text' => 'A key lets another system read and write ITFlow through its API, as one of your agents - it can do what their role allows, for the clients they see, until it expires.', 'actions' => [['label' => 'New API Key', 'modal' => 'modals/api/api_key_add.php']], ]; require_once "../includes/filter_footer.php"; ?>