Create server.js
Browse files
server.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const { collect } = require('@themarkup/blacklight-collector');
|
| 3 |
+
const path = require('path');
|
| 4 |
+
|
| 5 |
+
const app = express();
|
| 6 |
+
const PORT = process.env.PORT || 7860;
|
| 7 |
+
|
| 8 |
+
// تقديم الملفات الثابتة من مجلد public
|
| 9 |
+
app.use(express.static('public'));
|
| 10 |
+
app.use(express.json());
|
| 11 |
+
|
| 12 |
+
// نقطة نهاية الفحص
|
| 13 |
+
app.post('/scan', async (req, res) => {
|
| 14 |
+
const { url, mode } = req.body;
|
| 15 |
+
|
| 16 |
+
if (!url) {
|
| 17 |
+
return res.status(400).json({ error: 'URL is required' });
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
console.log(`🔍 Scanning: ${url} (Mode: ${mode || 'standard'})`);
|
| 21 |
+
|
| 22 |
+
try {
|
| 23 |
+
// إعدادات الفحص حسب النمط
|
| 24 |
+
const isDeep = mode === 'deep';
|
| 25 |
+
const config = {
|
| 26 |
+
inUrl: url,
|
| 27 |
+
blTests: isDeep ? 'all' : ['cookies', 'third_party_trackers', 'fb_pixel_events'],
|
| 28 |
+
numPages: isDeep ? 2 : 1,
|
| 29 |
+
defaultWaitUntil: isDeep ? 'networkidle2' : 'domcontentloaded',
|
| 30 |
+
captureHar: isDeep,
|
| 31 |
+
saveScreenshots: false,
|
| 32 |
+
headless: true,
|
| 33 |
+
emulateDevice: 'iPhone 12', // يجعل المتصفح يبدو كهاتف حقيقي
|
| 34 |
+
extraChromiumArgs: [
|
| 35 |
+
'--disable-blink-features=AutomationControlled',
|
| 36 |
+
'--no-sandbox',
|
| 37 |
+
'--disable-setuid-sandbox',
|
| 38 |
+
'--disable-dev-shm-usage',
|
| 39 |
+
'--disable-accelerated-2d-canvas',
|
| 40 |
+
'--disable-gpu'
|
| 41 |
+
]
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
const result = await collect(config);
|
| 45 |
+
|
| 46 |
+
// استخراج ملخص النتائج
|
| 47 |
+
const summary = {
|
| 48 |
+
url: result.url,
|
| 49 |
+
finalUrl: result.finalUrl,
|
| 50 |
+
scanTime: result.scanTime,
|
| 51 |
+
mode: mode || 'standard',
|
| 52 |
+
trackers: {
|
| 53 |
+
thirdParty: result.hosts?.thirdParty || [],
|
| 54 |
+
thirdPartyCount: result.hosts?.thirdParty?.length || 0
|
| 55 |
+
},
|
| 56 |
+
cookies: {
|
| 57 |
+
total: result.cookies?.length || 0,
|
| 58 |
+
thirdParty: result.cookies?.filter(c => c.thirdParty)?.length || 0
|
| 59 |
+
},
|
| 60 |
+
fingerprinting: {
|
| 61 |
+
canvas: result.canvasFingerprinters?.length > 0,
|
| 62 |
+
fonts: result.canvasFontFingerprinters?.length > 0
|
| 63 |
+
},
|
| 64 |
+
fbPixel: result.fbPixelEvents?.length > 0,
|
| 65 |
+
keyLogging: result.keyLogging?.length > 0,
|
| 66 |
+
sessionRecording: result.sessionRecorders?.length > 0
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
res.json({
|
| 70 |
+
success: true,
|
| 71 |
+
summary,
|
| 72 |
+
// إرسال النتائج الكاملة للفحص العميق
|
| 73 |
+
raw: isDeep ? result : undefined
|
| 74 |
+
});
|
| 75 |
+
|
| 76 |
+
} catch (error) {
|
| 77 |
+
console.error('Scan error:', error);
|
| 78 |
+
res.status(500).json({
|
| 79 |
+
success: false,
|
| 80 |
+
error: error.message
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
// الصفحة الرئيسية
|
| 86 |
+
app.get('/', (req, res) => {
|
| 87 |
+
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
app.listen(PORT, '0.0.0.0', () => {
|
| 91 |
+
console.log(`🚀 PrivacyScan running on port ${PORT}`);
|
| 92 |
+
});
|