MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _threat_monitor_loop

Function _threat_monitor_loop

webapp_modern.py:11799–11845  ·  view source on GitHub ↗

Background loop: runs threat sweeps at configured interval.

()

Source from the content-addressed store, hash-verified

11797 name: {
11798 'label': p['label'],
11799 'timing': p['timing'],
11800 'min_rate': p['min_rate'],
11801 'top_ports': p['top_ports'],
11802 'skip_gateway': p['skip_gateway'],
11803 } for name, p in SCAN_PROFILES.items()
11804 },
11805 })
11806
11807 data = request.get_json() or {}
11808 raw = str(data.get('intensity', '')).strip().lower()
11809 if raw not in SCAN_PROFILES:
11810 return jsonify({
11811 'error': f"Invalid intensity '{raw}'. Must be one of: {', '.join(SCAN_PROFILES.keys())}"
11812 }), 400
11813
11814 shared_data.config['scan_intensity'] = raw
11815 shared_data.scan_intensity = raw
11816 shared_data.save_config()
11817 socketio.emit('config_updated', shared_data.config)
11818 return jsonify({'success': True, 'current': raw, 'label': SCAN_PROFILES[raw]['label']})
11819
11820 except Exception as e:
11821 logger.error(f"Error managing scan intensity: {e}")
11822 return jsonify({'error': str(e)}), 500
11823
11824
11825@app.route('/api/config/scan-subnets', methods=['GET', 'POST', 'DELETE'])
11826def manage_scan_subnets():
11827 """Manage the list of extra subnets to scan.
11828
11829 GET: Return current list + auto-detected primary subnet.
11830 POST: Add a new CIDR (body: {"cidr": "10.0.0.0/24"}).
11831 DELETE: Remove a CIDR (body: {"cidr": "10.0.0.0/24"}).
11832 """
11833 import ipaddress as _ip
11834 try:
11835 subnets = list(shared_data.config.get('scan_subnets', []))
11836
11837 # Detect primary subnet for reference
11838 primary = None
11839 try:
11840 import netifaces
11841 gws = netifaces.gateways()
11842 gw_tuple = gws.get('default', {}).get(netifaces.AF_INET)
11843 if gw_tuple:
11844 iface_addrs = netifaces.ifaddresses(gw_tuple[1]).get(netifaces.AF_INET)
11845 if iface_addrs:
11846 my_ip = iface_addrs[0]['addr']
11847 mask = iface_addrs[0]['netmask']
11848 cidr_bits = sum(bin(int(x)).count('1') for x in mask.split('.'))

Callers

nothing calls this directly

Calls 7

network_threat_sweepFunction · 0.85
rangeFunction · 0.85
appendMethod · 0.80
addMethod · 0.80
warningMethod · 0.80
getMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected