type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* List Page Shield connections
* Lists all connections detected by Page Shield.
*/
export async function main(
auth: Cloudflare,
zone_id: string,
exclude_urls: string | undefined,
urls: string | undefined,
hosts: string | undefined,
page: string | undefined,
per_page: string | undefined,
order_by: "first_seen_at" | "last_seen_at" | undefined,
direction: "asc" | "desc" | undefined,
prioritize_malicious: string | undefined,
exclude_cdn_cgi: string | undefined,
status: string | undefined,
page_url: string | undefined,
_export: "csv" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_id}/page_shield/connections`
);
for (const [k, v] of [
["exclude_urls", exclude_urls],
["urls", urls],
["hosts", hosts],
["page", page],
["per_page", per_page],
["order_by", order_by],
["direction", direction],
["prioritize_malicious", prioritize_malicious],
["exclude_cdn_cgi", exclude_cdn_cgi],
["status", status],
["page_url", page_url],
["export", _export],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 383 days ago
type Cloudflare = {
token: string;
email: string;
key: string;
};
/**
* List Page Shield connections
* Lists all connections detected by Page Shield.
*/
export async function main(
auth: Cloudflare,
zone_id: string,
exclude_urls: string | undefined,
urls: string | undefined,
hosts: string | undefined,
page: string | undefined,
per_page: string | undefined,
order_by: "first_seen_at" | "last_seen_at" | undefined,
direction: "asc" | "desc" | undefined,
prioritize_malicious: string | undefined,
exclude_cdn_cgi: string | undefined,
status: string | undefined,
page_url: string | undefined,
_export: "csv" | undefined
) {
const url = new URL(
`https://api.cloudflare.com/client/v4/zones/${zone_id}/page_shield/connections`
);
for (const [k, v] of [
["exclude_urls", exclude_urls],
["urls", urls],
["hosts", hosts],
["page", page],
["per_page", per_page],
["order_by", order_by],
["direction", direction],
["prioritize_malicious", prioritize_malicious],
["exclude_cdn_cgi", exclude_cdn_cgi],
["status", status],
["page_url", page_url],
["export", _export],
]) {
if (v !== undefined && v !== "") {
url.searchParams.append(k, v);
}
}
const response = await fetch(url, {
method: "GET",
headers: {
"X-AUTH-EMAIL": auth.email,
"X-AUTH-KEY": auth.key,
Authorization: "Bearer " + auth.token,
},
body: undefined,
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 920 days ago