import * as https from 'https'; import { getBlockedList, getContentKeeperUnblocked } from '../categories'; interface PostFormData { [key: string]: string; } function postForm(url: string, data: PostFormData, timeoutMs: number): Promise { return new Promise((resolve, reject) => { const body = new URLSearchParams(data).toString(); const parsedUrl = new URL(url); const options = { hostname: parsedUrl.hostname, path: parsedUrl.pathname + parsedUrl.search, method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'Mozilla/5.0 Node.js Request', 'Content-Length': Buffer.byteLength(body) } }; const req = https.request(options, (res) => { const chunks: Buffer[] = []; res.on('data', (chunk) => chunks.push(chunk)); res.on('end', () => resolve(Buffer.concat(chunks).toString())); }); req.on('error', reject); if (timeoutMs) { req.setTimeout(timeoutMs, () => { try { req.destroy(new Error('timeout')); } catch (e) { } }); } req.write(body); req.end(); }); } function mapStatus(cat: string): 'B' | 'U' { const L: { [key: string]: 'B' | 'U' } = { 'Adult Content': 'B', 'News': 'B', 'Job Search': 'U', 'Gambling': 'B', 'Travel/Tourism': 'U', 'Shopping': 'B', 'Entertainment': 'B', 'Instant Messaging': 'B', 'Dating': 'B', 'Game Sites': 'B', 'Investment': 'B', 'E-Banking': 'B', 'Crime/Terrorism': 'B', 'Religion/Personal Beliefs': 'U', 'Politics': 'U', 'Sports': 'U', 'Web Mail': 'B', 'Violence/Undesirable': 'B', 'Malicious': 'B', 'Search Sites': 'U', 'Health Sites': 'U', 'Clubs and Societies': 'B', 'Video': 'B', 'Business Oriented': 'B', 'Government Blocking List': 'B', 'Educational': 'U', 'Advertising': 'B', 'Alcohol': 'B', 'Computing/IT': 'U', 'Swimsuit/Lingerie/Models': 'B', 'Remote Control/Desktops': 'B' }; const C: { [key: string]: 'B' | 'U' } = { 'Osceola-Block': 'B', 'Osceola-Whitelist': 'U', 'Blacklist-Student': 'B', 'BAE - Malicious': 'B', 'BAE - Suspicious': 'B', 'CSB - Malicious': 'B', 'CSB - Suspicious': 'B', 'CYL - Malicious': 'B', 'CYL - Suspicious': 'B', 'SMD - Malicious': 'B', 'Osceola-AI Sites': 'B', 'Abortion': 'B', 'Human Sexuality': 'B', 'Animals:Pet': 'U', 'Arts:Culture': 'U', 'Auctions': 'B', 'Backups:Storage': 'B', 'Audio Streaming Services': 'B', 'Botnets': 'B', 'Charities': 'U', 'Child Entertainment': 'B', 'Child Abuse Material': 'B', 'Dictionary': 'U', 'Drugs:Pharmaceuticals': 'B', 'Dynamic DNS': 'B', 'Chatrooms': 'B', 'Educational Games': 'U', 'Embedded Threats': 'B', 'Fashion': 'B', 'Government': 'B', 'Guns & Weapons': 'B', 'Hacking': 'B', 'Hobbies': 'U', 'Hosted Services': 'B', 'Humor': 'B', 'ISPs': 'B', 'Keyloggers': 'B', 'Media:File Sharing': 'B', 'Millitary': 'B', 'IT Security': 'U', 'Nudity': 'B', 'Online Meetings & Collaboration': 'B', 'Pay to Surf': 'B', 'Personal': 'B', 'Proishing:Frauds': 'B', 'Proxies:Filtering-Bypass': 'B', 'Real Estate': 'B', 'Radio': 'B', 'Restaurants/Dining/Food': 'B', 'Sex Education': 'B', 'Social Networking': 'B', 'Software Downloading/Sharing': 'B', 'Spam URLs': 'B', 'Special Events': 'U', 'Spyware': 'B', 'Stock Trading': 'B', 'Surveillance Monitoring Site Cams': 'B', 'Suspicious': 'B', 'Text Messaging': 'B', 'Tobacco': 'B', 'Unions & Professional Organisations': 'U', 'Vehicles': 'B', 'Viral Video': 'B', 'Weather': 'U', 'IT Forums:Blogs': 'U', 'Peer to Peer': 'B', 'ShareWare:FreeWare': 'B', 'TV': 'B', 'Drugs:illicit': 'B', 'Academic Fraud': 'B', 'Cults': 'B', 'AI Services': 'B' }; if (L[cat]) return L[cat]; if (C[cat]) return C[cat]; return 'B'; } export async function check(domain: string) { const start = Date.now(); try { const d = String(domain).replace(/^https?:\/\//, '').replace(/\/.*$/, ''); const html = await postForm( 'https://isc-ckf05-mgt.cfisd.net/cgi-bin/ck/re_u.cgi', { USER: '', URL_AREA: d, NUM_SUBMIT_URL: '1', SEL_1: '29', CAT_1: '-1', URL_1: d, DAT_1: 'n/a', SUBMIT_SITE_SECOND_CANCEL: 'Cancel' }, 8000 ); const match = html.match(/color:\s*#ff0000[^>]*>([^<]+)<\/td>/i); const cat = match ? match[1].trim() : 'Unknown'; const blockedList = getBlockedList('content_keeper'); const allowList = getContentKeeperUnblocked(); let blocked = false; if (blockedList && blockedList.includes(cat)) { blocked = true; } else if (allowList && allowList.includes(cat)) { blocked = false; } else { blocked = (mapStatus(cat) === 'B'); } const responseTime = Date.now() - start; const status = blocked ? 'BLOCKED' : 'ALLOWED'; return { blocked, category: cat, status, response_time: responseTime, provider: 'content_keeper' }; } catch (e) { return { blocked: false, category: 'Error', status: 'ERROR', error: 'Global Error, Service might be down. Please report it to "road.js" on discord please.', response_time: Date.now() - start, provider: 'content_keeper' }; } }