-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapi_new_user.php
44 lines (37 loc) · 1.29 KB
/
api_new_user.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>New User</title>
</head>
<body>
<div class="container">
<?php
## - https://stackoverflow.com/questions/5647461/how-do-i-send-a-post-request-with-php
## - Simple function to post and return JSON
function httpPost($url, $data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_POST, 1);
$response = curl_exec($ch);
curl_close($ch);
$json_response = json_decode($response, true);
return $json_response;
}
// API access
$api_ip = '127.0.0.1';
$api_port = '2302';
$api_path = 'v1/account/';
// Creating a new user
$fields = ['action' => 'add', 'user' => 'randus', 'domain' => 'randomdomain.example.com', 'pass' => 'SuperSecretPass', 'email' => '[email protected]', 'package' => 1, 'inode' => 0, 'limit_nproc' => 40, 'limit_nofile' => 150, 'server_ips' => '34.254.187.152'];
$api_uri = 'https://'.$api_ip.':'.$api_port.'/'.$api_path;
$output = httpPost($api_uri, $fields);
echo '<textarea class="form-control">' . json_encode($output) . '</textarea>';
?>
</div>
</body>
</html>