RADIUSdesk WiFi Hotspot Manager and GUI for FreeRADIUS
MESHdesk Streamlined Mesh Controller

Introduction

  • Like most modern web application RADIUSdesk features an API which enable you to do anything you do from the web interface trough standard HTTP calls.
  • This allows you to script things like the creation of Permanent Users or Vouchers by third party systems.

Getting started

  • Rather than giving you a fish we are rather going to teach you how to catch your own fishes. Once you know how to catch them; you can open a fish and chips store ;-)
  • The main important tool to use is Firebug (or something similar) to inspect the data which are submitted to the back end when you do an action from the web interface. Have a look at the Network tab
    • Take note of the URL that is called.
    • Take note of the Action (e.g. GET or POST)
    • Take note of the parameters included in the request.
  • We can then make use of these to create our own script which can be used for mass action.
  • See the following example which we created by looking at the POST url for adding a Permanent User.
user_add.php
<?php
 
print("RADIUSdesk API to Add a Permanent User");
/*
 
    *active	            active (leave out tocreate disabled account)
    address	
    always_active	    always_active
    *cap_data	        soft
    email	
    *language	        4_4
    name	
    *parent_id	        0
    *password	        hotel_room1
    phone	
    *profile_id	        9
    *realm_id	        34
    *sel_language	    4_4
    surname	
    *token	            52190fff-a800-48eb-b1f2-478bc0a80167 (replace with root or access provider's unique token)
    *track_acct	        track_acct
    *username	        hotel_room1
 
*/
 
$active         = 'active';
$cap_data       = 'soft';
$language       = '4_4';
$parent_id      = 0;
$profile_id     = 9;
$realm_id       = 34;
$token          = '52190fff-a800-48eb-b1f2-478bc0a80167';
 
$username       = 'hotel_room1';
$password       = 'hotel_room1';
 
$url            = 'http://127.0.0.1/cake2/rd_cake/permanent_users/add.json';
 
// The data to send to the API
$postData = array(
    'active'        => $active,
    'cap_data'      => $cap_data,
    'language'      => $language,
    'parent_id'     => $parent_id,
    'profile_id'    => $profile_id,
    'realm_id'      => $realm_id,
    'token'         => $token,
    'username'      => $username,
    'password'      => $password
);
 
// Setup cURL
$ch = curl_init($url);
curl_setopt_array($ch, array(
 
    CURLOPT_POST            => TRUE,
    CURLOPT_RETURNTRANSFER  => TRUE,
    CURLOPT_HTTPHEADER => array(
        'Content-Type: application/json'
    ),
    CURLOPT_POSTFIELDS => json_encode($postData)
));
 
// Send the request
$response = curl_exec($ch);
 
// Check for errors
if($response === FALSE){
    die(curl_error($ch));
}
 
// Decode the response
$responseData = json_decode($response, TRUE);
print_r($responseData);
 
?>