Vouchers
- Vouchers are a once off way to give someone access to the Internet.
- With a voucher you don't care who are using it and we thus do not record any personal information with a voucher.
- A Voucher has to belong to a Profile and Realm in order to be useful to RADIUS.
- There are dedicated Wiki Pages that cover adding a Profile and a Realm.
- In this page we will show you how to add a Voucher to a Cloud in RADIUSdesk using an API call.
- We will use PHP but the principles can be applied using any programming language.
Options available when creating vouchers
- There are two classes of vouchers.
- Single Field - Username and Password are of the same value and typically an easy to remember compound word.
- Username and Password - Username and Password are different where the username is easy to remember but the password is a random generated string.
- There is the option to create a single voucher or a batch of vouchers.
- Batches will be grouped by a batch name.
- Activate and Expire
- By default a voucher never expires.
- One can specify an expiry date where-after the voucher can not be used.
- There is also the option to activate the voucher when a user logs in for the first time.
- These type of vouchers are time based and you can specify the how long after the first login the voucher expires.
- Extra Fields
- There are an optional Extra field name and Extra field value that can be used to store extra information.
Add single or batch using the API
- When using the API to generate vouchers you have the option to create a single voucher or a batch of vouchers.
- add_voucher.php
<?php // Configuration $api_url = 'http://127.0.0.1/cake4/rd_cake/vouchers/add.json'; $token = 'fe707444-b00c-b00c-b00c-03ae7fc12345'; $cloud_id = 23; // replace with the Cloud ID that you want to work on. $realm = 'pppoe'; $profile = 'slow'; // Set API payload $payload = [ //Required Fields 'single_field' => 'true', //must be set to the string 'true' to be activated 'realm' => $realm, 'profile' => $profile, 'cloud_id' => $cloud_id, 'token' => $token, //To create a batch these are needed (leave out for single voucher creation) 'quantity' => 10, 'batch' => 'api_batch_one' ]; $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 single voucher: $response\n"; ?>
- The reply will be in JSON which can be used should there be a requirement