<?php
// URL API Anda
$api_url = 'https://api.nf22.my.id/subscribe/server2';

// Data yang akan dikirimkan via POST
$post_data = [
    'api_key' => '4HfbvZzcxW7wxMamGtknOffUsF7DharH',      // Ganti dengan API Key Anda
    'secret_key' => 'nfhr67430skf1ocI4gg',  // Ganti dengan Secret Key Anda
    'action' => 'tambah_subdomain', // Action Jangan Diubah
    'token' => 'hm37v8PLx4IseOY6WWyCujbPRVLhw_tgCHkXZvdP', // Ganti dengan Token CloudFlare Anda
    'zoneid' => '554326bd56b2ecdd303d3d4897033bec', // Ganti dengan Zone ID CloudFlare Anda
    'subdomain' => 'test', // Ganti dengan subdomain yang ingin dibuat
    'ip' => '8.219.116.134', // Ganti dengan IP Server Anda
    'type' => 'A', // Jenis record (A, AAAA, CNAME, MX, TXT)
    'proxied' => 'false' // CloudFlare proxy (true/false)
];

// Eksekusi request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);

$response = curl_exec($ch);

if (curl_errno($ch)) {
    die('Error: ' . curl_error($ch));
}

curl_close($ch);

// Proses response
$result = json_decode($response, true);

if ($result['status']) {
    echo "Subdomain berhasil dibuat!\n";
    echo "Detail:\n";
    echo "ID: " . $result['data']['id'] . "\n";
    echo "Name: " . $result['data']['name'] . "\n";
    echo "Type: " . $result['data']['type'] . "\n";
    echo "IP: " . $result['data']['content'] . "\n";
    echo "Proxied: " . ($result['data']['proxied'] ? 'Yes' : 'No') . "\n";
    echo "Created: " . $result['data']['created_on'] . "\n";
} else {
    echo "Gagal membuat subdomain!\n";
    echo "Error: " . ($result['data']['pesan'] ?? 'Unknown error') . "\n";
}
?>