Get recent log entries with enhanced activity information focused on security scanning
()
| 14635 | }) |
| 14636 | except Exception as e: |
| 14637 | logger.error(f"Error getting Wi-Fi networks: {e}") |
| 14638 | return jsonify({ |
| 14639 | 'success': False, |
| 14640 | 'error': str(e), |
| 14641 | 'manual_entry_available': True, |
| 14642 | 'networks': [], |
| 14643 | 'available': [], |
| 14644 | 'known': [] |
| 14645 | }), 500 |
| 14646 | |
| 14647 | @app.route('/api/wifi/connect', methods=['POST']) |
| 14648 | def connect_wifi(): |
| 14649 | """Connect to a Wi-Fi network""" |
| 14650 | try: |
| 14651 | data = request.get_json() |
| 14652 | if not data or 'ssid' not in data: |
| 14653 | return jsonify({'success': False, 'error': 'SSID is required'}), 400 |
| 14654 | |
| 14655 | ssid = data['ssid'] |
| 14656 | password = data.get('password') |
| 14657 | priority = data.get('priority', 1) |
| 14658 | save_network = data.get('save', True) |
| 14659 | |
| 14660 | wifi_manager = getattr(shared_data, 'ragnar_instance', None) |
| 14661 | if not wifi_manager or not hasattr(wifi_manager, 'wifi_manager'): |
| 14662 | return jsonify({'success': False, 'error': 'Wi-Fi manager not available'}), 503 |
| 14663 | |
| 14664 | # Log the connection attempt |
| 14665 | logger.info(f"API: Attempting to connect to WiFi network: {ssid}") |
| 14666 | |
| 14667 | # Check if currently in AP mode |
| 14668 | was_in_ap_mode = wifi_manager.wifi_manager.ap_mode_active |
| 14669 | if was_in_ap_mode: |
| 14670 | logger.info(f"API: Currently in AP mode, will stop AP before connecting to {ssid}") |
| 14671 | |
| 14672 | # Try to connect |
| 14673 | success = wifi_manager.wifi_manager.connect_to_network(ssid, password) |
| 14674 | |
| 14675 | if success: |
| 14676 | logger.info(f"API: Successfully connected to {ssid}") |
| 14677 | # Add to known networks if connection successful and save requested |
| 14678 | if save_network: |
| 14679 | wifi_manager.wifi_manager.add_known_network(ssid, password, priority) |
| 14680 | |
| 14681 | message = 'Connected successfully' |
| 14682 | if is_ap_client_request(): |
| 14683 | message = 'Connected successfully! Ragnar will now use this network. You can disconnect from this AP.' |
| 14684 | else: |
| 14685 | logger.error(f"API: Failed to connect to {ssid}") |
| 14686 | message = 'Connection failed. Please check the password and try again.' |
| 14687 | if was_in_ap_mode: |
| 14688 | message += ' Note: AP mode was stopped to attempt connection.' |
| 14689 | |
| 14690 | return jsonify({ |
| 14691 | 'success': success, |
| 14692 | 'message': message |
| 14693 | }) |
| 14694 |
no test coverage detected