This is an old revision of the document!
Profiles
- Each Permanent User, Voucher or BYOD Device has to belong to a Profile and Realm in order to be useful to RADIUS.
- Before we can bulk import Permanent Users using a CSV file, we need to ensure that all the profiles used by the users in the CSV file already exist.
- In this page we will show you how to read profile names from a text file and then add each one to RADIUSdesk using an API call.
- We will use PHP but the principles can be applied using any programming language.
Add Profiles From List
- Below is the list of profiles we want to add.
- names.txt
MzanziFibre-12/1 MzanziFibre-25/5 MzanziFibre-25/10 MzanziFibre-50/20 MzanziFibre-100/40 MzanziFibre-100/20 MzanziFibre-250/20 MzanziFibre-250/25 MzanziFibre-250/100 MzanziFibre-400/40 MzanziFibre-500/200 MzanziFibre-1000/50 MzanziFibre-1000/400
- We store this file in the same directory as the script we will run to add them.
- add_profiles.php
<?php // Configuration $api_url = 'http://127.0.0.1/cake4/rd_cake/profiles/simple_add.json'; $names_file = 'names.txt'; // replace with your text file $token = 'fe707fcd-6399-4c66-b133-03ae7fc49000'; // replace with your token (If you want to add the profile as system wide, you will need root's token) $cloud_id = 23; // replace with the Cloud ID that you want to work on. // Read names from file $names = file($names_file, FILE_IGNORE_NEW_LINES); // Set API payload $payload = [ // "for_system" => "on", "id" => "", "name" => "", "data_limit_enabled" => "false", "time_limit_enabled" => "false", "speed_limit_enabled" => "false", "logintime_1_span" => "disabled", "logintime_2_span" => "disabled", "logintime_3_span" => "disabled", "session_limit_enabled" => "false", "adv_data_limit_enabled"=> "false", "adv_time_limit_enabled"=> "false", "token" => $token, "sel_language" => "4_4", "cloud_id" => $cloud_id ]; // Loop through names and call API foreach ($names as $name) { $payload['name'] = $name; $json_payload = json_encode($payload); $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 "Added $name: $response\n"; } ?>
- There are a few items which will be unique to your specific deployment.
- It is
- The Token.
- The Cloud ID.
- The server's FQDN / IP Address.
- The Token can be found when you edit an Admin.
- The Cloud ID is listed under the Cloud Applet.
- Below is the result of our script: