----- ====== Enable and Disable Permanent Users ====== * RADIUSdesk includes a component called 'ISP-Plumbing' which needs to be configured first. * When this component is configured, any active sessions for a user will be terminated upon the completion of the enable or disable action. * This comes in handy to move a user into or out of an isolation VLAN or network. * 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. $operator, "value" => $value, // this stays a boolean! "property" => $filter ] ]; $encoded_filter = urlencode(json_encode($filter_array)); $find_url = "$server/cake4/rd_cake/permanent-users/index.json?page=1&start=0&limit=$limit&filter=$encoded_filter&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" ] ]); print($find_url); // 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\n"; 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;