Example #1
0
    def get_sys_info_message():
        date_now = strftime("%d/%m/%y")
        time_now = strftime("%H:%M")
        os_text = get_os_name_version()
        remote_ip = current_config.remote_tester_ip
        remote_port = app_variables.flask_http_port

        if current_config.running_on_rpi:
            lines = os_text.split(" ")
            os_text = lines[0] + " " + lines[2]

        eth_ip = network_ip.get_dhcpcd_ip()
        wifi_ip = network_ip.get_dhcpcd_ip(wireless=True)

        eth_dhcp = " - Static"
        wifi_dhcp = " - Static"
        if network_ip.check_for_dhcp():
            eth_dhcp = " - DHCP"
        if network_ip.check_for_dhcp(wireless=True):
            wifi_dhcp = " - DHCP"

        remote_version = str(get_remote_data("http://" + remote_ip + ":" + str(remote_port) + "/Version"))[2:-1]
        if 3 > len(remote_version) or len(remote_version) > 14:
            remote_version = "NA"
        text_msg = "Version: " + current_config.app_version + \
                   "\nOS: " + os_text + \
                   "\nDate: " + date_now + " (D/M/Y)" + \
                   "\nTime: " + time_now + \
                   "\n\nEthernet IP" + eth_dhcp + "\n" + eth_ip + \
                   "\nWireless IP" + wifi_dhcp + "\n" + wifi_ip + \
                   "\n\nRemote Server - " + check_tester_online_status(remote_ip, remote_port) + \
                   "\nIP " + current_config.remote_tester_ip + \
                   "\nVersion: " + remote_version
        return text_msg
    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))
def update_cached_variables():
    """ Updates app_cached_variables.py variables. """
    global first_run
    if first_run:
        first_run = False
        thread_function(_update_ks_info_table_data)
        demo_mode = app_config_access.primary_config.demo_mode
        if not app_cached_variables.running_with_root:
            click_msg = "Without root access, the following functions will be unavailable - "
            click_msg += "Hardware Sensors, Network Configurations, Upgrade & Power commands"
            icon = "fas fa-exclamation-triangle"
            notification_short_msg = "Warning: Not running with root<br>Click Here for more information"
            atpro_notifications.add_custom_message(notification_short_msg,
                                                   click_msg=click_msg,
                                                   icon=icon)
        if demo_mode:
            click_msg = "In Demo mode, there are no login prompts and the following functions will be unavailable - "
            click_msg += "Network Configurations, SSL, Change Login, Upgrade & Power commands"
            notification_short_msg = "Info: Running in Demo mode<br>Click Here for more information"
            atpro_notifications.add_custom_message(notification_short_msg,
                                                   click_msg=click_msg)
        if default_http_flask_user == app_cached_variables.http_flask_user and not demo_mode:
            if verify_password_to_hash(default_http_flask_password):
                atpro_notifications.manage_default_login_detected()

    if app_cached_variables.current_platform == "Linux":
        try:
            os_release_content_lines = get_file_content(
                "/etc/os-release").split("\n")
            os_release_name = ""
            for line in os_release_content_lines:
                name_and_value = line.split("=")
                if name_and_value[0].strip() == "PRETTY_NAME":
                    os_release_name = name_and_value[1].strip()[1:-1]
            app_cached_variables.operating_system_name = str(os_release_name)
        except Exception as error:
            logger.sensors_logger.error("Error caching OS Name: " + str(error))
            app_cached_variables.operating_system_name = "NA"

        if app_cached_variables.operating_system_name[:8] == "Raspbian":
            try:
                if app_cached_variables.running_with_root:
                    wifi_config_lines = get_file_content(
                        file_locations.wifi_config_file).split("\n")
                else:
                    wifi_config_lines = ""
                app_cached_variables.wifi_country_code = network_wifi.get_wifi_country_code(
                    wifi_config_lines)
                app_cached_variables.wifi_ssid = network_wifi.get_wifi_ssid(
                    wifi_config_lines)
                app_cached_variables.wifi_security_type = network_wifi.get_wifi_security_type(
                    wifi_config_lines)
                app_cached_variables.wifi_psk = network_wifi.get_wifi_psk(
                    wifi_config_lines)
            except Exception as error:
                logger.primary_logger.warning(
                    "Error checking WiFi configuration: " + str(error))

            try:
                dhcpcd_config_lines = get_file_content(
                    file_locations.dhcpcd_config_file).split("\n")
                if not network_ip.check_for_dhcp(dhcpcd_config_lines):
                    app_cached_variables.ip = network_ip.get_dhcpcd_ip(
                        dhcpcd_config_lines)
                    app_cached_variables.ip_subnet = network_ip.get_subnet(
                        dhcpcd_config_lines)
                    app_cached_variables.gateway = network_ip.get_gateway(
                        dhcpcd_config_lines)
                    app_cached_variables.dns1 = network_ip.get_dns(
                        dhcpcd_config_lines)
                    app_cached_variables.dns2 = network_ip.get_dns(
                        dhcpcd_config_lines, dns_server=1)
            except Exception as error:
                logger.primary_logger.warning("Error checking dhcpcd.conf: " +
                                              str(error))

    try:
        app_cached_variables.total_ram_memory = round(
            psutil.virtual_memory().total / 1024 / 1024 / 1024, 3)
    except Exception as error:
        logger.primary_logger.warning("Error caching total RAM: " + str(error))

    try:
        app_cached_variables.total_disk_space = round(
            psutil.disk_usage("/").total / 1024 / 1024 / 1024, 2)
    except Exception as error:
        logger.primary_logger.warning("Error caching total Disk Space: " +
                                      str(error))

    last_updated = ""
    if not os.path.isfile(file_locations.program_last_updated):
        logger.sensors_logger.debug(
            "Previous version file not found - Creating version file")
        write_file_to_disk(file_locations.program_last_updated,
                           "No Update Detected")
    last_updated_file = get_file_content(file_locations.program_last_updated)
    last_updated_lines = last_updated_file.split("\n")
    for line in last_updated_lines:
        last_updated += str(line)

    app_cached_variables.program_last_updated = last_updated.strip()
    app_cached_variables.zipped_db_backup_list = get_names_list_from_dir(
        file_locations.database_backup_folder)
    app_cached_variables.uploaded_databases_list = get_names_list_from_dir(
        file_locations.uploaded_databases_folder)
    _update_cached_sensor_reboot_count()
    _update_cached_note_variables()
    _update_cached_ip()
    _update_cached_hostname()