chore: super deep cleaning of temp scripts and mock data
This commit is contained in:
1 parent
764c87c3c8
commit
d559f00b8a
29 files changed
+6
-1224
No files matched your search
+6
-344
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user