This is an old revision of the document!
Enable and Disable Permanent Users
- To enable or disable a Permanent User we have to first determine the id of the Permanent User.
- A CRM system typically do not know the id of the Permanent User in RADIUSdesk.
- With the sample script we use two APIs
- The one API is used get a list of Permanent Users to collect their ids.
- The other API is used to either enable or disable the list of Permanent Users which was obtained.
- permanent_user_disable_enable.php
<?php // Configuration $server = 'http://127.0.0.1'; $api_url = "$server/cake4/rd_cake/permanent-users/enable-disable.json"; $token = 'b4c6ac81-8c7c-4802-b50a-0a6380555b50'; $cloud_id = 23; // replace with the Cloud ID that you want to work on. $username = 'testuser@dev'; $action = 'enable'; //Options 'enable' or 'disable' // Filter settings $filter = 'username'; //field that filter should apply to $operator = '=='; //Options '==','like' $value = $username; //can also be set to boolean e.g. true or false to filter for instance on the 'active' field $limit = 1000; $find_url = "$server/cake4/rd_cake/permanent-users/index.json?page=1&start=0&limit=$limit&filter=[{%22operator%22%3A%22$operator%22%2C%22value%22%3A%22".$value."%22%2C%22property%22%3A%22$filter%22}]&token=$token&cloud_id=$cloud_id"; $listOfIds = getIds(); if($listOfIds){ $listOfIds['cloud_id'] = $cloud_id; $listOfIds['token'] = $token; $listOfIds['rb'] = $action; $json_payload = json_encode($listOfIds); $ch = curl_init($api_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_payload); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); $response = curl_exec($ch); curl_close($ch); echo "Response: $response\n"; } function getIds(){ global $find_url; // Create stream context with headers $context = stream_context_create([ 'http' => [ 'header' => "Accept: application/json\r\n" . "Content-Type: application/json\r\n" ] ]); // Get the response $response = file_get_contents($find_url, false, $context); if ($response === false) { echo "Error fetching data"; exit; } // Decode JSON $data = json_decode($response, true); if (!empty($data['items']) && is_array($data['items'])) { $count = count($data['items']); $listOfIds = []; foreach($data['items'] as $permanentUser){ $id = $permanentUser['id']; $listOfIds[$id] = $id; } echo "There $count items!"; return $listOfIds; } else { echo "No items."; } return false; } ?>
- We are not limited to only one user but we can adjust the filter for instance to disable all the users with a specific suffix e.g. @dev.
- For this we have to make the following adjustments:
$username = '@dev'; $action = 'disable'; //Options 'enable' or 'disable' // Filter settings $filter = 'username'; //field that filter should apply to $operator = 'like'; //Options '==','like' $value = $username; //can also be set to boolean e.g. true or false to filter for instance on the 'active' field $limit = 1000;
- By the same token, if we want to enable all disabled users we can adjust the filter as follows:
$action = 'enable'; //Options 'enable' or 'disable' // Filter settings $filter = 'active'; //field that filter should apply to $operator = '=='; //Options '==','like' $value = false; //can also be set to boolean e.g. true or false to filter for instance on the 'active' field $limit = 1000;