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']; ?>