NETRAVE/lib/utils/networking_genie.rb
VetheonGames f8ea01ed1b Implement Initial System Setup and Packet Capture
1. Initial System Setup:
   - Implemented a first run initialization process that guides the user through setting up the necessary environment variables.
   - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process.
   - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process.

2. Packet Capture:
   - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface.
   - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly.
   - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers.

3. Networking Setup:
   - Created a NetworkingGenie class to handle the setup of the necessary networking components.
   - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface.

4. Logging:
   - Implemented logging for all major actions and errors throughout the system.

5. General Refactoring and Code Cleanup:
   - Refactored and cleaned up various parts of the code to improve readability and maintainability.
   - Fixed various minor bugs and issues.

This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00

38 lines
1.2 KiB
Ruby

# frozen_string_literal: true
require 'socket'
require_relative 'logg_man'
# The class for setting up all the necessary system networking stuff for NETRAVE to work with without
# interferring with the rest of the system
class NetworkingGenie
def initialize(logger)
@loggman = logger
end
def find_main_interface # rubocop:disable Metrics/MethodLength
@loggman.log_info('Identifying main network interface...')
route_info = `routel`.split("\n")
default_route = route_info.find { |line| line.include?('default') }
if default_route
main_interface = default_route.split.last
@loggman.log_info("Main network interface identified: #{main_interface}")
main_interface
else
@loggman.log_error('Failed to identify main network interface.')
nil
end
rescue StandardError => e
@loggman.log_error("Error occurred while identifying main network interface: #{e.message}")
nil
end
def create_dummy_interface
# TODO: Implement method to create a dummy network interface
end
def setup_traffic_mirroring
# TODO: Implement method to set up traffic mirroring from the main interface to the dummy interface
end
end