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

Function get_threat_intelligence_status

webapp_modern.py:13407–13485  ·  view source on GitHub ↗

Get threat intelligence system status

()

Source from the content-addressed store, hash-verified

13405 'error': '',
13406 'warnings': []
13407 }
13408
13409 # Remove stale lock files via sudo (the dir is not owned by ragnar).
13410 git_dir = os.path.join(repo_path, '.git')
13411 for lock_name in ('index.lock', 'shallow.lock', 'HEAD.lock',
13412 os.path.join('refs', 'heads', 'noai.lock'),
13413 os.path.join('refs', 'heads', 'main.lock')):
13414 lock_path = os.path.join(git_dir, lock_name)
13415 try:
13416 if os.path.isfile(lock_path):
13417 subprocess.run(
13418 ['sudo', '-n', 'rm', '-f', lock_path],
13419 capture_output=True, text=True, check=False
13420 )
13421 except Exception as e:
13422 logger.debug(f"Could not remove {lock_name}: {e}")
13423
13424 # Ensure safe.directory is configured (avoids ownership errors when
13425 # /opt/pwnagotchi is owned by root but git runs via sudo).
13426 try:
13427 subprocess.run(
13428 ['sudo', '-n', 'git', 'config', '--global',
13429 'safe.directory', repo_path],
13430 capture_output=True, text=True, check=False
13431 )
13432 except Exception:
13433 pass
13434
13435 # Perform git pull with one automatic retry on failure.
13436 max_attempts = 2
13437 for attempt in range(1, max_attempts + 1):
13438 try:
13439 pull_proc = subprocess.run(
13440 ['sudo', '-n', 'git', '-C', repo_path, 'pull'],
13441 capture_output=True,
13442 text=True,
13443 check=True,
13444 timeout=PWN_GIT_TIMEOUT
13445 )
13446 result['output'] = pull_proc.stdout.strip()
13447 logger.info(f"Pwn git pull completed: {result['output']}")
13448 break # success
13449 except (subprocess.CalledProcessError, subprocess.TimeoutExpired) as e:
13450 if isinstance(e, subprocess.TimeoutExpired):
13451 error_msg = f"git pull timed out after {PWN_GIT_TIMEOUT}s"
13452 else:
13453 error_msg = e.stderr.strip() or e.stdout.strip() or str(e)
13454 logger.error(f"Pwn git pull attempt {attempt}/{max_attempts} failed: {error_msg}")
13455
13456 if attempt >= max_attempts:
13457 result['error'] = f"Git pull failed: {error_msg}"
13458 return result
13459
13460 # Auto-recover before retrying.
13461 recovered = False
13462 err_lower = error_msg.lower()
13463
13464 # Lock file appeared during pull

Callers

nothing calls this directly

Calls 10

addMethod · 0.80
appendMethod · 0.80
errorMethod · 0.80
setFunction · 0.50
getMethod · 0.45
itemsMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected