Merge branch 'jokob-sk:main' into main
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
> Community translations of this file (might be out-of-date): <a href="https://github.com/jokob-sk/NetAlertX/blob/main/front/plugins/README_ES.md">Spanish(<img src="https://github.com/lipis/flag-icons/blob/main/flags/4x3/es.svg" alt="README_ES.md" style="height: 16px !important;width: 20px !important;padding-inline:3px !important;">)</a>, <a href="https://github.com/jokob-sk/NetAlertX/blob/main/front/plugins/README_DE.md">German(<img src="https://github.com/lipis/flag-icons/blob/main/flags/4x3/de.svg" alt="README_DE.md" style="height: 16px !important;width: 20px !important;padding-inline:3px !important;">)</a>
|
||||
|
||||
# 📚 Docs for individual plugins
|
||||
|
||||
>[!NOTE]
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "Specify when your Network-discovery scan will run. Typical setting would be <code>schedule</code> and then you specify a cron-like schedule in the <a href=\"#ARPSCAN_RUN_SCHD\"><code>ARPSCAN_RUN_SCHD</code>setting</a>. ⚠ Use the same schedule if you have multiple <i class=\"fa-solid fa-magnifying-glass-plus\"></i> Device scanners enabled."
|
||||
"string": "Specify when your Network-discovery scan will run. Typical setting would be <code>schedule</code> and then you specify a cron-like schedule in the <a href=\"#ARPSCAN_RUN_SCHD\"><code>ARPSCAN_RUN_SCHD</code>setting</a>. ⚠ Use the same schedule if you have multiple <i class=\"fa-solid fa-magnifying-glass-plus\"></i> Device scanners enabled. <br/><br/> Depends on the <a onclick=\"toggleAllSettings()\" href=\"#SCAN_SUBNETS\"><code>SCAN_SUBNETS</code> setting</a>."
|
||||
},
|
||||
{
|
||||
"language_code": "es_es",
|
||||
|
||||
@@ -1,15 +1,3 @@
|
||||
### Community translations of this file
|
||||
|
||||
<a href="https://github.com/jokob-sk/NetAlertX/blob/main/front/plugins/csv_backup/README_ES.md">
|
||||
<img src="https://github.com/lipis/flag-icons/blob/main/flags/4x3/es.svg" alt="README_ES.md" style="height: 20px !important;width: 20px !important;">
|
||||
Spanish (Spain)
|
||||
</a>
|
||||
<br>
|
||||
<a href="https://github.com/jokob-sk/NetAlertX/blob/main/front/plugins/csv_backup/README_DE.md">
|
||||
<img src="https://github.com/lipis/flag-icons/blob/main/flags/4x3/de.svg" alt="README_DE.md" style="height: 20px !important;width: 20px !important;">
|
||||
German (Germany)
|
||||
</a>
|
||||
|
||||
## Overview
|
||||
|
||||
Plugin generating CSV backups of your Devices database table, including the network mappings. Can be used for importing your setup via the Maintenance > Backup / Restore > CSV Import feature (See also: [Devices Bulk Editing](https://github.com/jokob-sk/NetAlertX/blob/main/docs/DEVICES_BULK_EDITING.md)).
|
||||
|
||||
@@ -82,7 +82,7 @@
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "Specify when your Network-discovery scan will run. Typical setting would be <code>schedule</code> and then you specify a cron-like schedule in the <a href=\"#NMAPDEV_RUN_SCHD\"><code>NMAPDEV_RUN_SCHD</code>setting</a>. ⚠ Use the same schedule if you have multiple <i class=\"fa-solid fa-magnifying-glass-plus\"></i> Device scanners enabled."
|
||||
"string": "Specify when your Network-discovery scan will run. Typical setting would be <code>schedule</code> and then you specify a cron-like schedule in the <a href=\"#NMAPDEV_RUN_SCHD\"><code>NMAPDEV_RUN_SCHD</code>setting</a>. ⚠ Use the same schedule if you have multiple <i class=\"fa-solid fa-magnifying-glass-plus\"></i> Device scanners enabled.<br/><br/> Depends on the <a onclick=\"toggleAllSettings()\" href=\"#SCAN_SUBNETS\"><code>SCAN_SUBNETS</code> setting</a>."
|
||||
},
|
||||
{
|
||||
"language_code": "es_es",
|
||||
@@ -300,7 +300,7 @@
|
||||
{
|
||||
"function": "ARGS",
|
||||
"type": "text",
|
||||
"default_value": "sudo nmap -sn ",
|
||||
"default_value": "sudo nmap -sn -PR -n ",
|
||||
"options": [],
|
||||
"localized": [
|
||||
"name",
|
||||
@@ -315,7 +315,7 @@
|
||||
"description": [
|
||||
{
|
||||
"language_code": "en_us",
|
||||
"string": "Arguments to run nmap-scan with. Recommended and tested only with the setting: <br/> <code>sudo nmap -sn </code>."
|
||||
"string": "Arguments to run nmap-scan with. Recommended and tested only with the setting: <br/> <code>sudo nmap -sn -PR -n </code>. <br/><br/> Note: The plugin attaches the interface and network mask, for example <code> -e eth1 192.168.1.0/24</code> and performs a separate scan for each interface specified in the <a onclick=\"toggleAllSettings()\" href=\"#SCAN_SUBNETS\"><code>SCAN_SUBNETS</code> setting</a>."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ sys.path.extend([f"{INSTALL_PATH}/front/plugins", f"{INSTALL_PATH}/server"])
|
||||
|
||||
from plugin_helper import Plugin_Object, Plugin_Objects, decodeBase64
|
||||
from logger import mylog, append_line_to_file
|
||||
from helper import timeNowTZ, get_setting_value
|
||||
from helper import timeNowTZ, get_setting_value, extract_between_strings, extract_ip_addresses, extract_mac_addresses
|
||||
from const import logPath, applicationPath, fullDbPath
|
||||
from database import DB
|
||||
from device import Device_obj
|
||||
@@ -52,20 +52,20 @@ def main():
|
||||
|
||||
unique_devices = execute_scan(subnets, timeout)
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] Unknown devices count: {len(unique_devices)}'])
|
||||
mylog('verbose', [f'[{pluginName}] Devices found: {len(unique_devices)}'])
|
||||
|
||||
for device in unique_devices:
|
||||
|
||||
plugin_objects.add_object(
|
||||
# "MAC", "IP", "Name", "Vendor", "Interface"
|
||||
primaryId = device[0],
|
||||
secondaryId = device[1],
|
||||
watched1 = device[2],
|
||||
watched2 = device[3],
|
||||
watched3 = device[4],
|
||||
primaryId = device['mac'].lower(),
|
||||
secondaryId = device['ip'],
|
||||
watched1 = device['name'],
|
||||
watched2 = device['vendor'],
|
||||
watched3 = device['interface'],
|
||||
watched4 = '',
|
||||
extra = '',
|
||||
foreignKey = device[0])
|
||||
foreignKey = device['mac'])
|
||||
|
||||
plugin_objects.write_result_file()
|
||||
|
||||
@@ -83,43 +83,49 @@ def execute_scan (subnets_list, timeout):
|
||||
devices_list = []
|
||||
|
||||
# scan each interface
|
||||
for interface in subnets_list:
|
||||
|
||||
nmap_output = execute_scan_on_interface(interface, timeout)
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] nmap_output: ', nmap_output])
|
||||
|
||||
if nmap_output is not None:
|
||||
nmap_output_ent = nmap_output.split('Nmap scan report for')
|
||||
# loop thru entries for individual devices
|
||||
for ent in nmap_output_ent:
|
||||
|
||||
lines = ent.split('\n')
|
||||
|
||||
if len(lines) >= 3:
|
||||
# lines[0] can be DESKTOP-DIHOG0E.localdomain (192.168.1.121) or 192.168.1.255
|
||||
# lines[1] can be Host is up (0.21s latency).
|
||||
# lines[2] can be MAC Address: 6C:4A:4A:7B:4A:43 (Motorola Mobility, a Lenovo Company)
|
||||
|
||||
ip_addresses = extract_ip_addresses(lines[0])
|
||||
host_name = extract_between_strings(lines[0], ' ', ' ')
|
||||
vendor = extract_between_strings(lines[2], '(', ')')
|
||||
mac_addresses = extract_mac_addresses(lines[2])
|
||||
|
||||
# only include results with a MAC address and IPs as it's used as a unique ID
|
||||
if len(mac_addresses) == 1 and len(ip_addresses) == 1:
|
||||
|
||||
devices_list.append({'name' : host_name,
|
||||
'ip' : ip_addresses[0],
|
||||
'mac' : mac_addresses[0],
|
||||
'vendor' : vendor,
|
||||
'interface': interface})
|
||||
else:
|
||||
mylog('verbose', [f"[{pluginName}] Skipped (Couldn't parse MAC or IP): ", lines])
|
||||
else:
|
||||
mylog('verbose', [f"[{pluginName}] Skipped (Not enough info in output): ", lines])
|
||||
|
||||
for interface in subnets_list :
|
||||
|
||||
scan_output = execute_scan_on_interface (interface, timeout)
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] scan_output: ', scan_output])
|
||||
|
||||
|
||||
# Regular expression patterns
|
||||
entry_pattern = r'Nmap scan report for (.*?) \((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\)'
|
||||
mac_pattern = r'MAC Address: ([0-9A-Fa-f:]+)'
|
||||
vendor_pattern = r'\((.*?)\)'
|
||||
|
||||
# Compile regular expression patterns
|
||||
entry_regex = re.compile(entry_pattern)
|
||||
mac_regex = re.compile(mac_pattern)
|
||||
vendor_regex = re.compile(vendor_pattern)
|
||||
|
||||
# Find all matches
|
||||
entries = entry_regex.findall(scan_output)
|
||||
mac_addresses = mac_regex.findall(scan_output)
|
||||
vendors = vendor_regex.findall(scan_output)
|
||||
|
||||
for i in range(len(entries)):
|
||||
name, ip_address = entries[i]
|
||||
|
||||
|
||||
devices_list.append([mac_addresses[i], ip_address, name, vendors[i], interface])
|
||||
|
||||
|
||||
return devices_list
|
||||
|
||||
|
||||
|
||||
def execute_scan_on_interface (interface, timeout):
|
||||
# Prepare command arguments
|
||||
scan_args = get_setting_value('NMAPDEV_ARGS').split() + [interface.split()[0]]
|
||||
scan_args = get_setting_value('NMAPDEV_ARGS').split() + interface.replace('--interface=','-e ').split()
|
||||
|
||||
mylog('verbose', [f'[{pluginName}] scan_args: ', scan_args])
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
}],
|
||||
"description": [{
|
||||
"language_code":"en_us",
|
||||
"string" : "When the plugin should be executed. If enabled this will execute the scan until there are no <code>(unknown)</code> or <code>(name not found)</code> devices. Setting this to <code>on_new_device</code> or a daily <code>schedule</code> is recommended."
|
||||
"string" : "When the plugin should be executed. If enabled this will execute the scan until there are no <code>(unknown)</code> or <code>(name not found)</code> devices. Setting this to <code>on_new_device</code> or a daily <code>schedule</code> is recommended.<br/><br/> Depends on the <a onclick=\"toggleAllSettings()\" href=\"#SCAN_SUBNETS\"><code>SCAN_SUBNETS</code> setting</a>."
|
||||
}]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -38,15 +38,17 @@ timeZoneSetting = configFile['TIMEZONE']
|
||||
timeZone = pytz.timezone(timeZoneSetting)
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Sanitizes plugin output
|
||||
def handleEmpty(input):
|
||||
if input == '' or None:
|
||||
if not input:
|
||||
return 'null'
|
||||
else:
|
||||
# Validate and sanitize message content
|
||||
# Remove potentially problematic characters if string
|
||||
if isinstance(input, str):
|
||||
if isinstance(input, str):
|
||||
input = re.sub(r'[^\x00-\x7F]+', ' ', input)
|
||||
return input
|
||||
input = input.replace('\n', '') # Removing new lines
|
||||
return input
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Check if a valid MAC address
|
||||
|
||||
Reference in New Issue
Block a user