def get_selected_previous_result(test_type="mtr"):
    if test_type == "mtr":
        if len(previous_mtr_results_file_locations) > 0:
            return get_file_content(previous_mtr_results_file_locations[
                previous_mtr_result_selected - 1])
    elif test_type == "iperf":
        if len(previous_iperf_results_file_locations) > 0:
            return get_file_content(previous_iperf_results_file_locations[
                previous_iperf_result_selected - 1])
    return "No Previous Results Found"
Пример #2
0
    def load_config_from_file(self):
        """ Loads Primary configuration from local disk and set's accordingly. """
        if os.path.isfile(file_locations.config_file_location):
            print("Loading Primary Configuration from: " +
                  file_locations.config_file_location)
            try:
                config_file_lines = get_file_content(
                    file_locations.config_file_location).split("\n")
                config_list = []
                for line in config_file_lines:
                    config_list.append(line.split("=")[0].strip())

                try:
                    self.is_iperf_server = int(config_list[1])
                    self.remote_tester_ip = config_list[2]
                    self.iperf_port = config_list[3]
                    self.mtr_run_count = config_list[4]
                except Exception as error:
                    print(
                        "Error loading config settings.  Writing new Configuration: "
                        + str(error))
                    self.write_config_to_file()
            except Exception as error:
                print("Unable to load Configuration File: " + str(error))
        else:
            print("No Configuration file found, saving default")
            self.write_config_to_file()
Пример #3
0
    def load_installed_hardware_from_file(self):
        """ Loads Installed Hardware configuration from local disk. """
        if os.path.isfile(file_locations.installed_hardware_file_location):
            log_msg = "Loading Installed Hardware Configuration from: "
            print(log_msg + file_locations.installed_hardware_file_location)
            try:
                config_file_lines = get_file_content(
                    file_locations.installed_hardware_file_location).split(
                        "\n")
                config_list = []
                for line in config_file_lines:
                    config_list.append(line.split("=")[0].strip())

                try:
                    self.installed_interactive_hw["WaveShare27"] = int(
                        config_list[1])
                except Exception as error:
                    print("Error loading Installed Hardware config: " +
                          str(error))
                    self.write_installed_hardware_to_file()
            except Exception as error:
                print(
                    "Unable to load Installed Hardware configuration File: " +
                    str(error))
        else:
            print(
                "No Installed Hardware Configuration file found, saving default"
            )
            self.write_installed_hardware_to_file()
def download_test_results_zip():
    try:
        if len(app_variables.previous_mtr_results_file_locations) > 0:
            date_time = datetime.date.today().strftime("D%dM%mY%Y")
            return_zip_file = BytesIO()
            zip_name = "TestResults_" + gethostname() + "_" + date_time + ".zip"
            file_meta_data_list = []
            names_of_files = []
            file_to_zip = []
            file_creation_dates = []
            previous_mtr_results_file_locations = app_variables.previous_mtr_results_file_locations
            previous_iperf_results_file_locations = app_variables.previous_iperf_results_file_locations
            for file_location in (previous_mtr_results_file_locations + previous_iperf_results_file_locations):
                file_to_zip.append(app_generic_functions.get_file_content(file_location))
                names_of_files.append(file_location.split("/")[-1])
                file_creation_dates.append(time.localtime(os.path.getmtime(file_location)))

            for name, modification_date in zip(names_of_files, file_creation_dates):
                name_data = ZipInfo(name)
                name_data.date_time = modification_date
                name_data.compress_type = ZIP_DEFLATED
                file_meta_data_list.append(name_data)
            with ZipFile(return_zip_file, "w") as zip_file:
                for file_meta_data, file_content in zip(file_meta_data_list, file_to_zip):
                    zip_file.writestr(file_meta_data, file_content)
            return_zip_file.seek(0)
            return send_file(return_zip_file, as_attachment=True, attachment_filename=zip_name)
    except Exception as error:
        primary_logger.error("Error zipping test results: " + str(error))
    return render_template("message_return.html", URL="/", TextMessage="No Results Found")
Пример #5
0
 def load_wpa_supplicant_wifi(self):
     try:
         app_variables.wpa_supplicant_file_content = get_file_content(
             file_locations.wpa_supplicant_file)
         self.wifi_country_code = network_wifi.get_wifi_country_code()
         self.wifi_ssid = network_wifi.get_wifi_ssid()
         self.wifi_security_type = network_wifi.get_wifi_security_type()
         self.wifi_pass_key = network_wifi.get_wifi_psk()
     except Exception as error:
         print(
             "Unable to get Wireless information from wpa_supplicant.conf: "
             + str(error))
Пример #6
0
    def load_config_from_file(self):
        """ Loads Primary configuration from local disk and set's accordingly. """
        primary_logger.debug("Loading Primary Configuration from: " +
                             file_locations.config_file_location)
        if os.path.isfile(file_locations.config_file_location):
            try:
                config_file_lines = get_file_content(
                    file_locations.config_file_location).split("\n")
                config_list = []
                for line in config_file_lines:
                    config_list.append(line.split("=")[0].strip())

                self.is_iperf_server = int(config_list[1])
                self.remote_tester_ip = config_list[2]
                self.iperf_port = config_list[3]
                self.mtr_run_count = config_list[4]
                if len(config_list) > 4:
                    if config_list[5].strip() == "0":
                        self.schedule_run_every_minutes = 0
                    else:
                        self.schedule_run_every_minutes = int(config_list[5])
                    if len(config_list) > 5:
                        if config_list[6].strip() == "0":
                            self.schedule_run_on_boot = 0
                        else:
                            self.schedule_run_on_boot = int(config_list[6])
                            if self.schedule_run_every_minutes < 5:
                                self.schedule_run_every_minutes = 5
                        if len(config_list) > 6:
                            if config_list[7].strip() == "0":
                                self.schedule_run_every_minutes_enabled = 0
                            else:
                                self.schedule_run_every_minutes_enabled = int(
                                    config_list[7])
                            if len(config_list) > 7:
                                if config_list[8].strip() == "0":
                                    self.schedule_run_once_enabled = 0
                                else:
                                    self.schedule_run_once_enabled = int(
                                        config_list[8])
                                self.schedule_run_once_at_time = config_list[9]

            except Exception as error:
                primary_logger.error(
                    "Unable to load Configuration File, saving default: " +
                    str(error))
                self.write_config_to_file()
        else:
            primary_logger.warning(
                "No Configuration file found, saving default")
            self.write_config_to_file()
Пример #7
0
    def load_dhcpcd_conf_from_file(self):
        try:
            app_variables.dhcpcd_config_file_content = get_file_content(
                file_locations.dhcpcd_config_file)
            self.local_ethernet_dhcp = network_ip.check_for_dhcp()
            self.local_ethernet_ip = network_ip.get_dhcpcd_ip()
            self.local_ethernet_subnet = network_ip.get_subnet()
            self.local_ethernet_gateway = network_ip.get_gateway()
            self.local_ethernet_dns1 = network_ip.get_dns(dns_server=0)
            self.local_ethernet_dns2 = network_ip.get_dns(dns_server=1)

            self.local_wireless_dhcp = network_ip.check_for_dhcp(wireless=True)
            self.local_wireless_ip = network_ip.get_dhcpcd_ip(wireless=True)
            self.local_wireless_subnet = network_ip.get_subnet(wireless=True)
            self.local_wireless_gateway = network_ip.get_gateway(wireless=True)
            self.local_wireless_dns1 = network_ip.get_dns(dns_server=0,
                                                          wireless=True)
            self.local_wireless_dns2 = network_ip.get_dns(dns_server=1,
                                                          wireless=True)
        except Exception as error:
            print("Unable to get IP information from dhcpcd.conf: " +
                  str(error))
previous_mtr_results_total = len(previous_mtr_results_file_locations)
# Previous iPerf Results variables
previous_iperf_result_selected = 1
previous_iperf_results_file_locations = get_previous_results_file_names(
    test_type="iperf")
previous_iperf_result_selected_cached = get_selected_previous_result(
    test_type="iperf")
previous_iperf_results_total = len(previous_iperf_results_file_locations)

# Monitored Thread placeholders. Replaced with class instances that have function and variables access
http_server = None
interactive_hw_server = None
iperf3_server = None
repeating_tests_server = None
run_once_test_server = None

# Used to restart run once test server (when settings are changed)
restart_run_once_test_server = 0

# Cached variables from disk
dhcpcd_config_file_content = ""
dhcpcd_config_file_content_template = get_file_content(
    file_locations.dhcpcd_config_file_template)
wpa_supplicant_file_content = ""
wpa_supplicant_file_content_template = get_file_content(
    file_locations.wpa_supplicant_file_template)

# Last state of Test checkboxes on the main HTML page
html_mtr_checked = "checked"
html_iperf_checked = "checked"