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

Function trigger_subnet_scan

webapp_modern.py:5162–5244  ·  view source on GitHub ↗

Trigger an immediate nmap scan of a specific subnet in the background. Body: {"cidr": "10.0.0.0/24"} Returns immediately — results appear in the subnet scan log.

()

Source from the content-addressed store, hash-verified

5160 return jsonify({'success': False, 'error': 'scan not found'}), 404
5161 return jsonify({'success': True, 'scan': scan})
5162
5163
5164@app.route('/api/mesh/scan/findings/<scan_id>', methods=['GET'])
5165def mesh_scan_findings(scan_id):
5166 """Findings for a delegated scan, pulled home on completion."""
5167 scanner = get_advanced_vuln_scanner()
5168 if not scanner:
5169 return jsonify({'success': False, 'error': 'Scanner not available'}), 503
5170 try:
5171 with scanner._lock:
5172 findings = [f.to_dict() for f in scanner.scan_results.get(scan_id, [])]
5173 except Exception as e:
5174 return jsonify({'success': False, 'error': str(e)}), 500
5175 return jsonify({'success': True, 'findings': findings})
5176
5177
5178@app.route('/api/mesh/scan/cancel/<scan_id>', methods=['POST'])
5179def mesh_scan_cancel_remote(scan_id):
5180 """Cancel a delegated scan running on this unit. Peer-write allowlisted."""
5181 scanner = get_advanced_vuln_scanner()
5182 if not scanner:
5183 return jsonify({'success': False, 'error': 'Scanner not available'}), 503
5184 return jsonify({'success': bool(scanner.cancel_scan(scan_id))})
5185
5186
5187def _mesh_poll_once():
5188 """Refresh cached peer health. Safe to call when Tailscale is absent."""
5189 global _mesh_last_poll
5190 if not _mesh_enabled():
5191 return
5192 state = mesh_manager.status()
5193 if not state.get('available'):
5194 return
5195 try:
5196 timeout = max(1, int(shared_data.config.get('mesh_poll_timeout', 6)))
5197 except (TypeError, ValueError):
5198 timeout = 6
5199 # Only tagged peers are Ragnars. Polling every tailnet device would mean
5200 # hammering the operator's laptop and phone with HTTP requests.
5201 tag = _mesh_tag()
5202 peers = [p for p in state.get('peers', []) if tag in p.get('tags', [])]
5203 # Poll every tagged unit, even ones Tailscale currently marks offline: its
5204 # Online flag lags real reachability, and skipping "offline" peers is what
5205 # silently stopped data sharing once units went idle. The poll doubles as
5206 # the keepalive that flips them back online.
5207 try:
5208 results = mesh_manager.poll_mesh(peers, port=_mesh_node_port(),
5209 timeout=timeout, include_offline=True)
5210 except TypeError:
5211 # Defends against a partial update: a stale mesh_manager whose poll_mesh
5212 # predates the include_offline argument would otherwise raise here and
5213 # kill ALL polling silently (every peer stuck on "Not polled") while the
5214 # rest of Ragnar looks current. Fall back to the old signature so peers
5215 # are still polled, and say loudly that the box needs a clean update.
5216 logger.warning("[mesh] poll_mesh() rejected include_offline — stale "
5217 "mesh_manager.py (partial update). Polling online peers "
5218 "only; run a clean 'git pull' + restart on this unit.")
5219 results = mesh_manager.poll_mesh(peers, port=_mesh_node_port(), timeout=timeout)

Callers

nothing calls this directly

Calls 3

errorMethod · 0.80
getMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected