mirror of
https://github.com/itflow-org/itflow
synced 2026-11-12 23:47:23 +00:00
Roles stage 3: roles and agents in the API and Admin > API Keys rebuilt; new api/v1/roles/read.php where an admin key reads every role with its level per module and agent count, archived on request, and any other key reads only its own user's role, and new api/v1/technicians/read.php listing agents with their role under Support at Read; API role refusals now say what the call needs and what the key's user has, naming the module, level and role, and technicians/time.php needs Read instead of Modify; Admin > API Keys shows each key's agent and role, what it can open and for which clients, whether it works (works until, expires in N days, expired, or won't work with the reason when its agent is disabled, archived, has no role or is missing) and when it was last used, with search by key or agent name; New and Edit windows show the picked agent's access as they are picked and offer only active agents, Create before ticking the copied box opens the Key tab, new keys default to a year and must end after today, and an expired key can be renamed and stay expired; handlers moved to functions/api_keys.php with validation, escaped messages and audit entries naming the agent and what an edit changed, fixing empty names on revoke, delete and bulk delete, a backslash shown for apostrophes in names, the bulk count of keys ticked rather than deleted, keys created already expired and expired keys that could not be renamed; database 3.1.7 adds api_keys.api_key_last_used_at, set at most once a minute in the configured timezone; changelog updated
This commit is contained in:
@@ -70,7 +70,7 @@ if (isset($_POST['api_key'])) {
|
||||
if (isset($api_key)) {
|
||||
$api_key = escapeSql($api_key);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT api_key_decrypt_hash, api_key_name, api_key_user_id FROM api_keys WHERE api_key_secret = '$api_key' AND api_key_expire > NOW() LIMIT 1");
|
||||
$sql = mysqli_query($mysqli, "SELECT api_key_id, api_key_decrypt_hash, api_key_name, api_key_user_id FROM api_keys WHERE api_key_secret = '$api_key' AND api_key_expire > NOW() LIMIT 1");
|
||||
|
||||
// Failed
|
||||
if (mysqli_num_rows($sql) !== 1) {
|
||||
@@ -96,6 +96,17 @@ if (isset($api_key)) {
|
||||
$api_key_decrypt_hash = $row['api_key_decrypt_hash']; // No sanitization
|
||||
$api_key_user_id = intval($row['api_key_user_id']);
|
||||
|
||||
// When it was last used, for Admin > API Keys - at most once a minute, not every call. In
|
||||
// ITFlow's own timezone, as the pages show it: the API doesn't set the clocks to it.
|
||||
$api_tz = mysqli_fetch_row(mysqli_query($mysqli, "SELECT config_timezone FROM settings WHERE company_id = 1"))[0] ?? '';
|
||||
try {
|
||||
$api_now = (new DateTime('now', new DateTimeZone($api_tz ?: 'UTC')))->format('Y-m-d H:i:s');
|
||||
} catch (Exception $e) {
|
||||
$api_now = date('Y-m-d H:i:s');
|
||||
}
|
||||
mysqli_query($mysqli, "UPDATE api_keys SET api_key_last_used_at = '$api_now' WHERE api_key_id = " . intval($row['api_key_id']) . "
|
||||
AND (api_key_last_used_at IS NULL OR api_key_last_used_at < '$api_now' - INTERVAL 1 MINUTE)");
|
||||
|
||||
// Set limit & offset for queries
|
||||
if (isset($_GET['limit'])) {
|
||||
$limit = intval($_GET['limit']);
|
||||
|
||||
Reference in New Issue
Block a user