<?php
$cloudflare_zone_id = "5a0376ac99c8211cde514fcdae260484";
$cloudflare_token = "FkGF29hrqGwqVm9Ux112nav2ybzBbxTWhAyPzlLV";
$subdomain = "alvo";
$main_domain = "mikrol.ink";
$server_ip = "13.232.62.241";
// Configure Cloudflare DNS
$cloudflare_url = "https://api.cloudflare.com/client/v4/zones/$cloudflare_zone_id/dns_records";
$cloudflare_data = json_encode([
  'type'    => 'A',
  'name'    => "$subdomain.$main_domain",
  'content' => $server_ip, // Ensure this is set
  'ttl'     => 3600,
  'proxied' => true
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $cloudflare_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $cloudflare_data);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  "Content-Type: application/json",
  "Authorization: Bearer $cloudflare_token"
]);
//

$response = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
} else {
    $response_data = json_decode($response, true);
    if ($response_data['success']) {
        echo "Subdomain $subdomain.$main_domain created successfully.";
    } else {
        echo "Failed to create subdomain: " . $response_data['errors'][0]['message'];
    }
}
