-
Notifications
You must be signed in to change notification settings - Fork 0
/
process.php
62 lines (50 loc) · 1.81 KB
/
process.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
<?php
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
function handleSubdomainError($message) {
echo json_encode(['success' => false, 'message' => $message]);
exit();
}
if (!isset($_POST['subdomain'], $_POST['domain'], $_POST['type'], $_POST['ip_address'])) {
handleSubdomainError('Invalid or missing parameters');
}
$apiKey = 'YOUR_APIKEY'; // Apikey
$apiEmail = 'YOUR_EMAIL'; // Email Cloudflare
$listDomain = [
'yourdomain.com' => 'ZONE_ID', // Zone ID
'yourdomain.org' => 'ZONE_ID', // Zone ID
];
$subdomain = $_POST['subdomain'];
$domain = $_POST['domain'];
$type = $_POST['type'];
$ipAddress = $_POST['ip_address'];
$proxyStatus = false;
$zoneID = $listDomain[$domain];
$apiEndpoint = "https://api.cloudflare.com/client/v4/zones/{$zoneID}/dns_records";
$data = [
'type' => $type,
'name' => "{$subdomain}.{$domain}",
'content' => $ipAddress,
'ttl' => 1,
'proxied' => $proxyStatus,
];
$headers = [
'X-Auth-Email: ' . $apiEmail,
'X-Auth-Key: ' . $apiKey,
'Content-Type: application/json',
];
$ch = curl_init($apiEndpoint);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
echo json_encode(['success' => true]);
} else {
handleSubdomainError('Error creating subdomain. Please try again. Response: ' . $response);
}
}
?>