Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
technical:api-pu-disable [2025/04/13 09:05] – created system | technical:api-pu-disable [2025/04/13 15:13] (current) – system | ||
---|---|---|---|
Line 6: | Line 6: | ||
----- | ----- | ||
- | ====== Permanent Users ====== | + | ====== |
- | * A **Permanent User** has to belong to a **Profile** and **Realm** in order to be useful to RADIUS. | + | <alert type=" |
- | * In the previous Wiki Pages we already covered adding | + | * RADIUSdesk includes |
- | * In this page we will show you how to add a Permanent User to a Cloud in RADIUSdesk | + | * When this component is configured, any active sessions for a user will be terminated upon the completion of the enable or disable action. |
- | * We will use PHP but the principles can be applied using any programming language. | + | * 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. | |
- | ====== Add a Permanent User using the API ====== | + | * With the sample script we use two APIs |
- | + | * The one API is used get a list of Permanent | |
- | * Below is a simple as possible script that can be used as reference when adding | + | * The other API is used to either enable or disable |
- | * We also show the optional fields that can be included in the API call. | + | <file php permanent_user_disable_enable.php> |
- | <file php add_permanent_users.php> | + | |
<?php | <?php | ||
// Configuration | // Configuration | ||
- | $api_url | + | $server |
+ | $api_url | ||
$token | $token | ||
$cloud_id | $cloud_id | ||
- | $username | ||
- | $password | ||
- | $realm | ||
- | $profile | ||
- | |||
- | // Set API payload | ||
- | $payload = [ | ||
| | ||
- | //Required Fields | + | |
- | 'username' | + | |
- | | + | |
- | ' | + | // Filter settings |
- | | + | |
- | | + | |
- | | + | |
- | ' | + | |
- | + | ||
- | /* | + | $filter_array |
- | //Optional Fields | + | |
- | ' | + | " |
- | ' | + | " |
- | ' | + | " |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
- | ' | + | |
- | ' | + | |
- | | + | |
]; | ]; | ||
+ | |||
+ | $encoded_filter = urlencode(json_encode($filter_array)); | ||
+ | |||
+ | $find_url = " | ||
+ | | ||
- | $json_payload = json_encode($payload); | + | |
- | $ch = curl_init($api_url); | + | if($listOfIds){ |
- | curl_setopt($ch, | + | |
- | curl_setopt($ch, | + | $listOfIds[' |
- | curl_setopt($ch, | + | $listOfIds[' |
- | curl_setopt($ch, | + | $listOfIds[' |
- | + | | |
- | $response = curl_exec($ch); | + | |
- | curl_close($ch); | + | |
- | echo "Added $username: $response\n"; | + | curl_setopt($ch, |
- | + | curl_setopt($ch, | |
- | ?> | + | curl_setopt($ch, |
- | </ | + | curl_setopt($ch, |
- | * 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. | + | |
+ | $response = curl_exec($ch); | ||
+ | curl_close($ch); | ||
+ | echo " | ||
+ | | ||
+ | } | ||
+ | | ||
+ | function getIds(){ | ||
+ | global $find_url; | ||
+ | // Create stream context with headers | ||
+ | $context = stream_context_create([ | ||
+ | ' | ||
+ | ' | ||
+ | " | ||
+ | ] | ||
+ | ]); | ||
+ | | ||
+ | print($find_url); | ||
+ | |||
+ | // Get the response | ||
+ | $response = file_get_contents($find_url, | ||
+ | | ||
+ | if ($response === false) { | ||
+ | echo "Error fetching data"; | ||
+ | exit; | ||
+ | } | ||
+ | |||
+ | // Decode JSON | ||
+ | $data = json_decode($response, | ||
+ | if (!empty($data[' | ||
+ | $count | ||
+ | $listOfIds | ||
+ | foreach($data[' | ||
+ | $id = $permanentUser[' | ||
+ | $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: | ||
+ | <code php> | ||
+ | $username | ||
+ | $action | ||
+ | | ||
+ | // Filter settings | ||
+ | $filter | ||
+ | $operator | ||
+ | $value | ||
+ | $limit | ||
+ | </ | ||
+ | * By the same token, if we want to enable all disabled users we can adjust the filter as follows: | ||
+ | <code php> | ||
+ | $action | ||
+ | | ||
+ | // Filter settings | ||
+ | $filter | ||
+ | $operator | ||
+ | $value | ||
+ | $limit | ||
+ | </ |