-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_bom.js
More file actions
65 lines (57 loc) · 4.74 KB
/
debug_bom.js
File metadata and controls
65 lines (57 loc) · 4.74 KB
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
const fs = require('fs');
const path = require('path');
const https = require('https');
// 1. Fetch the URL and inspect bytes
const url = 'https://mediumslateblue-hummingbird-258203.hostingersite.com/api/whatsapp/webhook?hub_mode=subscribe&hub_verify_token=GenSkytech_Secret_2027&hub_challenge=TEST_CHALLENGE_123';
console.log(`Checking Webhook Response from: ${url}`);
https.get(url, (res) => {
const chunks = [];
res.on('data', (chunk) => chunks.push(chunk));
res.on('end', () => {
const buffer = Buffer.concat(chunks);
console.log(`Response Status: ${res.statusCode}`);
console.log(`Response Length: ${buffer.length}`);
if (buffer.length > 0) {
console.log(`First 3 bytes: ${buffer[0].toString(16)} ${buffer[1].toString(16)} ${buffer[2].toString(16)}`);
if (buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
console.log("!!! BOM DETECTED IN RESPONSE !!!");
} else {
console.log("No BOM at start of response body.");
}
}
});
}).on('error', (e) => {
console.error(`Request Error: ${e.message}`);
});
function checkFile(filePath) {
try {
if (!fs.existsSync(filePath)) return;
const buffer = fs.readFileSync(filePath);
if (buffer.length >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
console.log(`[FIXING BOM] ${filePath}`);
const clean = buffer.slice(3);
fs.writeFileSync(filePath, clean);
}
} catch (e) {
console.error(`Error checking ${filePath}: ${e.message}`);
}
}
function checkDir(dir) {
if (!fs.existsSync(dir)) return;
const items = fs.readdirSync(dir, { withFileTypes: true });
for (const item of items) {
const fullPath = path.join(dir, item.name);
if (item.isDirectory()) {
if (item.name !== 'vendor' && item.name !== 'node_modules' && item.name !== '.git') {
checkDir(fullPath);
}
} else if (item.isFile() && item.name.endsWith('.php')) {
checkFile(fullPath);
}
}
}
console.log('Scanning local files for BOM...');
['app', 'bootstrap', 'config', 'public', 'routes'].forEach(d => {
checkDir(path.resolve(__dirname, d));
});
console.log('Scan complete.');