diff --git a/backend/netify.js b/backend/netify.js index e33ccbd..0916d83 100644 --- a/backend/netify.js +++ b/backend/netify.js @@ -17,343 +17,7 @@ function headersSite(useApiKey = false) { return headers; } -function getMockDataForPath(path, params = {}) { - return null; - if (path.includes('/data/stats/summary')) { - return { - download: 218648938113, - upload: 33551656812, - flow_hourly_count: 2970165, - download_speed: 2530000, - upload_speed: 390000, - flow_speed: 123756 - }; - } - if (path.includes('/data/stats/top/application/download')) { - return [ - { application: { id: 1, label: 'YouTube', tag: 'video', category: { label: 'Streaming' } }, download: Math.floor(Math.random() * 50000000) + 10000000, flows: Math.floor(Math.random() * 200) + 50 }, - { application: { id: 2, label: 'Netflix', tag: 'video', category: { label: 'Streaming' } }, download: Math.floor(Math.random() * 40000000) + 8000000, flows: Math.floor(Math.random() * 100) + 30 }, - { application: { id: 3, label: 'Web Browsing', tag: 'web', category: { label: 'General' } }, download: Math.floor(Math.random() * 30000000) + 5000000, flows: Math.floor(Math.random() * 500) + 200 }, - { application: { id: 4, label: 'Google Services', tag: 'google', category: { label: 'Tech' } }, download: Math.floor(Math.random() * 25000000) + 4000000, flows: Math.floor(Math.random() * 400) + 150 }, - { application: { id: 5, label: 'WhatsApp', tag: 'im', category: { label: 'Chat' } }, download: Math.floor(Math.random() * 15000000) + 2000000, flows: Math.floor(Math.random() * 300) + 100 }, - { application: { id: 6, label: 'Spotify', tag: 'music', category: { label: 'Streaming' } }, download: Math.floor(Math.random() * 12000000) + 1000000, flows: Math.floor(Math.random() * 80) + 20 }, - { application: { id: 7, label: 'GitHub', tag: 'developer', category: { label: 'General' } }, download: Math.floor(Math.random() * 8000000) + 500000, flows: Math.floor(Math.random() * 120) + 40 }, - { application: { id: 8, label: 'OpenVPN', tag: 'vpn', category: { label: 'Security' } }, download: Math.floor(Math.random() * 5000000) + 300000, flows: Math.floor(Math.random() * 50) + 10 }, - { application: { id: 9, label: 'BitTorrent', tag: 'p2p', category: { label: 'File Sharing' } }, download: Math.floor(Math.random() * 20000000) + 500000, flows: Math.floor(Math.random() * 300) + 50 } - ]; - } - if (path.includes('/data/stats/top/application/upload')) { - return [ - { application: { id: 1 }, upload: Math.floor(Math.random() * 5000000) + 1000000 }, - { application: { id: 2 }, upload: Math.floor(Math.random() * 2000000) + 500000 }, - { application: { id: 3 }, upload: Math.floor(Math.random() * 6000000) + 2000000 }, - { application: { id: 4 }, upload: Math.floor(Math.random() * 4000000) + 1000000 }, - { application: { id: 5 }, upload: Math.floor(Math.random() * 8000000) + 3000000 }, - { application: { id: 6 }, upload: Math.floor(Math.random() * 1000000) + 200000 }, - { application: { id: 7 }, upload: Math.floor(Math.random() * 3000000) + 800000 }, - { application: { id: 8 }, upload: Math.floor(Math.random() * 4000000) + 1000000 }, - { application: { id: 9 }, upload: Math.floor(Math.random() * 18000000) + 2000000 } - ]; - } - if (path.includes('/intelligence/discovery/devices')) { - return [ - { ip: { address: '192.168.1.10' }, mac_address: 'E4:5F:01:23:45:67', mac_vendor: 'Raspberry Pi', device: { label: 'Home Server' }, discovery_type: { label: 'Server' }, discovery_os: { label: 'Linux' }, last_seen_at: { date: new Date().toISOString() } }, - { ip: { address: '192.168.1.25' }, mac_address: 'B4:FB:E4:88:99:AA', mac_vendor: 'Samsung', device: { label: 'Smart TV' }, discovery_type: { label: 'TV' }, discovery_os: { label: 'Tizen' }, last_seen_at: { date: new Date().toISOString() } }, - { ip: { address: '192.168.1.100' }, mac_address: '3C:28:6D:AA:BB:CC', mac_vendor: 'Apple', device: { label: 'iPhone User' }, discovery_type: { label: 'Mobile' }, discovery_os: { label: 'iOS' }, last_seen_at: { date: new Date().toISOString() } }, - { ip: { address: '192.168.1.101' }, mac_address: '28:31:52:DD:EE:FF', mac_vendor: 'Xiaomi', device: { label: 'Redmi Phone' }, discovery_type: { label: 'Mobile' }, discovery_os: { label: 'Android' }, last_seen_at: { date: new Date().toISOString() } }, - { ip: { address: '192.168.1.102' }, mac_address: '00:15:5D:11:22:33', mac_vendor: 'Microsoft Hyper-V', device: { label: 'Windows PC' }, discovery_type: { label: 'Desktop' }, discovery_os: { label: 'Windows' }, last_seen_at: { date: new Date().toISOString() } } - ]; - } - if (path.includes('/data/stats/top/local_ip/download')) { - return [ - { local_ip: { address: '192.168.1.100' }, download: Math.floor(Math.random() * 40000000) + 10000000 }, - { local_ip: { address: '192.168.1.102' }, download: Math.floor(Math.random() * 30000000) + 8000000 }, - { local_ip: { address: '192.168.1.101' }, download: Math.floor(Math.random() * 15000000) + 3000000 }, - { local_ip: { address: '192.168.1.25' }, download: Math.floor(Math.random() * 25000000) + 5000000 }, - { local_ip: { address: '192.168.1.10' }, download: Math.floor(Math.random() * 8000000) + 2000000 } - ]; - } - if (path.includes('/data/stats/top/local_ip/upload')) { - return [ - { local_ip: { address: '192.168.1.100' }, upload: Math.floor(Math.random() * 5000000) + 1000000 }, - { local_ip: { address: '192.168.1.102' }, upload: Math.floor(Math.random() * 8000000) + 2000000 }, - { local_ip: { address: '192.168.1.101' }, upload: Math.floor(Math.random() * 2000000) + 500000 }, - { local_ip: { address: '192.168.1.25' }, upload: Math.floor(Math.random() * 1000000) + 100000 }, - { local_ip: { address: '192.168.1.10' }, upload: Math.floor(Math.random() * 4000000) + 1000000 } - ]; - } - if (path.includes('/data/stats/top/protocol/download')) { - return [ - { protocol: { id: 6, label: 'TCP' }, download: Math.floor(Math.random() * 100000000) + 40000000, flows: Math.floor(Math.random() * 1000) + 400 }, - { protocol: { id: 17, label: 'UDP' }, download: Math.floor(Math.random() * 30000000) + 10000000, flows: Math.floor(Math.random() * 800) + 200 } - ]; - } - if (path.includes('/data/stats/top/protocol/upload')) { - return [ - { protocol: { id: 6 }, upload: Math.floor(Math.random() * 20000000) + 5000000 }, - { protocol: { id: 17 }, upload: Math.floor(Math.random() * 10000000) + 2000000 } - ]; - } - if (path.includes('/data/stats/top/country/download')) { - return [ - { country: { code: 'US', label: 'United States' }, download: Math.floor(Math.random() * 60000000) + 20000000, flows: Math.floor(Math.random() * 500) + 200 }, - { country: { code: 'SG', label: 'Singapore' }, download: Math.floor(Math.random() * 40000000) + 10000000, flows: Math.floor(Math.random() * 300) + 100 }, - { country: { code: 'ID', label: 'Indonesia' }, download: Math.floor(Math.random() * 20000000) + 5000000, flows: Math.floor(Math.random() * 400) + 150 }, - { country: { code: 'NL', label: 'Netherlands' }, download: Math.floor(Math.random() * 10000000) + 2000000, flows: Math.floor(Math.random() * 100) + 30 } - ]; - } - if (path.includes('/data/stats/top/country/upload')) { - return [ - { country: { code: 'US' }, upload: Math.floor(Math.random() * 12000000) + 3000000 }, - { country: { code: 'SG' }, upload: Math.floor(Math.random() * 8000000) + 2000000 }, - { country: { code: 'ID' }, upload: Math.floor(Math.random() * 4000000) + 1000000 }, - { country: { code: 'NL' }, upload: Math.floor(Math.random() * 2000000) + 500000 } - ]; - } - if (path.includes('/data/stats/top/hostname/download')) { - return [ - { hostname: { name: 'youtube.com', application_name: 'YouTube', application_category_label: 'Streaming' }, download: Math.floor(Math.random() * 30000000) + 10000000, flows: Math.floor(Math.random() * 100) + 20 }, - { hostname: { name: 'netflix.com', application_name: 'Netflix', application_category_label: 'Streaming' }, download: Math.floor(Math.random() * 20000000) + 5000000, flows: Math.floor(Math.random() * 50) + 10 }, - { hostname: { name: 'google.com', application_name: 'Google', application_category_label: 'Web' }, download: Math.floor(Math.random() * 15000000) + 3000000, flows: Math.floor(Math.random() * 400) + 100 }, - { hostname: { name: 'github.com', application_name: 'GitHub', application_category_label: 'Web' }, download: Math.floor(Math.random() * 8000000) + 2000000, flows: Math.floor(Math.random() * 150) + 30 } - ]; - } - if (path.includes('/data/stats/top/hostname/upload')) { - return [ - { hostname: { name: 'youtube.com' }, upload: Math.floor(Math.random() * 2000000) + 500000 }, - { hostname: { name: 'netflix.com' }, upload: Math.floor(Math.random() * 1000000) + 200000 }, - { hostname: { name: 'google.com' }, upload: Math.floor(Math.random() * 3000000) + 500000 }, - { hostname: { name: 'github.com' }, upload: Math.floor(Math.random() * 2000000) + 400000 } - ]; - } - if (path.includes('/data/flows')) { - return [ - { flow_id: 'flow_1', local_ip: { address: '192.168.1.100' }, local_mac: '3C:28:6D:AA:BB:CC', remote_ip: { address: '172.217.194.95' }, remote_port: 443, ip_protocol: { label: 'TCP' }, download: Math.floor(Math.random() * 50000) + 5000, upload: Math.floor(Math.random() * 5000) + 500, first_seen_at: { date: new Date(Date.now() - 300000).toISOString() }, last_seen_at: { date: new Date().toISOString() } }, - { flow_id: 'flow_2', local_ip: { address: '192.168.1.102' }, local_mac: '00:15:5D:11:22:33', remote_ip: { address: '140.82.112.4' }, remote_port: 443, ip_protocol: { label: 'TCP' }, download: Math.floor(Math.random() * 20000) + 2000, upload: Math.floor(Math.random() * 10000) + 1000, first_seen_at: { date: new Date(Date.now() - 600000).toISOString() }, last_seen_at: { date: new Date().toISOString() } }, - { flow_id: 'flow_3', local_ip: { address: '192.168.1.101' }, local_mac: '28:31:52:DD:EE:FF', remote_ip: { address: '31.13.78.35' }, remote_port: 443, ip_protocol: { label: 'TCP' }, download: Math.floor(Math.random() * 15000) + 1000, upload: Math.floor(Math.random() * 2000) + 200, first_seen_at: { date: new Date(Date.now() - 120000).toISOString() }, last_seen_at: { date: new Date().toISOString() } }, - { flow_id: 'flow_4', local_ip: { address: '192.168.1.10' }, local_mac: 'E4:5F:01:23:45:67', remote_ip: { address: '8.8.8.8' }, remote_port: 53, ip_protocol: { label: 'UDP' }, download: Math.floor(Math.random() * 2000) + 200, upload: Math.floor(Math.random() * 2000) + 200, first_seen_at: { date: new Date(Date.now() - 50000).toISOString() }, last_seen_at: { date: new Date().toISOString() } } - ]; - } - if (path.includes('/event/events')) { - return [ - { id: Math.floor(Math.random() * 10000), basename: 'threat.cryptomining', severity: 30, label: 'Suspicious Cryptomining Activity', description: JSON.stringify({ default: 'Connection to mining pool detected from {{ device_ip }}', tags: { device_ip: '192.168.1.10' } }), created_at: { date: new Date().toISOString() } }, - { id: Math.floor(Math.random() * 10000), basename: 'threat.insecure', severity: 20, label: 'Insecure Cleartext Transmission', description: JSON.stringify({ default: 'Cleartext credentials transmitted by {{ device_ip }}', tags: { device_ip: '192.168.1.102' } }), created_at: { date: new Date(Date.now() - 300000).toISOString() } }, - { id: Math.floor(Math.random() * 10000), basename: 'new.device', severity: 10, label: 'New Device Discovered', description: JSON.stringify({ default: 'New device {{ device_label }} discovered at {{ device_ip }}', tags: { device_label: 'Redmi Phone', device_ip: '192.168.1.101' } }), created_at: { date: new Date(Date.now() - 600000).toISOString() } } - ]; - } - - if (path.includes('/data/stats/top/')) { - const segments = path.split('/'); - const fieldName = segments[segments.length - 2]; - const direction = segments[segments.length - 1]; - - if (fieldName === 'application_category') { - const cats = ['Streaming', 'Social Media', 'Web Browsing', 'File Sharing', 'Communication', 'Collaboration', 'Security']; - return cats.map((c) => ({ - application_category: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 40000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'continent') { - const conts = ['North America', 'Asia', 'Europe', 'Oceania']; - return conts.map((c) => ({ - continent: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 50000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 15000000) + 2000000 : 0 - })); - } - if (fieldName === 'region') { - const regs = ['California', 'Singapore Region', 'Jakarta Region', 'Frankfurt Region']; - return regs.map((c) => ({ - region: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'city') { - const cities = ['San Francisco', 'Singapore', 'Jakarta', 'Frankfurt']; - return cities.map((c) => ({ - city: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'vlan') { - const vlans = ['VLAN 1 (Default)', 'VLAN 10 (IoT)', 'VLAN 20 (Guest)']; - return vlans.map((c) => ({ - vlan: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 50000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 15000000) + 2000000 : 0 - })); - } - if (fieldName === 'interface') { - const ifaces = ['eth0 (WAN)', 'eth1 (LAN)', 'wlan0 (WiFi)']; - return ifaces.map((c) => ({ - interface: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 60000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 20000000) + 2000000 : 0 - })); - } - if (fieldName === 'flow_type') { - const types = ['HTTP/HTTPS', 'DNS', 'SSH', 'VPN', 'P2P']; - return types.map((c) => ({ - flow_type: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 40000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'flow_origin') { - const origs = ['Local LAN', 'Inbound WAN']; - return origs.map((c) => ({ - flow_origin: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 50000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 15000000) + 2000000 : 0 - })); - } - if (fieldName === 'ip_version') { - const versions = ['IPv4', 'IPv6']; - return versions.map((c) => ({ - ip_version: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 80000000) + 20000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 25000000) + 5000000 : 0 - })); - } - if (fieldName === 'remote_ip') { - const ips = ['8.8.8.8', '1.1.1.1', '140.82.112.4', '172.217.194.95']; - return ips.map((c) => ({ - remote_ip: { address: c, version: 4 }, - download: direction === 'download' ? Math.floor(Math.random() * 20000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 5000000) + 500000 : 0 - })); - } - if (fieldName === 'local_mac') { - const macs = ['3C:28:6D:AA:BB:CC', '00:15:5D:11:22:33', '28:31:52:DD:EE:FF', 'E4:5F:01:23:45:67']; - return macs.map((c) => ({ - local_mac: c, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'discovery_os') { - const oss = ['iOS', 'Android', 'Windows', 'Linux', 'macOS']; - return oss.map((c) => ({ - discovery_os: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'tls_version') { - const vers = ['TLS 1.3', 'TLS 1.2', 'TLS 1.1']; - return vers.map((c) => ({ - tls_version: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 50000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 15000000) + 2000000 : 0 - })); - } - if (fieldName === 'tls_cipher') { - const ciphers = ['TLS_AES_256_GCM_SHA384', 'TLS_CHACHA20_POLY1305_SHA256', 'ECDHE-RSA-AES128-GCM-SHA256']; - return ciphers.map((c) => ({ - tls_cipher: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 40000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 12000000) + 2000000 : 0 - })); - } - if (fieldName === 'tls_security') { - const secs = ['Modern (TLS 1.3)', 'Secure (TLS 1.2)', 'Weak']; - return secs.map((c) => ({ - tls_security: { name: c, label: c, color: c === 'Weak' ? 'red' : 'green' }, - download: direction === 'download' ? Math.floor(Math.random() * 40000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 12000000) + 2000000 : 0 - })); - } - if (fieldName === 'netbios_hostname') { - const hosts = ['DESKTOP-PC', 'NAS-SERVER', 'PRINTER-OFFICE']; - return hosts.map((c) => ({ - netbios_hostname: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 10000000) + 2000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 4000000) + 500000 : 0 - })); - } - if (fieldName === 'dhcp_class') { - const classes = ['dhcpcd-9.4.1', 'MSFT 5.0', 'android-dhcp-10']; - return classes.map((c) => ({ - dhcp_class: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 20000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 5000000) + 1000000 : 0 - })); - } - if (fieldName === 'http_useragent') { - const uas = [ - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', - 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1', - 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Mobile Safari/537.36' - ]; - return uas.map((c) => ({ - http_useragent: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'https_sni_hostname') { - const snis = ['*.google.com', '*.netflix.com', 'github.com', '*.facebook.com']; - return snis.map((c) => ({ - https_sni_hostname: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'ssl_server_cn') { - const cns = ['Google Internet Authority', 'DigiCert TLS RSA SHA256 2020 CA1', 'Let\'s Encrypt Authority X3']; - return cns.map((c) => ({ - ssl_server_cn: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 40000000) + 10000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 12000000) + 2000000 : 0 - })); - } - if (fieldName === 'quic_hostname') { - const quics = ['*.google.com', '*.youtube.com', 'instagram.com']; - return quics.map((c) => ({ - quic_hostname: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 30000000) + 5000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 1000000 : 0 - })); - } - if (fieldName === 'bittorrent_info_hash') { - const hashes = ['8f9e1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f', '1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9e1a']; - return hashes.map((c, i) => ({ - bittorrent_info_hash: { hash: c, label: `Torrent_${i+1}` }, - download: direction === 'download' ? Math.floor(Math.random() * 10000000) + 2000000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 10000000) + 2000000 : 0 - })); - } - if (fieldName === 'ssh_client') { - const clients = ['SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5', 'SSH-2.0-PuTTY_Release_0.76']; - return clients.map((c) => ({ - ssh_client: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 1000000) + 100000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 500000) + 50000 : 0 - })); - } - if (fieldName === 'ssh_server') { - const servers = ['SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5', 'SSH-2.0-dropbear_2019.78']; - return servers.map((c) => ({ - ssh_server: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 1000000) + 100000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 500000) + 50000 : 0 - })); - } - if (fieldName === 'mdns_hostname') { - const mdns = ['apple-tv.local', 'printer-office.local', 'nas-home.local']; - return mdns.map((c) => ({ - mdns_hostname: { name: c, label: c }, - download: direction === 'download' ? Math.floor(Math.random() * 5000000) + 500000 : 0, - upload: direction === 'upload' ? Math.floor(Math.random() * 2000000) + 200000 : 0 - })); - } - } - return []; -} + function fixDates(obj) { if (Array.isArray(obj)) { @@ -384,8 +48,8 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul } } if (!JWT_TOKEN || !SITE_UUID || JWT_TOKEN === 'YOUR_JWT_TOKEN' || SITE_UUID === 'YOUR_SITE_UUID' || JWT_TOKEN.startsWith('change_me') || JWT_TOKEN.startsWith('YOUR_')) { - console.log('[DEBUG] FALLBACK due to invalid config', {hasToken: !!JWT_TOKEN, SITE_UUID}); - return getMockDataForPath(path, params); + console.error('[Netify] Failed due to invalid config', {hasToken: !!JWT_TOKEN, SITE_UUID}); + return null; } try { const res = await axios.get(`${BASE_URL}${path}`, { @@ -394,17 +58,15 @@ async function netifyFetch(path, params = {}, useApiKey = false, agentUuid = nul const json = res.data; if (json?.status_code !== 0) { console.error(`[Netify] API Error ${json?.status_code} pada ${path}: ${json?.status_message}`); - console.log('[DEBUG] FALLBACK due to API error', json); - return getMockDataForPath(path, params); + return null; } if (json && json.data) fixDates(json.data); return json?.data ?? null; } catch (err) { const s = err.response?.status; const msg = JSON.stringify(err.response?.data ?? err.message); - console.error(`[Netify] ${s ?? 'ERR'} ${path}: ${msg}. Falling back to mock data.`); - console.log('[DEBUG] FALLBACK due to catch error'); - return getMockDataForPath(path, params); + console.error(`[Netify] ${s ?? 'ERR'} ${path}: ${msg}`); + return null; } } diff --git a/deploy_to_server.js b/deploy_to_server.js deleted file mode 100644 index 9adbda5..0000000 --- a/deploy_to_server.js +++ /dev/null @@ -1,91 +0,0 @@ -const { Client } = require('ssh2'); -const fs = require('fs'); - -const conn = new Client(); - -const script = ` -set -e -export PATH=/home/adminbackend/node20/bin:$PATH - -echo "=== 1. STOPPING PM2 PROCESSES ===" -npx pm2 delete all || true - -echo "=== 2. BACKING UP DB & ENV ===" -mkdir -p /home/adminbackend/deploy_backup -cp /home/adminbackend/web/demoplace.my.id/public_html/.env.local /home/adminbackend/deploy_backup/.env.local || echo "No .env.local found" -cp /home/adminbackend/web/demoplace.my.id/public_html/backend/netify_data.db /home/adminbackend/deploy_backup/netify_data.db || echo "No DB found" -cp -r /home/adminbackend/web/demoplace.my.id/public_html/backend/uploads /home/adminbackend/deploy_backup/uploads || echo "No uploads found" - -echo "=== 3. CLEARING TARGET DIRECTORY ===" -cd /home/adminbackend/web/demoplace.my.id/public_html -mkdir -p /home/adminbackend/trash -mv * /home/adminbackend/trash/ 2>/dev/null || true -mv .[^.]* /home/adminbackend/trash/ 2>/dev/null || true - -echo "=== 4. EXTRACTING UPLOADED TARBALL ===" -tar -xzf /home/adminbackend/deploy.tar.gz -C . -rm -f /home/adminbackend/deploy.tar.gz - -echo "=== 5. RESTORING BACKUP ===" -cp /home/adminbackend/deploy_backup/.env.local ./.env.local || true -mkdir -p backend -cp /home/adminbackend/deploy_backup/netify_data.db ./backend/netify_data.db || true -rm -rf ./backend/uploads || true -cp -r /home/adminbackend/deploy_backup/uploads ./backend/uploads || true - -echo "=== 6. INSTALLING DEPS & BUILDING ===" -npm install --legacy-peer-deps -npm run build - -echo "=== 6.5. CREATING NGINX SYMLINKS ===" -ln -sfn .next _next -ln -sfn public/backone-logo.png backone-logo.png -ln -sfn public/favicon.ico favicon.ico - -echo "=== 7. STARTING PM2 ===" -PORT=10000 npx pm2 start npm --name "dpi-web" -- start -npx pm2 start backend/server.js --name "dpi-api" -npx pm2 save - -echo "=== DEPLOYMENT SUCCESSFUL ===" -npx pm2 status -`; - -conn.on('ready', () => { - console.log('Connected to server. Uploading tarball...'); - conn.sftp((err, sftp) => { - if (err) throw err; - const readStream = fs.createReadStream('deploy.tar.gz'); - const writeStream = sftp.createWriteStream('/home/adminbackend/deploy.tar.gz'); - - writeStream.on('close', () => { - console.log('Upload complete. Executing deploy script...'); - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code, signal) => { - console.log('Deployment script finished with code ' + code); - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); - }); - - writeStream.on('error', (err) => { - console.error('SFTP Error:', err); - conn.end(); - }); - - readStream.pipe(writeStream); - }); -}).on('error', (err) => { - console.error('SSH Error:', err); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH', - readyTimeout: 99999 -}); diff --git a/diff.patch b/diff.patch deleted file mode 100644 index 968d9e7..0000000 Binary files a/diff.patch and /dev/null differ diff --git a/fix_db.js b/fix_db.js deleted file mode 100644 index 1dc3884..0000000 --- a/fix_db.js +++ /dev/null @@ -1,47 +0,0 @@ -const { Client } = require('ssh2'); - -const conn = new Client(); - -const script = ` -set -e -export PATH=/home/adminbackend/node20/bin:$PATH - -echo "Stopping PM2" -npx pm2 stop dpi-api || true - -echo "Deleting corrupted database" -cd /home/adminbackend/web/demoplace.my.id/public_html/backend -rm -f netify_data.db netify_data.db-wal netify_data.db-shm - -echo "Running scheduler to recreate DB" -node scheduler.js & -SCHED_PID=$! -sleep 15 -kill $SCHED_PID || true - -echo "Restarting PM2" -npx pm2 restart dpi-api -`; - -conn.on('ready', () => { - console.log('Connected to server. Executing script...'); - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code, signal) => { - console.log('Script finished with code ' + code); - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).on('error', (err) => { - console.error('SSH Error:', err); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH', - readyTimeout: 99999 -}); diff --git a/fix_db_v2.js b/fix_db_v2.js deleted file mode 100644 index 7707355..0000000 --- a/fix_db_v2.js +++ /dev/null @@ -1,43 +0,0 @@ -const { Client } = require('ssh2'); - -const conn = new Client(); - -const script = ` -set -e -export PATH=/home/adminbackend/node20/bin:$PATH - -echo "Stopping PM2" -npx pm2 stop dpi-api || true - -echo "Deleting database to force recreation" -cd /home/adminbackend/web/demoplace.my.id/public_html/backend -rm -f netify_data.db netify_data.db-wal netify_data.db-shm - -echo "Restarting PM2" -npx pm2 restart dpi-api - -echo "Done" -`; - -conn.on('ready', () => { - console.log('Connected to server. Executing script...'); - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code, signal) => { - console.log('Script finished with code ' + code); - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).on('error', (err) => { - console.error('SSH Error:', err); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH', - readyTimeout: 99999 -}); diff --git a/remove_headers.js b/remove_headers.js deleted file mode 100644 index 1182b32..0000000 --- a/remove_headers.js +++ /dev/null @@ -1,39 +0,0 @@ -const fs = require('fs'); -const path = require('path'); - -function walk(dir) { - let results = []; - const list = fs.readdirSync(dir); - list.forEach(function(file) { - file = path.join(dir, file); - const stat = fs.statSync(file); - if (stat && stat.isDirectory()) { - results = results.concat(walk(file)); - } else { - if (file.endsWith('.tsx')) results.push(file); - } - }); - return results; -} - -const files = walk('src/app/(dashboard)'); - -for (const file of files) { - let content = fs.readFileSync(file, 'utf8'); - - let regex1 = /
\s*
\s*

\s*

]*>[\s\S]*?<\/h2>/g; - - let newContent = content.replace(regex1, '').replace(regex2, ''); - - // Also clean up stray headers that might not have the div wrapper - if(newContent.match(regex3)) { - newContent = newContent.replace(regex3, ''); - } - - if (content !== newContent) { - fs.writeFileSync(file, newContent); - console.log('Updated ' + file); - } -} diff --git a/restore_headers.js b/restore_headers.js deleted file mode 100644 index 6cecfaf..0000000 --- a/restore_headers.js +++ /dev/null @@ -1,48 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const execSync = require('child_process').execSync; - -function walk(dir) { - let results = []; - const list = fs.readdirSync(dir); - list.forEach(function(file) { - file = path.join(dir, file); - const stat = fs.statSync(file); - if (stat && stat.isDirectory()) { - results = results.concat(walk(file)); - } else { - if (file.endsWith('.tsx')) results.push(file); - } - }); - return results; -} - -const files = walk('src/app/(dashboard)'); - -for (const file of files) { - try { - const gitFile = file.replace(/\\/g, '/'); - const original = execSync('git show HEAD:"' + gitFile + '"').toString(); - const current = fs.readFileSync(file, 'utf8'); - - let regex1 = /
\s*(
\s*)?

\s*

]*>[\s\S]*?<\/h2>/; - - let match = original.match(regex1) || original.match(regex2) || original.match(regex3); - - if (match && !current.includes('

', insertPos); - let newContent = current.slice(0, closingBracket + 1) + '\n' + match[0] + current.slice(closingBracket + 1); - fs.writeFileSync(file, newContent); - console.log('Restored header in ' + file); - } - } - } catch(e) { - console.log("Error processing " + file + ": " + e.message); - } -} diff --git a/src/app/api/wipe/route.ts b/src/app/api/wipe/route.ts deleted file mode 100644 index 85ad23c..0000000 --- a/src/app/api/wipe/route.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { NextResponse } from 'next/server'; -import mongoose from 'mongoose'; -import { DeviceStat, Summary, AppStat, ProtocolStat, Flow, Threat } from '../../../../backend/models/Schemas'; - -export async function GET() { - try { - // Check if mongoose is connected - if (mongoose.connection.readyState !== 1) { - return NextResponse.json({ error: 'MongoDB not connected on frontend route' }, { status: 500 }); - } - - await DeviceStat.deleteMany({}); - await Summary.deleteMany({}); - await AppStat.deleteMany({}); - await ProtocolStat.deleteMany({}); - await Flow.deleteMany({}); - await Threat.deleteMany({}); - - return NextResponse.json({ message: 'All dummy data wiped from in-memory database successfully!' }); - } catch (err: any) { - console.error(err); - return NextResponse.json({ error: err.message }, { status: 500 }); - } -} diff --git a/temp_check_db.js b/temp_check_db.js deleted file mode 100644 index e8eb68d..0000000 --- a/temp_check_db.js +++ /dev/null @@ -1,28 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -sqlite3 /home/adminbackend/web/backend.demoplace.my.id/public_html/backend/netify_data.db "PRAGMA integrity_check;" -echo "Backup DB Check:" -sqlite3 /home/adminbackend/deploy_backup/netify_data.db "PRAGMA integrity_check;" -echo "Current DB Check:" -sqlite3 /home/adminbackend/web/demoplace.my.id/public_html/backend/netify_data.db "PRAGMA integrity_check;" -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_check_mongo.js b/temp_check_mongo.js deleted file mode 100644 index 1e0aafe..0000000 --- a/temp_check_mongo.js +++ /dev/null @@ -1,8 +0,0 @@ -const mongoose = require('mongoose'); -const { AppStat, DeviceStat } = require('./backend/models/Schemas'); - -mongoose.connect('mongodb://127.0.0.1:27017/backone_dpi').then(async () => { - console.log('AppStats count:', await AppStat.countDocuments()); - console.log('DeviceStats count:', await DeviceStat.countDocuments()); - process.exit(0); -}); diff --git a/temp_fetch.js b/temp_fetch.js deleted file mode 100644 index 0d5f564..0000000 --- a/temp_fetch.js +++ /dev/null @@ -1,4 +0,0 @@ -fetch('http://localhost:3000/api/dashboard/apps?limit=10') - .then(r => r.json()) - .then(j => console.log(JSON.stringify(j, null, 2))) - .catch(console.error); diff --git a/temp_fix_cors.js b/temp_fix_cors.js deleted file mode 100644 index 240c1b4..0000000 --- a/temp_fix_cors.js +++ /dev/null @@ -1,26 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -sed -i "s|ALLOWED_ORIGINS=.*|ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000,https://backend.demoplace.my.id,http://backend.demoplace.my.id,https://demoplace.my.id,http://demoplace.my.id|g" /home/adminbackend/web/demoplace.my.id/public_html/.env.local -cd /home/adminbackend/web/demoplace.my.id/public_html -npx pm2 restart dpi-api -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_fix_next.js b/temp_fix_next.js deleted file mode 100644 index d66ab42..0000000 --- a/temp_fix_next.js +++ /dev/null @@ -1,33 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -set -e - -echo "=== STOPPING PM2 ===" -npx pm2 delete dpi-web || true - -echo "=== STARTING PM2 ===" -cd /home/adminbackend/web/demoplace.my.id/public_html -# Restarting pm2 daemon and processes -PORT=10000 npx pm2 start ./node_modules/next/dist/bin/next --name "dpi-web" --interpreter /home/adminbackend/node20/bin/node -- start -npx pm2 save -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_fix_pm2.js b/temp_fix_pm2.js deleted file mode 100644 index 7007130..0000000 --- a/temp_fix_pm2.js +++ /dev/null @@ -1,47 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -set -e -export PATH=/home/adminbackend/node20/bin:$PATH - -echo "=== STOPPING PM2 ===" -npx pm2 delete all || true - -echo "=== REBUILDING NATIVE MODULES ===" -cd /home/adminbackend/web/demoplace.my.id/public_html -# Make sure sqlite3 is rebuilt for node20 -npm rebuild better-sqlite3 - -echo "=== STARTING PM2 ===" -# Next.js must run on 10000 because Hestia Nginx proxy looks for 10000 -# Backend API runs on 3001 -PORT=10000 npx pm2 start /home/adminbackend/node20/bin/npm --name "dpi-web" --interpreter /home/adminbackend/node20/bin/node -- start -PORT=3001 npx pm2 start backend/server.js --name "dpi-api" --interpreter /home/adminbackend/node20/bin/node - -npx pm2 save -npx pm2 status -`; - -const conn = new Client(); -conn.on('ready', () => { - console.log('Connected. Running fix script...'); - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code, signal) => { - console.log('Fix script finished with code ' + code); - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).on('error', (err) => { - console.error('SSH Error:', err); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH', - readyTimeout: 99999 -}); diff --git a/temp_fix_port.js b/temp_fix_port.js deleted file mode 100644 index 48085c2..0000000 --- a/temp_fix_port.js +++ /dev/null @@ -1,28 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -export PATH=/home/adminbackend/node20/bin:$PATH -cd /home/adminbackend/web/demoplace.my.id/public_html -npx pm2 delete dpi-web || true -PORT=10000 npx pm2 start /home/adminbackend/node20/bin/npm --name "dpi-web" -- start -npx pm2 save -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_fix_prod.js b/temp_fix_prod.js deleted file mode 100644 index 9038ad1..0000000 --- a/temp_fix_prod.js +++ /dev/null @@ -1,44 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -set -e -export PATH=/home/adminbackend/node20/bin:$PATH -cd /home/adminbackend/web/demoplace.my.id/public_html/backend -echo "=== STOPPING API TO PREVENT WRITES ===" -npx pm2 stop dpi-api || true - -echo "=== FIXING CORS IN .env.local ===" -sed -i "s|ALLOWED_ORIGINS=.*|ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000,https://backend.demoplace.my.id,http://backend.demoplace.my.id,https://demoplace.my.id,http://demoplace.my.id|g" /home/adminbackend/web/demoplace.my.id/public_html/.env.local - -echo "=== BACKING UP CORRUPTED DB ===" -cp netify_data.db netify_data_corrupted.db -echo "=== DUMPING CORRUPTED DB TO SQL ===" -sqlite3 netify_data.db ".recover" > recovery.sql || echo "Recovery completed with some warnings" -echo "=== REBUILDING DB ===" -rm netify_data.db -sqlite3 netify_data.db < recovery.sql -rm recovery.sql - -echo "=== RESTARTING API ===" -npx pm2 start dpi-api -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - console.log('Script finished with code ' + code); - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_restore_db.js b/temp_restore_db.js deleted file mode 100644 index 4a0aaf5..0000000 --- a/temp_restore_db.js +++ /dev/null @@ -1,46 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -set -e - -echo "=== STOPPING PM2 ===" -npx pm2 stop all -npx pm2 kill - -echo "=== RESTORING DB FROM BACKUP ===" -cd /home/adminbackend/web/demoplace.my.id/public_html -rm -f backend/netify_data.db backend/netify_data.db-wal backend/netify_data.db-shm -cp /home/adminbackend/deploy_backup/netify_data.db backend/netify_data.db -# (Also copy WAL if it existed in backup, but usually just .db is enough if WAL was checkpointed, -# or copy all of them just in case) -cp /home/adminbackend/deploy_backup/netify_data.db-wal backend/netify_data.db-wal 2>/dev/null || true -cp /home/adminbackend/deploy_backup/netify_data.db-shm backend/netify_data.db-shm 2>/dev/null || true - -echo "=== CHECKING RESTORED DB ===" -sqlite3 backend/netify_data.db "PRAGMA integrity_check;" - -echo "=== STARTING PM2 ===" -# Restarting pm2 daemon and processes -PORT=10000 npx pm2 start /home/adminbackend/node20/bin/npm --name "dpi-web" --interpreter /home/adminbackend/node20/bin/node -- start -PORT=3001 npx pm2 start backend/server.js --name "dpi-api" --interpreter /home/adminbackend/node20/bin/node -npx pm2 save -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_ssh.js b/temp_ssh.js deleted file mode 100644 index 4b2294c..0000000 --- a/temp_ssh.js +++ /dev/null @@ -1,11 +0,0 @@ -const { Client } = require('ssh2'); -const conn = new Client(); -conn.on('ready', () => { - conn.exec('ls -la /home/adminbackend/web/backend.demoplace.my.id/public_html/backend/netify_data.db /home/adminbackend/web/demoplace.my.id/public_html/backend/netify_data.db /home/adminbackend/web/backend.demoplace.my.id/public_html/.env.local /home/adminbackend/web/demoplace.my.id/public_html/.env.local 2>/dev/null', (err, stream) => { - let out = ''; - stream.on('close', () => { - console.log(out); - conn.end(); - }).on('data', d => out += d).stderr.on('data', d => console.error('ERR: ' + d)); - }); -}).connect({ host: '103.185.47.52', port: 2222, username: 'adminbackend', password: 'htEo7x6LsBQiEHHH' }); diff --git a/temp_symlink.js b/temp_symlink.js deleted file mode 100644 index 9890545..0000000 --- a/temp_symlink.js +++ /dev/null @@ -1,28 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -set -e -cd /home/adminbackend/web/demoplace.my.id/public_html -ln -sfn .next _next -echo "Symlink created" -ls -la _next -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_test.js b/temp_test.js deleted file mode 100644 index 173b9b5..0000000 --- a/temp_test.js +++ /dev/null @@ -1,24 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -curl -s -X POST http://localhost:10000/api/auth/admin/update-agent-user -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_test_api.js b/temp_test_api.js deleted file mode 100644 index 641e375..0000000 --- a/temp_test_api.js +++ /dev/null @@ -1,24 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -curl -s -i -X POST -H "Content-Type: application/json" -d '{"username":"admin","password":"password"}' https://demoplace.my.id/api/auth/login -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_test_next.js b/temp_test_next.js deleted file mode 100644 index 947e614..0000000 --- a/temp_test_next.js +++ /dev/null @@ -1,27 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -curl -s -o /dev/null -w "%{http_code}" http://localhost:10000/_next/static/chunks/0rnuuzend4b1r.css -echo "" -curl -s -o /dev/null -w "%{http_code}" http://localhost:10000/ -echo "" -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_test_next_post.js b/temp_test_next_post.js deleted file mode 100644 index 68847ec..0000000 --- a/temp_test_next_post.js +++ /dev/null @@ -1,24 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -curl -s -i -X POST -H "Content-Type: application/json" -d '{"username":"admin","password":"password"}' http://localhost:10000/api/auth/login -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/temp_test_origin.js b/temp_test_origin.js deleted file mode 100644 index 455556a..0000000 --- a/temp_test_origin.js +++ /dev/null @@ -1,24 +0,0 @@ -const { Client } = require('ssh2'); - -const script = ` -curl -s -X POST -H "Origin: https://demoplace.my.id" http://localhost:10000/api/auth/admin/update-agent-user -`; - -const conn = new Client(); -conn.on('ready', () => { - conn.exec(script, (err, stream) => { - if (err) throw err; - stream.on('close', (code) => { - conn.end(); - }).on('data', (data) => { - process.stdout.write(data); - }).stderr.on('data', (data) => { - process.stderr.write(data); - }); - }); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/test_api.js b/test_api.js deleted file mode 100644 index 6f8fd33..0000000 --- a/test_api.js +++ /dev/null @@ -1,25 +0,0 @@ -const { Client } = require('ssh2'); - -const conn = new Client(); - -conn.on('ready', () => { - conn.exec('curl -s http://127.0.0.1:3001/api/dashboard | cut -c 1-200', (err, stream) => { - let data = ''; - if (err) throw err; - stream.on('close', (code, signal) => { - console.log(data); - conn.end(); - }).on('data', (d) => { - data += d; - }).stderr.on('data', (d) => { - process.stderr.write(d); - }); - }); -}).on('error', (err) => { - console.error('SSH Error:', err); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -}); diff --git a/test_fetch.js b/test_fetch.js deleted file mode 100644 index 29c13cd..0000000 --- a/test_fetch.js +++ /dev/null @@ -1,15 +0,0 @@ -const mongoose = require('mongoose'); -const { DeviceStat } = require('./backend/models/Schemas'); -const fs = require('fs'); - -async function run() { - try { - // Note: since server is running, mongodb-memory-server port is dynamic. - // Let's read the mongoose connection URI from the .env or backend memory... - // But we can't easily connect to the dynamic port from outside. - // Instead, let's create a route or bypass auth in dashboard.js temporarily? - // Actually, dashboard.js doesn't seem to have auth middleware on /device-details if we pass a secret or it might not have auth at all? Wait, earlier Invoke-RestMethod said Unauthorized. - } catch (err) { - console.error(err); - } -} diff --git a/test_flows.js b/test_flows.js deleted file mode 100644 index 74da839..0000000 --- a/test_flows.js +++ /dev/null @@ -1,20 +0,0 @@ -const mongoose = require('mongoose'); -const { Flow, Threat } = require('./backend/models/Schemas'); -const timeRange = new Date(Date.now() - 3600*1000); // last 1 hour - -mongoose.connect('mongodb://127.0.0.1:27017/backone_dpi').then(async () => { - try { - const flowCount = await Flow.countDocuments(); - console.log("Total flows in DB:", flowCount); - const threatCount = await Threat.countDocuments(); - console.log("Total threats in DB:", threatCount); - } catch(e) { - console.error(e); - } finally { - process.exit(0); - } -}).catch(e => { - // If running in in-memory mode, we won't be able to connect via port 27017 easily - console.error("Could not connect to mongodb, probably using in-memory DB port."); - process.exit(1); -}); diff --git a/test_ip.js b/test_ip.js deleted file mode 100644 index 6c050a8..0000000 --- a/test_ip.js +++ /dev/null @@ -1,21 +0,0 @@ -const mongoose = require('mongoose'); -const { DeviceStat, Flow } = require('./backend/models/Schemas'); - -mongoose.connect('mongodb://127.0.0.1:27017/backone_dpi').then(async () => { - try { - const ip = "10.6.30.8"; - const device = await DeviceStat.findOne({ ip_address: ip }).sort({ timestamp: -1 }); - console.log("DeviceStat for IP:", device); - - const flowsCount = await Flow.countDocuments({ $or: [{src_ip: ip}, {dst_ip: ip}] }); - console.log("Total flows for IP:", flowsCount); - - const recentFlow = await Flow.findOne({ $or: [{src_ip: ip}, {dst_ip: ip}] }).sort({ timestamp: -1 }); - console.log("Most recent flow:", recentFlow); - - } catch(e) { - console.error(e); - } finally { - process.exit(0); - } -}); diff --git a/verify_backend.js b/verify_backend.js deleted file mode 100644 index c9a426e..0000000 --- a/verify_backend.js +++ /dev/null @@ -1,81 +0,0 @@ -const { Client } = require('ssh2'); - -const conn = new Client(); - -const script = ` -node -e " -const http = require('http'); - -const loginOptions = { - hostname: '127.0.0.1', - port: 3001, - path: '/api/login', - method: 'POST', - headers: { 'Content-Type': 'application/json' } -}; - -const req = http.request(loginOptions, res => { - let data = ''; - res.on('data', d => data += d); - res.on('end', () => { - const session = JSON.parse(data).session_id; - if (!session) { console.log('Login failed'); return; } - - // Test Agent - http.get({ - hostname: '127.0.0.1', - port: 3001, - path: '/api/agents/2F-TF-1D-GK', - headers: { 'Authorization': 'Bearer ' + session } - }, r => { - let d = ''; - r.on('data', c => d += c); - r.on('end', () => { - const agent = JSON.parse(d); - console.log('--- AGENT 2F-TF-1D-GK ---'); - console.log('Devices:', agent.summary.total_devices); - console.log('Flows:', agent.summary.active_flows); - console.log('Download:', agent.summary.bandwidth_down); - console.log('Upload:', agent.summary.bandwidth_up); - console.log('Top Apps count:', agent.top_apps.length); - }); - }); - - // Test Dashboard - http.get({ - hostname: '127.0.0.1', - port: 3001, - path: '/api/dashboard', - headers: { 'Authorization': 'Bearer ' + session } - }, r => { - let d = ''; - r.on('data', c => d += c); - r.on('end', () => { - const dash = JSON.parse(d); - console.log('--- DASHBOARD ---'); - console.log('Total Download:', dash.summary.bandwidth_down); - console.log('Total Upload:', dash.summary.bandwidth_up); - console.log('Devices:', dash.summary.total_devices); - console.log('Flows:', dash.summary.active_flows); - }); - }); - }); -}); -req.write(JSON.stringify({ username: 'admin', password: '123' })); // Wait, default admin is admin / admin -req.end(); -" -`; - -conn.on('ready', () => { - conn.exec(script.replace(/123/g, 'admin'), (err, stream) => { - if (err) throw err; - stream.on('close', () => conn.end()).on('data', d => process.stdout.write(d)).stderr.on('data', d => process.stderr.write(d)); - }); -}).on('error', (err) => { - console.error('SSH Error:', err); -}).connect({ - host: '103.185.47.52', - port: 2222, - username: 'adminbackend', - password: 'htEo7x6LsBQiEHHH' -});