NETRAVE/lib/utils/system_information_gather.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

100 lines
3.2 KiB
Ruby

# frozen_string_literal: true
require 'curses'
require 'yaml'
require_relative 'utilities'
require_relative 'database_manager'
require 'dynamic_curses_input'
# gather system info
class SystemInformationGather
include Utilities
def initialize(db_manager, logger)
@db_manager = db_manager
@loggman = logger
end
def gather_system_info # rubocop:disable Metrics/MethodLength
uplink_speed = ask_for_uplink_speed
downlink_speed = ask_for_downlink_speed
services = ask_for_services
total_bandwidth = uplink_speed + downlink_speed
system_info = {
uplink_speed:,
downlink_speed:,
total_bandwidth:
}
@db_manager.create_system_info_table unless @db_manager.table_exists?(:system_info)
@db_manager.store_system_info(system_info)
@db_manager.create_services_table unless @db_manager.table_exists?(:services)
@db_manager.store_services(services)
end
def ask_for_uplink_speed # rubocop:disable Metrics/MethodLength
loop do
Curses.clear
Curses.addstr("Please enter your uplink speed (upload speed, e.g., 150Mbps or 1Gbps).\n" \
"This is typically the maximum upload speed provided by your ISP.\n" \
"You can check your ISP bill, use an online speed test, or contact your ISP if you're unsure.\n\n")
Curses.refresh
Curses.addstr('Uplink Speed: ')
speed = DCI.catch_input(true)
return convert_speed_to_mbps(speed) if valid_speed?(speed)
Curses.setpos(5, 0)
Curses.addstr("Whoops! That didn't appear to be a valid speed. Please try again!")
Curses.refresh
end
end
def ask_for_downlink_speed # rubocop:disable Metrics/MethodLength
loop do
Curses.clear
Curses.addstr("Please enter your downlink speed (download speed, e.g., 1000Mbps or 1Gbps).\n" \
"This is typically the maximum download speed provided by your ISP.\n"\
"You can check your ISP bill, use an online speed test, or contact your ISP if you're unsure.\n\n")
Curses.refresh
Curses.addstr('Downlink Speed: ')
speed = DCI.catch_input(true)
return convert_speed_to_mbps(speed) if valid_speed?(speed)
Curses.setpos(5, 0)
Curses.addstr("Whoops! That didn't appear to be a valid speed. Please try again!")
Curses.refresh
end
end
def valid_speed?(speed)
speed.to_i.positive? && speed.match?(/\A\d+(gbps|mbps)\z/i)
end
def ask_for_services # rubocop:disable Metrics/MethodLength
loop do
Curses.clear
Curses.addstr("Please enter the services the system should be aware of (e.g., webserver or database).\n" \
"Enter the services as a comma-separated list (e.g., webserver,database).\n\n")
Curses.refresh
Curses.addstr('Services: ')
services = DCI.catch_input(true)
services_arr = services.strip.downcase.split(',').map(&:strip)
return services_arr if valid_services?(services_arr)
Curses.setpos(7, 0)
Curses.addstr("Whoops! Thatdidn't appear to be a valid list of services. Please try again!")
Curses.refresh
end
end
def valid_services?(services)
# TODO: Validate the services
# For now, just check if the array is not empty
!services.empty?
end
end