Files

233 lines
6.8 KiB
JavaScript

// backend/utils/categoryDictionary.js
// ─────────────────────────────────────────────────────────────────────────────
// Category Dictionary & Resolvers for BackOne DPI
// Maps category IDs, tags, and app labels to human-readable categories.
// ─────────────────────────────────────────────────────────────────────────────
const CATEGORY_ID_MAP = {
'1': 'Unclassified',
'2': 'Adult',
'3': 'Advertiser',
'4': 'Arts and Entertainment',
'5': 'Business',
'6': 'Career and Education',
'9': 'Financial',
'10': 'File Sharing',
'11': 'Gambling',
'12': 'Games',
'13': 'Government',
'15': 'Mail',
'16': 'Malware',
'17': 'Messaging',
'18': 'News',
'19': 'Portal',
'20': 'Recreation',
'21': 'Reference',
'23': 'Shopping',
'24': 'Social Media',
'26': 'Sports',
'27': 'Technology',
'28': 'VPN and Proxy',
'29': 'Streaming Media',
'30': 'Cybersecurity',
'31': 'OS/Software Updates',
'32': 'VoIP/Conferencing',
'33': 'Device/IoT',
'34': 'Remote Desktop',
'35': 'CDN',
'36': 'Hosting',
'37': 'ISP/Telco',
'40': 'Identified'
};
const APP_CATEGORY_MAP = {
// Streaming Media
'youtube': 'Streaming Media',
'netflix': 'Streaming Media',
'spotify': 'Streaming Media',
'twitch': 'Streaming Media',
'disney': 'Streaming Media',
'disney-plus': 'Streaming Media',
'googlevideo': 'Streaming Media',
'vimeo': 'Streaming Media',
'soundcloud': 'Streaming Media',
'tiktokv': 'Streaming Media',
'bigo': 'Streaming Media',
'vidio': 'Streaming Media',
// Social Media
'facebook': 'Social Media',
'instagram': 'Social Media',
'tiktok': 'Social Media',
'twitter': 'Social Media',
'x': 'Social Media',
'threads': 'Social Media',
'reddit': 'Social Media',
'pinterest': 'Social Media',
'linkedin': 'Social Media',
'snapchat': 'Social Media',
// Messaging
'whatsapp': 'Messaging',
'telegram': 'Messaging',
'discord': 'Messaging',
'slack': 'Messaging',
'signal': 'Messaging',
'signalr': 'Messaging',
'line': 'Messaging',
'wechat': 'Messaging',
'messenger': 'Messaging',
// VoIP / Conferencing
'zoom': 'VoIP/Conferencing',
'teams': 'VoIP/Conferencing',
'skype': 'VoIP/Conferencing',
'webex': 'VoIP/Conferencing',
'google-meet': 'VoIP/Conferencing',
// Technology
'google': 'Technology',
'google-drive': 'Technology',
'google-ads': 'Technology',
'google-play': 'Technology',
'microsoft': 'Technology',
'apple': 'Technology',
'apple-updates': 'Technology',
'bytedance': 'Technology',
'yahoo': 'Technology',
'bing': 'Technology',
// CDN
'cloudflare': 'CDN',
'akamai': 'CDN',
'fastly': 'CDN',
'cdn77': 'CDN',
'edgecast': 'CDN',
// Hosting / Cloud
'amazon': 'Hosting',
'amazon-aws': 'Hosting',
'amazon-s3': 'Hosting',
'amazon-cloudfront': 'CDN',
'aws': 'Hosting',
'azure': 'Hosting',
'digitalocean': 'Hosting',
// Games
'steam': 'Games',
'epic': 'Games',
'roblox': 'Games',
'riot': 'Games',
'riot-games': 'Games',
'valorant': 'Games',
'garena': 'Games',
'genshin': 'Games',
'moonton': 'Games',
'netease': 'Games',
'netease-games': 'Games',
'unity': 'Games',
'playstation': 'Games',
'xbox': 'Games',
// Shopping
'shopee': 'Shopping',
'shopeepay': 'Shopping',
'tokopedia': 'Shopping',
'lazada': 'Shopping',
'bukalapak': 'Shopping',
'blibli': 'Shopping',
'ebay': 'Shopping',
'alibaba': 'Shopping',
'aliexpress': 'Shopping',
// Financial
'bca': 'Financial',
'mandiri': 'Financial',
'bri': 'Financial',
'bni': 'Financial',
'cimb': 'Financial',
'paypal': 'Financial',
'stripe': 'Financial',
// OS / Updates
'windowsupdate': 'OS/Software Updates',
'android': 'OS/Software Updates',
// Remote Desktop
'anydesk': 'Remote Desktop',
'teamviewer': 'Remote Desktop',
'rdp': 'Remote Desktop',
'ssh': 'Remote Desktop',
'vnc': 'Remote Desktop',
// Network Infrastructure
'dns': 'Network Infrastructure',
'ntp': 'Network Infrastructure',
'dhcp': 'Network Infrastructure',
'icmp': 'Network Infrastructure',
'reverse-dns': 'Network Infrastructure',
'root-servers': 'Network Infrastructure',
'dyn-ddns': 'Network Infrastructure',
// Development
'github': 'Technology',
'gitlab': 'Technology',
};
function resolveAppCategory(appLabel, lookupMap = {}) {
if (!appLabel || appLabel === 'Unknown' || appLabel === 'backone.unclassified' || appLabel === 'netify.unclassified') {
return 'Unclassified';
}
// 1. Check exact match in lookupMap (which contains LookupApp entries)
if (lookupMap[appLabel]?.category) {
return lookupMap[appLabel].category;
}
if (typeof lookupMap[appLabel] === 'string') {
return lookupMap[appLabel];
}
// 2. Clean prefix
const clean = String(appLabel).toLowerCase().replace(/^(?:backone|netify|siab|nexus)\./i, '');
if (lookupMap[clean]?.category) {
return lookupMap[clean].category;
}
if (typeof lookupMap[clean] === 'string') {
return lookupMap[clean];
}
// 3. Fallback dictionary by exact clean key
if (APP_CATEGORY_MAP[clean]) {
return APP_CATEGORY_MAP[clean];
}
// 4. Substring match against known apps
for (const [key, cat] of Object.entries(APP_CATEGORY_MAP)) {
if (clean.includes(key)) return cat;
}
// 5. Port-based categories
if (/^(?:port\s+)?(\d+)$/i.test(clean)) {
const port = parseInt(clean.replace(/^(?:port\s+)?/i, ''), 10);
if ([80, 443, 8080, 8443].includes(port)) return 'Technology';
if ([53, 67, 68, 123, 161, 162].includes(port)) return 'Network Infrastructure';
if ([22, 23, 3389, 5900].includes(port)) return 'Remote Desktop';
if ([25, 110, 143, 465, 587, 993, 995].includes(port)) return 'Mail';
return 'General Traffic';
}
return 'General Traffic';
}
function getAppCategoryFallback(appLabel) {
return resolveAppCategory(appLabel, {});
}
module.exports = {
CATEGORY_ID_MAP,
APP_CATEGORY_MAP,
resolveAppCategory,
getAppCategoryFallback
};