diff --git a/front/devices.php b/front/devices.php index c93da0d8..88119941 100755 --- a/front/devices.php +++ b/front/devices.php @@ -367,12 +367,6 @@ function mapColumnIndexToFieldName(index, tableColumnVisible) { "devSourcePlugin" ]; - console.log(index); - console.log(tableColumnVisible); - console.log(tableColumnOrder); // this - console.log(missingNumbers); - console.log(columnNames[tableColumnOrder[index]]); - return columnNames[tableColumnOrder[index]] || null; } diff --git a/server/api.py b/server/api.py index 5e204270..0ac45225 100755 --- a/server/api.py +++ b/server/api.py @@ -48,15 +48,17 @@ def update_api(db, all_plugins, isNotification = False, updateOnlyDataSources = # Start the GraphQL server graphql_port_value = get_setting_value("GRAPHQL_PORT") + api_token_value = get_setting_value("API_TOKEN") - if graphql_port_value is not None: + # Validate and start the server if settings are available + if graphql_port_value is not None and api_token_value is not None: try: - graphql_port_value = int(graphql_port_value) - start_server(graphql_port=graphql_port_value) # Pass the port if the server accepts it + graphql_port_value = int(graphql_port_value) # Ensure port is an integer + start_server(graphql_port=graphql_port_value) # Start the server except ValueError: mylog('none', [f"[API] Invalid GRAPHQL_PORT value, must be an integer: {graphql_port_value}"]) else: - mylog('none', [f"[API] GRAPHQL_PORT is not set, will try later."]) + mylog('none', [f"[API] GRAPHQL_PORT or API_TOKEN is not set, will try later."]) #------------------------------------------------------------------------------- diff --git a/server/graphql_server/graphql_server_start.py b/server/graphql_server/graphql_server_start.py index ba1c8be6..e2924740 100755 --- a/server/graphql_server/graphql_server_start.py +++ b/server/graphql_server/graphql_server_start.py @@ -4,60 +4,57 @@ from .graphql_schema import devicesSchema from graphene import Schema import sys -# Global variable to track the server thread -server_thread = None - # Register NetAlertX directories -INSTALL_PATH="/app" +INSTALL_PATH = "/app" sys.path.extend([f"{INSTALL_PATH}/server"]) from logger import mylog from helper import get_setting_value, timeNowTZ, updateState from notification import write_notification +# Flask application app = Flask(__name__) -API_TOKEN = get_setting_value("API_TOKEN") +# Retrieve API token and port +graphql_port_value = get_setting_value("GRAPHQL_PORT") +api_token_value = get_setting_value("API_TOKEN") +# Endpoint for GraphQL queries @app.route("/graphql", methods=["POST"]) def graphql_endpoint(): # Check for API token in headers token = request.headers.get("Authorization") - if token != f"Bearer {API_TOKEN}": + if token != f"Bearer {api_token_value}": mylog('verbose', [f'[graphql_server] Unauthorized access attempt']) - return jsonify({"error": "Unauthorized"}), 401 + # Retrieve and log request data data = request.get_json() mylog('verbose', [f'[graphql_server] data: {data}']) - - # Use the schema to execute the GraphQL query + # Execute the GraphQL query result = devicesSchema.execute(data.get("query"), variables=data.get("variables")) - # Return the data from the query in JSON format + # Return the result as JSON return jsonify(result.data) def start_server(graphql_port): - """Function to start the GraphQL server in a background thread.""" - - state = updateState("GraphQL: Starting", None, None, None, None) + """Start the GraphQL server in a background thread.""" + state = updateState("GraphQL: Starting", None, None, None, None) if state.graphQLServerStarted == 0: - mylog('verbose', [f'[graphql_server] Starting on port: {graphql_port}']) - # Start the Flask app in a separate thread - thread = threading.Thread(target=lambda: app.run(host="0.0.0.0", port=graphql_port, debug=True, use_reloader=False)) + # Start Flask app in a separate thread + thread = threading.Thread( + target=lambda: app.run( + host="0.0.0.0", + port=graphql_port, + debug=True, + use_reloader=False + ) + ) thread.start() - - # update API endpoint to indicate that the GraphQL backend started - # updateState(newState (text), - # settingsSaved = None (timestamp), - # settingsImported = None (timestamp), - # showSpinner = False (1/0), - # graphQLServerStarted = False (1/0) - # ) - state = updateState("Process: Wait", None, None, None, 1) - + # Update the state to indicate the server has started + state = updateState("Process: Wait", None, None, None, 1) \ No newline at end of file