PHP code example of sokolnikov911 / cloudflare-abuse-reports

1. Go to this page and download the library: Download sokolnikov911/cloudflare-abuse-reports library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sokolnikov911 / cloudflare-abuse-reports example snippets


use CloudflareAbuse\AbuseReportClient;

$client = new AbuseReportClient('your-cloudflare-api-token');

use CloudflareAbuse\AbuseReportClient;
use CloudflareAbuse\HttpTransport\CurlHttpTransport;

$client = new AbuseReportClient('your-api-token', new CurlHttpTransport(timeout: 60));

use CloudflareAbuse\Request\PhishingReportRequest;

$response = $client->submitReport('account-id', new PhishingReportRequest(
    email: '[email protected]',
    name: 'Jane Doe',
    urls: "https://evil.example.com/login\nhttps://evil.example.com/steal",
    justification: 'This page impersonates a bank login form.',
));

echo $response->abuseRand; // report identifier

use CloudflareAbuse\Request\DmcaReportRequest;

$response = $client->submitReport('account-id', new DmcaReportRequest(
    email: '[email protected]',
    name: 'John Copyright',
    urls: 'https://infringing.example.com/stolen-content',
    originalWork: 'https://original.example.com/my-work',
    address1: '123 Main St',
    city: 'New York',
    state: 'NY',
    country: 'US',
));

use CloudflareAbuse\Request\TrademarkReportRequest;

$response = $client->submitReport('account-id', new TrademarkReportRequest(
    email: '[email protected]',
    name: 'Legal Team',
    urls: 'https://infringing.example.com',
    trademarkNumber: 'TM12345',
    trademarkOffice: 'USPTO',
    trademarkSymbol: 'ACME',
    justification: 'Unauthorized use of our registered trademark.',
));

use CloudflareAbuse\Request\GeneralReportRequest;

$response = $client->submitReport('account-id', new GeneralReportRequest(
    email: '[email protected]',
    name: 'Security Team',
    urls: 'https://malicious.example.com',
    justification: 'C2 server distributing malware.',
    destinationIps: '203.0.113.42',
    portsProtocols: '443/TCP',
    sourceIps: '198.51.100.1',
));

use CloudflareAbuse\Enum\NotificationOption;
use CloudflareAbuse\Request\ThreatReportRequest;

new ThreatReportRequest(
    email: '[email protected]',
    name: 'Alice',
    urls: 'https://threat.example.com',
    hostNotification: NotificationOption::SendAnon,
    ownerNotification: NotificationOption::None,
);

$report = $client->getReport('account-id', 'report-id');

echo $report->id;
echo $report->domain;
echo $report->status; // "accepted" or "in_review"
echo $report->type;
echo $report->cdate;  // RFC 3339

use CloudflareAbuse\ListReportsParams;
use CloudflareAbuse\Enum\ReportStatus;
use CloudflareAbuse\Enum\ReportType;

$page = $client->listReports('account-id', new ListReportsParams(
    status: ReportStatus::InReview,
    type: ReportType::Phishing,
    domain: 'evil.example.com',
    perPage: 20,
    page: 1,
));

echo $page->totalCount;

foreach ($page->items as $report) {
    echo "{$report->id}: {$report->domain} ({$report->status})\n";
}

$mitigations = $client->listMitigations('account-id', 'report-id');

foreach ($mitigations as $m) {
    echo "{$m->id}: {$m->type} — {$m->status}\n";
}

$client->appealMitigations('account-id', 'report-id', 'This content is not infringing.');

use CloudflareAbuse\Exception\ApiException;

try {
    $report = $client->getReport('account-id', 'unknown-id');
} catch (ApiException $e) {
    echo $e->getMessage();    // Cloudflare error message
    echo $e->getStatusCode(); // HTTP status code
    print_r($e->getErrors()); // raw Cloudflare errors array
}