diff --git a/front/devices.php b/front/devices.php index cb497356..a4a06143 100755 --- a/front/devices.php +++ b/front/devices.php @@ -286,7 +286,7 @@ function processDeviceTotals(devicesData) { (getSetting('UI_shown_cards') == "" || getSetting('UI_shown_cards').includes(filter.status)) ) { dataArray.push({ - onclickEvent: `initializeDatatable('${filter.status}')`, + onclickEvent: `forceLoadUrl('/devices.php#${filter.status}')`, color: filter.color, title: count, label: filter.label, @@ -444,6 +444,8 @@ function initializeDatatable (status) { } } + // todo: dynamically filter based on status + var table = $('#tableDevices').DataTable({ "serverSide": true, @@ -514,8 +516,10 @@ function initializeDatatable (status) { "field": mapColumnIndexToFieldName(d.order[0].column, tableColumnVisible), // Sort field from DataTable column "order": d.order[0].dir.toUpperCase() // Sort direction (ASC/DESC) }] : [], // Default to an empty array if no sorting is defined - "search": d.search.value // Search query + "search": d.search.value, // Search query + "status": deviceStatus } + } }; diff --git a/front/js/common.js b/front/js/common.js index c967ab9a..1582683c 100755 --- a/front/js/common.js +++ b/front/js/common.js @@ -689,6 +689,13 @@ function openUrl(urls) { } } +// ----------------------------------------------------------------------------- +// force laod URL in current window with specific anchor +function forceLoadUrl(relativeUrl) { + window.location.replace(relativeUrl); + window.location.reload() +} + // ----------------------------------------------------------------------------- function navigateToDeviceWithIp (ip) { diff --git a/front/php/templates/header.php b/front/php/templates/header.php index 4f8065fe..f4a5791c 100755 --- a/front/php/templates/header.php +++ b/front/php/templates/header.php @@ -255,28 +255,28 @@ + diff --git a/front/plugins/arp_scan/script.py b/front/plugins/arp_scan/script.py index 7bcc4c74..deb7806e 100755 --- a/front/plugins/arp_scan/script.py +++ b/front/plugins/arp_scan/script.py @@ -112,7 +112,7 @@ def execute_arpscan(userSubnets): re_ip = r'(?P((2[0-5]|1[0-9]|[0-9])?[0-9]\.){3}((2[0-5]|1[0-9]|[0-9])?[0-9]))' re_mac = r'(?P([0-9a-fA-F]{2}[:-]){5}([0-9a-fA-F]{2}))' re_hw = r'(?P.*)' - re_pattern = re.compile (re_ip + '\s+' + re_mac + '\s' + re_hw) + re_pattern = re.compile(rf"{re_ip}\s+{re_mac}\s{re_hw}") devices_list_tmp = [ {**device.groupdict(), "interface": interface} diff --git a/server/graphql_server/graphql_schema.py b/server/graphql_server/graphql_schema.py index 1f2bbf81..e47cb48e 100755 --- a/server/graphql_server/graphql_schema.py +++ b/server/graphql_server/graphql_schema.py @@ -9,7 +9,7 @@ sys.path.extend([f"{INSTALL_PATH}/server"]) from logger import mylog from const import apiPath -from helper import is_random_mac, get_number_of_children, format_ip_long +from helper import is_random_mac, get_number_of_children, format_ip_long, get_setting_value # Define a base URL with the user's home directory folder = apiPath @@ -24,6 +24,7 @@ class PageQueryOptionsInput(InputObjectType): limit = Int() sort = List(SortOptionsInput) search = String() + status = String() # Device ObjectType class Device(ObjectType): @@ -74,7 +75,7 @@ class Query(ObjectType): devices = Field(DeviceResult, options=PageQueryOptionsInput()) def resolve_devices(self, info, options=None): - mylog('none', f'[graphql_schema] resolve_devices: {self}') + # mylog('none', f'[graphql_schema] resolve_devices: {self}') try: with open(folder + 'table_devices.json', 'r') as f: devices_data = json.load(f)["data"] @@ -93,15 +94,50 @@ class Query(ObjectType): mylog('none', f'[graphql_schema] devices_data: {devices_data}') - # Define static list of searchable fields - searchable_fields = [ - "devName", "devMac", "devOwner", "devType", "devVendor", - "devGroup", "devComments", "devLocation", "devStatus", - "devSSID", "devSite", "devSourcePlugin", "devSyncHubNode" - ] + # Apply sorting if options are provided if options: + + + # Define status-specific filtering + if options.status: + status = options.status + mylog('none', f'[graphql_schema] Applying status filter: {status}') + + # Example filtering based on the "status" + if status == "my_devices": + # Include devices matching criteria in UI_MY_DEVICES + allowed_statuses = get_setting_value("UI_MY_DEVICES") + + mylog('none', f'[graphql_schema] allowed_statuses: {allowed_statuses}') + + devices_data = [ + device for device in devices_data + if ( + (device["devPresentLastScan"] == 1 and 'online' in allowed_statuses) or + (device["devIsNew"] == 1 and 'new' in allowed_statuses) or + (device["devPresentLastScan"] == 0 and device["devAlertDown"] and 'down' in allowed_statuses) or + (device["devPresentLastScan"] == 0 and 'offline' in allowed_statuses) + ) + ] + elif status == "connected": + devices_data = [device for device in devices_data if device["devPresentLastScan"] == 1] + elif status == "favorites": + devices_data = [device for device in devices_data if device["devFavorite"] == 1] + elif status == "new": + devices_data = [device for device in devices_data if device["devIsNew"] == 1] + elif status == "down": + devices_data = [ + device for device in devices_data + if device["devPresentLastScan"] == 0 and device["devAlertDown"] + ] + elif status == "archived": + devices_data = [device for device in devices_data if device["devIsArchived"] == 1] + elif status == "offline": + devices_data = [device for device in devices_data if device["devPresentLastScan"] == 0] + + # sorting if options.sort: for sort_option in options.sort: devices_data = sorted( @@ -112,6 +148,13 @@ class Query(ObjectType): # Filter data if a search term is provided if options.search: + # Define static list of searchable fields + searchable_fields = [ + "devName", "devMac", "devOwner", "devType", "devVendor", + "devGroup", "devComments", "devLocation", "devStatus", + "devSSID", "devSite", "devSourcePlugin", "devSyncHubNode" + ] + search_term = options.search.lower() devices_data = [