manual merge of leiweibau and TeroRERO changes

This commit is contained in:
jokob-sk
2022-08-04 19:39:07 +10:00
parent 86ffe8ba36
commit c99f1a6e0d
9 changed files with 108 additions and 40 deletions

View File

@@ -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

View File

@@ -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
#===============================================================================

View File

@@ -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'

View File

@@ -1141,7 +1141,7 @@ function getDeviceData (readAllData=false) {
$('#txtLocation').val ('--');
$('#txtComments').val ('--');
$('#txtNetworkNodeMac').val ('--');
$('#txtNetworkPort').val ('--');
$('#txtNetworkPort').val ('--');
$('#txtFirstConnection').val ('--');
$('#txtLastConnection').val ('--');

View File

@@ -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) {
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<form action="/pialert/index.php" method="post">
<p class="login-box-msg"><?php echo $pia_lang['Login_Box'];?></p>
<form action="/pialert/index.php" method="post">
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password" name="loginpassword">
<input type="password" class="form-control" placeholder="<?php echo $pia_lang['Login_Psw-box'];?>" name="loginpassword">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox" disabled> Remember Me
<input type="checkbox" disabled> <?php echo $pia_lang['Login_Remember'];?>
</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">Sign In</button>
<button type="submit" class="btn btn-primary btn-block btn-flat"><?php echo $pia_lang['Login_Submit'];?></button>
</div>
<!-- /.col -->
</div>
@@ -134,7 +152,7 @@ if ($ENABLED_DARKMODE === True) {
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<h4><i class="icon fa <?php echo $login_icon;?>"></i><?php echo $login_headline;?></h4>
<p><?php echo $login_info;?></p>
<p>To set a new password run:<br><span style="border: solid 1px yellow; padding: 2px;">./reset_password.sh yournewpassword</span><br>in the config folder.</p>
<p><?php echo $pia_lang['Login_Psw_run'];?><br><span style="border: solid 1px yellow; padding: 2px;">./reset_password.sh <?php echo $pia_lang['Login_Psw_new'];?></span><br><?php echo $pia_lang['Login_Psw_folder'];?></p>
</div>
</div>

View File

@@ -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);

View File

@@ -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';
?>

View File

@@ -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

View File

@@ -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..."