This is an old revision of the document!
Permanent Users
- A Permanent User has to belong to a Profile and Realm in order to be useful to RADIUS.
- In the previous Wiki Pages we already covered adding a Profile and a Realm.
- In this page we will show you how to add a Permanent User to a Cloud in RADIUSdesk using an API call.
- We will use PHP but the principles can be applied using any programming language.
Add a Permanent User using the API
- Below is a simple as possible script that can be used as reference when adding a Permanent User using the API.
- We also show the optional fields that can be included in the API call.
- 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; } ?>
- Now that we have created a Permanent User, we will cover some common actions that can be done on the Permanent User via the API.