Main entry point: menu loop -> launch Ragnar -> repeat.
()
| 430 | |
| 431 | |
| 432 | def main(): |
| 433 | """Main entry point: menu loop -> launch Ragnar -> repeat.""" |
| 434 | menu = None |
| 435 | log_file = os.path.join(DATA_DIR, 'payload.log') |
| 436 | try: |
| 437 | while True: |
| 438 | interfaces = detect_interfaces() |
| 439 | time.sleep(0.3) |
| 440 | |
| 441 | try: |
| 442 | menu = RagnarMenu(interfaces) |
| 443 | except Exception as e: |
| 444 | time.sleep(1) |
| 445 | try: |
| 446 | menu = RagnarMenu(interfaces) |
| 447 | except Exception: |
| 448 | sys.stderr.write(f"Failed to init display: {e}\n") |
| 449 | break |
| 450 | |
| 451 | result = menu.show_main_menu() |
| 452 | |
| 453 | if result is None: |
| 454 | menu.cleanup() |
| 455 | menu = None |
| 456 | # Brief delay lets the hardware fully settle before |
| 457 | # pineapplepager service restarts and re-claims the display. |
| 458 | time.sleep(0.5) |
| 459 | break |
| 460 | |
| 461 | menu._show_message("Starting Ragnar...", TITLE_COLOR, result['interface'] + " " + result['ip'], DIM_COLOR) |
| 462 | menu.cleanup() |
| 463 | menu = None |
| 464 | |
| 465 | # Small delay to let the display hardware settle after cleanup |
| 466 | time.sleep(0.3) |
| 467 | |
| 468 | # Launch PagerRagnar as subprocess |
| 469 | env = os.environ.copy() |
| 470 | env['RAGNAR_INTERFACE'] = result['interface'] |
| 471 | env['RAGNAR_IP'] = result['ip'] |
| 472 | env['RAGNAR_WEB_UI'] = 'on' if result['web_ui'] else 'off' |
| 473 | |
| 474 | # Open log for capturing subprocess output |
| 475 | try: |
| 476 | os.makedirs(DATA_DIR, exist_ok=True) |
| 477 | with open(log_file, 'a') as lf: |
| 478 | lf.write(f"\n=== PagerRagnar.py starting at {time.strftime('%H:%M:%S')} ===\n") |
| 479 | proc = subprocess.run( |
| 480 | ['python3', 'PagerRagnar.py'], |
| 481 | cwd=PAYLOAD_DIR, |
| 482 | env=env, |
| 483 | stdout=lf, |
| 484 | stderr=lf, |
| 485 | ) |
| 486 | except Exception as e: |
| 487 | sys.stderr.write(f"Failed to launch PagerRagnar.py: {e}\n") |
| 488 | break |
| 489 |
no test coverage detected