// Create allowlist rule
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/$zone_id/firewall/rules");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'filter' => array(
'expression' => $allowlist_rule
),
'action' => 'allow'
)));
$result = curl_exec($ch);
echo $result;
// Check if allowlist rule addition is successful
if ($result->success === false) {
echo "Failed to add allowlist rule for domain {$domain} to Cloudflare\n";
continue;
}
// Create denyrule rule
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/$zone_id/firewall/rules");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'filter' => array(
'expression' => $denyrule_rule
),
'action' => 'block'
)));
// Create allowlist rule
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/$zone_id/firewall/rules");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'filter' => array(
'expression' => $allowlist_rule
),
'action' => 'allow'
)));
$result = curl_exec($ch);
echo $result;
// Check if allowlist rule addition is successful
if ($result->success === false) {
echo "Failed to add allowlist rule for domain {$domain} to Cloudflare\n";
continue;
}
// Create denyrule rule
curl_setopt($ch, CURLOPT_URL, "https://api.cloudflare.com/client/v4/zones/$zone_id/firewall/rules");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array(
'filter' => array(
'expression' => $denyrule_rule
),
'action' => 'block'
)));