def html_atpro_send_reports_email():
    logger.network_logger.debug("** HTML Reports Email Sent - Source: " +
                                str(request.remote_addr))
    button_pressed = request.form.get("test_email_button")
    email_address = request.form.get("test_email_address")

    msg = "Check the Network logs for more information"
    if email_is_valid(email_address):
        if button_pressed == "reports":
            thread_function(send_report_emails, args=[email_address])
            return get_message_page("Reports email is being sent",
                                    msg,
                                    page_url="sensor-settings")
        elif button_pressed == "graphs":
            thread_function(send_db_graph_emails, args=[email_address])
            return get_message_page("Graph email is being sent",
                                    msg,
                                    page_url="sensor-settings")
        elif button_pressed == "settings":
            thread_function(send_test_email, args=email_address)
            return get_message_page("Test email is being sent",
                                    msg,
                                    page_url="sensor-settings")
    return get_message_page("Please Specify a valid email address to send to",
                            page_url="sensor-settings")
Beispiel #2
0
def run_system_command(command):
    logger.network_logger.debug("* Sensor Control '" + command +
                                "' initiated by " + str(request.remote_addr))
    if len(app_config_access.sensor_control_config.
           get_raw_ip_addresses_as_list()) < 1:
        return _get_missing_sensor_addresses_page()
    elif _missing_login_credentials():
        return _get_missing_login_credentials_page(full_reload=False)

    ip_list = app_config_access.sensor_control_config.get_clean_ip_addresses_as_list(
    )
    if len(ip_list) < 1:
        msg_1 = "Sensors Offline"
        msg_2 = "All sensors appear to be Offline"
        return get_message_page(msg_1,
                                msg_2,
                                page_url="sensor-rm",
                                full_reload=False)

    for ip in ip_list:
        thread = Thread(target=_system_command_thread, args=(ip, command))
        thread.daemon = True
        thread.start()
    msg_1 = command + " is now being sent to " + str(len(ip_list)) + " Sensors"
    return get_message_page("Sending Sensor Commands",
                            msg_1,
                            page_url="sensor-rm",
                            full_reload=False)
def html_atpro_sensor_settings_upgrades():
    bad_cred_msg = "The username must be alphanumeric and the password must not contain single quotes or ="
    if not validate_smb_username(request.form.get("smb_username")) \
            or not validate_smb_password(request.form.get("smb_password")) and request.form.get("smb_password") != "":
        logger.primary_logger.warning(
            "The provided SMB username or password has invalid characters")
        return get_message_page("Invalid SMB username or password",
                                message=bad_cred_msg,
                                page_url="sensor-settings")
    app_config_access.upgrades_config.update_with_html_request(request)
    app_config_access.upgrades_config.save_config_to_file()
    thread_function(update_checks_interface.update_versions_info_variables)
    app_cached_variables.restart_automatic_upgrades_thread = True
    return get_message_page("Upgrade Settings Updated",
                            page_url="sensor-settings")
def _vacuum_database(selected_database):
    if selected_database == "MainDatabase":
        db_location = file_locations.sensor_database
    elif selected_database == "MQTTSubscriberDatabase":
        db_location = file_locations.mqtt_subscriber_database
    elif selected_database == "CheckinDatabase":
        db_location = file_locations.sensor_checkin_database
    else:
        db_location = file_locations.uploaded_databases_folder + "/" + selected_database
    if os.path.isfile(db_location):
        write_to_sql_database("VACUUM;", None, sql_database_location=db_location)
        msg = selected_database + " Database has been Shrunk"
        return get_message_page("Database Vacuum Successful", msg, page_url="sensor-system", skip_menu_select=True)
    msg = selected_database + " Database not found"
    return get_message_page("Database Vacuum Failed", msg, page_url="sensor-system", skip_menu_select=True)
def html_atpro_sensor_settings_mqtt_subscriber():
    if request.method == "POST":
        app_config_access.mqtt_subscriber_config.update_with_html_request(request)
        app_config_access.mqtt_subscriber_config.save_config_to_file()
        atpro_notifications.manage_service_restart()
        return get_message_page("MQTT Subscriber Settings Updated", page_url="sensor-settings")

    mqtt_qos = app_config_access.mqtt_subscriber_config.mqtt_subscriber_qos
    enable_mqtt_subscriber = app_config_access.mqtt_subscriber_config.enable_mqtt_subscriber
    enable_mqtt_sql_recording = app_config_access.mqtt_subscriber_config.enable_mqtt_sql_recording
    enable_broker_auth = app_config_access.mqtt_subscriber_config.enable_broker_auth
    return render_template(
        "ATPro_admin/page_templates/settings/settings-mqtt-subscriber.html",
        MaxSensorPosts=app_config_access.mqtt_subscriber_config.mqtt_page_view_max_entries,
        MQTTSubscriberChecked=get_html_checkbox_state(enable_mqtt_subscriber),
        MQTTSQLRecordingChecked=get_html_checkbox_state(enable_mqtt_sql_recording),
        MQTTBrokerAddress=app_config_access.mqtt_subscriber_config.broker_address,
        MQTTBrokerPort=str(app_config_access.mqtt_subscriber_config.broker_server_port),
        MQTTQoSLevel0=get_html_selected_state(_check_if_equal(mqtt_qos, 0)),
        MQTTQoSLevel1=get_html_selected_state(_check_if_equal(mqtt_qos, 1)),
        MQTTQoSLevel2=get_html_selected_state(_check_if_equal(mqtt_qos, 2)),
        MQTTSubscriberAuthChecked=get_html_checkbox_state(enable_broker_auth),
        MQTTSubscriberUsername=app_config_access.mqtt_subscriber_config.broker_user,
        SubscriberTopics=_get_csv_matt_topics()
    )
def html_atpro_sensor_settings_checkin_server():
    if request.method == "POST":
        app_config_access.checkin_config.update_with_html_request(request)
        app_config_access.checkin_config.save_config_to_file()
        return get_message_page("Sensor Checkin Settings Updated",
                                page_url="sensor-settings")
    return _get_checkin_settings_page_render()
Beispiel #7
0
def html_atpro_sensor_settings_wu():
    weather_underground_config = app_config_access.weather_underground_config
    if request.method == "POST":
        app_config_access.weather_underground_config.update_with_html_request(request)
        app_config_access.weather_underground_config.save_config_to_file()
        return_msg = "Stopping Weather Underground"
        if app_config_access.weather_underground_config.weather_underground_enabled:
            return_msg = "Starting Weather Underground"
            if app_cached_variables.weather_underground_thread.current_state != "Disabled":
                if app_cached_variables.weather_underground_thread.monitored_thread.is_alive():
                    return_msg = "Re-Starting Weather Underground"
                    app_cached_variables.restart_weather_underground_thread = True
                else:
                    start_weather_underground_server()
            else:
                start_weather_underground_server()
        else:
            if app_cached_variables.weather_underground_thread is not None:
                app_cached_variables.weather_underground_thread.shutdown_thread = True
                app_cached_variables.restart_weather_underground_thread = True
        return get_message_page("Weather Underground Settings Updated", return_msg, page_url="sensor-settings")
    return render_template(
        "ATPro_admin/page_templates/settings/settings-3rd-p-wu.html",
        CheckedWUEnabled=get_html_checkbox_state(weather_underground_config.weather_underground_enabled),
        WUIntervalSeconds=weather_underground_config.interval_seconds,
        CheckedWUOutdoor=get_html_checkbox_state(weather_underground_config.outdoor_sensor),
        WUStationID=weather_underground_config.station_id,
    )
Beispiel #8
0
def _get_missing_sensor_addresses_page(full_reload=True):
    msg_1 = "No Sensors set Sensor Address List"
    msg_2 = "Press 'Show/Hide Sensor Address List' under Remote Sensor Management to view & set sensor addresses"
    return get_message_page(msg_1,
                            msg_2,
                            page_url="sensor-rm",
                            full_reload=full_reload)
Beispiel #9
0
def html_atpro_sensor_settings_luftdaten():
    if request.method == "POST":
        app_config_access.luftdaten_config.update_with_html_request(request)
        app_config_access.luftdaten_config.save_config_to_file()
        return_msg = "Stopping Luftdaten"
        if app_config_access.luftdaten_config.luftdaten_enabled:
            return_msg = "Starting Luftdaten"
            if app_cached_variables.luftdaten_thread.current_state != "Disabled":
                if app_cached_variables.luftdaten_thread.monitored_thread.is_alive():
                    return_msg = "Re-Starting Luftdaten"
                    app_cached_variables.restart_luftdaten_thread = True
                else:
                    start_luftdaten_server()
            else:
                start_luftdaten_server()
        else:
            if app_cached_variables.luftdaten_thread is not None:
                app_cached_variables.luftdaten_thread.shutdown_thread = True
                app_cached_variables.restart_luftdaten_thread = True
        return get_message_page("Luftdaten Settings Updated", return_msg, page_url="sensor-settings")
    return render_template(
        "ATPro_admin/page_templates/settings/settings-3rd-p-luftdaten.html",
        CheckedLuftdatenEnabled=get_html_checkbox_state(app_config_access.luftdaten_config.luftdaten_enabled),
        LuftdatenIntervalSeconds=app_config_access.luftdaten_config.interval_seconds,
        LuftdatenStationID=app_config_access.luftdaten_config.station_id
    )
Beispiel #10
0
def _get_missing_login_credentials_page(full_reload=True):
    msg_1 = "Missing Remote Sensor Management Credentials"
    msg_2 = "Login Credentials cannot be blank for this operation"
    return get_message_page(msg_1,
                            msg_2,
                            page_url="sensor-rm",
                            full_reload=full_reload)
def html_atpro_sensor_settings_database_management():
    if request.method == "POST":
        upload_db_folder = uploaded_databases_folder + "/"
        try:
            db_full_path = upload_db_folder + sanitize_text(request.form.get("db_selected"))
            if sanitize_text(request.form.get("db_backups")) == "download_backup_db":
                backup_db_folder = file_locations.database_backup_folder + "/"
                db_selected_name = sanitize_text(request.form.get("DatabaseBackupSelection"))
                db_full_path = backup_db_folder + db_selected_name
                if db_selected_name in app_cached_variables.zipped_db_backup_list:
                    return send_file(db_full_path, as_attachment=True, attachment_filename=db_selected_name)
            elif sanitize_text(request.form.get("db_management")) == "rename_db":
                old_name = db_full_path.split("/")[-1]
                new_name = get_clean_db_name(str(request.form.get("rename_db")))
                new_db_full_path = upload_db_folder + new_name
                os.rename(db_full_path, new_db_full_path)
                uploaded_db_filenames = get_list_of_filenames_in_dir(uploaded_databases_folder)
                app_cached_variables.uploaded_databases_list = uploaded_db_filenames
                msg = "Database renamed from " + old_name + " to " + new_name
                return get_message_page("Database Renamed", msg, page_url="sensor-system", skip_menu_select=True)
            elif sanitize_text(request.form.get("db_management")) == "shrink_db":
                selected_database = sanitize_text(request.form.get("SQLDatabaseSelection"))
                return _vacuum_database(selected_database)
            elif sanitize_text(request.form.get("db_management")) == "delete_db":
                os.remove(db_full_path)
                uploaded_db_filenames = get_list_of_filenames_in_dir(uploaded_databases_folder)
                app_cached_variables.uploaded_databases_list = uploaded_db_filenames
                msg = sanitize_text(request.form.get("db_selected")) + " Database has been deleted"
                return get_message_page("Database Deleted", msg, page_url="sensor-system", skip_menu_select=True)
            elif sanitize_text(request.form.get("db_management")) == "delete_backup_db":
                db_full_path = file_locations.database_backup_folder + "/" + str(request.form.get("db_selected"))
                os.remove(db_full_path)
                backup_db_zip_filenames = get_list_of_filenames_in_dir(file_locations.database_backup_folder)
                app_cached_variables.zipped_db_backup_list = backup_db_zip_filenames
                msg = str(request.form.get("db_selected")) + " Database backup has been deleted"
                return get_message_page("Database Backup Deleted", msg, page_url="sensor-system", skip_menu_select=True)
            return get_html_atpro_index(run_script="SelectNav('sensor-system');")
        except Exception as error:
            return_text2 = "HTML Database Management Error: " + str(error)
            logger.network_logger.error(return_text2)
            msg_name = "Database Management Error"
            return get_message_page(msg_name, str(error), page_url="sensor-system", skip_menu_select=True)
    return render_template(
        "ATPro_admin/page_templates/system/system-db-management.html",
        UploadedDBOptionNames=_get_drop_down_items(app_cached_variables.uploaded_databases_list),
        BackupDBOptionNames=_get_drop_down_items(app_cached_variables.zipped_db_backup_list)
    )
def services_restart():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info("** Service restart Initiated by " +
                                   str(request.remote_addr))
        system_access.restart_services()
        return get_message_page("Restarting Program",
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
def html_atpro_sensor_settings_checkin_adv():
    if request.method == "POST":
        app_config_access.checkin_config.update_with_html_request_advanced_checkin(
            request)
        app_config_access.checkin_config.save_config_to_file()
        app_cached_variables.restart_sensor_checkin_thread = True
        return get_message_page("Advanced Checkin Settings Updated",
                                page_url="sensor-settings")
    return _get_checkin_settings_page_render()
def html_atpro_sensor_settings_main():
    if request.method == "POST":
        app_config_access.primary_config.update_with_html_request(request)
        app_config_access.primary_config.save_config_to_file()
        if app_config_access.primary_config.web_portal_port_changed:
            atpro_notifications.manage_service_restart()
        return get_message_page("Main Settings Updated",
                                page_url="sensor-settings")

    debug_logging = get_html_checkbox_state(
        app_config_access.primary_config.enable_debug_logging)
    enable_major_upgrades = get_html_checkbox_state(
        app_config_access.upgrades_config.enable_automatic_upgrades_feature)
    enable_minor_upgrades = get_html_checkbox_state(
        app_config_access.upgrades_config.enable_automatic_upgrades_minor)
    enable_dev_up = get_html_checkbox_state(
        app_config_access.upgrades_config.
        enable_automatic_upgrades_developmental)
    upgrade_method_http = ""
    upgrade_method_smb = ""
    if app_config_access.upgrades_config.selected_upgrade_type == app_config_access.upgrades_config.upgrade_type_http:
        upgrade_method_http = "selected"
    else:
        upgrade_method_smb = "selected"
    return render_template(
        "ATPro_admin/page_templates/settings/settings-main.html",
        IPWebPort=app_config_access.primary_config.web_portal_port,
        CheckedDebug=debug_logging,
        HourOffset=app_config_access.primary_config.utc0_hour_offset,
        SelectedUpgradeType=app_config_access.upgrades_config.
        selected_upgrade_type.upper(),
        CheckinAddress=app_config_access.urls_config.url_checkin_server,
        UpdateServerAddress=app_config_access.urls_config.url_update_server,
        UpdateServerAddressSMB=app_config_access.urls_config.
        url_update_server_smb,
        EnableAutoUpgrades=get_html_checkbox_state(
            app_config_access.upgrades_config.enable_automatic_upgrades),
        AutoUpDelayHours=str(
            app_config_access.upgrades_config.automatic_upgrade_delay_hours),
        EnableMD5Validation=get_html_checkbox_state(
            app_config_access.upgrades_config.md5_validation_enabled),
        SMBUsername=app_config_access.upgrades_config.smb_user,
        HTTPSelected=upgrade_method_http,
        SMBSelected=upgrade_method_smb,
        EnableStableFeatureAutoUpgrades=enable_major_upgrades,
        EnableStableMinorAutoUpgrades=enable_minor_upgrades,
        EnableDevAutoUpgrades=enable_dev_up,
        USMD5=_get_file_present_color(
            update_checks_interface.update_server_file_present_md5),
        USVersion=_get_file_present_color(
            update_checks_interface.update_server_file_present_version),
        USFullInstaller=_get_file_present_color(
            update_checks_interface.update_server_file_present_full_installer),
        USUpgradeInstaller=_get_file_present_color(
            update_checks_interface.
            update_server_file_present_upgrade_installer))
def delete_sensors_older_then():
    delete_sensors_older_days = 365000  # 1000 years
    if request.form.get("delete_sensors_older_days") is not None:
        delete_sensors_older_days = float(
            request.form.get("delete_sensors_older_days"))
    thread_function(_thread_delete_sensors_older_then,
                    args=delete_sensors_older_days)
    return get_message_page("Old Sensor Clean-up Started",
                            "Check Logs for more info",
                            page_url="sensor-checkin-view")
def html_atpro_sensor_settings_display():
    if request.method == "POST":
        app_config_access.display_config.update_with_html_request(request)
        app_config_access.display_config.save_config_to_file()
        app_cached_variables.restart_mini_display_thread = True
        return get_message_page("Display Settings Updated",
                                page_url="sensor-settings")

    display_numerical_checked = ""
    display_graph_checked = ""
    display_type_numerical = app_config_access.display_config.display_type_numerical
    if app_config_access.display_config.display_type == display_type_numerical:
        display_numerical_checked = "checked"
    else:
        display_graph_checked = "checked"
    return render_template(
        "ATPro_admin/page_templates/settings/settings-display.html",
        CheckedEnableDisplay=get_html_checkbox_state(
            app_config_access.display_config.enable_display),
        DisplayIntervalDelay=app_config_access.display_config.
        minutes_between_display,
        DisplayNumericalChecked=display_numerical_checked,
        DisplayGraphChecked=display_graph_checked,
        CheckedSensorUptime=get_html_checkbox_state(
            app_config_access.display_config.sensor_uptime),
        CheckedCPUTemperature=get_html_checkbox_state(
            app_config_access.display_config.system_temperature),
        CheckedEnvTemperature=get_html_checkbox_state(
            app_config_access.display_config.env_temperature),
        CheckedPressure=get_html_checkbox_state(
            app_config_access.display_config.pressure),
        CheckedAltitude=get_html_checkbox_state(
            app_config_access.display_config.altitude),
        CheckedHumidity=get_html_checkbox_state(
            app_config_access.display_config.humidity),
        CheckedDewPoint=get_html_checkbox_state(
            app_config_access.display_config.dew_point),
        CheckedDistance=get_html_checkbox_state(
            app_config_access.display_config.distance),
        CheckedGas=get_html_checkbox_state(
            app_config_access.display_config.gas),
        CheckedPM=get_html_checkbox_state(
            app_config_access.display_config.particulate_matter),
        CheckedLumen=get_html_checkbox_state(
            app_config_access.display_config.lumen),
        CheckedColour=get_html_checkbox_state(
            app_config_access.display_config.color),
        CheckedUltraViolet=get_html_checkbox_state(
            app_config_access.display_config.ultra_violet),
        CheckedAccelerometer=get_html_checkbox_state(
            app_config_access.display_config.accelerometer),
        CheckedMagnetometer=get_html_checkbox_state(
            app_config_access.display_config.magnetometer),
        CheckedGyroscope=get_html_checkbox_state(
            app_config_access.display_config.gyroscope))
def upgrade_http():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info("* Upgrade - HTTP Initiated by " +
                                   str(request.remote_addr))
        upgrade_interface = CreateUpgradeScriptInterface()
        upgrade_interface.start_kootnet_sensors_upgrade()
        msg = "HTTP" + upgrade_msg
        return get_message_page("Upgrade Started",
                                msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
def upgrade_pip_modules():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info(
            "** Program pip3 modules upgrade Initiated by " +
            str(request.remote_addr))
        upgrade_python_pip_modules()
        msg = "Python Modules for Kootnet Sensors are being upgraded. Once complete, the program will be restarted."
        return get_message_page("Upgrading Python Modules",
                                message=msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
def upgrade_system_os():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info("** OS Upgrade and Reboot Initiated by " +
                                   str(request.remote_addr))
        upgrade_linux_os()
        msg = "Upgrading the Operating System requires Internet & may take up to an hour or more.<br>"
        msg = msg + "Once complete, the system will automatically reboot."
        return get_message_page("Upgrading Operating System",
                                message=msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
def system_reboot():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info("** System Reboot Initiated by " +
                                   str(request.remote_addr))
        app_generic_functions.thread_function(
            os.system, args=app_cached_variables.bash_commands["RebootSystem"])
        return_msg = "This may take a few Minutes ..."
        return get_message_page("Rebooting System",
                                message=return_msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
def system_shutdown():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info("** System Shutdown Initiated by " +
                                   str(request.remote_addr))
        app_generic_functions.thread_function(
            os.system,
            args=app_cached_variables.bash_commands["ShutdownSystem"])
        msg = "You must physically turn the sensor back on for future access"
        return get_message_page("Shutting Down System",
                                message=msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
def create_new_self_signed_ssl():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info(
            "** Create New Self-Signed SSL Initiated by " +
            str(request.remote_addr))
        os.system("rm -f -r " + file_locations.http_ssl_folder)
        system_access.restart_services()
        msg = "You may have to clear your browser cache to re-gain access. The program is now restarting."
        return get_message_page("New SSL Key Created",
                                message=msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
Beispiel #23
0
def login():
    if request.method == 'POST':
        ip_address = str(request.remote_addr)
        if _address_is_banned(ip_address):
            _ip_failed_login(ip_address)
            return_msg = "Too many failed login attempts, your IP address has been banned for 15 Min"
            return get_message_page("IP Banned from Logins",
                                    message=return_msg)
        else:
            username = request.form['login_username']
            password = request.form['login_password']

            if username == app_cached_variables.http_flask_user and verify_password_to_hash(
                    password):
                new_session_id = sha256(urandom(12)).hexdigest()
                session['user_id'] = new_session_id
                app_cached_variables.http_flask_login_session_ids[
                    new_session_id] = datetime.utcnow()
                return redirect('/atpro/')
        _ip_failed_login(ip_address)
        return get_message_page("Login Failed", page_url="sensor-settings")
    return render_template("ATPro_admin/page_templates/login.html")
def html_atpro_system_change_login():
    if request.method == "POST":
        if primary_config.demo_mode:
            return get_message_page("Function Disabled", "Unable to change Login in Demo mode")
        else:
            new_http_flask_user = app_cached_variables.http_flask_user
            temp_username = str(request.form.get("login_username"))
            temp_password = str(request.form.get("login_password"))
            if len(temp_username) >= min_length_username and len(temp_password) >= min_length_password:
                save_http_auth_to_file(temp_username, temp_password)
                default_password = default_http_flask_password
                if default_http_flask_user == new_http_flask_user and verify_password_to_hash(default_password):
                    atpro_notifications.manage_default_login_detected()
                else:
                    atpro_notifications.manage_default_login_detected(enable=False)
                msg1 = "Username and Password Updated"
                msg2 = "The Username and Password has been updated"
            else:
                msg1 = "Invalid Username or Password"
                msg2 = "Username and Password must be 4 to 62 characters long and cannot be blank"
            return get_message_page(msg1, msg2)
    return render_template("ATPro_admin/page_templates/system/system-change-login.html")
def upgrade_smb_dev():
    if not app_config_access.primary_config.demo_mode:
        logger.network_logger.info("** Developer Upgrade - SMB Initiated by " +
                                   str(request.remote_addr))
        upgrade_interface = CreateUpgradeScriptInterface()
        upgrade_interface.download_type = download_type_smb
        upgrade_interface.dev_upgrade = True
        upgrade_interface.start_kootnet_sensors_upgrade()
        msg = "SMB Development" + upgrade_msg
        return get_message_page("Upgrade Started",
                                msg,
                                page_url="sensor-dashboard")
    return demo_mode_enabled_msg
Beispiel #26
0
def html_atpro_osm_registration():
    status = add_sensor_to_account(request)
    message1 = "OSM Sensor Registration Failed"
    if status == 201:
        message1 = "Sensor Registered OK"
        message2 = "Sensor Registered to Open Sense Map."
    elif status == 415:
        message2 = "Invalid or Missing content type"
    elif status == 422:
        message2 = "Invalid Location Setting"
    elif status == "FailedLogin":
        message2 = "Login Failed - Bad UserName or Password"
    else:
        message2 = "Unknown Error: " + status
    return get_message_page(message1, message2, page_url="sensor-settings")
Beispiel #27
0
def html_atpro_sensor_settings_osm():
    if request.method == "POST":
        app_config_access.open_sense_map_config.update_with_html_request(request)
        app_config_access.open_sense_map_config.save_config_to_file()
        return_msg = "Stopping Open Sense Map"
        if app_config_access.open_sense_map_config.open_sense_map_enabled:
            return_msg = "Starting Open Sense Map"
            if app_cached_variables.open_sense_map_thread.current_state != "Disabled":
                if app_cached_variables.open_sense_map_thread.monitored_thread.is_alive():
                    return_msg = "Re-Starting Open Sense Map"
                    app_cached_variables.restart_open_sense_map_thread = True
                else:
                    start_open_sense_map_server()
            else:
                start_open_sense_map_server()
        else:
            if app_cached_variables.open_sense_map_thread is not None:
                app_cached_variables.open_sense_map_thread.shutdown_thread = True
                app_cached_variables.restart_open_sense_map_thread = True
        return get_message_page("Open Sense Map Settings Updated", return_msg, page_url="sensor-settings")
    return render_template(
        "ATPro_admin/page_templates/settings/settings-3rd-p-osm.html",
        CheckedOSMEnabled=get_html_checkbox_state(app_config_access.open_sense_map_config.open_sense_map_enabled),
        OSMStationID=app_config_access.open_sense_map_config.sense_box_id,
        OSMIntervalSeconds=app_config_access.open_sense_map_config.interval_seconds,
        OSMSEnvTempID=app_config_access.open_sense_map_config.temperature_id,
        OSMPressureID=app_config_access.open_sense_map_config.pressure_id,
        OSMAltitudeID=app_config_access.open_sense_map_config.altitude_id,
        OSMHumidityID=app_config_access.open_sense_map_config.humidity_id,
        OSMGasIndexID=app_config_access.open_sense_map_config.gas_voc_id,
        OSMGasNH3ID=app_config_access.open_sense_map_config.gas_nh3_id,
        OSMOxidisingID=app_config_access.open_sense_map_config.gas_oxidised_id,
        OSMGasReducingID=app_config_access.open_sense_map_config.gas_reduced_id,
        OSMPM1ID=app_config_access.open_sense_map_config.pm1_id,
        OSMPM25ID=app_config_access.open_sense_map_config.pm2_5_id,
        OSMPM4ID=app_config_access.open_sense_map_config.pm4_id,
        OSMPM10ID=app_config_access.open_sense_map_config.pm10_id,
        OSMLumenID=app_config_access.open_sense_map_config.lumen_id,
        OSMRedID=app_config_access.open_sense_map_config.red_id,
        OSMOrangeID=app_config_access.open_sense_map_config.orange_id,
        OSMYellowID=app_config_access.open_sense_map_config.yellow_id,
        OSMGreenID=app_config_access.open_sense_map_config.green_id,
        OSMBlueID=app_config_access.open_sense_map_config.blue_id,
        OSMVioletID=app_config_access.open_sense_map_config.violet_id,
        OSMUVIndexID=app_config_access.open_sense_map_config.ultra_violet_index_id,
        OSMUVAID=app_config_access.open_sense_map_config.ultra_violet_a_id,
        OSMUVBID=app_config_access.open_sense_map_config.ultra_violet_b_id
    )
def html_atpro_sensor_settings_offsets():
    if request.method == "POST":
        app_config_access.sensor_offsets.update_with_html_request(request)
        app_config_access.sensor_offsets.save_config_to_file()
        return get_message_page("Sensor Offset Settings Updated",
                                page_url="sensor-settings")

    return render_template(
        "ATPro_admin/page_templates/settings/settings-sensor-offsets.html",
        CheckedCustomTempOffset=get_html_checkbox_state(
            app_config_access.sensor_offsets.enable_temp_offset),
        temperature_offset=app_config_access.sensor_offsets.temperature_offset,
        CheckedCustomTempComp=get_html_checkbox_state(
            app_config_access.sensor_offsets.enable_temperature_comp_factor),
        CustomTempComp=app_config_access.sensor_offsets.
        temperature_comp_factor,
    )
def html_atpro_sensor_settings_interval():
    if request.method == "POST":
        app_config_access.interval_recording_config.update_with_html_request(
            request)
        app_config_access.interval_recording_config.save_config_to_file()
        app_cached_variables.restart_interval_recording_thread = True
        return get_message_page("Interval Settings Updated",
                                page_url="sensor-settings")

    interval_config = app_config_access.interval_recording_config
    return render_template(
        "ATPro_admin/page_templates/settings/settings-recording-interval.html",
        CheckedInterval=get_html_checkbox_state(
            interval_config.enable_interval_recording),
        IntervalDelay=float(interval_config.sleep_duration_interval),
        CheckedSensorUptime=get_html_checkbox_state(
            interval_config.sensor_uptime_enabled),
        CheckedCPUTemperature=get_html_checkbox_state(
            interval_config.cpu_temperature_enabled),
        CheckedEnvTemperature=get_html_checkbox_state(
            interval_config.env_temperature_enabled),
        CheckedPressure=get_html_checkbox_state(
            interval_config.pressure_enabled),
        CheckedAltitude=get_html_checkbox_state(
            interval_config.altitude_enabled),
        CheckedHumidity=get_html_checkbox_state(
            interval_config.humidity_enabled),
        CheckedDewPoint=get_html_checkbox_state(
            interval_config.dew_point_enabled),
        CheckedDistance=get_html_checkbox_state(
            interval_config.distance_enabled),
        CheckedLumen=get_html_checkbox_state(interval_config.lumen_enabled),
        CheckedColour=get_html_checkbox_state(interval_config.colour_enabled),
        CheckedUltraViolet=get_html_checkbox_state(
            interval_config.ultra_violet_enabled),
        CheckedGas=get_html_checkbox_state(interval_config.gas_enabled),
        CheckedPM=get_html_checkbox_state(
            interval_config.particulate_matter_enabled),
        CheckedAccelerometer=get_html_checkbox_state(
            interval_config.accelerometer_enabled),
        CheckedMagnetometer=get_html_checkbox_state(
            interval_config.magnetometer_enabled),
        CheckedGyroscope=get_html_checkbox_state(
            interval_config.gyroscope_enabled),
        CheckedGPS=get_html_checkbox_state(interval_config.gps_enabled))
Beispiel #30
0
def _push_data_to_sensors(url_command, html_dictionary_data):
    if len(app_config_access.sensor_control_config.
           get_raw_ip_addresses_as_list()) < 1:
        return _get_missing_sensor_addresses_page()
    elif _missing_login_credentials():
        return _get_missing_login_credentials_page()

    ip_address_length = len(
        app_config_access.sensor_control_config.get_raw_ip_addresses_as_list())
    push_thread = Thread(target=_push_config_thread_worker,
                         args=[url_command, html_dictionary_data])
    push_thread.daemon = True
    push_thread.start()
    msg_2 = "Kootnet Sensors configuration data is being sent to " + str(
        ip_address_length) + " Sensors"
    return get_message_page("Sensor Control - Configuration(s) Sent",
                            msg_2,
                            page_url="sensor-rm")