1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
|
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import https from 'https';
import http from 'http';
import yaml from 'js-yaml';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const NAMES_DIR = path.join(__dirname, '..', 'src', 'content', 'names');
const TIMEOUT = 5000; // 5 seconds timeout
// Parse command line arguments
const args = process.argv.slice(2);
const VERIFY_INVALID_ONLY = args.includes('--verify-invalid');
function makeRequest(url, useHttps = true) {
return new Promise((resolve, reject) => {
const client = useHttps ? https : http;
const parsedUrl = new URL(url);
const options = {
hostname: parsedUrl.hostname,
port: parsedUrl.port || (useHttps ? 443 : 80),
path: parsedUrl.pathname + parsedUrl.search,
method: 'GET',
timeout: TIMEOUT,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
}
};
const req = client.request(options, (res) => {
// Consume response body to avoid hanging connections
res.on('data', () => {});
res.on('end', () => {
resolve({
statusCode: res.statusCode,
success: res.statusCode >= 200 && res.statusCode < 400
});
});
});
req.on('error', (err) => {
reject(err);
});
req.on('timeout', () => {
req.destroy();
reject(new Error('Request timeout'));
});
req.end();
});
}
async function checkDomain(domain, explicitUrl = null) {
const urlsToTry = [];
if (explicitUrl) {
urlsToTry.push(explicitUrl);
} else {
urlsToTry.push(`https://${domain}`);
urlsToTry.push(`http://${domain}`);
}
for (const url of urlsToTry) {
try {
const isHttps = url.startsWith('https://');
const result = await makeRequest(url, isHttps);
if (result.success) {
return { success: true, url, statusCode: result.statusCode };
}
} catch (error) {
// Continue to next URL
continue;
}
}
return { success: false, url: null, statusCode: null };
}
async function processYamlFile(filePath) {
try {
const content = fs.readFileSync(filePath, 'utf8');
const data = yaml.load(content);
if (!data || !data.domain) {
console.log(`SKIP: ${path.basename(filePath)} - No domain field`);
return { updated: false, skipped: true };
}
// If in verify-invalid mode, skip domains that aren't marked as invalid
if (VERIFY_INVALID_ONLY && !data.invalid) {
return { updated: false, skipped: true };
}
const domain = data.domain;
const explicitUrl = data.url || null;
console.log(`CHECKING: ${domain}${explicitUrl ? ` (explicit URL: ${explicitUrl})` : ''}${data.invalid ? ' (marked invalid)' : ''}`);
const result = await checkDomain(domain, explicitUrl);
if (result.success) {
console.log(`✓ FOUND: ${domain} at ${result.url} (${result.statusCode})`);
// Remove invalid flag if it was previously set
if (data.invalid) {
delete data.invalid;
const updatedYaml = yaml.dump(data, {
lineWidth: -1,
noCompatMode: true,
quotingType: '"',
forceQuotes: false
});
fs.writeFileSync(filePath, updatedYaml);
return { updated: true };
}
return { updated: false };
} else {
console.log(`✗ NOT FOUND: ${domain}`);
// Mark as invalid if not already marked
if (!data.invalid) {
data.invalid = true;
const updatedYaml = yaml.dump(data, {
lineWidth: -1,
noCompatMode: true,
quotingType: '"',
forceQuotes: false
});
fs.writeFileSync(filePath, updatedYaml);
return { updated: true };
}
return { updated: false };
}
} catch (error) {
console.error(`ERROR processing ${filePath}: ${error.message}`);
return { updated: false, skipped: false };
}
}
async function main() {
try {
const files = fs.readdirSync(NAMES_DIR)
.filter(file => file.endsWith('.yml'))
.map(file => path.join(NAMES_DIR, file));
if (VERIFY_INVALID_ONLY) {
console.log(`Running in verify-invalid mode - only checking domains marked as invalid\n`);
}
console.log(`Found ${files.length} YAML files to process\n`);
let processedCount = 0;
let skippedCount = 0;
let updatedCount = 0;
let foundCount = 0;
let notFoundCount = 0;
for (const file of files) {
const result = await processYamlFile(file);
if (result.skipped) {
skippedCount++;
} else {
processedCount++;
if (result.updated) {
updatedCount++;
}
}
// Small delay to be respectful to servers
await new Promise(resolve => setTimeout(resolve, 100));
}
console.log(`\n--- SUMMARY ---`);
if (VERIFY_INVALID_ONLY) {
console.log(`Mode: Verify invalid domains only`);
}
console.log(`Total files: ${files.length}`);
console.log(`Processed: ${processedCount} files`);
console.log(`Skipped: ${skippedCount} files`);
console.log(`Updated: ${updatedCount} files`);
} catch (error) {
console.error('Error:', error.message);
process.exit(1);
}
}
main();
|