-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.php
56 lines (45 loc) · 1.63 KB
/
generate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
session_start();
$name = $_POST['user'];
require("config.php");
/**
* PHP API usage example
*
* contributed by: Art of WiFi
* description: example basic PHP script to create a set of vouchers, returns an array containing the newly created vouchers
*/
//Replace {name} in the note variable by the name of the user.
$voucher_note = str_replace("{name}", $name, $voucher_note);
/**
* using the composer autoloader
*/
require_once('client.php');
/**
* include the config file (place your credentials etc. there if not already present)
* see the config.template.php file for an example
*/
require_once('config.php');
/**
* initialize the UniFi API connection class and log in to the controller
*/
$unifi_connection = new UniFi_API\Client($controlleruser, $controllerpassword, $controllerurl, $siteid, $controllerversion);
$set_debug_mode = $unifi_connection->set_debug($debug);
$loginresults = $unifi_connection->login();
/**
* then we create the required number of vouchers with the requested expiration value
*/
$voucher_result = $unifi_connection->create_voucher($voucher_expiration, "1", $voucher_usages, $voucher_note, $voucher_up, $voucher_down, $voucher_bandwith);
/**
* we then fetch the newly created vouchers by the create_time returned
*/
$vouchers = $unifi_connection->stat_voucher($voucher_result[0]->create_time);
/**
* provide feedback (the newly created vouchers) in json format
*/
echo json_encode($vouchers, JSON_PRETTY_PRINT);
foreach($vouchers as $voucher) {
$_SESSION['voucher'] = $voucher->code;
echo $_SESSION['voucher'];
header("Location: view/");
}
?>