Update server.js
Browse files
server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
const express = require('express');
|
| 2 |
const { collect } = require('@themarkup/blacklight-collector');
|
| 3 |
-
const
|
| 4 |
const path = require('path');
|
| 5 |
|
| 6 |
const app = express();
|
|
@@ -9,6 +9,10 @@ const PORT = process.env.PORT || 7860;
|
|
| 9 |
app.use(express.static('public'));
|
| 10 |
app.use(express.json());
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
function normalizeUrl(inputUrl) {
|
| 13 |
let url = inputUrl.trim();
|
| 14 |
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
@@ -21,18 +25,43 @@ function normalizeUrl(inputUrl) {
|
|
| 21 |
}
|
| 22 |
}
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
let score = 100;
|
| 26 |
-
|
|
|
|
| 27 |
score -= Math.min(trackerCount * 5, 40);
|
|
|
|
| 28 |
const hasFingerprinting = (blacklight?.canvasFingerprinters?.length > 0) ||
|
| 29 |
(blacklight?.canvasFontFingerprinters?.length > 0);
|
| 30 |
if (hasFingerprinting) score -= 25;
|
|
|
|
| 31 |
if (blacklight?.sessionRecorders?.length > 0) score -= 15;
|
| 32 |
if (blacklight?.keyLogging?.length > 0) score -= 20;
|
| 33 |
-
|
| 34 |
-
if (!securecheck?.headers?.strictTransportSecurity) score -= 5;
|
| 35 |
-
if (!securecheck?.headers?.contentSecurityPolicy) score -= 5;
|
| 36 |
score = Math.max(0, Math.min(100, Math.round(score)));
|
| 37 |
|
| 38 |
let grade;
|
|
@@ -42,29 +71,42 @@ function calculatePrivacyGrade(blacklight, securecheck) {
|
|
| 42 |
else if (score >= 65) grade = 'C';
|
| 43 |
else if (score >= 55) grade = 'D';
|
| 44 |
else grade = 'F';
|
|
|
|
| 45 |
return { score, grade };
|
| 46 |
}
|
| 47 |
|
| 48 |
app.post('/scan', async (req, res) => {
|
| 49 |
const { url: inputUrl, mode } = req.body;
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
const url = normalizeUrl(inputUrl);
|
| 53 |
-
if (!url)
|
|
|
|
|
|
|
| 54 |
|
| 55 |
console.log(`🔍 Scanning: ${url} (Mode: ${mode || 'deep'})`);
|
| 56 |
|
| 57 |
try {
|
| 58 |
const isDeep = mode === 'deep';
|
|
|
|
| 59 |
const allTests = [
|
| 60 |
-
'cookies',
|
| 61 |
-
'
|
| 62 |
-
'
|
| 63 |
-
'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
];
|
| 65 |
|
| 66 |
-
//
|
| 67 |
-
const
|
| 68 |
blTests: isDeep ? allTests : ['cookies', 'third_party_trackers', 'fb_pixel_events'],
|
| 69 |
numPages: isDeep ? 2 : 1,
|
| 70 |
defaultWaitUntil: isDeep ? 'networkidle2' : 'domcontentloaded',
|
|
@@ -83,66 +125,93 @@ app.post('/scan', async (req, res) => {
|
|
| 83 |
]
|
| 84 |
};
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
// تجنب الأخطاء إذا فشل Blacklight
|
| 92 |
-
const blacklight = blacklightResult.error ? { hosts: {} } : blacklightResult;
|
| 93 |
-
const securecheck = secureCheckResult.error ? { ssl: {}, headers: {} } : secureCheckResult;
|
| 94 |
-
|
| 95 |
-
const thirdPartyDomains = blacklight.hosts?.thirdParty || [];
|
| 96 |
-
const trackerCount = thirdPartyDomains.length;
|
| 97 |
-
const cookiesCount = blacklight.cookies?.length || 0;
|
| 98 |
-
const thirdPartyCookies = blacklight.cookies?.filter(c => c.thirdParty)?.length || 0;
|
| 99 |
-
const hasFingerprinting = (blacklight.canvasFingerprinters?.length > 0) ||
|
| 100 |
-
(blacklight.canvasFontFingerprinters?.length > 0);
|
| 101 |
-
const hasSessionRecording = blacklight.sessionRecorders?.length > 0;
|
| 102 |
-
const hasKeyLogging = blacklight.keyLogging?.length > 0;
|
| 103 |
-
|
| 104 |
-
const { score, grade } = calculatePrivacyGrade(blacklight, securecheck);
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
const summary = {
|
| 112 |
-
url:
|
| 113 |
-
final_url:
|
| 114 |
-
grade
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
key_logging: { detected: hasKeyLogging },
|
| 121 |
-
ssl: {
|
| 122 |
-
valid: securecheck?.ssl?.valid || false,
|
| 123 |
-
issuer: securecheck?.ssl?.issuer || 'Unknown',
|
| 124 |
-
expires_in_days: securecheck?.ssl?.daysRemaining || 0,
|
| 125 |
-
grade: securecheck?.ssl?.grade || 'N/A'
|
| 126 |
},
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
x_frame_options: securecheck?.headers?.xFrameOptions || 'Missing'
|
| 131 |
},
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
};
|
| 134 |
|
| 135 |
res.json({
|
| 136 |
success: true,
|
| 137 |
-
summary,
|
| 138 |
-
details: {
|
|
|
|
|
|
|
|
|
|
| 139 |
});
|
|
|
|
| 140 |
} catch (error) {
|
| 141 |
console.error('Scan error:', error);
|
| 142 |
-
res.status(500).json({
|
|
|
|
|
|
|
|
|
|
| 143 |
}
|
| 144 |
});
|
| 145 |
|
| 146 |
-
app.get('/', (req, res) =>
|
|
|
|
|
|
|
| 147 |
|
| 148 |
-
app.listen(PORT, '0.0.0.0', () =>
|
|
|
|
|
|
|
|
|
| 1 |
const express = require('express');
|
| 2 |
const { collect } = require('@themarkup/blacklight-collector');
|
| 3 |
+
const trackerdb = require('@ghostery/trackerdb');
|
| 4 |
const path = require('path');
|
| 5 |
|
| 6 |
const app = express();
|
|
|
|
| 9 |
app.use(express.static('public'));
|
| 10 |
app.use(express.json());
|
| 11 |
|
| 12 |
+
// تهيئة قاعدة بيانات Ghostery TrackerDB
|
| 13 |
+
const db = new trackerdb.TrackerDB();
|
| 14 |
+
|
| 15 |
+
// تحسين الرابط تلقائياً
|
| 16 |
function normalizeUrl(inputUrl) {
|
| 17 |
let url = inputUrl.trim();
|
| 18 |
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
|
|
| 25 |
}
|
| 26 |
}
|
| 27 |
|
| 28 |
+
// دالة للحصول على معلومات غنية عن المتتبع
|
| 29 |
+
async function enrichTrackerInfo(domain) {
|
| 30 |
+
try {
|
| 31 |
+
const tracker = await db.getTracker(domain);
|
| 32 |
+
if (tracker) {
|
| 33 |
+
return {
|
| 34 |
+
name: tracker.name || domain,
|
| 35 |
+
category: tracker.category || 'unknown',
|
| 36 |
+
organization: tracker.organization || 'Unknown',
|
| 37 |
+
privacyPolicy: tracker.privacyPolicy || null,
|
| 38 |
+
website: tracker.website || null
|
| 39 |
+
};
|
| 40 |
+
}
|
| 41 |
+
} catch (error) {
|
| 42 |
+
// نتجاهل الأخطاء بهدوء
|
| 43 |
+
}
|
| 44 |
+
return {
|
| 45 |
+
name: domain,
|
| 46 |
+
category: 'unknown',
|
| 47 |
+
organization: 'Unknown'
|
| 48 |
+
};
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// حساب درجة الخصوصية (A+ إلى F)
|
| 52 |
+
function calculatePrivacyGrade(blacklight, enrichedTrackers) {
|
| 53 |
let score = 100;
|
| 54 |
+
|
| 55 |
+
const trackerCount = enrichedTrackers?.length || 0;
|
| 56 |
score -= Math.min(trackerCount * 5, 40);
|
| 57 |
+
|
| 58 |
const hasFingerprinting = (blacklight?.canvasFingerprinters?.length > 0) ||
|
| 59 |
(blacklight?.canvasFontFingerprinters?.length > 0);
|
| 60 |
if (hasFingerprinting) score -= 25;
|
| 61 |
+
|
| 62 |
if (blacklight?.sessionRecorders?.length > 0) score -= 15;
|
| 63 |
if (blacklight?.keyLogging?.length > 0) score -= 20;
|
| 64 |
+
|
|
|
|
|
|
|
| 65 |
score = Math.max(0, Math.min(100, Math.round(score)));
|
| 66 |
|
| 67 |
let grade;
|
|
|
|
| 71 |
else if (score >= 65) grade = 'C';
|
| 72 |
else if (score >= 55) grade = 'D';
|
| 73 |
else grade = 'F';
|
| 74 |
+
|
| 75 |
return { score, grade };
|
| 76 |
}
|
| 77 |
|
| 78 |
app.post('/scan', async (req, res) => {
|
| 79 |
const { url: inputUrl, mode } = req.body;
|
| 80 |
+
|
| 81 |
+
if (!inputUrl) {
|
| 82 |
+
return res.status(400).json({ success: false, error: 'URL is required' });
|
| 83 |
+
}
|
| 84 |
|
| 85 |
const url = normalizeUrl(inputUrl);
|
| 86 |
+
if (!url) {
|
| 87 |
+
return res.status(400).json({ success: false, error: 'Invalid URL format' });
|
| 88 |
+
}
|
| 89 |
|
| 90 |
console.log(`🔍 Scanning: ${url} (Mode: ${mode || 'deep'})`);
|
| 91 |
|
| 92 |
try {
|
| 93 |
const isDeep = mode === 'deep';
|
| 94 |
+
|
| 95 |
const allTests = [
|
| 96 |
+
'cookies',
|
| 97 |
+
'third_party_trackers',
|
| 98 |
+
'fb_pixel_events',
|
| 99 |
+
'canvas_fingerprinters',
|
| 100 |
+
'canvas_font_fingerprinters',
|
| 101 |
+
'key_logging',
|
| 102 |
+
'session_recorders',
|
| 103 |
+
'google_analytics',
|
| 104 |
+
'twitter_pixel',
|
| 105 |
+
'tiktok_pixel'
|
| 106 |
];
|
| 107 |
|
| 108 |
+
// إعدادات Blacklight المستقرة
|
| 109 |
+
const options = {
|
| 110 |
blTests: isDeep ? allTests : ['cookies', 'third_party_trackers', 'fb_pixel_events'],
|
| 111 |
numPages: isDeep ? 2 : 1,
|
| 112 |
defaultWaitUntil: isDeep ? 'networkidle2' : 'domcontentloaded',
|
|
|
|
| 125 |
]
|
| 126 |
};
|
| 127 |
|
| 128 |
+
// تشغيل Blacklight فقط (بدون SecureCheck)
|
| 129 |
+
const blacklightResult = await collect(url, options).catch(err => {
|
| 130 |
+
console.error('Blacklight error:', err.message);
|
| 131 |
+
return { error: err.message };
|
| 132 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
+
// استخراج النطاقات الخارجية من Blacklight
|
| 135 |
+
const thirdPartyDomains = blacklightResult.hosts?.thirdParty || [];
|
| 136 |
+
|
| 137 |
+
// نصنف المتتبعين باستخدام Ghostery TrackerDB (بشكل منفصل وآمن)
|
| 138 |
+
const enrichedTrackers = [];
|
| 139 |
+
for (const domain of thirdPartyDomains) {
|
| 140 |
+
const info = await enrichTrackerInfo(domain);
|
| 141 |
+
enrichedTrackers.push({ domain, ...info });
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
const scanTime = blacklightResult.scanTime || 0;
|
| 145 |
+
const cookiesCount = blacklightResult.cookies?.length || 0;
|
| 146 |
+
const thirdPartyCookies = blacklightResult.cookies?.filter(c => c.thirdParty)?.length || 0;
|
| 147 |
+
|
| 148 |
+
const hasFingerprinting = (blacklightResult.canvasFingerprinters?.length > 0) ||
|
| 149 |
+
(blacklightResult.canvasFontFingerprinters?.length > 0);
|
| 150 |
+
const hasSessionRecording = blacklightResult.sessionRecorders?.length > 0;
|
| 151 |
+
const hasKeyLogging = blacklightResult.keyLogging?.length > 0;
|
| 152 |
+
|
| 153 |
+
const { score, grade } = calculatePrivacyGrade(blacklightResult, enrichedTrackers);
|
| 154 |
+
|
| 155 |
+
// بناء نصيحة بالعربية
|
| 156 |
+
let advice = '';
|
| 157 |
+
if (grade === 'A+' || grade === 'A') {
|
| 158 |
+
advice = '✅ هذا الموقع يحترم خصوصيتك بشكل ممتاز.';
|
| 159 |
+
} else if (grade === 'B' || grade === 'C') {
|
| 160 |
+
advice = '⚠️ هذا الموقع به بعض المخاوف المتعلقة بالخصوصية.';
|
| 161 |
+
} else if (grade === 'D') {
|
| 162 |
+
advice = '🔴 هذا الموقع يستخدم العديد من المتتبعين. كن حذرًا.';
|
| 163 |
+
} else {
|
| 164 |
+
advice = '⛔️ هذا الموقع ينتهك خصوصيتك بشكل خطير. تجنب مشاركة أي معلومات حساسة.';
|
| 165 |
+
}
|
| 166 |
|
| 167 |
const summary = {
|
| 168 |
+
url: blacklightResult.url || url,
|
| 169 |
+
final_url: blacklightResult.uri_dest || url,
|
| 170 |
+
grade: grade,
|
| 171 |
+
score: score,
|
| 172 |
+
scan_time_sec: scanTime,
|
| 173 |
+
trackers: {
|
| 174 |
+
count: enrichedTrackers.length,
|
| 175 |
+
list: enrichedTrackers.slice(0, 10) // أول 10 متتبعين
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
},
|
| 177 |
+
cookies: {
|
| 178 |
+
total: cookiesCount,
|
| 179 |
+
third_party: thirdPartyCookies
|
|
|
|
| 180 |
},
|
| 181 |
+
fingerprinting: {
|
| 182 |
+
detected: hasFingerprinting
|
| 183 |
+
},
|
| 184 |
+
session_recording: {
|
| 185 |
+
detected: hasSessionRecording
|
| 186 |
+
},
|
| 187 |
+
key_logging: {
|
| 188 |
+
detected: hasKeyLogging
|
| 189 |
+
},
|
| 190 |
+
advice: advice
|
| 191 |
};
|
| 192 |
|
| 193 |
res.json({
|
| 194 |
success: true,
|
| 195 |
+
summary: summary,
|
| 196 |
+
details: {
|
| 197 |
+
blacklight: blacklightResult,
|
| 198 |
+
trackers_enriched: enrichedTrackers
|
| 199 |
+
}
|
| 200 |
});
|
| 201 |
+
|
| 202 |
} catch (error) {
|
| 203 |
console.error('Scan error:', error);
|
| 204 |
+
res.status(500).json({
|
| 205 |
+
success: false,
|
| 206 |
+
error: error.message
|
| 207 |
+
});
|
| 208 |
}
|
| 209 |
});
|
| 210 |
|
| 211 |
+
app.get('/', (req, res) => {
|
| 212 |
+
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
| 213 |
+
});
|
| 214 |
|
| 215 |
+
app.listen(PORT, '0.0.0.0', () => {
|
| 216 |
+
console.log(`🚀 Private Eye v3.0 running on port ${PORT}`);
|
| 217 |
+
});
|