diff --git a/front/plugins/__template/config.json b/front/plugins/__template/config.json index 5f1b8ee2..dafc1986 100755 --- a/front/plugins/__template/config.json +++ b/front/plugins/__template/config.json @@ -2,6 +2,7 @@ "code_name": "__template", "unique_prefix": "TMP", "plugin_type": "device_scanner", + "execution_order" : "Layer_0", "enabled": true, "data_source": "script", "mapped_to_table": "CurrentScan", diff --git a/front/plugins/arp_scan/config.json b/front/plugins/arp_scan/config.json index 801bf6e5..c2273a65 100755 --- a/front/plugins/arp_scan/config.json +++ b/front/plugins/arp_scan/config.json @@ -1,6 +1,7 @@ { "code_name": "arp_scan", "unique_prefix": "ARPSCAN", + "execution_order" : "Layer_2", "plugin_type": "device_scanner", "enabled": true, "data_source": "script", diff --git a/front/plugins/dhcp_leases/config.json b/front/plugins/dhcp_leases/config.json index 3f516f3a..4900929b 100755 --- a/front/plugins/dhcp_leases/config.json +++ b/front/plugins/dhcp_leases/config.json @@ -2,6 +2,7 @@ "code_name": "dhcp_leases", "unique_prefix": "DHCPLSS", "plugin_type": "device_scanner", + "execution_order" : "Layer_3", "enabled": true, "data_source": "script", "data_filters": [ @@ -513,12 +514,23 @@ ], "transformers": [] }, + { + "elementType": "button", + "elementOptions": [ + { "sourceSuffixes": ["_in"] }, + { "separator": "" }, + { "cssClasses": "col-xs-12" }, + { "onClick": "addList(this, false)" }, + { "getStringKey": "Gen_Add" } + ], + "transformers": [] + }, { "elementType": "button", "elementOptions": [ { "sourceSuffixes": [] }, { "separator": "" }, - { "cssClasses": "col-sm-3" }, + { "cssClasses": "col-xs-6" }, { "onClick": "removeAllOptions(this)" }, { "getStringKey": "Gen_Remove_All" } ], @@ -529,23 +541,12 @@ "elementOptions": [ { "sourceSuffixes": [] }, { "separator": "" }, - { "cssClasses": "col-sm-3" }, + { "cssClasses": "col-xs-6" }, { "onClick": "removeFromList(this)" }, { "getStringKey": "Gen_Remove_Last" } ], "transformers": [] }, - { - "elementType": "button", - "elementOptions": [ - { "sourceSuffixes": ["_in"] }, - { "separator": "" }, - { "cssClasses": "col-sm-2" }, - { "onClick": "addList(this, false)" }, - { "getStringKey": "Gen_Add" } - ], - "transformers": [] - }, { "elementType": "select", "elementOptions": [ diff --git a/front/plugins/dhcp_servers/config.json b/front/plugins/dhcp_servers/config.json index 5e388470..1f1021e1 100755 --- a/front/plugins/dhcp_servers/config.json +++ b/front/plugins/dhcp_servers/config.json @@ -2,6 +2,7 @@ "code_name": "dhcp_servers", "unique_prefix": "DHCPSRVS", "plugin_type": "other", + "execution_order" : "Layer_3", "enabled": true, "data_source": "script", "show_ui": true, diff --git a/front/plugins/internet_ip/config.json b/front/plugins/internet_ip/config.json index 11255107..5478e15e 100755 --- a/front/plugins/internet_ip/config.json +++ b/front/plugins/internet_ip/config.json @@ -2,6 +2,7 @@ "code_name": "internet_ip", "unique_prefix": "INTRNT", "plugin_type": "device_scanner", + "execution_order" : "Layer_3", "enabled": true, "mapped_to_table": "CurrentScan", "data_filters": [ diff --git a/front/plugins/nbtscan_scan/config.json b/front/plugins/nbtscan_scan/config.json index 3d44a064..dca01697 100755 --- a/front/plugins/nbtscan_scan/config.json +++ b/front/plugins/nbtscan_scan/config.json @@ -4,6 +4,7 @@ "plugin_type": "other", "enabled": true, "data_source": "script", + "execution_order" : "Layer_3", "show_ui": true, "localized": ["display_name", "description", "icon"], "display_name": [ diff --git a/front/plugins/nmap_dev_scan/config.json b/front/plugins/nmap_dev_scan/config.json index 0d1cfa8a..ca17d547 100755 --- a/front/plugins/nmap_dev_scan/config.json +++ b/front/plugins/nmap_dev_scan/config.json @@ -2,6 +2,7 @@ "code_name": "nmap_dev_scan", "unique_prefix": "NMAPDEV", "plugin_type": "device_scanner", + "execution_order" : "Layer_3", "enabled": true, "data_source": "script", "mapped_to_table": "CurrentScan", diff --git a/front/plugins/nmap_scan/config.json b/front/plugins/nmap_scan/config.json index 88c448a0..e1a3da78 100755 --- a/front/plugins/nmap_scan/config.json +++ b/front/plugins/nmap_scan/config.json @@ -2,6 +2,7 @@ "code_name": "nmap_scan", "unique_prefix": "NMAP", "plugin_type": "other", + "execution_order" : "Layer_4", "enabled": true, "data_source": "script", "data_filters": [ diff --git a/front/plugins/nslookup_scan/config.json b/front/plugins/nslookup_scan/config.json index b2773683..adb67255 100755 --- a/front/plugins/nslookup_scan/config.json +++ b/front/plugins/nslookup_scan/config.json @@ -2,6 +2,7 @@ "code_name": "nslookup_scan", "unique_prefix": "NSLOOKUP", "plugin_type": "other", + "execution_order" : "Layer_4", "enabled": true, "data_source": "script", "show_ui": true, diff --git a/front/plugins/omada_sdn_imp/config.json b/front/plugins/omada_sdn_imp/config.json index f9648365..8bc11949 100755 --- a/front/plugins/omada_sdn_imp/config.json +++ b/front/plugins/omada_sdn_imp/config.json @@ -2,6 +2,7 @@ "code_name": "omada_sdn_imp", "unique_prefix": "OMDSDN", "plugin_type": "device_scanner", + "execution_order" : "Layer_1", "enabled": true, "data_source": "script", "mapped_to_table": "CurrentScan", diff --git a/front/plugins/pihole_scan/config.json b/front/plugins/pihole_scan/config.json index e3f77629..818f4273 100755 --- a/front/plugins/pihole_scan/config.json +++ b/front/plugins/pihole_scan/config.json @@ -2,6 +2,7 @@ "code_name": "pihole_scan", "unique_prefix": "PIHOLE", "plugin_type": "device_scanner", + "execution_order" : "Layer_2", "enabled": true, "data_source": "sqlite-db-query", "mapped_to_table": "CurrentScan", diff --git a/front/plugins/snmp_discovery/config.json b/front/plugins/snmp_discovery/config.json index 172f5049..67f72466 100755 --- a/front/plugins/snmp_discovery/config.json +++ b/front/plugins/snmp_discovery/config.json @@ -2,6 +2,7 @@ "code_name": "snmp_discovery", "unique_prefix": "SNMPDSC", "plugin_type": "device_scanner", + "execution_order" : "Layer_1", "enabled": true, "data_source": "script", "data_filters": [ diff --git a/front/plugins/unifi_import/config.json b/front/plugins/unifi_import/config.json index 85465f6c..85d7763e 100755 --- a/front/plugins/unifi_import/config.json +++ b/front/plugins/unifi_import/config.json @@ -3,6 +3,7 @@ "show_ui": true, "unique_prefix": "UNFIMP", "plugin_type": "device_scanner", + "execution_order" : "Layer_1", "data_source": "script", "localized": ["display_name", "description", "icon"], "display_name": [ diff --git a/server/device.py b/server/device.py index 18c34baf..cff15651 100755 --- a/server/device.py +++ b/server/device.py @@ -96,33 +96,33 @@ def print_scan_stats(db): mylog('verbose', f'[Scan Stats] IP Changes.............: {stats[0]["ip_changes"]}') # if str(stats[0]["new_devices"]) != '0': - mylog('debug', f' ================ DEVICES table content ================') + mylog('trace', f' ================ DEVICES table content ================') sql.execute('select * from Devices') rows = sql.fetchall() for row in rows: row_dict = dict(row) - mylog('debug', f' {row_dict}') + mylog('trace', f' {row_dict}') - mylog('debug', f' ================ CurrentScan table content ================') + mylog('trace', f' ================ CurrentScan table content ================') sql.execute('select * from CurrentScan') rows = sql.fetchall() for row in rows: row_dict = dict(row) - mylog('debug', f' {row_dict}') + mylog('trace', f' {row_dict}') - mylog('debug', f' ================ Events table content where eve_PendingAlertEmail = 1 ================') + mylog('trace', f' ================ Events table content where eve_PendingAlertEmail = 1 ================') sql.execute('select * from Events where eve_PendingAlertEmail = 1') rows = sql.fetchall() for row in rows: row_dict = dict(row) - mylog('debug', f' {row_dict}') + mylog('trace', f' {row_dict}') - mylog('debug', f' ================ Events table COUNT ================') + mylog('trace', f' ================ Events table COUNT ================') sql.execute('select count(*) from Events') rows = sql.fetchall() for row in rows: row_dict = dict(row) - mylog('debug', f' {row_dict}') + mylog('trace', f' {row_dict}') mylog('verbose', '[Scan Stats] Scan Method Statistics:') diff --git a/server/initialise.py b/server/initialise.py index 2838ba6a..a53b84ba 100755 --- a/server/initialise.py +++ b/server/initialise.py @@ -133,7 +133,7 @@ def importConfigs (db, all_plugins): conf.LOADED_PLUGINS = ccd('LOADED_PLUGINS', [] , c_d, 'Loaded plugins', '{"dataType":"array", "elements": [{"elementType" : "select", "elementOptions" : [{"multiple":"true"}] ,"transformers": []}]}', '[]', 'General') conf.SCAN_SUBNETS = ccd('SCAN_SUBNETS', ['192.168.1.0/24 --interface=eth1', '192.168.1.0/24 --interface=eth0'] , c_d, 'Subnets to scan', '{"dataType": "array","elements": [ {"elementType": "input","elementOptions": [{ "placeholder": "192.168.1.0/24 --interface=eth1" },{ "suffix": "_in" },{ "cssClasses": "col-sm-10" },{ "prefillValue": "null" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": ["_in"] },{ "separator": "" },{ "cssClasses": "col-xs-12" },{ "onClick": "addList(this, false)" },{ "getStringKey": "Gen_Add" }],"transformers": [] }, {"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeAllOptions(this)" },{ "getStringKey": "Gen_Remove_All" }],"transformers": []},{"elementType": "button","elementOptions": [{ "sourceSuffixes": [] },{ "separator": "" },{ "cssClasses": "col-xs-6" },{ "onClick": "removeFromList(this)" },{ "getStringKey": "Gen_Remove_Last" }],"transformers": []}, {"elementType": "select","elementOptions": [{ "multiple": "true" },{ "readonly": "true" },{ "editable": "true" }],"transformers": [] }]}', '[]', 'General') - conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['none', 'minimal', 'verbose', 'debug']", 'General') + conf.LOG_LEVEL = ccd('LOG_LEVEL', 'verbose' , c_d, 'Log verboseness', '{"dataType":"string", "elements": [{"elementType" : "select", "elementOptions" : [] ,"transformers": []}]}', "['none', 'minimal', 'verbose', 'debug', 'trace']", 'General') conf.TIMEZONE = ccd('TIMEZONE', 'Europe/Berlin' , c_d, 'Time zone', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General') conf.PLUGINS_KEEP_HIST = ccd('PLUGINS_KEEP_HIST', 250 , c_d, 'Keep history entries', '{"dataType":"integer", "elements": [{"elementType" : "input", "elementOptions" : [{"type": "number"}] ,"transformers": []}]}', '[]', 'General') conf.REPORT_DASHBOARD_URL = ccd('REPORT_DASHBOARD_URL', 'http://netalertx/' , c_d, 'NetAlertX URL', '{"dataType":"string", "elements": [{"elementType" : "input", "elementOptions" : [] ,"transformers": []}]}', '[]', 'General') diff --git a/server/logger.py b/server/logger.py index 32e49a64..fb1c42b7 100755 --- a/server/logger.py +++ b/server/logger.py @@ -22,7 +22,7 @@ def timeNowTZ(): #------------------------------------------------------------------------------- # More verbose as the numbers go up debugLevels = [ - ('none', 0), ('minimal', 1), ('verbose', 2), ('debug', 3) + ('none', 0), ('minimal', 1), ('verbose', 2), ('debug', 3), ('trace', 4) ] currentLevel = 0 diff --git a/server/plugin_utils.py b/server/plugin_utils.py index 8eedc2da..d9f5f0c9 100755 --- a/server/plugin_utils.py +++ b/server/plugin_utils.py @@ -172,15 +172,25 @@ def resolve_wildcards_arr(commandArr, params): return commandArr - +#------------------------------------------------------------------------------- +# Function to extract layer number from "execution_order" +def get_layer(plugin): + order = plugin.get("execution_order", "Layer_N") + if order == "Layer_N": + return float('inf') # Treat as the last layer if "execution_order" is missing + return int(order.split('_')[1]) #------------------------------------------------------------------------------- def get_plugins_configs(): pluginsList = [] # Create an empty list to store plugin configurations + pluginsListSorted = [] # Sorted by "execution_order" : "Layer_0" first, Layer_N last # Get a list of top-level directories in the specified pluginsPath dirs = next(os.walk(pluginsPath))[1] + # Sort the directories list if needed + dirs.sort() # This will sort the directories alphabetically + # Loop through each directory (plugin folder) in dirs for d in dirs: # Check if the directory name does not start with "__" to skip python cache @@ -194,7 +204,10 @@ def get_plugins_configs(): # Load the contents of the config.json file as a JSON object and append it to pluginsList pluginsList.append(json.loads(get_file_content(config_path))) - return pluginsList # Return the list of plugin configurations + # Sort pluginsList based on "execution_order" + pluginsListSorted = sorted(pluginsList, key=get_layer) + + return pluginsListSorted # Return the sorted list of plugin configurations #-------------------------------------------------------------------------------