diff --git a/docker-compose.yml b/docker-compose.yml index e4a25b2c..1baec208 100755 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -30,6 +30,11 @@ services: - ${DEV_LOCATION}/front/css:/home/pi/pialert/front/css - ${DEV_LOCATION}/front/lib/AdminLTE:/home/pi/pialert/front/lib/AdminLTE - ${DEV_LOCATION}/front/js:/home/pi/pialert/front/js + - ${DEV_LOCATION}/dockerfiles/start.sh:/home/pi/pialert/dockerfiles/start.sh + - ${DEV_LOCATION}/dockerfiles/user-mapping.sh:/home/pi/pialert/dockerfiles/user-mapping.sh + - ${DEV_LOCATION}/install/install.sh:/home/pi/pialert/install/install.sh + - ${DEV_LOCATION}/install/install_python.sh:/home/pi/pialert/install/install_python.sh + - ${DEV_LOCATION}/install/install_dependencies.sh:/home/pi/pialert/install/install_dependencies.sh - ${DEV_LOCATION}/front/api:/home/pi/pialert/front/api - ${DEV_LOCATION}/front/php:/home/pi/pialert/front/php - ${DEV_LOCATION}/front/deviceDetails.php:/home/pi/pialert/front/deviceDetails.php diff --git a/front/plugins/_publisher_mqtt/config.json b/front/plugins/_publisher_mqtt/config.json index d4d32bcb..f9a48e3f 100755 --- a/front/plugins/_publisher_mqtt/config.json +++ b/front/plugins/_publisher_mqtt/config.json @@ -67,7 +67,7 @@ "column": "Object_PrimaryID", "css_classes": "col-sm-2", "show": true, - "type": "url", + "type": "label", "default_value":"", "options": [], "localized": ["name"], @@ -161,8 +161,8 @@ { "column": "Watched_Value4", "css_classes": "col-sm-2", - "show": false, - "type": "label", + "show": true, + "type": "device_mac", "default_value":"", "options": [], "localized": ["name"], diff --git a/front/plugins/_publisher_mqtt/mqtt.py b/front/plugins/_publisher_mqtt/mqtt.py index 4b6c891f..6ecb208e 100755 --- a/front/plugins/_publisher_mqtt/mqtt.py +++ b/front/plugins/_publisher_mqtt/mqtt.py @@ -78,7 +78,7 @@ def check_config(): #------------------------------------------------------------------------------- class sensor_config: - def __init__(self, deviceId, deviceName, sensorType, sensorName, icon): + def __init__(self, deviceId, deviceName, sensorType, sensorName, icon, mac): self.deviceId = deviceId self.deviceName = deviceName self.sensorType = sensorType @@ -102,13 +102,16 @@ class sensor_config: # Log sensor global plugin_objects + if mac == '': + mac = "N/A" + plugin_objects.add_object( primaryId = deviceId, secondaryId = sensorName, watched1 = deviceName, watched2 = sensorType, - watched3 = hash, - watched4 = 'null', + watched3 = hash_value, + watched4 = mac, extra = 'null', foreignKey = deviceId ) @@ -147,11 +150,11 @@ def create_generic_device(client): #------------------------------------------------------------------------------- -def create_sensor(client, deviceId, deviceName, sensorType, sensorName, icon): +def create_sensor(client, deviceId, deviceName, sensorType, sensorName, icon, mac=""): global mqtt_sensors - new_sensor_config = sensor_config(deviceId, deviceName, sensorType, sensorName, icon) + new_sensor_config = sensor_config(deviceId, deviceName, sensorType, sensorName, icon, mac) # save if new if new_sensor_config.isNew: @@ -271,11 +274,11 @@ def mqtt_start(db): deviceId = 'mac_' + device["dev_MAC"].replace(" ", "").replace(":", "_").lower() deviceNameDisplay = re.sub('[^a-zA-Z0-9-_\s]', '', device["dev_Name"]) - create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'last_ip', 'ip-network') - create_sensor(client, deviceId, deviceNameDisplay, 'binary_sensor', 'is_present', 'wifi') - create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'mac_address', 'folder-key-network') - create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'is_new', 'bell-alert-outline') - create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'vendor', 'cog') + create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'last_ip', 'ip-network', device["dev_MAC"]) + create_sensor(client, deviceId, deviceNameDisplay, 'binary_sensor', 'is_present', 'wifi', device["dev_MAC"]) + create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'mac_address', 'folder-key-network', device["dev_MAC"]) + create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'is_new', 'bell-alert-outline', device["dev_MAC"]) + create_sensor(client, deviceId, deviceNameDisplay, 'sensor', 'vendor', 'cog', device["dev_MAC"]) # update device sensors in home assistant diff --git a/front/plugins/dhcp_leases/script.py b/front/plugins/dhcp_leases/script.py index 540cf12c..af044f46 100755 --- a/front/plugins/dhcp_leases/script.py +++ b/front/plugins/dhcp_leases/script.py @@ -44,25 +44,31 @@ def main(): def get_entries(path, plugin_objects): # Check if the path exists - if os.path.exists(path) == False: - mylog('none', [f'[{pluginName}] Error: "{path}" does not exist.']) + if not os.path.exists(path): + mylog('none', [f'[{pluginName}] Error: "{path}" does not exist.']) else: - # Handle pihole specific dhcp.leases files - if 'pihole' in path: - - with open(path, 'r') as f: - for line in f: + # Detect file encoding + with open(path, 'rb') as f: + result = chardet.detect(f.read()) + + # Use the detected encoding + encoding = result['encoding'] + + # Handle pihole-specific dhcp.leases files + if 'pihole' in path: + with open(path, 'r', encoding=encoding, errors='replace') as f: + for line in f: row = line.rstrip().split() if len(row) == 5: plugin_objects.add_object( - primaryId = handleEmpty(row[1]), - secondaryId = handleEmpty(row[2]), - watched1 = handleEmpty('True'), - watched2 = handleEmpty(row[3]), - watched3 = handleEmpty(row[4]), - watched4 = handleEmpty('True'), - extra = handleEmpty(path), - foreignKey = handleEmpty(row[1]) + primaryId=handleEmpty(row[1]), + secondaryId=handleEmpty(row[2]), + watched1=handleEmpty('True'), + watched2=handleEmpty(row[3]), + watched3=handleEmpty(row[4]), + watched4=handleEmpty('True'), + extra=handleEmpty(path), + foreignKey=handleEmpty(row[1]) ) else: # Handle generic dhcp.leases files diff --git a/install/pialert_front.conf b/install/pialert_front.conf deleted file mode 100755 index ff8dbd9d..00000000 --- a/install/pialert_front.conf +++ /dev/null @@ -1,12 +0,0 @@ -# ------------------------------------------------------------------------------ -# Pi.Alert -# Open Source Network Guard / WIFI & LAN intrusion detector -# -# pialert_front.conf - lighttpd domain redirection -# ------------------------------------------------------------------------------ -# Puche 2021 GNU GPLv3 -# ------------------------------------------------------------------------------ - -$HTTP["host"] == "pi.alert" { - server.document-root = "/var/www/html/" -} diff --git a/pialert/plugin_utils.py b/pialert/plugin_utils.py index 07998714..e00fa354 100755 --- a/pialert/plugin_utils.py +++ b/pialert/plugin_utils.py @@ -82,13 +82,24 @@ def list_to_csv(arr): mylog('debug', f'[{module_name}] isinstance(arr, list) : {isinstance(arr, list)} | isinstance(arr, str) : {isinstance(arr, str)}') if isinstance(arr, str): - return arr.replace('[','').replace(']','').replace("'", '') # removing brackets and single quotes (not allowed) + tmpStr = arr.replace('[','').replace(']','').replace("'", '') # removing brackets and single quotes (not allowed) + + if ',' in tmpStr: + # Split the string into a list and trim whitespace + cleanedStr = [tmpSubStr.strip() for tmpSubStr in tmpStr.split(',')] + + # Join the list elements using a comma + result_string = ",".join(cleanedStr) + else: + result_string = tmpStr + + return result_string elif isinstance(arr, list): for arrayItem in arr: # only one column flattening is supported - if isinstance(arrayItem, list): - arrayItemStr = str(arrayItem[0]).replace("'", '') # removing single quotes - not allowed + if isinstance(arrayItem, list): + arrayItemStr = str(arrayItem[0]).replace("'", '').strip() # removing single quotes - not allowed else: # is string already arrayItemStr = arrayItem