-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateguest.php
93 lines (83 loc) · 2.96 KB
/
createguest.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<html>
<head>
<title>Create</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Cutive" rel="stylesheet">
</head>
<body>
<img src="logo.jpg">
<p>
guest credential
<p>
<?php
include 'tokens.php';
curl_setopt($process, CURLOPT_SSL_VERIFYPEER, true);
# Gets the logged in user's UPN, which is the Azure AD account used to login to the web app.
$userName = $_SERVER["HTTP_X_MS_CLIENT_PRINCIPAL_NAME"];
$email = $_POST["email"];
$phone = $_POST["phone"];
# Adds US country code to mobile phone
$phoneconvert ="1$phone";
#Allows a user to provide email, mobile phone, or both. Displays error if both fields are empty.
#Contents of $phoneinput variable cannot be included in the CURLOPT_POSTFIELDS below if $delivermethod is only EMAIL
if (($email == NULL) && ($phone == NULL)){
$error = "You need to provide a valid email or mobile phone number";
}elseif ($phone == NULL){
$phoneinput = NULL;
$delivermethod = "EMAIL";
}elseif ($email == NULL){
$phoneinput = ",\r\n \"phone\": \"$phoneconvert\"";
$delivermethod = "SMS";
}else {
$phoneinput = ",\r\n \"phone\": \"$phoneconvert\"";
$delivermethod = "EMAIL_AND_SMS";
}
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://cloud-va.aerohive.com/xapi/v1/identity/credentials?ownerId=$ownerId",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\r\n \"deliverMethod\": \"$delivermethod\",\r\n \"policy\": \"$policy\",\r\n \"email\": \"$email\",\r\n \"firstName\": \"$firstName\",\r\n \"groupId\": \"$groupIdguest\",\r\n \"lastName\": \"$lastName\",\r\n \"userName\": \"g.$userName\"$phoneinput\r\n}",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer $accesstoken",
"cache-control: no-cache",
"content-type: application/json",
"x-ah-api-client-id: $clientid",
"x-ah-api-client-redirect-uri: $redirecturi",
"x-ah-api-client-secret: $clientsecret"
),
));
$response = curl_exec($curl);
$json = json_decode($response);
$err = curl_error($curl);
curl_close($curl);
$ssid = $json->data->ssid[0];
$password = $json->data->password;
#If user already exists this will show the error reponse. Otherwise the SSID and PPSK will display.
if ($password == NULL) {
echo $response;
} else {
echo "SSID: " .$ssid;
echo "<br>Password: " .$password;
}
#Conditions for credential delivery messages
if ($password == NULL){
echo " ";
}elseif ($_POST["email"] == NULL){
echo "<p>Credentials have been sent via text to " .$phoneconvert;
}
elseif ($_POST["phone"] == NULL){
echo "<p>Credentials have been emailed to " .$email;
}else {
echo "<p>Credentials have been emailed to " .$email;
echo "<p>Credentials have been sent via text to " .$phoneconvert;
}
?>
<p>
<a id="returnbutton" href="<?php echo $returnurl ?>">Return</a>
</body>
</html>