diff --git a/README.md b/README.md index 55069a83..61c4e505 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,6 @@ JavaScript)* ![Main screen dark][main_dark] Dark mode (and Device presence over time) within this fork courtesy of [leiweibau](https://github.com/leiweibau/Pi.Alert) -## Modifications within this Fork -... will follow soon - ## How it works The system continuously scans the network for: - New devices @@ -60,6 +57,7 @@ In charge of: - Store the information in the DB - Report the changes detected by e-mail and/or other services (Pushsafer, NTFY, Gotify) - Optional speedtest for Device "Internet" + - DB cleanup tasks via cron | ![Report 1][report1] | ![Report 2][report2] | | -------------------- | -------------------- | @@ -67,7 +65,7 @@ In charge of: ### Front There is a configurable login to prevent unauthorized use. -> * Set `PIALERT_WEB_PROTECTION = True` in `pialert.conf` to enable +> * Set `PIALERT_WEB_PROTECTION = True` in `pialert.conf` to enable. The default password is `123456`. A web frontend that allows: - Manage the devices inventory and the characteristics @@ -183,7 +181,7 @@ Instructions for [leiweibau's fork](https://github.com/leiweibau/Pi.Alert/) This code is a collaborative body of work, with special thanks to: - - [leiweibau](https://github.com/leiweibau/Pi.Alert): Dark mode (and Last X scans activity chart) + - [leiweibau](https://github.com/leiweibau/Pi.Alert): Things - [Macleykun](https://github.com/Macleykun): Help with Dockerfile clean-up - [Final-Hawk](https://github.com/Final-Hawk): Help with NTFY, styling and other fixes - [TeroRERO](https://github.com/terorero): Spanish translation diff --git a/back/pialert.py b/back/pialert.py index 16314b7a..5a985c3e 100644 --- a/back/pialert.py +++ b/back/pialert.py @@ -71,7 +71,7 @@ def main (): # Check parameters if len(sys.argv) != 2 : - print ('usage pialert [scan_cycle] | internet_IP | update_vendors' ) + print ('usage pialert [scan_cycle] | internet_IP | update_vendors | cleanup' ) return cycle = str(sys.argv[1]) @@ -81,6 +81,8 @@ def main (): ## Main Commands if cycle == 'internet_IP': res = check_internet_IP() + elif cycle == 'cleanup': + res = cleanup_database() elif cycle == 'update_vendors': res = update_devices_MAC_vendors() elif cycle == 'update_vendors_silent': @@ -256,6 +258,28 @@ def check_IP_format (pIP): return IP.group(0) +#=============================================================================== +# Cleanup Online History chart +#=============================================================================== +def cleanup_database (): + # Header + print ('Cleanup Database') + print (' Timestamp:', startTime ) + + openDB() + + # Cleanup Online History + print ('\nCleanup Online_History...') + sql.execute ("""DELETE FROM Online_History WHERE Scan_Date <= date('now', '-1 day')""") + print ('\nOptimize Database...') + sql.execute ("VACUUM;") + + closeDB() + + # OK + return 0 + + #=============================================================================== # UPDATE DEVICE MAC VENDORS #=============================================================================== diff --git a/config/version.conf b/config/version.conf index 232e1d0f..1d319dc0 100644 --- a/config/version.conf +++ b/config/version.conf @@ -1,3 +1,3 @@ -VERSION = '3.6_leiweibau' +VERSION = '3.6_jokobsk' VERSION_YEAR = '2022' -VERSION_DATE = '2022-07-07' +VERSION_DATE = '2022-08-04' diff --git a/front/deviceDetails.php b/front/deviceDetails.php index 74e9313a..3895dda9 100644 --- a/front/deviceDetails.php +++ b/front/deviceDetails.php @@ -1141,7 +1141,7 @@ function getDeviceData (readAllData=false) { $('#txtLocation').val ('--'); $('#txtComments').val ('--'); $('#txtNetworkNodeMac').val ('--'); - $('#txtNetworkPort').val ('--'); + $('#txtNetworkPort').val ('--'); $('#txtFirstConnection').val ('--'); $('#txtLastConnection').val ('--'); diff --git a/front/index.php b/front/index.php index 6272222a..2dd44c3a 100644 --- a/front/index.php +++ b/front/index.php @@ -5,6 +5,25 @@ if ($_REQUEST['action'] == 'logout') { session_destroy(); header('Location: /pialert/index.php'); } +// ################################### +// ## Login settings locale start +// ################################### + if (file_exists('../db/setting_darkmode')) { + $ENABLED_DARKMODE = True; + } + foreach (glob("../db/setting_skin*") as $filename) { + $pia_skin_selected = str_replace('setting_','',basename($filename)); + } + if (strlen($pia_skin_selected) == 0) {$pia_skin_selected = 'skin-blue';} + + foreach (glob("../db/setting_language*") as $filename) { + $pia_lang_selected = str_replace('setting_language_','',basename($filename)); + } + if (strlen($pia_lang_selected) == 0) {$pia_lang_selected = 'en_us';} + require 'php/templates/language/'.$pia_lang_selected.'.php'; +// ################################### +// ## Login settings locale end +// ################################### // ################################################## // ## Login Processing start // ################################################## @@ -103,24 +122,23 @@ if ($ENABLED_DARKMODE === True) {
-

Sign in to start your session

- -
+ +
- +
- +
@@ -134,7 +152,7 @@ if ($ENABLED_DARKMODE === True) {

-

To set a new password run:
./reset_password.sh yournewpassword
in the config folder.

+


./reset_password.sh

diff --git a/front/php/server/devices.php b/front/php/server/devices.php index dbfb6080..421787ea 100644 --- a/front/php/server/devices.php +++ b/front/php/server/devices.php @@ -159,23 +159,23 @@ function setDeviceData() { // sql $sql = 'UPDATE Devices SET - dev_Name = "'. quotes($_REQUEST['name']) .'", - dev_Owner = "'. quotes($_REQUEST['owner']) .'", - dev_DeviceType = "'. quotes($_REQUEST['type']) .'", - dev_Vendor = "'. quotes($_REQUEST['vendor']) .'", - dev_Favorite = "'. quotes($_REQUEST['favorite']) .'", - dev_Group = "'. quotes($_REQUEST['group']) .'", - dev_Location = "'. quotes($_REQUEST['location']) .'", - dev_Comments = "'. quotes($_REQUEST['comments']) .'", + dev_Name = "'. quotes($_REQUEST['name']) .'", + dev_Owner = "'. quotes($_REQUEST['owner']) .'", + dev_DeviceType = "'. quotes($_REQUEST['type']) .'", + dev_Vendor = "'. quotes($_REQUEST['vendor']) .'", + dev_Favorite = "'. quotes($_REQUEST['favorite']) .'", + dev_Group = "'. quotes($_REQUEST['group']) .'", + dev_Location = "'. quotes($_REQUEST['location']) .'", + dev_Comments = "'. quotes($_REQUEST['comments']) .'", dev_Network_Node_MAC = "'. quotes($_REQUEST['networknode']).'", - dev_Network_Node_port = "'. quotes($_REQUEST['networknodeport']).'", - dev_StaticIP = "'. quotes($_REQUEST['staticIP']) .'", - dev_ScanCycle = "'. quotes($_REQUEST['scancycle']) .'", - dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'", - dev_AlertDeviceDown = "'. quotes($_REQUEST['alertdown']) .'", - dev_SkipRepeated = "'. quotes($_REQUEST['skiprepeated']) .'", - dev_NewDevice = "'. quotes($_REQUEST['newdevice']) .'", - dev_Archived = "'. quotes($_REQUEST['archived']) .'" + dev_Network_Node_port = "'. quotes($_REQUEST['networknodeport']).'", + dev_StaticIP = "'. quotes($_REQUEST['staticIP']) .'", + dev_ScanCycle = "'. quotes($_REQUEST['scancycle']) .'", + dev_AlertEvents = "'. quotes($_REQUEST['alertevents']) .'", + dev_AlertDeviceDown = "'. quotes($_REQUEST['alertdown']) .'", + dev_SkipRepeated = "'. quotes($_REQUEST['skiprepeated']) .'", + dev_NewDevice = "'. quotes($_REQUEST['newdevice']) .'", + dev_Archived = "'. quotes($_REQUEST['archived']) .'" WHERE dev_MAC="' . $_REQUEST['mac'] .'"'; // update Data $result = $db->query($sql); diff --git a/front/php/templates/language/es_es.php b/front/php/templates/language/es_es.php index f490274e..3fb07f85 100644 --- a/front/php/templates/language/es_es.php +++ b/front/php/templates/language/es_es.php @@ -11,13 +11,14 @@ $pia_lang['Gen_Restore'] = 'Ejecutar restauración'; $pia_lang['Gen_Switch'] = 'Cambiar'; ////////////////////////////////////////////////////////////////// -// Device Page - Update by @TeroRERO 25jul2022 +// Device Page - Update by @TeroRERO 03ago2022 ////////////////////////////////////////////////////////////////// $pia_lang['Navigation_Devices'] = 'Dispositivos'; $pia_lang['Navigation_Presence'] = 'Historial'; $pia_lang['Navigation_Events'] = 'Eventos'; $pia_lang['Navigation_Maintenance'] = 'Mantenimiento'; +$pia_lang['Navigation_Network'] = 'Red'; $pia_lang['Device_Title'] = 'Dispositivos'; $pia_lang['Device_Shortcut_AllDevices'] = 'Todos'; $pia_lang['Device_Shortcut_Connected'] = 'Conectado(s)'; @@ -167,7 +168,7 @@ $pia_lang['DevDetail_Nmap_buttonDefault_text'] = 'Escaneo predeterminado: NMAP e $pia_lang['DevDetail_Nmap_buttonDetail_text'] = 'Escaneo detallado: escaneo predeterminado con detección de sistema operativo habilitado, detección de versiones, escaneo de script y traceroute (hasta 30 segundos o más)'; ////////////////////////////////////////////////////////////////// -// Maintenance Page - Update by @TeroRERO 25jul2022 +// Maintenance Page - Update by @TeroRERO 03ago2022 ////////////////////////////////////////////////////////////////// $pia_lang['Maintenance_Title'] = 'Herramientas de mantenimiento'; @@ -221,6 +222,10 @@ $pia_lang['Maintenance_Tool_del_allevents'] = 'Eliminar todo (Restablecer histor $pia_lang['Maintenance_Tool_del_allevents_text'] = 'Antes de usar esta función, haga una copia de seguridad. La eliminación no se puede deshacer. Se eliminarán todos los eventos en la base de datos. En ese momento se restablecerá la presencia de todos los dispositivos. Esto puede conducir a sesiones no válidas. Esto significa que los dispositivos se muestran como "presentes", aunque están fuera de línea. Un escaneo mientras el dispositivo en cuestión está en línea resuelve el problema.'; $pia_lang['Maintenance_Tool_del_allevents_noti'] = 'Eliminar eventos'; $pia_lang['Maintenance_Tool_del_allevents_noti_text'] = '¿Estás seguro de que quieres eliminar todos los eventos? Esto restablece la presencia de todos los dispositivos.'; +$pia_lang['Maintenance_Tool_del_allevents30'] = 'Eliminar eventos antiguos (30 días)'; +$pia_lang['Maintenance_Tool_del_allevents30_text'] = 'Antes de usar esta función, haga una copia de seguridad. La eliminación no se puede deshacer. Se eliminarán todos los eventos mayores a 30 días en la base de datos. En ese momento se restablecerá la presencia de todos los dispositivos. Esto puede conducir a sesiones no válidas. Esto significa que los dispositivos se muestran como "presentes", aunque están fuera de línea. Un escaneo mientras el dispositivo en cuestión está en línea resuelve el problema.'; +$pia_lang['Maintenance_Tool_del_allevents30_noti'] = 'Eliminar eventos'; +$pia_lang['Maintenance_Tool_del_allevents30_noti_text'] = '¿Está seguro de eliminar todos los eventos mayores a 30 días? Esto restablece la presencia de todos los dispositivos.'; $pia_lang['Maintenance_Tool_backup'] = 'Respaldar DB'; $pia_lang['Maintenance_Tool_backup_text'] = 'Las copias de seguridad de la base de datos se encuentran en el directorio de la base de datos como una Zip-Archive, nombrada con la fecha de creación. No hay un número máximo de copias de seguridad.'; $pia_lang['Maintenance_Tool_backup_noti'] = 'Respaldar DB'; @@ -295,4 +300,18 @@ $pia_lang['Network_ManageDel_Submit'] = 'Eliminar'; $pia_lang['Network_Table_State'] = 'Estado'; $pia_lang['Network_Table_Hostname'] = 'Nombre de host'; $pia_lang['Network_Table_IP'] = 'Dirección IP'; + +////////////////////////////////////////////////////////////////// +// Login Page - Update by @TeroRERO 03ago2022 +////////////////////////////////////////////////////////////////// + +// TeroRERO Off $pia_lang['Login_Box'] = 'Inicie su sesión'; +$pia_lang['Login_Box'] = 'Ingrese su contraseña'; +$pia_lang['Login_Remember'] = 'Recordar'; +$pia_lang['Login_Submit'] = 'Ingresar'; +$pia_lang['Login_Psw_run'] = 'Para cambiar contraseña ejecute:'; +$pia_lang['Login_Psw_new'] = 'nueva_contraseña'; +$pia_lang['Login_Psw_folder'] = 'en la carpeta config.'; +$pia_lang['Login_Psw_alert'] = '¡Alerta de Contraseña!'; +$pia_lang['Login_Psw-box'] = 'Contraseña'; ?> diff --git a/install/pialert.cron b/install/pialert.cron index ee48fe30..47dd997e 100644 --- a/install/pialert.cron +++ b/install/pialert.cron @@ -9,7 +9,8 @@ TZ=Europe/Berlin -0 3 * * 1 python /home/pi/pialert/back/pialert.py update_vendors >/home/pi/pialert/log/pialert.vendors.log 2>&1 -*/3 * * * * python /home/pi/pialert/back/pialert.py internet_IP >/home/pi/pialert/log/pialert.IP.log 2>&1 -*/5 * * * * python /home/pi/pialert/back/pialert.py 1 >/home/pi/pialert/log/pialert.1.log 2>&1 +0 3 * * 1 python /home/pi/pialert/back/pialert.py update_vendors >/home/pi/pialert/log/pialert.vendors.log 2>&1 +*/3 * * * * python /home/pi/pialert/back/pialert.py internet_IP >/home/pi/pialert/log/pialert.IP.log 2>&1 +*/5 * * * * python /home/pi/pialert/back/pialert.py 1 >/home/pi/pialert/log/pialert.1.log 2>&1 +0 2 * * */4 python /home/pi/pialert/back/pialert.py cleanup >/home/pi/pialert/log/pialert.cleanup.log 2>&1 diff --git a/install/pialert_install.sh b/install/pialert_install.sh index 0bc60215..4c997cd5 100644 --- a/install/pialert_install.sh +++ b/install/pialert_install.sh @@ -342,7 +342,7 @@ install_lighttpd() { # Install arp-scan & dnsutils # ------------------------------------------------------------------------------ install_arpscan() { - print_header "arp-scan & dnsutils" + print_header "arp-scan, dnsutils and nmap" print_msg "- Installing arp-scan..." sudo apt-get install arp-scan -y 2>&1 >> "$LOG" @@ -352,6 +352,9 @@ install_arpscan() { print_msg "- Installing dnsutils & net-tools..." sudo apt-get install dnsutils net-tools -y 2>&1 >> "$LOG" + + print_msg "- Installing nmap and zip..." + sudo apt-get install nmap zip -y 2>&1 >> "$LOG" } @@ -384,7 +387,7 @@ install_python() { print_msg "- Using Python 2" else print_msg "- Installing Python 2..." - sudo apt-get install python -y 2>&1 >> "$LOG" + sudo apt-get install python pip -y 2>&1 >> "$LOG" fi PYTHON_BIN="python" elif [ $USE_PYTHON_VERSION -eq 3 ] ; then @@ -392,7 +395,8 @@ install_python() { print_msg "- Using Python 3" else print_msg "- Installing Python 3..." - sudo apt-get install python3 -y 2>&1 >> "$LOG" + sudo apt-get install python3 pip -y 2>&1 >> "$LOG" + python3 -m pip install requests fi PYTHON_BIN="python3" else @@ -525,6 +529,10 @@ test_pialert() { print_msg "*** PLEASE WAIT A COUPLE OF MINUTES..." stdbuf -i0 -o0 -e0 $PYTHON_BIN $PIALERT_HOME/back/pialert.py 1 2>&1 | tee -ai "$LOG" + echo "" + print_msg "- Enable optional Speedtest..." + chmod +x $PIALERT_HOME/back/speedtest-cli + if $FIRST_SCAN_KNOWN ; then echo "" print_msg "- Set devices as Known devices..."