seo-supervisor 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/icon.png +0 -0
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +16 -3
- package/CHANGELOG.md +430 -0
- package/NOTICE +7 -0
- package/README.md +230 -25
- package/agents/seo-auditor.md +16 -0
- package/agents/seo-reviewer.md +16 -0
- package/bin/agents.mjs +194 -29
- package/bin/extras.mjs +422 -0
- package/bin/prompt.mjs +34 -14
- package/bin/seo-supervisor.mjs +386 -53
- package/commands/seo-audit.md +29 -3
- package/commands/seo-brief.md +28 -0
- package/commands/seo-connect.md +27 -0
- package/commands/seo-fix.md +24 -3
- package/commands/seo-grow.md +26 -0
- package/commands/seo-launch.md +17 -3
- package/commands/seo-review.md +13 -1
- package/commands/seo-rewrite.md +25 -0
- package/commands/seo-setup.md +17 -1
- package/commands/seo-watch.md +28 -0
- package/hooks/hooks.json +117 -0
- package/package.json +20 -7
- package/skills/seo-supervisor/NOTICE +7 -0
- package/skills/seo-supervisor/SKILL.md +302 -21
- package/skills/seo-supervisor/audience.md +61 -0
- package/skills/seo-supervisor/examples/drafts/security.md +41 -0
- package/skills/seo-supervisor/examples/hooks/README.md +28 -0
- package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
- package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
- package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
- package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
- package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
- package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
- package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
- package/skills/seo-supervisor/examples/sample-audit.json +94 -2
- package/skills/seo-supervisor/examples/sample-report.html +111 -61
- package/skills/seo-supervisor/examples/sample-report.md +147 -44
- package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
- package/skills/seo-supervisor/examples/snippets.md +648 -1
- package/skills/seo-supervisor/grow.md +342 -0
- package/skills/seo-supervisor/og-images.md +85 -0
- package/skills/seo-supervisor/page-types.md +124 -0
- package/skills/seo-supervisor/planning.md +19 -7
- package/skills/seo-supervisor/profile-template.md +41 -0
- package/skills/seo-supervisor/report-format.md +177 -10
- package/skills/seo-supervisor/rewrite.md +59 -0
- package/skills/seo-supervisor/rules/ai-search.md +65 -12
- package/skills/seo-supervisor/rules/content.md +33 -9
- package/skills/seo-supervisor/rules/crawl-index.md +33 -6
- package/skills/seo-supervisor/rules/internal-linking.md +49 -6
- package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
- package/skills/seo-supervisor/rules/media.md +13 -1
- package/skills/seo-supervisor/rules/metadata.md +41 -9
- package/skills/seo-supervisor/rules/performance.md +50 -5
- package/skills/seo-supervisor/rules/rendering.md +39 -2
- package/skills/seo-supervisor/rules/search-intent.md +32 -0
- package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
- package/skills/seo-supervisor/rules/structured-data.md +37 -14
- package/skills/seo-supervisor/rules/trust-security.md +25 -2
- package/skills/seo-supervisor/rules/urls.md +10 -2
- package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
- package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
- package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
- package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
- package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
- package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
- package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
- package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
- package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
- package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
- package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
- package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
- package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
- package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
- package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
- package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
- package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
- package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
- package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
- package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
- package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
- package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
- package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
- package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
- package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
- package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
- package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
- package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
- package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
- package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
- package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
- package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
- package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
- package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
- package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
- package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
- package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
- package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
- package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
- package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
- package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
- package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
- package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
- package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
- package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
- package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
- package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
- package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
- package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
- package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
- package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
- package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
- package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
- package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
- package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
- package/skills/seo-supervisor/scripts/google.mjs +1341 -0
- package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
- package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
- package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
- package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
- package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
- package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
- package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
- package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
- package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
- package/skills/seo-supervisor/scripts/guard.mjs +74 -0
- package/skills/seo-supervisor/scripts/images.mjs +408 -0
- package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
- package/skills/seo-supervisor/scripts/issues.mjs +217 -0
- package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
- package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
- package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
- package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
- package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
- package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
- package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
- package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
- package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
- package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
- package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
- package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
- package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
- package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
- package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
- package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
- package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
- package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
- package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
- package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
- package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
- package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
- package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
- package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
- package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
- package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
- package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
- package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
- package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
- package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
- package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
- package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
- package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
- package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
- package/skills/seo-supervisor/scripts/osm.mjs +359 -0
- package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
- package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
- package/skills/seo-supervisor/scripts/report/client.js +37 -0
- package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
- package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
- package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
- package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
- package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
- package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
- package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
- package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
- package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
- package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
- package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
- package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
- package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
- package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
- package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
- package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
- package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
- package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
- package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
- package/skills/seo-supervisor/scripts/report/styles.css +223 -0
- package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
- package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
- package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
- package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
- package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
- package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
- package/skills/seo-supervisor/site-types/content.md +34 -1
- package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
- package/skills/seo-supervisor/site-types/local-business.md +96 -6
- package/skills/seo-supervisor/site-types/services.md +46 -0
- package/skills/seo-supervisor/site-types/tools.md +3 -3
- package/skills/seo-supervisor/strategy.md +232 -0
- package/skills/seo-supervisor/troubleshooting.md +56 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Reads the site's own access logs to show how search and AI crawlers actually treat the site.
|
|
4
|
+
import { createReadStream, existsSync, statSync, readdirSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { pipeline } from "node:stream";
|
|
6
|
+
import { createGunzip } from "node:zlib";
|
|
7
|
+
import { createInterface } from "node:readline";
|
|
8
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
9
|
+
import { BlockList, isIP } from "node:net";
|
|
10
|
+
import { promises as dns } from "node:dns";
|
|
11
|
+
import { isMain } from "./lib/is-main.mjs";
|
|
12
|
+
import { parseArgs } from "./lib/args.mjs";
|
|
13
|
+
import { Fail, runMain } from "./lib/cli.mjs";
|
|
14
|
+
import { findingOf, numbered } from "./lib/findings.mjs";
|
|
15
|
+
import { BOTS as BOT_ROWS } from "./checks/agents.mjs";
|
|
16
|
+
|
|
17
|
+
// --site is the other scripts' name for --site-origin.
|
|
18
|
+
const USAGE =
|
|
19
|
+
"usage: node log-scan.mjs --log access.log [--log logs/] [--since YYYY-MM-DD] [--site-origin https://x] [--crawl seo-audit/seo-crawl.json] [--verify-ips [folder]] [--out seo-audit/log-scan.json]";
|
|
20
|
+
async function main(argv) {
|
|
21
|
+
const args = parseArgs(argv, {
|
|
22
|
+
flags: ["since", "site-origin", "crawl", "verify-ips", "out"],
|
|
23
|
+
lists: ["log"],
|
|
24
|
+
aliases: { site: "site-origin" },
|
|
25
|
+
positionals: 0,
|
|
26
|
+
usage: USAGE,
|
|
27
|
+
});
|
|
28
|
+
args.log ||= [];
|
|
29
|
+
/** @type {(msg: string) => never} */
|
|
30
|
+
const fail = msg => {
|
|
31
|
+
throw new Fail(`log-scan: ${msg}`);
|
|
32
|
+
};
|
|
33
|
+
if (!args.log.length || args.log.some(v => typeof v !== "string")) throw new Fail(USAGE);
|
|
34
|
+
const OUT = resolve(typeof args.out === "string" ? args.out : "seo-audit/log-scan.json");
|
|
35
|
+
const SINCE = args.since === undefined ? null : Date.parse(`${args.since}T00:00:00Z`);
|
|
36
|
+
if (args.since !== undefined && (!/^\d{4}-\d{2}-\d{2}$/.test(args.since) || isNaN(SINCE)))
|
|
37
|
+
fail(`--since takes a date as YYYY-MM-DD (e.g. 2026-10-01), not "${args.since}".`);
|
|
38
|
+
let ORIGIN = "";
|
|
39
|
+
if (typeof args["site-origin"] === "string") {
|
|
40
|
+
try {
|
|
41
|
+
ORIGIN = new URL(args["site-origin"]).origin;
|
|
42
|
+
} catch {
|
|
43
|
+
fail(`--site-origin must be a URL like https://www.example.com, not "${args["site-origin"]}".`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Matched as a case-insensitive User-Agent substring and the first match wins, so Google's other agents sit above
|
|
48
|
+
// Googlebot in data/ai-bots.json. Rows with no group (Google-Extended, Applebot-Extended, YandexAdditionalBot) are
|
|
49
|
+
// robots.txt tokens, not user agents, so logs can't show them.
|
|
50
|
+
const BOTS = BOT_ROWS.filter(b => b.group).map(({ name, vendor, group, purpose }) => ({
|
|
51
|
+
name,
|
|
52
|
+
token: name.toLowerCase(),
|
|
53
|
+
vendor,
|
|
54
|
+
group,
|
|
55
|
+
purpose,
|
|
56
|
+
}));
|
|
57
|
+
// Every vendor list uses the { prefixes: [{ ipv4Prefix | ipv6Prefix }] } format. Google doesn't tie Gemini Notebook
|
|
58
|
+
// or Messages to one of its two user-triggered files, so either counts.
|
|
59
|
+
// https://developers.google.com/search/docs/crawling-indexing/verifying-googlebot
|
|
60
|
+
// Lists published only as TOML or web pages (a row's ipsAt) can't be read here; UNREADABLE names them in a note.
|
|
61
|
+
const IP_LISTS = Object.fromEntries(BOT_ROWS.filter(b => b.group && b.ips).map(b => [b.name, b.ips]));
|
|
62
|
+
const UNREADABLE = Object.fromEntries(BOT_ROWS.filter(b => b.group && b.ipsAt).map(b => [b.name, b.ipsAt]));
|
|
63
|
+
// bot name -> the BlockLists of its lists that loaded; null without --verify-ips. A folder holds lists saved under
|
|
64
|
+
// their own file names (searchbot.json, common-crawlers.json …); a list that's missing or unreadable is skipped.
|
|
65
|
+
// Downloading sends one GET per list and nothing about the site.
|
|
66
|
+
let ipLists = null;
|
|
67
|
+
if (args["verify-ips"] !== undefined) {
|
|
68
|
+
const from = args["verify-ips"],
|
|
69
|
+
loaded = new Map();
|
|
70
|
+
for (const u of new Set(Object.values(IP_LISTS).flat())) {
|
|
71
|
+
try {
|
|
72
|
+
const j =
|
|
73
|
+
typeof from === "string"
|
|
74
|
+
? JSON.parse(readFileSync(join(from, basename(new URL(u).pathname)), "utf8"))
|
|
75
|
+
: await (await fetch(u, { signal: AbortSignal.timeout(20000) })).json();
|
|
76
|
+
const bl = new BlockList();
|
|
77
|
+
for (const p of j.prefixes || []) {
|
|
78
|
+
const [net, bits] = String(p.ipv4Prefix || p.ipv6Prefix || "").split("/"),
|
|
79
|
+
v = isIP(net);
|
|
80
|
+
if (v) bl.addSubnet(net, Number(bits ?? (v === 6 ? 128 : 32)), v === 6 ? "ipv6" : "ipv4");
|
|
81
|
+
}
|
|
82
|
+
loaded.set(u, bl);
|
|
83
|
+
} catch {}
|
|
84
|
+
}
|
|
85
|
+
ipLists = new Map(
|
|
86
|
+
Object.entries(IP_LISTS)
|
|
87
|
+
.map(([bot, us]) => /** @type {const} */ ([bot, us.filter(u => loaded.has(u)).map(u => loaded.get(u))]))
|
|
88
|
+
.filter(([, bls]) => bls.length),
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
// The log's client address, an IPv4-mapped IPv6 one read as IPv4; null when the line has none.
|
|
92
|
+
const addrOf = ip => {
|
|
93
|
+
const a = String(ip ?? "")
|
|
94
|
+
.trim()
|
|
95
|
+
.replace(/^::ffff:(?=\d+\.\d+\.\d+\.\d+$)/i, "");
|
|
96
|
+
return isIP(a) ? a : null;
|
|
97
|
+
};
|
|
98
|
+
const family = a => (isIP(a) === 6 ? "ipv6" : "ipv4");
|
|
99
|
+
// true when ip is in the bot's lists, false when it isn't, null when the line has no address.
|
|
100
|
+
const fromVendor = (name, ip) => {
|
|
101
|
+
const a = addrOf(ip);
|
|
102
|
+
return a ? ipLists.get(name).some(bl => bl.check(a, family(a))) : null;
|
|
103
|
+
};
|
|
104
|
+
// Yandex publishes no IP list: a reverse lookup must give a yandex.ru, .net or .com name whose forward lookup gives
|
|
105
|
+
// the address back. https://yandex.com/support/webmaster/en/robot-workings/check-yandex-robots
|
|
106
|
+
// Lookups use this computer's DNS server, once per distinct address, at most 200 a bot, busiest first. With a folder
|
|
107
|
+
// (OFFLINE) nothing is contacted, so those bots get a note instead.
|
|
108
|
+
const DNS_CHECK = { YandexBot: /(^|\.)yandex\.(ru|net|com)\.?$/i },
|
|
109
|
+
DNS_MAX = 200,
|
|
110
|
+
OFFLINE = typeof args["verify-ips"] === "string";
|
|
111
|
+
// true: the names lead back to the address; false: no name on those domains, or it doesn't lead back; null: no
|
|
112
|
+
// answer.
|
|
113
|
+
const byDns = async (re, a) => {
|
|
114
|
+
try {
|
|
115
|
+
const bl = new BlockList();
|
|
116
|
+
bl.addAddress(a, family(a));
|
|
117
|
+
for (const name of (await dns.reverse(a)).filter(n => re.test(n))) {
|
|
118
|
+
try {
|
|
119
|
+
if ((await dns.lookup(name, { all: true })).some(x => bl.check(x.address, x.family === 6 ? "ipv6" : "ipv4")))
|
|
120
|
+
return true;
|
|
121
|
+
} catch (e) {
|
|
122
|
+
if (e.code !== "ENOTFOUND" && e.code !== "ENODATA") return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return false;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
return e.code === "ENOTFOUND" || e.code === "ENODATA" ? false : null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const AI_REFERRERS = [
|
|
131
|
+
"chatgpt.com",
|
|
132
|
+
"chat.openai.com",
|
|
133
|
+
"perplexity.ai",
|
|
134
|
+
"claude.ai",
|
|
135
|
+
"gemini.google.com",
|
|
136
|
+
"copilot.microsoft.com",
|
|
137
|
+
];
|
|
138
|
+
// Google Search, Images and Discover send a Google domain or the Android app as Referer. Only landing pages count:
|
|
139
|
+
// Google Images loads full-size files with the same Referer.
|
|
140
|
+
// https://developers.google.com/search/docs/monitor-debug/identify-google-search-traffic
|
|
141
|
+
// Known limit: a page path ending in a short extension (/notes.post) reads as a file.
|
|
142
|
+
const GOOGLE_HOST = /^(www\.)?google\.(com|[a-z]{2}|com?\.[a-z]{2})$/,
|
|
143
|
+
GOOGLE_APP = /^android-app:\/\/com\.google\.android\.googlequicksearchbox(\/|$)/i;
|
|
144
|
+
const FILE = /\.(?!html?$|php$|aspx?$)[a-z0-9]{1,5}$/i;
|
|
145
|
+
|
|
146
|
+
// ---------- parsing ----------
|
|
147
|
+
const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
|
|
148
|
+
const clfTime = s => {
|
|
149
|
+
// "10/Oct/2026:13:55:36 +0500"
|
|
150
|
+
const m = /^(\d{2})\/(\w{3})\/(\d{4}):(\d{2}:\d{2}:\d{2}) ([+-]\d{2})(\d{2})$/.exec(s),
|
|
151
|
+
mo = m && MONTHS.indexOf(m[2].toLowerCase()) + 1;
|
|
152
|
+
return mo ? new Date(`${m[3]}-${String(mo).padStart(2, "0")}-${m[1]}T${m[4]}${m[5]}:${m[6]}`) : null;
|
|
153
|
+
};
|
|
154
|
+
const anyTime = v => {
|
|
155
|
+
if (typeof v === "string" && /^\d+(\.\d+)?$/.test(v)) v = Number(v);
|
|
156
|
+
if (typeof v === "number") return new Date(v > 1e15 ? v / 1e6 : v > 1e11 ? v : v * 1000); // ns, ms or s since 1970
|
|
157
|
+
return typeof v === "string" ? clfTime(v) || new Date(v) : null;
|
|
158
|
+
};
|
|
159
|
+
const pick = (o, ...keys) => {
|
|
160
|
+
for (const k of keys) if (o[k] != null && o[k] !== "") return o[k];
|
|
161
|
+
};
|
|
162
|
+
const Q = String.raw`"((?:[^"\\]|\\.)*)"`; // a quoted field; Apache escapes quotes inside it as \"
|
|
163
|
+
// Detected per line: Apache/Nginx combined and common format (anything may precede [time], so vhost_combined works),
|
|
164
|
+
// or JSON lines, Cloudflare Logpush field names included.
|
|
165
|
+
const CLF = new RegExp(String.raw`\[([^\]]+)\] ${Q} (\d{3}) \S+(?: ${Q} ${Q})?`);
|
|
166
|
+
const parse = line => {
|
|
167
|
+
if (line[0] === "{") {
|
|
168
|
+
let o;
|
|
169
|
+
try {
|
|
170
|
+
o = JSON.parse(line);
|
|
171
|
+
} catch {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
time: anyTime(
|
|
176
|
+
pick(o, "time", "timestamp", "@timestamp", "date", "time_local", "time_iso8601", "EdgeStartTimestamp"),
|
|
177
|
+
),
|
|
178
|
+
target: pick(o, "path", "url", "uri", "request_uri", "ClientRequestURI", "ClientRequestPath"),
|
|
179
|
+
status: Number(pick(o, "status", "status_code", "EdgeResponseStatus")),
|
|
180
|
+
ua: pick(o, "ua", "user_agent", "userAgent", "http_user_agent", "ClientRequestUserAgent"),
|
|
181
|
+
referer: pick(o, "referer", "referrer", "http_referer", "ClientRequestReferer"),
|
|
182
|
+
ip: pick(o, "ip", "remote_addr", "client_ip", "clientIp", "ClientIP", "remote_ip", "remoteIp"),
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
const m = CLF.exec(line);
|
|
186
|
+
// The client address is the third field before [time] (host ident user), whatever comes before it.
|
|
187
|
+
return (
|
|
188
|
+
m && {
|
|
189
|
+
time: clfTime(m[1]),
|
|
190
|
+
target: m[2].split(" ")[1],
|
|
191
|
+
status: Number(m[3]),
|
|
192
|
+
ua: m[5],
|
|
193
|
+
referer: m[4],
|
|
194
|
+
ip: /(\S+) \S+ \S+ \[/.exec(line)?.[1],
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
};
|
|
198
|
+
// Path plus query, whether the log wrote "/a?b" or "https://host/a?b".
|
|
199
|
+
const pathOf = t => {
|
|
200
|
+
try {
|
|
201
|
+
const u = new URL(t, "http://x.invalid");
|
|
202
|
+
return u.pathname + u.search;
|
|
203
|
+
} catch {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
const hostOf = s => {
|
|
208
|
+
try {
|
|
209
|
+
return new URL(s).hostname.toLowerCase();
|
|
210
|
+
} catch {
|
|
211
|
+
return "";
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
// Paths the crawl reached, which it only does through internal links, the sitemap or the start URL.
|
|
215
|
+
let CRAWLED = null;
|
|
216
|
+
if (args.crawl !== undefined) {
|
|
217
|
+
try {
|
|
218
|
+
const c = JSON.parse(readFileSync(args.crawl, "utf8"));
|
|
219
|
+
CRAWLED = new Set([...c.pages, ...(c.errors || [])].map(p => pathOf(p.url)));
|
|
220
|
+
} catch {
|
|
221
|
+
fail(`--crawl takes the crawler's seo-audit/seo-crawl.json, and ${args.crawl} isn't one.`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// ---------- reading ----------
|
|
226
|
+
const files = [];
|
|
227
|
+
for (const p of args.log) {
|
|
228
|
+
if (!existsSync(p)) fail(`${p} doesn't exist. Pass an access log, a .gz of one, or a folder of them.`);
|
|
229
|
+
if (statSync(p).isDirectory())
|
|
230
|
+
files.push(
|
|
231
|
+
...readdirSync(p)
|
|
232
|
+
.sort()
|
|
233
|
+
.map(f => join(p, f))
|
|
234
|
+
.filter(f => statSync(f).isFile()),
|
|
235
|
+
);
|
|
236
|
+
else files.push(p);
|
|
237
|
+
}
|
|
238
|
+
if (!files.length) fail(`no files in ${args.log.join(", ")}.`);
|
|
239
|
+
|
|
240
|
+
// One Map entry per distinct path per bot, held in memory: fine for a few million paths. Stream to disk past that.
|
|
241
|
+
const bots = {},
|
|
242
|
+
referrals = {},
|
|
243
|
+
google = new Map(),
|
|
244
|
+
period = { from: null, to: null },
|
|
245
|
+
notes = [];
|
|
246
|
+
const stats = { files: files.length, lines: 0, parsed: 0, unparsed: 0, beforeSince: 0, undated: 0 };
|
|
247
|
+
let sawUa = false;
|
|
248
|
+
const iso = d => d && d.toISOString();
|
|
249
|
+
const handle = raw => {
|
|
250
|
+
const line = raw.replace(/^/, "").trim();
|
|
251
|
+
if (!line) return;
|
|
252
|
+
stats.lines++;
|
|
253
|
+
const r = parse(line),
|
|
254
|
+
path = r && typeof r.target === "string" ? pathOf(r.target) : null;
|
|
255
|
+
if (!path || !(r.status >= 100 && r.status < 600)) {
|
|
256
|
+
stats.unparsed++;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
const time = r.time && !isNaN(r.time.getTime()) ? r.time : null;
|
|
260
|
+
if (SINCE !== null && !time) {
|
|
261
|
+
stats.undated++;
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
if (SINCE !== null && +time < SINCE) {
|
|
265
|
+
stats.beforeSince++;
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
stats.parsed++;
|
|
269
|
+
if (r.ua != null) sawUa = true;
|
|
270
|
+
if (time) {
|
|
271
|
+
if (!period.from || time < period.from) period.from = time;
|
|
272
|
+
if (!period.to || time > period.to) period.to = time;
|
|
273
|
+
}
|
|
274
|
+
const ua = String(r.ua ?? "").toLowerCase(),
|
|
275
|
+
bot = BOTS.find(b => ua.includes(b.token));
|
|
276
|
+
if (bot) {
|
|
277
|
+
const b = (bots[bot.name] ||= {
|
|
278
|
+
bot,
|
|
279
|
+
requests: 0,
|
|
280
|
+
refused: 0,
|
|
281
|
+
status: { "2xx": 0, "3xx": 0, "4xx": 0, "5xx": 0 },
|
|
282
|
+
paths: new Map(),
|
|
283
|
+
first: null,
|
|
284
|
+
last: null,
|
|
285
|
+
ip: null,
|
|
286
|
+
});
|
|
287
|
+
b.requests++;
|
|
288
|
+
if (ipLists?.has(bot.name)) {
|
|
289
|
+
const ok = fromVendor(bot.name, r.ip),
|
|
290
|
+
c = (b.ip ||= { verified: 0, other: 0, unknown: 0, refused: 0 });
|
|
291
|
+
c[ok === null ? "unknown" : ok ? "verified" : "other"]++;
|
|
292
|
+
if (ok && (r.status === 401 || r.status === 403)) c.refused++;
|
|
293
|
+
} else if (ipLists && DNS_CHECK[bot.name] && !OFFLINE) {
|
|
294
|
+
const a = addrOf(r.ip) ?? "",
|
|
295
|
+
m = (b.dns ||= new Map());
|
|
296
|
+
m.set(a, (m.get(a) || 0) + 1);
|
|
297
|
+
} // checked after reading
|
|
298
|
+
const cls = `${Math.floor(r.status / 100)}xx`;
|
|
299
|
+
if (cls in b.status) b.status[cls]++;
|
|
300
|
+
const p =
|
|
301
|
+
b.paths.get(path) || b.paths.set(path, { n: 0, s5xx: 0, s404: 0, refused: 0, realRefused: 0 }).get(path);
|
|
302
|
+
p.n++;
|
|
303
|
+
if (r.status >= 500) p.s5xx++;
|
|
304
|
+
if (r.status === 404) p.s404++;
|
|
305
|
+
if (r.status === 401 || r.status === 403) {
|
|
306
|
+
p.refused++;
|
|
307
|
+
b.refused++;
|
|
308
|
+
if (ipLists?.has(bot.name) && fromVendor(bot.name, r.ip)) p.realRefused++; // from the vendor's own addresses
|
|
309
|
+
}
|
|
310
|
+
if (time) {
|
|
311
|
+
if (!b.first || time < b.first) b.first = time;
|
|
312
|
+
if (!b.last || time > b.last) b.last = time;
|
|
313
|
+
}
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (r.status < 200 || r.status >= 300) return; // a redirect and the page it leads to would be two visits
|
|
317
|
+
const host = hostOf(r.referer),
|
|
318
|
+
page = path.split("?")[0],
|
|
319
|
+
source =
|
|
320
|
+
AI_REFERRERS.find(d => host === d || host.endsWith("." + d)) ||
|
|
321
|
+
(/[?&]utm_source=chatgpt\.com(&|$)/i.test(path) ? "chatgpt.com" : null);
|
|
322
|
+
if (source) {
|
|
323
|
+
const pages = (referrals[source] ||= new Map());
|
|
324
|
+
pages.set(page, (pages.get(page) || 0) + 1);
|
|
325
|
+
}
|
|
326
|
+
if ((GOOGLE_HOST.test(host) || GOOGLE_APP.test(String(r.referer ?? ""))) && !FILE.test(page))
|
|
327
|
+
google.set(page, (google.get(page) || 0) + 1);
|
|
328
|
+
};
|
|
329
|
+
for (const f of files) {
|
|
330
|
+
const input = f.endsWith(".gz") ? pipeline(createReadStream(f), createGunzip(), () => {}) : createReadStream(f);
|
|
331
|
+
try {
|
|
332
|
+
for await (const line of createInterface({ input, crlfDelay: Infinity })) handle(line);
|
|
333
|
+
} catch (e) {
|
|
334
|
+
if (files.length === 1) fail(`couldn't read ${f}: ${e.message}`);
|
|
335
|
+
notes.push(`Couldn't read ${f} (${e.message}), so it was skipped from there on.`);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
const named = files.length === 1 ? files[0] : `${files.length} files in ${args.log.join(", ")}`;
|
|
339
|
+
if (!stats.lines) fail(`${named} has no log lines.`);
|
|
340
|
+
if (!stats.parsed && !stats.beforeSince && !stats.undated)
|
|
341
|
+
fail(
|
|
342
|
+
`${named} isn't an access log: none of its ${stats.lines} line(s) is Apache/Nginx combined or common log format, or JSON lines with a time, path or url, status and user agent.`,
|
|
343
|
+
);
|
|
344
|
+
// The DNS check, 10 addresses at a time. noAnswer counts requests whose lookup got no answer, or past DNS_MAX. A
|
|
345
|
+
// batch with no answer at all means the DNS server is out of reach, so the rest aren't asked (each would time out).
|
|
346
|
+
for (const b of Object.values(bots))
|
|
347
|
+
if (b.dns) {
|
|
348
|
+
const c = (b.ip = { verified: 0, other: 0, unknown: 0, refused: 0 }),
|
|
349
|
+
list = [...b.dns].sort((x, y) => y[1] - x[1]);
|
|
350
|
+
let down = false;
|
|
351
|
+
b.noAnswer = 0;
|
|
352
|
+
for (let i = 0; i < list.length; i += 10) {
|
|
353
|
+
const batch = list.slice(i, i + 10),
|
|
354
|
+
oks = await Promise.all(
|
|
355
|
+
batch.map(([a], j) => (a && !down && i + j < DNS_MAX ? byDns(DNS_CHECK[b.bot.name], a) : null)),
|
|
356
|
+
);
|
|
357
|
+
batch.forEach(([a, n], j) => {
|
|
358
|
+
c[oks[j] === null ? "unknown" : oks[j] ? "verified" : "other"] += n;
|
|
359
|
+
if (a && oks[j] === null) b.noAnswer += n;
|
|
360
|
+
});
|
|
361
|
+
down ||= batch.some(([a]) => a) && oks.every(ok => ok === null);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// ---------- summary ----------
|
|
366
|
+
const top = (map, value, n) =>
|
|
367
|
+
[...map]
|
|
368
|
+
.filter(([, v]) => value(v) > 0)
|
|
369
|
+
.sort((a, b) => value(b[1]) - value(a[1]))
|
|
370
|
+
.slice(0, n);
|
|
371
|
+
const botsOut = Object.fromEntries(
|
|
372
|
+
Object.values(bots)
|
|
373
|
+
.sort((a, b) => b.requests - a.requests)
|
|
374
|
+
.map(b => [
|
|
375
|
+
b.bot.name,
|
|
376
|
+
{
|
|
377
|
+
vendor: b.bot.vendor,
|
|
378
|
+
group: b.bot.group,
|
|
379
|
+
purpose: b.bot.purpose,
|
|
380
|
+
requests: b.requests,
|
|
381
|
+
paths: b.paths.size,
|
|
382
|
+
status: b.status,
|
|
383
|
+
topPaths: top(b.paths, v => v.n, 10).map(([path, v]) => ({ path, requests: v.n })),
|
|
384
|
+
firstSeen: iso(b.first),
|
|
385
|
+
lastSeen: iso(b.last),
|
|
386
|
+
...(b.ip ? { ipCheck: { verified: b.ip.verified, other: b.ip.other, unknown: b.ip.unknown } } : {}),
|
|
387
|
+
},
|
|
388
|
+
]),
|
|
389
|
+
);
|
|
390
|
+
const aiReferrals = Object.fromEntries(
|
|
391
|
+
Object.entries(referrals)
|
|
392
|
+
.map(
|
|
393
|
+
([s, pages]) =>
|
|
394
|
+
/** @type {const} */ ([
|
|
395
|
+
s,
|
|
396
|
+
{
|
|
397
|
+
visits: [...pages.values()].reduce((a, b) => a + b, 0),
|
|
398
|
+
topPages: top(pages, v => v, 10).map(([path, visits]) => ({ path, visits })),
|
|
399
|
+
},
|
|
400
|
+
]),
|
|
401
|
+
)
|
|
402
|
+
.sort((a, b) => b[1].visits - a[1].visits),
|
|
403
|
+
);
|
|
404
|
+
|
|
405
|
+
// ---------- findings ----------
|
|
406
|
+
const findings = [];
|
|
407
|
+
const url = p => ORIGIN + p,
|
|
408
|
+
pct = x => `${Math.round(x * 1000) / 10}%`,
|
|
409
|
+
list = ps => ps.map(([p, n]) => `${p} (${n})`).join(", ");
|
|
410
|
+
const finding = (check, rule, severity, category, title, why, fix, evidence, count = evidence.length) => {
|
|
411
|
+
if (evidence.length)
|
|
412
|
+
findings.push(
|
|
413
|
+
findingOf(check, [rule, severity, title, why, fix], { count, evidence }, { source: "server-logs", category }),
|
|
414
|
+
);
|
|
415
|
+
};
|
|
416
|
+
const crawlers = Object.values(bots).filter(b => b.requests >= 5);
|
|
417
|
+
|
|
418
|
+
// A few server errors are noise; a pattern is at least 5 errors and 1% of the bot's requests.
|
|
419
|
+
const failingBots = Object.values(bots).filter(
|
|
420
|
+
b =>
|
|
421
|
+
(b.bot.group === "search" || b.bot.group === "ai-search") &&
|
|
422
|
+
b.status["5xx"] >= 5 &&
|
|
423
|
+
b.status["5xx"] / b.requests >= 0.01,
|
|
424
|
+
);
|
|
425
|
+
const errors = failingBots.map(b => {
|
|
426
|
+
const failing = top(b.paths, v => v.s5xx, 3).map(([p, v]) => [p, v.s5xx]);
|
|
427
|
+
return {
|
|
428
|
+
url: url(failing[0][0]),
|
|
429
|
+
detail: `${b.bot.name}: ${b.status["5xx"]} of ${b.requests} requests (${pct(b.status["5xx"] / b.requests)}) got a server error, most on ${list(failing)}`,
|
|
430
|
+
};
|
|
431
|
+
});
|
|
432
|
+
const inGroup = g => failingBots.filter(b => b.bot.group === g).length;
|
|
433
|
+
const who = [
|
|
434
|
+
inGroup("search") && `${inGroup("search")} search crawler(s)`,
|
|
435
|
+
inGroup("ai-search") && `${inGroup("ai-search")} AI search or answer bot(s)`,
|
|
436
|
+
]
|
|
437
|
+
.filter(Boolean)
|
|
438
|
+
.join(" and ");
|
|
439
|
+
finding(
|
|
440
|
+
"bot-errors",
|
|
441
|
+
"CRAWL-05",
|
|
442
|
+
failingBots.some(b => b.status["5xx"] >= 50 || b.status["5xx"] / b.requests >= 0.05) ? "high" : "medium",
|
|
443
|
+
"Crawling & indexing",
|
|
444
|
+
() => `${who} got server errors (5xx) on 1% or more of their requests`,
|
|
445
|
+
"Requests claiming to be these crawlers got 5xx responses. Crawlers slow down on a site that keeps failing, and pages that fail again and again drop out of the index and out of AI answers.",
|
|
446
|
+
"Look up the failing routes in the server's error log at those times and fix them; a page must not fail because a slow API or database is down. Planned maintenance that answers 503 with a Retry-After header is fine and needs no fix.",
|
|
447
|
+
errors,
|
|
448
|
+
);
|
|
449
|
+
|
|
450
|
+
// Bots and scanners probe for these on every site; a 404 is the right answer, so they're left out.
|
|
451
|
+
const PROBE = /^\/(\.env|wp-|xmlrpc\.php|\.git(\/|$))/i;
|
|
452
|
+
const notFound = new Map();
|
|
453
|
+
for (const b of Object.values(bots))
|
|
454
|
+
if (b.bot.group === "search")
|
|
455
|
+
for (const [p, v] of b.paths)
|
|
456
|
+
if (v.s404 && !PROBE.test(p)) {
|
|
457
|
+
const x = notFound.get(p) || notFound.set(p, { n: 0, bots: new Set() }).get(p);
|
|
458
|
+
x.n += v.s404;
|
|
459
|
+
x.bots.add(b.bot.name);
|
|
460
|
+
}
|
|
461
|
+
const repeated = top(notFound, v => (v.n >= 5 ? v.n : 0), Infinity);
|
|
462
|
+
// A 404 is right for a removed page, so only the ones the site itself still links to (per --crawl) are findings.
|
|
463
|
+
const linked = ([p]) => !!CRAWLED?.has(p),
|
|
464
|
+
linked404 = repeated.filter(linked);
|
|
465
|
+
const repeated404s = repeated
|
|
466
|
+
.filter(r => !linked(r))
|
|
467
|
+
.map(([path, v]) => ({ path, requests: v.n, bots: [...v.bots] }));
|
|
468
|
+
finding(
|
|
469
|
+
"bot-404s",
|
|
470
|
+
"CRAWL-07",
|
|
471
|
+
"medium",
|
|
472
|
+
"Crawling & indexing",
|
|
473
|
+
n => `${n} URL(s) the site links to keep returning 404 to search crawlers`,
|
|
474
|
+
"Search crawlers keep asking for these URLs and get a 404, and the site's own links or sitemap still point at them, so visitors hit the same dead ends.",
|
|
475
|
+
"If the page moved, 301 the old URL to its new home and update the links. If it's gone for good, keep the 404 or return 410 and remove the internal links and sitemap entries that still point at it (the crawler's broken-internal-link check lists them).",
|
|
476
|
+
linked404
|
|
477
|
+
.slice(0, 20)
|
|
478
|
+
.map(([p, v]) => ({ url: url(p), detail: `404 for ${v.n} requests from ${[...v.bots].join(", ")}` })),
|
|
479
|
+
linked404.length,
|
|
480
|
+
);
|
|
481
|
+
if (repeated404s.length)
|
|
482
|
+
notes.push(
|
|
483
|
+
`${repeated404s.length} URL(s) keep returning 404 to search crawlers (listed under repeated404s)${CRAWLED ? " and the site doesn't link to them" : ""}. A 404 is the right answer for a removed page; if one moved, 301 it to its new home${CRAWLED ? "." : ", and pass --crawl seo-audit/seo-crawl.json to see which are linked from the site."}`,
|
|
484
|
+
);
|
|
485
|
+
|
|
486
|
+
// With --verify-ips, only requests from the vendor's addresses count (a fake is rightly refused), once any line had
|
|
487
|
+
// one.
|
|
488
|
+
const checked = b => b.ip && b.ip.verified + b.ip.other > 0;
|
|
489
|
+
const refused = crawlers
|
|
490
|
+
.filter(b => b.bot.group === "ai-search")
|
|
491
|
+
.map(b => [b, ...(checked(b) ? [b.ip.refused, b.ip.verified] : [b.refused, b.requests])])
|
|
492
|
+
.filter(([, n, of]) => of >= 5 && n / of > 0.5)
|
|
493
|
+
.map(([b, n, of]) => ({
|
|
494
|
+
url: url(top(b.paths, checked(b) ? v => v.realRefused : v => v.refused, 1)[0][0]),
|
|
495
|
+
detail: `${b.bot.name}: ${n} of ${of} requests${checked(b) ? ` from ${b.bot.vendor}'s addresses` : ""} (${pct(n / of)}) refused with 403 or 401`,
|
|
496
|
+
}));
|
|
497
|
+
finding(
|
|
498
|
+
"ai-bots-blocked-in-practice",
|
|
499
|
+
"MAP-06",
|
|
500
|
+
"needs-decision",
|
|
501
|
+
"Sitemaps & robots",
|
|
502
|
+
n => `${n} AI search crawler(s) are mostly refused by the server (403/401)`,
|
|
503
|
+
"Requests claiming to be these AI search crawlers are mostly refused. That's usually a firewall, CDN bot setting or security plugin, and robots.txt doesn't show it, so the site can be left out of ChatGPT, Claude or Perplexity answers without anyone deciding that. Spoofed bots are rightly refused, so check the IPs first.",
|
|
504
|
+
"Decide whether these crawlers should reach the site and record it in the profile (MAP-06). To allow them, let the vendor's published IP ranges through the WAF or CDN bot rules (openai.com/searchbot.json, perplexity.ai/perplexitybot.json); to keep them out, a robots.txt rule says so openly.",
|
|
505
|
+
refused,
|
|
506
|
+
);
|
|
507
|
+
numbered(findings, "L");
|
|
508
|
+
|
|
509
|
+
notes.unshift(
|
|
510
|
+
ipLists
|
|
511
|
+
? "User agents can be spoofed, so every count here is requests claiming to be that bot; ipCheck says how many came from the vendor's published addresses (for YandexBot, addresses a DNS check confirms are Yandex's)."
|
|
512
|
+
: "User agents can be spoofed, so every count here is requests claiming to be that bot. Before acting on one bot's numbers, check its IPs against the vendor's published IP list: --verify-ips does that.",
|
|
513
|
+
);
|
|
514
|
+
if (ipLists) {
|
|
515
|
+
const fakes = Object.values(bots)
|
|
516
|
+
.filter(b => b.ip?.other)
|
|
517
|
+
.map(b => `${b.bot.name} ${b.ip.other} of ${b.requests}`);
|
|
518
|
+
if (fakes.length)
|
|
519
|
+
notes.push(
|
|
520
|
+
`Some requests claiming to be a known bot came from addresses outside the vendor's published list (for YandexBot, addresses whose DNS name isn't Yandex's or doesn't lead back to them), so they're most likely fakes (or the log records a proxy's or CDN's address instead of the visitor's): ${fakes.join(", ")}. The finding about refused AI crawlers counts only requests from the vendors' addresses.`,
|
|
521
|
+
);
|
|
522
|
+
const noIp = Object.values(bots)
|
|
523
|
+
.filter(b => b.ip && !checked(b) && !b.noAnswer)
|
|
524
|
+
.map(b => b.bot.name);
|
|
525
|
+
if (noIp.length)
|
|
526
|
+
notes.push(`The log lines for ${noIp.join(", ")} carry no client address, so --verify-ips couldn't check them.`);
|
|
527
|
+
const byDnsOnly = OFFLINE ? Object.keys(bots).filter(n => DNS_CHECK[n]) : [];
|
|
528
|
+
if (byDnsOnly.length)
|
|
529
|
+
notes.push(
|
|
530
|
+
`${byDnsOnly.join(", ")} weren't checked: their vendor publishes no list of addresses to save, and --verify-ips with a folder contacts nothing. Run --verify-ips without a folder to check them in DNS.`,
|
|
531
|
+
);
|
|
532
|
+
for (const b of Object.values(bots).filter(b => b.noAnswer))
|
|
533
|
+
notes.push(
|
|
534
|
+
`${b.noAnswer} ${b.bot.name} request(s) couldn't be checked in DNS, so they're counted as unknown: the DNS server gave no answer${b.dns.size > DNS_MAX ? `, or they came from beyond the ${DNS_MAX} busiest addresses, the most looked up` : ""}. Yandex Webmaster's IP address check tool (Tools → IP address check) checks one address at a time by hand.`,
|
|
535
|
+
);
|
|
536
|
+
const unlisted = Object.keys(bots).filter(n => IP_LISTS[n] && !ipLists.has(n));
|
|
537
|
+
if (unlisted.length) notes.push(`No IP list loaded for ${unlisted.join(", ")}, so those requests weren't checked.`);
|
|
538
|
+
const unreadable = Object.keys(bots).filter(n => UNREADABLE[n]);
|
|
539
|
+
if (unreadable.length)
|
|
540
|
+
notes.push(
|
|
541
|
+
`These vendors publish their addresses in a form --verify-ips can't read yet, so these bots weren't checked: ${unreadable.map(n => `${n} (${UNREADABLE[n]})`).join("; ")}.`,
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
if (stats.parsed && !sawUa)
|
|
545
|
+
notes.push(
|
|
546
|
+
"These logs don't record user agents, so bots can't be told apart. Log in the combined format (or JSON with the user agent) to see crawler activity.",
|
|
547
|
+
);
|
|
548
|
+
else if (!Object.values(bots).some(b => b.bot.group === "ai-search"))
|
|
549
|
+
notes.push(
|
|
550
|
+
`No requests claiming to be an AI search or answer bot (${BOTS.filter(b => b.group === "ai-search")
|
|
551
|
+
.map(b => b.name)
|
|
552
|
+
.join(
|
|
553
|
+
", ",
|
|
554
|
+
)}) in these logs. That's common and not a problem by itself; if the site wants to be cited in AI answers, check robots.txt and the firewall let them in (MAP-06).`,
|
|
555
|
+
);
|
|
556
|
+
const googleReferrals = google.size
|
|
557
|
+
? {
|
|
558
|
+
visits: [...google.values()].reduce((a, b) => a + b, 0),
|
|
559
|
+
topPages: top(google, v => v, 10).map(([path, visits]) => ({ path, visits })),
|
|
560
|
+
}
|
|
561
|
+
: null;
|
|
562
|
+
if (!googleReferrals)
|
|
563
|
+
notes.push(
|
|
564
|
+
"No visits with a Google Search referrer in these logs. Browsers and apps often drop the referrer (private browsing, some new tabs, apps), and common log format doesn't record it, so Search Console's clicks are the real number.",
|
|
565
|
+
);
|
|
566
|
+
if (!Object.keys(aiReferrals).length)
|
|
567
|
+
notes.push(
|
|
568
|
+
`No visits referred by AI assistants (${AI_REFERRERS.join(", ")}, or utm_source=chatgpt.com) in these logs. Some assistants and apps send no referrer, so this undercounts anyway.`,
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
mkdirSync(dirname(OUT), { recursive: true });
|
|
572
|
+
writeFileSync(
|
|
573
|
+
OUT,
|
|
574
|
+
JSON.stringify(
|
|
575
|
+
{
|
|
576
|
+
source: "server-logs",
|
|
577
|
+
since: args.since ?? null,
|
|
578
|
+
period: { from: iso(period.from), to: iso(period.to) },
|
|
579
|
+
stats,
|
|
580
|
+
bots: botsOut,
|
|
581
|
+
aiReferrals,
|
|
582
|
+
googleReferrals,
|
|
583
|
+
repeated404s,
|
|
584
|
+
notes,
|
|
585
|
+
findings,
|
|
586
|
+
},
|
|
587
|
+
null,
|
|
588
|
+
2,
|
|
589
|
+
),
|
|
590
|
+
);
|
|
591
|
+
console.log(
|
|
592
|
+
`log-scan: ${stats.lines} lines from ${stats.files} file(s) (${stats.unparsed} unparsed), ${Object.keys(botsOut).length} bots, ${Object.keys(aiReferrals).length} AI referral sources, ${findings.length} findings · wrote ${OUT}`,
|
|
593
|
+
);
|
|
594
|
+
return 0;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
if (isMain(import.meta.url)) await runMain(() => main(process.argv.slice(2)));
|